<commit_before>;;; pastebin.el --- pastebin example with simple-httpd

(require 'cl)
(require 'url-util)
(require 'simple-httpd)

(defvar pastebin-data-root (file-name-directory load-file-name))

(defvar pastebin-db (make-hash-table))

(defun pastebin-get-file (file)
  (with-temp-buffer
    (insert-file-literally (expand-file-name file pastebin-data-root))
    (buffer-string)))

(defservlet pastebin text/html (path)
  (let* ((id (string-to-number (file-name-nondirectory path)))
         (content (url-insert-entities-in-string (gethash id pastebin-db ""))))
    (insert (format (pastebin-get-file "paste.html") content))))

(defun httpd/pastebin/post (proc path query request)
  (let* ((id (random most-positive-fixnum))
         (content (cadr (assoc "Content" request)))
         (decode (url-unhex-string (substitute ?  ?+ content) t)))
    (puthash id (substring decode 2) pastebin-db)
    (httpd-redirect proc (format "/pastebin/%d" id))))<commit_msg>Put IDs in base 16.<commit_after>;;; pastebin.el --- pastebin example with simple-httpd

(require 'cl)
(require 'url-util)
(require 'simple-httpd)

(defvar pastebin-data-root (file-name-directory load-file-name))

(defvar pastebin-db (make-hash-table))

(defun pastebin-get-file (file)
  (with-temp-buffer
    (insert-file-literally (expand-file-name file pastebin-data-root))
    (buffer-string)))

(defservlet pastebin text/html (path)
  (let* ((id (string-to-number (file-name-nondirectory path) 16))
         (content (url-insert-entities-in-string (gethash id pastebin-db ""))))
    (insert (format (pastebin-get-file "paste.html") content))))

(defun httpd/pastebin/post (proc path query request)
  (let* ((id (random most-positive-fixnum))
         (content (cadr (assoc "Content" request)))
         (decode (url-unhex-string (substitute ?  ?+ content) t)))
    (puthash id (substring decode 2) pastebin-db)
    (httpd-redirect proc (format "/pastebin/%x" id))))
{'fraction_non_alphanumeric': 0.1631279129984464, 'fraction_numerical': 0.0031071983428275505, 'mean_word_length': 3.966580976863753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3651460', 'n_tokens_mistral': 674, 'n_tokens_neox': 656, 'n_words': 160}