Skip to content

Instantly share code, notes, and snippets.

@dzzzchhh
dzzzchhh / rename-js-to-jsx.el
Created November 9, 2023 08:18
silly, but came in handy once
(defun dzch/js-to-jsx-rename-file ()
(interactive)
(let*
((path buffer-file-name)
(new-path (format "%sx" path)))
(rename-file path new-path)
(kill-buffer)
(find-file new-path)))
@dzzzchhh
dzzzchhh / quick-blame.el
Created January 9, 2023 13:29
quickly list file authors for the current buffer
(defun dzch/list-file-authors ()
(interactive)
(let* ((path buffer-file-name)
(cmd "git log --pretty=format:%s %s | sort -r | uniq -c | sort -r")
(result (shell-command-to-string (format cmd "%ae" path))))
(display-message-or-buffer result)))
@dzzzchhh
dzzzchhh / all-commit-authors.fish
Created October 12, 2022 08:38
display all commit authors for a specific folder
git log --pretty=format:"%ae" . | sort -r | uniq -c
(defun duplicate-line ()
(interactive)
(evil-yank-line (line-beginning-position)(line-end-position))
(end-of-line)
(newline)
(evil-paste-before 1))
(defun git/commit-from-current-org-heading ()
(interactive)
(setq commit-message (list/join (org-get-outline-path t) " - "))
(shell-command (format "git commit -m %s" commit-messsage))
(org-todo "DONE"))
(defun list/join (list delimiter)
(mapconcat 'identity list delimiter))
@dzzzchhh
dzzzchhh / change-font.el
Created July 20, 2022 08:47
simple interactive function for changing font in doom-emacs
(defconst dzch-fonts '("Fira Code" "Monaco"))
(defun font/change ()
(interactive)
(setq next-active-font (ivy-completing-read "Choose font: " dzch-fonts))
(setq doom-font (font-spec :family next-active-font :size 12))
(doom/reload-font))
(defun gist/create-from-region (start end)
(interactive "r")
(setq contents (buffer-substring start end))
(setq new-file-name
(read-string "Enter filename: "))
(setq visibility (ivy-completing-read "Specify gist's visibility: " '("public" "secret")))
(write-region start end new-file-name)
(shell-command (format "gh gist create %s --%s" new-file-name visibility))
(delete-file new-file-name))
(defn sock-merchant
[ar]
(->>
(frequencies ar)
(vals)
(map #(int (/ % 2)))
(reduce +)))
#!/usr/bin/env fish
function batch-ext-change
echo "Batch renaming files in the currect directory (recursively)"
read -l -P 'Old extension (without the "."): ' old_ext
read -l -P 'New extension (without the "."): ' new_ext
fd .$old_ext -X rename .$old_ext .$new_ext {}
end
@dzzzchhh
dzzzchhh / first-reccurring-character-problem.clj
Last active June 9, 2022 09:14
The most naive way of solving this problem by a person who is super new to Closure, but I did get joy from solving this nonetheless :)
(defn first-reccurring-character
([string-sequence] (first-reccurring-character string-sequence #{}))
([string-sequence lookup]
(let [current-character (first string-sequence)]
(if (contains? lookup current-character)
current-character
(recur (rest string-sequence) (conj lookup current-character))))))