Skip to content

Instantly share code, notes, and snippets.

View wsgac's full-sized avatar

Wojciech S. Gac wsgac

  • Keepit
  • Warszawa, Poland
View GitHub Profile
@wsgac
wsgac / package.yaml
Last active April 19, 2022 12:25
Practical Servant.Client example - querying a mail tracking API endpoint
...
dependencies:
- base >= 4.7 && < 5
- mtl
- aeson
- servant
- http-client
- http-client-tls
- servant-client
...
@wsgac
wsgac / fiveam-quickcheck.lisp
Last active March 29, 2022 14:57
A random QuickCheck-like test in Common Lisp with FiveAM
(ql:quickload :fiveam)
(ql:quickload :trivia)
(use-package :fiveam)
(use-package :trivia)
;; Haskell-inspired insertion sort implementation, making use of
;; pattern matching
(defun insertion-sort (list)
@wsgac
wsgac / iagon-haskell.el
Last active March 18, 2022 16:09
My Haskell setup for working with or without Nix-shell
;;;;;;;;;;;;;;;;;;
;; Environments ;;
;;;;;;;;;;;;;;;;;;
(setenv "PATH" "$HOME/.nix-profile/bin:$HOME/.local/bin:$HOME/.roswell/bin:$PATH" '("PATH" "HOME"))
(add-to-list 'exec-path "~/.roswell/bin")
(add-to-list 'exec-path "~/.local/bin")
(add-to-list 'exec-path "~/.nix-profile/bin")
(use-package direnv
@wsgac
wsgac / iso-paper-formats.el
Created December 9, 2021 16:26
Formulas for calculating the A, B and C series ISO paper format sizes (Elisp)
(defvar *a0-surface-area* 1000000 "Surface area of an A0 sheet in mm^2.")
(cl-defun a-format (n)
"Calculate the A series paper format sizes from first principles."
(assert (<= 0 n 10))
(let* ((area (ash *a0-surface-area* (- n)))
(shorter (sqrt (/ area (sqrt 2)))))
`(:shorter ,(round shorter) :longer ,(round (* shorter (sqrt 2))))))
(cl-defun b-format (n)
@wsgac
wsgac / advent-of-code-2021-day-01.el
Last active December 22, 2021 00:42
Advent of Code 2021 - Emacs Lisp
;;;;;;;;;;;
;; Day 1 ;;
;;;;;;;;;;;
;; Input
(defvar *day-1-puzzle-1-input*
'(174 180 179 186 184 176 177 190 173 174 176 175 172 175 174 175
176 179 206 207 206 205 208 209 215 221 228 227 214 215 216 218 244
246 242 249 250 253 259 256 261 256 252 254 256 261 274 270 300 301
@wsgac
wsgac / config.h
Last active October 19, 2021 11:49
ZSA Moonlander layout and configuration
/*
Set any config.h overrides for your specific keymap here.
See config.h options at https://docs.qmk.fm/#/config_options?id=the-configh-file
*/
#define ORYX_CONFIGURATOR
#define USB_SUSPEND_WAKEUP_DELAY 0
#define FIRMWARE_VERSION u8"DAVGK/raM0n"
#define RGB_MATRIX_STARTUP_SPD 60
@wsgac
wsgac / restclient.el
Created September 22, 2021 11:11
Modification to Restclient allowing capturing of just the response body
(defcustom restclient-response-body-only nil
"When parsing response, only return its body."
:group 'restclient
:type 'boolean)
(defun restclient-prettify-response (method url)
(save-excursion
(let ((start (point)) (guessed-mode) (end-of-headers))
(while (and (not (looking-at restclient-empty-line-regexp))
(eq (progn
@wsgac
wsgac / lyrical-crypto.el
Created August 9, 2021 16:09
Programmatic response to a joke I made to a colleague about encrypting public messages as post-modern poems.
(defvar *dict*
'((?a . (alas ask am))
(?b . (be beaver boulder beam))
(?c . (can cheat cover))
(?d . (did does deed dead))
(?e . (egg elevate eager))
(?f . (fight false friendship))
(?g . (gain goal get goose))
(?h . (help))
(?i . (indicate insight inside inter))
@wsgac
wsgac / nextcloud-upload.lisp
Created July 21, 2021 23:27
NextCloud file uploader in Common Lisp
(ql:quickload :drakma)
(ql:quickload :puri)
(ql:quickload :chanl)
(defparameter *nc-host* "https://ma.sdf.org/nc/remote.php/webdav/")
(defparameter *nc-base-collection* "Photos/")
(defparameter *nc-user* "username")
(defparameter *nc-pass* "password")
(defun nc-ensure-collection-exists (collection &key
@wsgac
wsgac / currency-calculator.el
Created July 21, 2021 13:41
Simple currency calculator, drawing data from Polish National Bank's (NBP's) API
(require 'request)
(defvar *exchange-rates-url* "http://api.nbp.pl/api/exchangerates/tables/A/")
(defvar *currencies* '("USD" "CAD" "EUR" "GBP" "JPY" "CHF") "Exchange rate table, relative to PLN")
(defvar *exchange-rates-file* "~/.emacs.d/lisp/exchange-rates.el")
(defvar *exchange-rates* nil)
(defvar *exchange-rates-timer* nil)
(defvar *exchange-rates-update-interval* 60)
(cl-defun fetch-exchange-rates (&key (currencies *currencies*))