summaryrefslogtreecommitdiff
path: root/emacs/elisp
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/elisp')
-rw-r--r--emacs/elisp/my-buffers.el39
-rw-r--r--emacs/elisp/my-cheeseboard.el55
-rw-r--r--emacs/elisp/my-git-extra.el50
-rw-r--r--emacs/elisp/my-packages-extra.el65
-rw-r--r--emacs/elisp/my-strings.el23
-rw-r--r--emacs/elisp/my-uptime.el55
-rw-r--r--emacs/elisp/my-web.el32
-rw-r--r--emacs/elisp/my-work.el21
8 files changed, 0 insertions, 340 deletions
diff --git a/emacs/elisp/my-buffers.el b/emacs/elisp/my-buffers.el
deleted file mode 100644
index 8c03905..0000000
--- a/emacs/elisp/my-buffers.el
+++ /dev/null
@@ -1,39 +0,0 @@
-;;; my-buffers.el --- Functions related to buffer manipulations
-;;; Commentary:
-;;; Code:
-
-(defun my/copy-whole-buffer ()
- "Select the buffer and copy it."
- (interactive)
- (save-excursion
- (mark-whole-buffer)
- (copy-region-as-kill 1 (buffer-size))))
-
-(defun my/rename-this-buffer-and-file ()
- "Renames current buffer and file it is visiting."
- (interactive)
- (let ((name (buffer-name))
- (filename (buffer-file-name))
- (read-file-name-function 'read-file-name-default))
- (if (not (and filename (file-exists-p filename)))
- (error "Buffer '%s' is not visiting a file!" name)
- (let ((new-name (read-file-name "New name: " filename)))
- (cond ((get-buffer new-name)
- (error "A buffer named '%s' already exists!" new-name))
- (t
- (rename-file filename new-name 1)
- (rename-buffer new-name)
- (set-visited-file-name new-name)
- (set-buffer-modified-p nil)
- (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
-
-(defun my/uniquify-region-lines (beg end)
- "Remove duplicate adjacent lines in region between BEG and END."
- (interactive "*r")
- (save-excursion
- (goto-char beg)
- (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
- (replace-match "\\1"))))
-
-(provide 'my-buffers)
-;;; my-buffers.el ends here
diff --git a/emacs/elisp/my-cheeseboard.el b/emacs/elisp/my-cheeseboard.el
deleted file mode 100644
index 9713e14..0000000
--- a/emacs/elisp/my-cheeseboard.el
+++ /dev/null
@@ -1,55 +0,0 @@
-;;; my-cheeseboard.el --- summary -*- lexical-binding: t -*-
-;; Author: Franck Cuny <franck@fcuny.net>
-
-;;; Commentary:
-
-;; commentary:
-;; As everybody knows, the best pizza in the world is at
-;; cheeseboard[0]. I like to check during the week the pizzas for the
-;; week and see if there are any we would like to have. This module
-;; gets the list of pizzas for the week and display them in a buffer.
-;;
-;; [0] https://cheeseboardcollective.coop/
-
-;;; Code:
-
-(require 'dom)
-
-(defconst my/cheeseboard-buffer "*cheeseboard-menu*"
- "Name of the buffer for displaying the week's menu.")
-
-(defconst my/cheeseboard-url "https://cheeseboardcollective.coop/pizza/"
- "URL to fetch to get the list of pizzas for the week.")
-
-(defun my/cheeseboard-menu ()
- "Display the list of pizzas for the week."
- (interactive)
- (let* ((dom (with-current-buffer (url-retrieve-synchronously my/cheeseboard-url)
- (libxml-parse-html-region (point-min) (point-max))))
- ;; a class named `pizza-list' contains all the items for the
- ;; week. they are wrapped in a `article' tag.
- (menus (dom-by-tag (dom-by-class dom "pizza-list") 'article))
- (inhibit-read-only t)
- (buffer-undo-list t))
- (pop-to-buffer my/cheeseboard-buffer)
- (erase-buffer)
- (insert (format "if you want to look at the menu on the website => %s\n\n" my/cheeseboard-url))
- (dolist (menu menus)
- (my/pizza-of-the-day menu))
- (special-mode)))
-
-(defun my/pizza-of-the-day (menu)
- "Print the pizzas for the day from the MENU."
- (let* ((date (car (dom-strings (dom-by-tag (dom-by-class menu "date") 'p))))
- (pizza (dom-by-tag (dom-by-class menu "menu") 'p)))
- (if (string= "The pizzeria is closed today." (nth 0 (dom-strings pizza)))
- (insert (format "%s: cheeseboard is closed :(\n\n" (propertize date 'face 'italic)))
- (insert (format "%s: 🍕 %s\n(note: %s, %s)\n\n"
- (propertize date 'face 'italic)
- (propertize (replace-regexp-in-string "\n" "" (nth 2 (dom-strings pizza))) 'face 'highlight)
- (nth 0 (dom-strings pizza))
- (nth 1 (dom-strings pizza)))))))
-
-(provide 'my-cheeseboard)
-
-;;; my-cheeseboard.el ends here
diff --git a/emacs/elisp/my-git-extra.el b/emacs/elisp/my-git-extra.el
deleted file mode 100644
index 30fff78..0000000
--- a/emacs/elisp/my-git-extra.el
+++ /dev/null
@@ -1,50 +0,0 @@
-;;; my-git-extra.el --- Extra functions to work with git
-;;; Commentary:
-;;; Code:
-
-(require 'magit)
-(require 'git-link)
-
-(defun my/clone-repo (url)
- "Clone a repository in the workspace using URL."
- (interactive "sURL:")
- (let* ((repo-name (magit-clone--url-to-name url))
- (target-dir (concat "~/workspace/" repo-name)))
- (magit-clone-regular url target-dir nil)))
-
-(defun my/sg-instance (hostname)
- "Return the base URL for a sourcegraph instance based on HOSTNAME."
- (cond ((string-match "cl\.fcuny\.net" hostname) (format "cs.fcuny.xyz/%s" hostname))
- (t (format "sourcegraph.rbx.com/%s" hostname))))
-
-(defun my/git-link-sourcegraph (hostname dirname filename _branch commit start end)
- "Create a link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END."
- (let ((sg-base-url (my/sg-instance hostname))
- ;; Use the default branch of the repository instead of the
- ;; current one (we might be on a feature branch that is not
- ;; available on the remote).
- (main-branch (magit-main-branch))
- ;; repositories cloned with gerrit have a "a/" prefix which we
- ;; need to remove, as it's not part of the repository name in
- ;; sourcegraph.
- (dirname (replace-regexp-in-string "a\/" "" dirname)))
- (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
-
-(defun my/git-link-commit-sourcegraph (hostname dirname commit)
- "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT."
- (let ((sg-base-url (my/sg-instance hostname))
- (dirname (replace-regexp-in-string "a\/" "" dirname)))
- (git-link-commit-sourcegraph sg-base-url dirname commit)))
-
-;; for work related repositories, open them in our instance of sourcegraph
-(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" my/git-link-sourcegraph))
-(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" my/git-link-work-sourcegraph))
-
-;; for personal code I use cgit and gerrit
-(add-to-list 'git-link-remote-alist '("git\\.fcuny\\.net" my/git-link-sourcegraph))
-(add-to-list 'git-link-remote-alist '("cl\\.fcuny\\.net" my/git-link-sourcegraph))
-(add-to-list 'git-link-commit-remote-alist '("git\\.fcuny\\.net" my/git-link-commit-sourcegraph))
-(add-to-list 'git-link-commit-remote-alist '("cl\\.fcuny\\.net" my/git-link-commit-sourcegraph))
-
-(provide 'my-git-extra)
-;;; my-git-extra.el ends here
diff --git a/emacs/elisp/my-packages-extra.el b/emacs/elisp/my-packages-extra.el
deleted file mode 100644
index de37752..0000000
--- a/emacs/elisp/my-packages-extra.el
+++ /dev/null
@@ -1,65 +0,0 @@
-;;; my-packages-extra.el --- Provides additional functions related to
-;;; packages
-
-;;; Commentary:
-
-;;; Code:
-
-(require 'package)
-
-;; Original idea: https://www.manueluberti.eu/emacs/2021/09/01/package-report/
-(defun my/package-report ()
- "Report total package counts grouped by archive."
- (interactive)
- (package-refresh-contents)
- (my/display-package-report
- (let* ((arch-pkgs (my/archive-packages))
- (counts (seq-sort-by #'cdr #'> (my/archive-counts arch-pkgs)))
- (by-arch (seq-group-by #'car arch-pkgs)))
- (concat
- (format "Total packages: %s\n\n" (apply #'+ (mapcar #'cdr counts)))
- (mapconcat
- (lambda (archive)
- (concat "• "
- (format "%s (%s)" (car archive) (cdr archive))
- ": "
- (mapconcat (lambda (ap-pair) (cdr ap-pair))
- (alist-get (car archive) by-arch)
- ", ")))
- counts
- "\n\n")))))
-
-(defun my/display-package-report (output)
- "Display OUTPUT in a popup buffer."
- (let ((buffer-name "*package-report*"))
- (with-help-window buffer-name
- (with-current-buffer buffer-name
- (visual-line-mode 1)
- (erase-buffer)
- (insert output)
- (goto-char (point-min))))))
-
-(defun my/archive-packages ()
- "Return a list of (archive . package) cons cells."
- (seq-reduce
- (lambda (res package)
- (let ((archive (package-desc-archive
- (cadr (assq package package-archive-contents))))
- (pkg (symbol-name package)))
- (push (cons archive pkg) res)))
- (mapcar #'car package-alist)
- nil))
-
-(defun my/archive-counts (arch-pkgs)
- "Return a list of cons cells from alist ARCH-PKGS.
-The cars are package archives, the cdrs are the number of
-packages installed from each archive."
- (seq-reduce
- (lambda (counts key)
- (cons (cons key (+ 1 (or (cdr (assoc key counts)) 0)))
- (assoc-delete-all key counts)))
- (mapcar #'car arch-pkgs)
- nil))
-
-(provide 'my-packages-extra)
-;;; my-packages-extra.el ends here
diff --git a/emacs/elisp/my-strings.el b/emacs/elisp/my-strings.el
deleted file mode 100644
index 40ad888..0000000
--- a/emacs/elisp/my-strings.el
+++ /dev/null
@@ -1,23 +0,0 @@
-;;; my-strings.el --- Functions related to strings manipulation
-;;; Commentary:
-;;; Code:
-
-(defun my/remove-sql-columns ()
- "Remove \"|\" from strings.
-This is useful when I want to drop the column separator from some
-text coming from a mysql query."
- (interactive)
- (while (search-forward-regexp "\s?|\s?")
- (replace-match " ")))
-
-;; from https://karl-voit.at/2014/08/10/bookmarks-with-orgmode/
-(defun my/string-replace (this withthat in)
- "Replace THIS with WITHTHAT' in the string IN."
- (with-temp-buffer
- (insert in)
- (goto-char (point-min))
- (replace-string this withthat)
- (buffer-substring (point-min) (point-max))))
-
-(provide 'my-strings)
-;;; my-strings.el ends here
diff --git a/emacs/elisp/my-uptime.el b/emacs/elisp/my-uptime.el
deleted file mode 100644
index 77c9957..0000000
--- a/emacs/elisp/my-uptime.el
+++ /dev/null
@@ -1,55 +0,0 @@
-;;; my-uptime.el --- calculates uptime for SLOs
-
-;;; Commentary:
-
-;; Calculate how much downtime is allowed for different period of time
-;; based on a given SLO.
-
-;;; Code:
-
-(defconst my-uptime/buffer-name "*slo-calculator*")
-
-(defconst my-uptime/seconds-per-hour 3600
- "Number of seconds in an hour.")
-(defconst my-uptime/seconds-per-day (* my-uptime/seconds-per-hour 24)
- "Number of seconds in a day.")
-(defconst my-uptime/seconds-per-week (* my-uptime/seconds-per-day 7)
- "Number of seconds in a week.")
-(defconst my-uptime/seconds-per-month (* my-uptime/seconds-per-day 30)
- "Number of seconds in a month.")
-(defconst my-uptime/seconds-per-quarter (* my-uptime/seconds-per-month 3)
- "Number of seconds in a quarter.")
-(defconst my-uptime/seconds-per-year (* my-uptime/seconds-per-month 12)
- "Number of seconds in a year.")
-
-(defun my/uptime-is (slo)
- "Return the amount of allowed downtime for a given SLO."
- (interactive "nSLO:")
- (let* ((slo (cond ((< slo 0) 0)
- ((> slo 100) 100)
- (t slo)))
- (allowed (/ (- (* 100 100) (* slo 100.0)) (* 100 100))))
- (my/uptime--message allowed slo)))
-
-(defun my/uptime--message (seconds slo)
- "Insert buffer text with allowed downtime based on SECONDS (derived from SLO)."
- (let ((inhibit-read-only t)
- (buffer-undo-list t))
- (pop-to-buffer my-uptime/buffer-name)
- (erase-buffer)
- (insert (format "calculated allowed downtime for %s%% availability.\n" slo))
- (insert
- (format "daily: %s\n" (format-seconds "%H %M %S" (seconds-to-time (* my-uptime/seconds-per-day seconds)))))
- (insert
- (format "weekly: %s\n" (format-seconds "%H %M %S" (seconds-to-time (* my-uptime/seconds-per-week seconds)))))
- (insert
- (format "monthly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-month seconds)))))
- (insert
- (format "quarterly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-quarter seconds)))))
- (insert
- (format "yearly: %s\n" (format-seconds "%D %H %M %S" (seconds-to-time (* my-uptime/seconds-per-year seconds))))))
- (special-mode))
-
-(provide 'my-uptime)
-
-;;; my-uptime.el ends here
diff --git a/emacs/elisp/my-web.el b/emacs/elisp/my-web.el
deleted file mode 100644
index 4e86790..0000000
--- a/emacs/elisp/my-web.el
+++ /dev/null
@@ -1,32 +0,0 @@
-;;; my-web.el --- Functions related to web interactions
-;;; Commentary:
-;;; Code:
-
-(require 'my-strings)
-
-(defun my/get-page-title (url)
- "Make URL into an 'org-mode' link."
- (let ((title))
- (with-current-buffer (url-retrieve-synchronously url)
- (goto-char (point-min))
- (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
- (setq title (match-string 1))
- (goto-char (point-min))
- (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
- (my/string-replace "&nbsp;" " "
- (decode-coding-string title 'utf-8))
- (concat "[[" url "][" title "]]"))))
-
-(defun my/github-code-search ()
- "Search code on github for a given language."
- (interactive)
- (let ((language (completing-read
- "Language: "
- '("Emacs Lisp" "Python" "Go" "Nix")))
- (code (read-string "Code: ")))
- (browse-url
- (concat "https://github.com/search?l=" language
- "&type=code&q=" code))))
-
-(provide 'my-web)
-;;; my-web.el ends here
diff --git a/emacs/elisp/my-work.el b/emacs/elisp/my-work.el
deleted file mode 100644
index f0c59d8..0000000
--- a/emacs/elisp/my-work.el
+++ /dev/null
@@ -1,21 +0,0 @@
-;;; my-work.el --- Functions related to work
-;;; Commentary:
-;;; Code:
-
-(defun my/check-work-machine-p ()
- "Return t if this is a work machine."
- (string-match "HQ\\.*" (system-name)))
-
-(defun my/work-code-search ()
- "Search code on sourcegraph for a given language."
- (interactive)
- (let ((language (completing-read
- "Language: "
- '("Ruby" "Python" "Go")))
- (code (read-string "Code: ")))
- (browse-url
- (concat "https://sourcegraph.rbx.com/search?q=context:global+lang:" language
- "+" code))))
-
-(provide 'my-work)
-;;; my-work.el ends here