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 / pillage298c.py
Created May 20, 2014 20:14
Pillage production data from IHS 98c (aka 298c) files.
from sys import argv, stderr, stdout, exit
def main(args):
fname = args[1]
stdout.write('UID\tName\tAPI\tLatitude\tLongitude\tMonth\tOil\tGas\tWater\tWells\n')
with open(fname) as f:
for w in well_production(f):
n_records = len(w['Month'])
for i in range(n_records):
stdout.write('\t'.join((w['UID'], w['Name'], w['API'],
@derrickturk
derrickturk / cpu.pony
Last active September 18, 2022 17:42
AoC 2019/07, but it crashes the Pony runtime
use "collections"
interface Sendable
fun tag send(word: I64)
primitive Running
primitive Blocked
primitive Halted
primitive IllegalInstruction
@derrickturk
derrickturk / abstype.kk
Created July 29, 2022 03:01
"Abstract"-ish types in Koka (and module naming whatevers)
abstract type meat
Beef
pub Lamb(age: int)
@derrickturk
derrickturk / vecs.kk
Created July 29, 2022 02:30
Fun with heap and vector in Koka
fun iota_vec(n: int): vector<int>
vector-init(n, id)
fun oddity(n: int): exn vector<int>
var v := iota_vec(n)
for(0, n) fn(i)
v[i] := v[i] + 3
v
fun space-oddity(n: int): exn vector<int>
@derrickturk
derrickturk / ext.kk
Created July 29, 2022 02:06
Extensible variant types (I think? they're not documented except in the grammar) in Koka
open type openvar
A
B
extend type openvar
C
fun do_it_try_it(v: openvar): console ()
match v
A -> println("got an A")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@derrickturk
derrickturk / save.eff
Created July 23, 2022 03:47
now this is podracing
(* yeah, so, Eff doesn't actually support polymorphic effects *)
effect Save: string -> int
effect Load: string * int -> empty
let save name = perform (Save name)
let load name v = absurd (perform (Load (name, v)))
let savegames = handler
| effect (Save name) k ->
@derrickturk
derrickturk / quicksave.eff
Last active July 23, 2022 03:32
play a game of "Guess or Die", with aggressive save-scumming
effect QuickSave: int option
effect QuickLoad: int -> empty
let quicksave () = perform QuickSave
let quickload n = absurd (perform (QuickLoad n))
let quicksaving = handler
| effect QuickSave k ->
let rec quickloading () = handler
| effect (QuickLoad n) _ ->
@derrickturk
derrickturk / revtree.pl
Created July 11, 2022 20:25
Stunting on Dumb Twitter Coding Interview guy, in Prolog
tree(nil).
tree([_, Left, Right]) :- tree(Left), tree(Right).
revtree(nil, nil).
revtree([Data, RLeft, RRight], [Data, Left, Right]) :-
revtree(RLeft, Right),
revtree(RRight, Left).
@derrickturk
derrickturk / ziphead.py
Created June 30, 2022 15:38
Dump the first N lines of CSV files inside a ZIP archive
import sys
from zipfile import ZipFile
LINES = 10
def main(argv: list[str]) -> int:
with ZipFile(argv[1]) as z:
for fn in z.namelist():
if not fn.endswith('.csv'):
continue