Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
(Come in under the shadow of this red rock)

Derrick Turk derrickturk

💭
(Come in under the shadow of this red rock)
View GitHub Profile
@derrickturk
derrickturk / extensible_variants.ml
Created May 23, 2022
fun with extensible variants, including extensible GADTs
View extensible_variants.ml
(* extensible variant types, including GADTs
* not to be confused with polymorphic variants
*)
type extend_me = ..
type extend_me += This
type extend_me += That of int
type extend_me += TheOther of string
View rot13.rs
use std::io::{self, BufRead};
fn rot13(s: &str) -> String {
s.chars().map(|c| {
if c.is_ascii_lowercase() {
((c as u8 - b'a' + 13) % 26 + b'a') as char
} else if c.is_ascii_uppercase() {
((c as u8 - b'A' + 13) % 26 + b'A') as char
} else {
c
@derrickturk
derrickturk / stream_video.sh
Created Feb 23, 2022
stream video from a Raspberry Pi 2, also, bash is hard
View stream_video.sh
#!/usr/bin/env bash
trap "trap - SIGTERM && echo 'shutting down!' && kill -- -$$" SIGINT SIGTERM EXIT
echo "kill me with 'kill $$'"
(nohup raspivid -o - -t 0 -w 800 -h 600 -fps 15 2>/dev/null | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8080/}' :demux=h264 --h264-fps=15 >/dev/null 2>&1) &
PID=$!
wait $PID
trap - SIGINT SIGTERM EXIT
wait $PID
@derrickturk
derrickturk / fake.nix
Last active Feb 20, 2022
a really minimal Nix derivation
View fake.nix
with import <nixpkgs> {}; derivation { name = "fake"; builder = "${coreutils}/bin/touch"; args=[(placeholder "out")]; system = builtins.currentSystem; }
@derrickturk
derrickturk / iota.dhall
Created Feb 18, 2022
step step step step step it up
View iota.dhall
{- requires to >= from -}
let stepsFromTo: Natural -> Natural -> Natural -> Natural =
\(from: Natural) ->
\(to: Natural) ->
\(step: Natural) ->
let diff = Natural/subtract from to
let State = { i: Natural, val: Natural }
let state = { i = 0, val = from }
let foldState = \(s: State) -> if Natural/isZero (Natural/subtract s.val to)
then s
@derrickturk
derrickturk / Circ.hs
Created Nov 29, 2021
A circular buffer, WIP, from the AOC cutting room floor
View Circ.hs
{-# LANGUAGE DeriveFunctor #-}
module Circ (
Circ
, empty
, singleton
, length
, null
, delete
, rotateR
@derrickturk
derrickturk / geo_dump.py
Created Oct 4, 2021
Bits & bobs for reverse engineering complex geopandas code
View geo_dump.py
import inspect
import shapely
class DataDumper:
def __init__(self, path):
self._handle = open(path, 'w')
def __enter__(self):
return self
View gensym.m4
divert(-1)
changequote(`{', `}')
# gensym counter
define({%n}, 0)
# association for generic bodies
# _generic_setbody(name, body) -> store generic body by name
define({_generic_setbody}, {define({%gen[$1]}, $2)})
@derrickturk
derrickturk / bollocks.py
Created May 20, 2021
are Pandas users masochists or idiots?
View bollocks.py
import numpy as np
import pandas as pd
# our goal is to standardize exactly 2 out of 4 columns in a grouped frame,
# using the within-group standard deviation and mean
df = pd.DataFrame({
'a': ['Bennie', 'Bennie', 'Bennie', 'The Jets', 'The Jets'],
'b': [1.0, 3.0, 2.5, 7.1, 8.9],
'c': [-71.3, -80.4, -68.1, 2.5, 3.4],
'd': [25, 30, 40, 10, 15] # don't standardize me!
@derrickturk
derrickturk / Makefile
Created May 17, 2021
minimal example of building a DLL with GHC Haskell and calling it
View Makefile
# there is probably a way to get this from "stack path"
INCLUDE=C:\Users\Derrick\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.4\lib\include
all: hsdll.dll hsdll_stub.h usehsdll.exe
%.dll %_stub.h: %.hs %.def
stack ghc -- $^ --make -O2 -shared -static -o $@
%.exe: %.c hsdll_stub.h hsdll.dll
gcc -O2 -I$(INCLUDE) -Wall -Wextra -std=c11 -pedantic $^ hsdll.dll -o $@