Skip to content

Instantly share code, notes, and snippets.

@rtrppl
rtrppl / switch-mastodon-user.el
Last active February 15, 2024 03:19
mastodon in .emacs
(setq instance-selection-list '())
(push "https://mastodon.social@laotang" instance-selection-list)
(push "https://emacs.ch@laotang" instance-selection-list)
(defun lt/switch-mastodon-user ()
(interactive)
(let* ((instance-user (completing-read "" instance-selection-list)))
(when (string-match "\\(.*\\)\\(@.*\\)" instance-user)
(let* ((selected-instance (match-string 1 instance-user))
@rtrppl
rtrppl / fastgpt-dictionary-sentence.el
Created December 22, 2023 18:48
using fastgpt as a dictionary
(defun fastgpt-dictionary-sentence ()
"Provide a separate translation and dictionary look-up for all Chinese words in the next sentence, including pinyin."
(interactive)
(set-mark (point))
(forward-sentence)
(unless (region-active-p)
(user-error "No region active"))
(let ((buffer (get-buffer-create "*ChatGPT Chinese Dictionary*"))
(prompt "You emulate a traditional dictionary. First repeat the Chinese sentence, then provide a separate translation for all words in the Chinese sentence that follows. The format of the translation should be: X (Y) - Z, whereby X stands for the Chinese characters, Y stands for pinyin with markers for tones and Z stands for English. Add a line break after each translation. Add a translation of the whole sentence at the end. Also, do not translate the interpunction and do not provide additional links. ")
(buffer-text (buffer-substring-no-properties (region-beginning) (region-end))))
@rtrppl
rtrppl / kagi-in-emacs.el
Created December 15, 2023 07:40
kagi this
(defun lt/kagi ()
"Kagi the selected region if any, display a query prompt otherwise."
(interactive)
(browse-url
(concat
"https://kagi.com/search?q="
(url-hexify-string (if mark-active
(buffer-substring (region-beginning) (region-end))
(read-string "Kagi: "))))))
@rtrppl
rtrppl / hacks-for-mastodon.el
Last active December 14, 2023 01:09
Hacks for mastodon.el
(defun lt/mastodon-toot--copy-orgified-toot-to-clipboard ()
"Copy org-ified toot at point to clipboard."
(interactive)
(let* ((toot (or (mastodon-tl--property 'base-toot)
(mastodon-tl--property 'item-json))))
(let* ((url (mastodon-toot--toot-url))
(content (mastodon-tl--content toot)))
(-let* ((dom (plz 'get url :as #'org-web-tools--sanitized-dom))
((title . readable) (org-web-tools--eww-readable dom)))
(with-temp-buffer
@rtrppl
rtrppl / wttr+world_clock.el
Last active October 6, 2023 20:47
wttr+world_clock.el
(defun lt/wttr ()
"A tiny wrapper for wttr and world clock."
(interactive)
(with-current-buffer (get-buffer-create "*wttr*")
(erase-buffer)
(insert (shell-command-to-string "curl -s de.wttr.in/Freiburg?3nFqT"))
(insert "\n")
(lt/world-clock-display (time--display-world-list)))
(switch-to-buffer "*wttr*")
(read-char "")
@rtrppl
rtrppl / gpt-dictionary-sentence.el
Created August 6, 2023 16:23
gpt-dictionary-sentence
(defun lt/gpt-dictionary-sentence ()
"Provide a separate translation and dictionary look-up for all Chinese words in the current sentence, including pinyin."
(interactive)
(set-mark (point))
(forward-sentence)
(unless (region-active-p)
(user-error "No region active"))
(let ((buffer (get-buffer-create "*ChatGPT Chinese Dictionary*"))
(prompt "You emulate a traditional dictionary. Provide a separate translation for all (!) words in the Chinese sentence that follows the final colon. The format of the translation should be: Chinese characters &nbsp (pinyin) - English. Add a line break after each translation. Add a translation of the whole sentence at the end, but don't start this translation with Translation: : ")
(buffer-text (buffer-substring-no-properties (region-beginning) (region-end))))
@rtrppl
rtrppl / auto-add-org-agenda.el
Last active March 1, 2023 06:58
lt/auto-add-org-agenda
(defun lt/auto-add-org-agenda ()
"Automatically add org-files to org-agenda-files or remove them, based on whether or not they contain org-keywords."
(interactive)
(with-temp-file org-agenda-files (insert (shell-command-to-string (concat "rg -e '\\*.(TODO|NEXT|WAITING|RECREATION|PROJECT).[^%]' -g \"*.org\" -l " org-directory)))))
(add-hook 'org-agenda-mode-hook 'lt/auto-add-org-agenda)