Skip to content

Instantly share code, notes, and snippets.

@yveszoundi
Last active December 20, 2021 22:52
Show Gist options
  • Save yveszoundi/4f7fd999f7b7ff60f18905b219e9c235 to your computer and use it in GitHub Desktop.
Save yveszoundi/4f7fd999f7b7ff60f18905b219e9c235 to your computer and use it in GitHub Desktop.
Create a paste at paste-c-net.org
(defvar paste-c-net-url "https://paste.c-net.org/")
(defvar paste-c-net-buffer-name "*paste-c-net*")
(defun paste-c-net--buffer-whole-string (buffer)
"Retrieve the text contents from an HTTP response BUFFER."
(with-current-buffer buffer
(save-restriction
(widen)
(re-search-forward "^$")
(buffer-substring-no-properties (point) (point-max)))))
(defun paste-c-net--switch-to-url-buffer (_status)
"Display the file upload repsonse regardless of the status."
(let ((txt (paste-c-net--buffer-whole-string (current-buffer))))
(let ((newb (get-buffer-create paste-c-net-buffer-name)))
(switch-to-buffer newb)
(erase-buffer)
(insert (string-trim txt)))))
(defun paste-c-net--send-string (txt)
"Upload some text."
(let ((url-request-method "POST")
(url-request-data txt))
(url-retrieve paste-c-net-url 'paste-c-net--switch-to-url-buffer)))
(defun paste-c-net-send-buffer ()
"Upload the current buffer text to paste.c-net.org."
(interactive)
(let ((txt (buffer-substring-no-properties (point-min) (point-max))))
(paste-c-net--send-string txt)))
(defun paste-c-net-send-file ()
"Upload a given file to paste.c-net.org."
(interactive)
(let ((file (read-file-name "Select file:" nil nil t)))
(with-temp-buffer
(insert-file-contents file)
(goto-char (point-min))
(paste-c-net--send-string
(buffer-substring-no-properties (point) (point-max))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment