Skip to content

Instantly share code, notes, and snippets.

@slotrans
slotrans / history_stuff.sql
Created August 6, 2021 23:50
Building blocks for generic history-keeping in Postgres.
/*
Replace "your_schema" with whatever schema is appropriate in your environment.
It is possible to use "public"... but you shouldn't!
*/
/*
Function to stamp a "modified" timestamp. Adjust the name to suit your environment,
but that name is hard-coded so it is assumed that you only use _one_ such name.
#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
@acutmore
acutmore / README.md
Last active January 21, 2024 20:30
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
  [
    ["push", N_1],         // 1
    ["push", False],       // 2
 ["peek", _], // 3
@zeux
zeux / simplifier.cpp
Created February 18, 2019 04:03
SIMD sloppy simplifier for "Flavors of SIMD" blog post
// This file is part of meshoptimizer library; see meshoptimizer.h for version/license details
#include "meshoptimizer.h"
#include <assert.h>
#include <float.h>
#include <math.h>
#include <string.h>
#ifndef TRACE
#define TRACE 0

A quadratic space is a real vector space V with a quadratic form Q(x), e.g. V = R^n with Q as the squared length. The Clifford algebra Cl(V) of a quadratic space is the associative algebra that contains V and satisfies x^2 = Q(x) for all x in V. We're imposing by fiat that the square of a vector should be the quadratic form's value and seeing where it takes us. Treat x^2 = Q(x) as a symbolic rewriting rule that lets you replace x^2 or x x with Q(x) and vice versa whenever x is a vector. Beyond that Cl(V) satisfies the standard axioms of an algebra: it lets you multiply by scalars, it's associative and distributive, but not necessarily commutative.

Remarkably, this is all you need to derive everything about Clifford algebras.

Let me show you how easy it is to bootstrap the theory from nothing.

We know Cl(V) contains a copy of V. Since x^2 = Q(x) for all x, it must also contain a copy of some nonnegative reals.

@dlaehnemann
dlaehnemann / flamegraph_rust.md
Last active February 14, 2024 14:14
flamegraphing rust binaries' cpu usage with perf
@amosr
amosr / tower-tuple.v
Created June 19, 2018 05:21
Coq encoding of Towers of Hanoi
(* A very simple Coq encoding of the "Towers of Hanoi" puzzle game. *)
Require Import Coq.Lists.List.
Import ListNotations.
Require Import Coq.Arith.Compare_dec.
(* Proof of a sorted list *)
Inductive Sorted : list nat -> Prop :=
| sorted'nil : Sorted []
@damncabbage
damncabbage / Examples.ex
Created June 6, 2018 08:50
Elixir "Traversing Error Mountain" Code Samples
defmodule Examples do
def zero do
files = ["abc.json", "def.json", "ghi.json"]
contents = files
|> Enum.map(fn (file) ->
File.read(file)
end)
# => [{:ok, "..."}, {:error, :enoent}, {:ok, "..."}]

The original code (~7.2s on my laptop).

import System.Random
import System.CPUTime

rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
@amosr
amosr / House.v
Last active September 11, 2019 10:45
Coq text adventure
Set Implicit Arguments.
Inductive Place
:= Kitchen | Bedroom | Hallway | Outside.
Inductive Card := NORTH | EAST | SOUTH | WEST.
Definition moveTo (p : Place) (c : Card) : option Place :=
match p, c with