From a187752c824b47052d33d3bc12749b5a7d2e8191 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 1 Jun 2023 19:35:59 -0700 Subject: 🤡 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I06b104d79deac199f9cd9cdae705e333d23cc852 --- lisp/my-cheeseboard.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/my-uptime.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 lisp/my-cheeseboard.el create mode 100644 lisp/my-uptime.el (limited to 'lisp') diff --git a/lisp/my-cheeseboard.el b/lisp/my-cheeseboard.el new file mode 100644 index 0000000..9713e14 --- /dev/null +++ b/lisp/my-cheeseboard.el @@ -0,0 +1,55 @@ +;;; my-cheeseboard.el --- summary -*- lexical-binding: t -*- +;; Author: Franck Cuny + +;;; 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/lisp/my-uptime.el b/lisp/my-uptime.el new file mode 100644 index 0000000..77c9957 --- /dev/null +++ b/lisp/my-uptime.el @@ -0,0 +1,55 @@ +;;; 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 -- cgit 1.4.1