Skip to content

Instantly share code, notes, and snippets.

View derrickturk's full-sized 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 / stream_video.sh
Created February 23, 2022 07:10
stream video from a Raspberry Pi 2, also, bash is hard
#!/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 February 20, 2022 19:50
a really minimal Nix derivation
with import <nixpkgs> {}; derivation { name = "fake"; builder = "${coreutils}/bin/touch"; args=[(placeholder "out")]; system = builtins.currentSystem; }
@derrickturk
derrickturk / iota.dhall
Created February 18, 2022 23:30
step step step step step it up
{- 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 November 29, 2021 23:23
A circular buffer, WIP, from the AOC cutting room floor
{-# LANGUAGE DeriveFunctor #-}
module Circ (
Circ
, empty
, singleton
, length
, null
, delete
, rotateR
@derrickturk
derrickturk / geo_dump.py
Created October 4, 2021 20:15
Bits & bobs for reverse engineering complex geopandas code
import inspect
import shapely
class DataDumper:
def __init__(self, path):
self._handle = open(path, 'w')
def __enter__(self):
return self
@derrickturk
derrickturk / gensym.m4
Last active July 14, 2021 19:39
fun with 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 16:48
are Pandas users masochists or idiots?
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 18:41
minimal example of building a DLL with GHC Haskell and calling it
# 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 $@
@derrickturk
derrickturk / bbencoding.dhall
Created April 17, 2021 20:34
Fun with Boehm-Berarduccin encoding, in Dhall, where you really need it
-- https://docs.dhall-lang.org/howtos/How-to-translate-recursive-code-to-Dhall.html
let Person : Type
= ∀(Person : Type)
→ ∀(MakePerson : { children : List Person, name : Text } → Person)
→ Person
let example : Person
= λ(Person : Type) →
λ(MakePerson : { children : List Person, name : Text } → Person) →
@derrickturk
derrickturk / bbencoding.hs
Created April 17, 2021 20:05
fun with Boehm-Berarducci encoding
-- see https://www.haskellforall.com/2021/01/the-visitor-pattern-is-essentially-same.html
{-# LANGUAGE RankNTypes #-}
-- with ADTs:
data Shape
= Circle Double Double Double
| Rectangle Double Double Double Double
deriving (Eq, Show)