<commit_before>;;; Author: <NAME>
;;; Date: Thu Apr  9 15:26:24 NZST 2015

;;; A Bencode-editor webapp

;;; Requirements: HTML5 supported webbrowser!

(use awful libencode s json)

(enable-sxml #t)
(literal-script/style? #t)

(page-css "editor.css")

(define (partition-indexed f l)
  (letrec ((part (lambda (fi se count ll)
		   (if (null? ll)
		       (values fi se)
		       (cond
			((f (car ll) count)
			 (part (cons (car ll) fi) se
			       (+ count 1)
			       (cdr ll)))
			(else
			 (part fi (cons (car ll) se)
			       (+ count 1)
			       (cdr ll))))))))
    (part '() '() 0 l)))

(define (hex->ascii hstr)
  (let ((hstrl (string->list hstr)))
    (let-values (((f s) (partition-indexed
			 (lambda (_ i)
			   (equal? (modulo i 2) 0)) hstrl)))
      (if (= (length f) (length s))
	  (let ((ff (foldl
		     (lambda (l pr)
		       (let ((p
			      (integer->char
			       (string->number
				(s-prepend "#x"(list->string pr))))))
			 (cons p l)))
			   '() (zip f s))))
	    (list->string ff))
	  (error "Malformed URI"
		 (cons (length hstrl)
		       (cons (length f) (length s))))))))

(define input-handle 
  (lambda ()
    (let* ((x ($ 'fcontent as-string))
	   (iport (open-input-string (hex->ascii x)))
	   (oport (open-output-string))
	   (_ (json-write (lib:decode iport) oport))<commit_msg>updated the code to use the utilities from libencode<commit_after>;;; Author: <NAME>
;;; Date: Thu Apr  9 15:26:24 NZST 2015

;;; A Bencode-editor webapp

;;; Requirements: HTML5 supported webbrowser!

(use awful libencode s json)

(enable-sxml #t)
(literal-script/style? #t)

(page-css "editor.css")

(define (hex->ascii hstr)
  (let ((hstrl (string->list hstr)))
    (let-values (((f s) (partition-indexed
			 (lambda (_ i)
			   (equal? (modulo i 2) 0)) hstrl)))
      (if (= (length f) (length s))
	  (let ((ff (foldl
		     (lambda (l pr)
		       (let ((p
			      (integer->char
			       (string->number
				(s-prepend "#x"(list->string pr))))))
			 (cons p l)))
			   '() (zip f s))))
	    (list->string ff))
	  (error "Malformed URI"
		 (cons (length hstrl)
		       (cons (length f) (length s))))))))

(define input-handle 
  (lambda ()
    (let* ((x ($ 'fcontent as-string))
	   (iport (open-input-string (hex->ascii x)))
	   (oport (open-output-string))
	   (_ (json-write (lib:decode iport) oport))
{'fraction_non_alphanumeric': 0.1879021879021879, 'fraction_numerical': 0.013299013299013299, 'mean_word_length': 2.5876923076923077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3156821', 'n_tokens_mistral': 977, 'n_tokens_neox': 838, 'n_words': 255}