Skip to content

Instantly share code, notes, and snippets.

@scythe
scythe / antiantivala.md
Created March 30, 2020 21:59
The anti-anti-Vala FAQ

The goal of this FAQ is to provide a humorous response to the inevitable question that comes up whenever people discuss a project that is written in Vala. Hopefully, it will save some time in the long run.

Why didn't you just use...

C#?

That was called Mono, and nobody liked it.

@scythe
scythe / complex3.c
Created April 3, 2020 23:22
SIMD-friendly complex numbers with redundancy
/* example implementation -- not recommended for actual use, but it would work!
* (SIMD-friendly in principle; not shown)
* (probably not ideal for memory-bound workloads; uses 50% more space)
* based on two insights:
* - complex multiplication (a+bi)(c+di) with i^2 = -1 is equivalent to
* split-complex multiplication (a+bk)(c+dk) - 2*b*d with k^2 = +1
* - the split-complex numbers are isomorphic to the direct product R*R with the
* basis (1+k)/sqrt(2), (1-k)/sqrt(2), both idempotents, thus split-complex
* multiplication (a+bk)(c+dk) can be done by (a+b)(c+d) and (a-b)(c-d)
*/
@scythe
scythe / array.lua
Last active April 25, 2020 23:54
Array library for lua
-- A simple array-manipulation library for Lua.
-- The natural question is: why bother writing this?
-- After all, it's very short, and anyone reasonably familiar with
-- normal array-manipulation libraries could replicate it in a few
-- hours.
-- But despite this, such a library does not exist in the wild, and
-- the existing counterparts are bad. For instance, penlight.List
-- lacks foldr(), and includes a bunch of things that it shouldn't,
-- like t:put(x), which is equivalent to t:insert(1, x), but also
-- prevents anyone reading your code from knowing what it does.
@scythe
scythe / sortedcitations.lua
Created March 31, 2021 17:41
Fix the dumb LaTeX bibliography
-- This script attempts to automatically sort the \bibitem{}s in the bibliography of a .tex file according to occurrences of \cite{}.
-- Pretty much everyone wants this, but LaTeX you to use extra files or sort by hand. This is annoying for small projects which only
-- need to use a single .tex file.
-- Assumptions: all \cite{} and \bibitem{} occurrences are in one file; only one \bibitem{} on each line; string.lower() works with
-- your citation handles.
tfile = [==[ PASTE .tex FILE HERE ]==] -- or use file i/o and io:lines() instead of the first call to gmatch()
local orders, count, lines = {}, 1, {}
(defn echo [x] (do (prn x) x))
(defn readmap [fn fl]
(with-open [r (clojure.java.io/reader fl)] (doall (map fn (line-seq r)))))
(defn zip-county-frac [s] (let [l (clojure.string/split s #",")] (list (second l) (first l) (nth l 4))))
(defn cbsa-county [s] (list (first (clojure.string/split s #"," 2)) (clojure.string/replace (or (re-find #",\d\d,\d\d\d," s) "") #"," "")))
def gen_primes():
"""Generate an infinite sequence of prime numbers."""
D = {}
q = 2
S = 4
r = 2
while True:
if q not in D:
if q == S:
S = S + r