Skip to content

Instantly share code, notes, and snippets.

@saikyun
saikyun / loc-since-day.janet
Last active April 11, 2022 11:56
Functions for seeing changes to lines of code since a given day.
(defn git-log-stat-since
[&opt date]
(let [d (os/date)
date (or date
(string/format "%i-%02i-%02i" (d :year)
(inc (d :month)) # 0-indexed
(inc (d :month-day)) # 0-indexed
))
p (os/spawn ["git" "log" "--stat" (string `--since="` date ` 00:00"`)]
:p
@saikyun
saikyun / compile-and-run
Last active December 30, 2022 15:00
example of how to automatically reload dylibs when they change
#!/bin/zsh
# exit when a command fails
set -e
mkdir -p bin
cc -dynamiclib lib.c -o ./bin/lib.dylib
cc reload_dylibs.c -o bin/main && ./bin/main
@saikyun
saikyun / copy-on-write-tuple.janet
Last active February 28, 2023 21:35
Copy on write tuples for janet
(defn push
[l v]
[;l v])
(defn pop
[l]
(if (empty? l)
l
(tuple/slice l 0 -2)))
export class AssertionError extends Error {
constructor(message) {
super(message)
this.name = "AssertionError"
}
}
export const assert = (pred, msg = "") => {
if (typeof pred === "function") {
if (pred()) return true
@saikyun
saikyun / timer.js
Created April 2, 2025 07:49
node script that runs a timer while the lid is open, pauses on lid close. Macos only.
const exec = require("node:util").promisify(require("node:child_process").exec)
const get = (l, n) => (l == null ? null : l.length <= n ? null : l[n])
const lid_open = async () => {
const { stdout: res } = await exec(
"ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1"
)
const re = /.*"AppleClamshellState" = (No|Yes).*/
return get(re.exec(res), 1) == "No"