Skip to content

Instantly share code, notes, and snippets.

@jdf-id-au
jdf-id-au / align.c
Created February 5, 2025 11:28
Alignment calculation for arena
// Trying to understand the padding calculation from https://nullprogram.com/blog/2023/09/27/
byte *alloc(arena *a, size objsize, size align, size count) {
size avail = a->end - a->beg;
/*
Padding is how far the next aligned address is beyond the beginning of the arena.
(The "beginning" of the arena advances as data is added, and is really the beginning of the remaining avilable space.)
Use wrapping unsigned integer negation of the beginning address to measure what's left rather than what's in use.
Calculate how far this address is beyond the previous aligned address using modulo:
@jdf-id-au
jdf-id-au / lzw.clj
Created October 29, 2023 06:45
Lempel-Ziv-Welch decoder
(ns lzw
"After https://github.com/pgodwin/OcfLzw"
(:import (java.io ByteArrayInputStream StringWriter)))
(defn read-bits
"Read `n` bits from `partial-byte` (most significant first) then `bais` as needed.
Return vector of value, new bits-remaining-of and new partial-byte.
Nil if requested number of bits not available or > Long.SIZE/2 ."
[n ^ByteArrayInputStream bais bits-remaining-of partial-byte]
(if (> n (/ Long/SIZE 2))
@jdf-id-au
jdf-id-au / datalevin_migration.clj
Last active June 19, 2023 02:11
Migrate tricky data between datalevin verisons
(ns datalevin-migration
"Migrate evil prn-incompatible stuff like space-containing keywords.
Simplified from datalevin.core/dump-datalog and load-datalog"
(:require [taoensso.nippy :as nippy]
[datalevin.core :as dtlv]
[datalevin.db]
[datalevin.atom]))
(def db-path "path/to/db.old-version.dtlv")
(def new-db-path "path/to/db.new-version.dtlv")
;; after https://www.emacswiki.org/emacs/SmartOrangeTheme
;; then https://www.reddit.com/r/retrobattlestations/comments/elwuk9/ibm_ps2_p70_this_is_one_of_my_favorite_1980s/
(deftheme gas-plasma "IBM PS/2 P70 Gas Plasma")
(custom-theme-set-faces
'gas-plasma
'(default ((t (:foreground "#ea7d30" :background "#170e0d"))))
'(cursor ((t (:background "#f2b74d"))))
'(highlight ((t (:inverse-video t))))
@jdf-id-au
jdf-id-au / ios.md
Created September 12, 2021 11:22 — forked from dzt/ios.md
iOS Development Cheatsheet (Swift Edition)

#iOS Development Cheatsheet

TODO:

  • [] Screenshots
  • [] Videos

Note: In order to create your user interface Programmatically make sure withing your projects settings that Main Interface and the Launch Screen File are left blank. also...

  • Navigate to project settings
  • Under "App Icons and Launch Images" click on "Use Asset Catalog"
@jdf-id-au
jdf-id-au / fragmenter.clj
Created May 16, 2021 06:57
Fragment outgoing websocket text messages in yada and aleph
(ns fragmenter
"Support fragmenting outgoing websocket text messages,
while waiting for yada to incorporpate https://github.com/clj-commons/aleph/pull/502
( https://github.com/juxt/yada/issues/266 )"
(:require [taoensso.timbre :as log])
(:import (io.netty.channel ChannelOutboundHandler ChannelFutureListener ChannelPipeline ChannelHandler)
(io.netty.handler.codec.http.websocketx TextWebSocketFrame ContinuationWebSocketFrame)))
(defprotocol Fragmentable
(smash [this frag-size]))
@jdf-id-au
jdf-id-au / child.html
Last active August 11, 2021 00:09
Debugging nimWebTemplates
{% extends "parent.html" %}
{% block head %}
head!
{{key1}} {{key2}}
{% endblock %}
{% block content %}
content!
{{key1}} {{key2}}
{% endblock %}
@jdf-id-au
jdf-id-au / db.clj
Last active August 7, 2025 15:35
Use LocalDate and LocalDateTime with sqlite, juxt/tick and next.jdbc
(ns db
(:require [tick.alpha.api :as t]
[next.jdbc.result-set :as rs])
(extend-protocol rs/ReadableColumn
String
(read-column-by-index [val rsmeta idx]
(case (.getColumnTypeName ^ResultSetMetaData rsmeta idx)
"DATE" (t/date val)
"DATETIME" (t/date-time (s/replace val " " "T"))
#!/bin/zsh
# For 1200x1900 lowdpi (portrait) monitor to right of xps15 9550 laptop 3840x2160 282dpi
# https://blog.summercat.com/configuring-mixed-dpi-monitors-with-xrandr.html
# requires `prime-select nvidia` and reboot!
# stupid HDMI-1 doesn't seem to respect scale with intel video
# xrandr --query
# 3840+(2*1080) x (2*1920) = 6000x3840
xrandr --fb 6000x3840 \
--output eDP-1-1 --scale 1x1 --primary \
--output HDMI-1-1 --scale 2x2 --rotate left --right-of eDP-1-1
@jdf-id-au
jdf-id-au / transit-connection.cljc
Last active September 10, 2023 09:32
Sketch for connecting henryw374/time-literals to transit
(ns transit-connection
"Connect time-literals to transit."
(:require [time-literals.read-write]
#?(:cljs [java.time :refer [Period
LocalDate
LocalDateTime
ZonedDateTime
OffsetTime
Instant
OffsetDateTime