Skip to content

Instantly share code, notes, and snippets.

View kristianlm's full-sized avatar

Kristian Lein-Mathisen kristianlm

View GitHub Profile
@kristianlm
kristianlm / constant folding.scm
Created January 2, 2024 20:43
s-expression constant folding experiment
(import test matchable)
;; how to turn
`(* 2 (+ x 3 (+ 4 10)) y 10)
;; into `(* 20 (+ 17 x ) y) ?
`(+ (+ 1 2 x) (+ 3 4 x) 5) =>
`(+ 15 x x)
(begin
@kristianlm
kristianlm / system.scm
Created September 13, 2022 09:10
Custom services in Guix
;; I find it hard to read the Guix Manual and figure out how to make a custom shepherd service
;; that just keeps a process running. I came up with this and though it was a keeper:
(operating-system
(service (service-type
(name 'tmuxkirc')
(extensions
(list (service-extension
shepherd-root-service-type
;;; I named this "hetzner", but the only VPS-specific feature is
;;; probably the virtio_scsi initrd module addition.
;;;
;;;
;;; OBS: change id_ed25519.pub below to id_rsa.pub unless you've used my favorite key algorithm:
;;;
;;; ssh-keygen -t ed25519
;;;
(use-modules (gnu)
(gnu packages ssh))
@kristianlm
kristianlm / config.scm
Last active August 13, 2022 20:42
can't build etc-polkit-1 on guix @ a8bd13c3993810428fc2e207791465bd8b297a17
(use-modules (gnu)
(gnu packages shells)
(gnu packages ssh)
(gnu services pm)
((gnu services cups) #:select (cups-service-type cups-configuration))
(gnu packages cups)
(gnu services sound)
(gnu packages wm)
(gnu services virtualization)
((gnu packages gnustep) #:select (windowmaker))
@kristianlm
kristianlm / config.snippet.scm
Last active August 9, 2022 07:58
guix i3status-rust: remove kdeconnect dependency
(define-public i3status-rust-no-kdeconnect
(package
(inherit i3status-rust)
(name "i3status-rust-no-kdeconnect")
(arguments
(substitute-keyword-arguments (package-arguments i3status-rust)
((#:phases old-phases)
#~(modify-phases #$old-phases
(replace 'wrap-i3status
(lambda* (#:key outputs inputs #:allow-other-keys)
/gamepad-train-main
/gamepad-train
/gamepad-train.build.sh
/gamepad-train.install.sh
/gamepad-train.link
;;; trying to implement avro binary encoding
;;; as described here:
;;; https://avro.apache.org/docs/current/spec.html#map_encoding
;;;
(import chicken.string chicken.bitwise chicken.io chicken.port
(only chicken.memory.representation number-of-bytes)
(only chicken.random random-bytes)
zstd medea matchable test)
(define (debug . args)
@kristianlm
kristianlm / atmega328 low power sleep.c
Created May 26, 2021 16:32
My atmega328 and attiny85 avr-gcc snippet collection
// prescaler timings:
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void watchdog_init(uint8_t prescaler) {
MCUSR &= ~(1<<WDRF); // <-- reset wdt
WDTCSR |= (1<<WDCE) | (1<<WDE); // <-- start timed sequence
WDTCSR = (1<<WDCE) | (1<<WDIE) |
((prescaler>>3) & 1)<<WDP3 |
((prescaler>>2) & 1)<<WDP2 |