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 / queue.awk
Created Dec 2, 2022
SICKOS: hahahahah, yes
View queue.awk
function make_queue(arr) {
delete arr
arr["head"] = 0
arr["tail"] = 0
arr["next_id"] = 1
}
function push(arr, val) {
next_id = arr["next_id"]++
arr[next_id]["next"] = 0
@derrickturk
derrickturk / good.hs
Last active Nov 30, 2022
hell with type-level map
View good.hs
{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
module Data.HList
( HList(..)
, TypeMap
) where
import Data.Kind (Type)
import Data.Maybe (fromJust, fromMaybe)
@derrickturk
derrickturk / base26.hs
Last active Nov 21, 2022
say, Excel column names, super inefficiently
View base26.hs
base26 :: Integer -> String
base26 n =
let (m, n') = n `divMod` 26
ones = [toEnum (fromEnum 'A' + fromInteger n')]
in case m of
0 -> ones
m -> base26 (m - 1) ++ ones
@derrickturk
derrickturk / rev_ll.c
Created Oct 26, 2022
every time I see someone bitch about "reversing linked lists" I have this terrible compulsion
View rev_ll.c
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node *next;
} node, *list;
void list_free(list l)
@derrickturk
derrickturk / cpu.pony
Last active Sep 18, 2022
AoC 2019/07, but it crashes the Pony runtime
View cpu.pony
use "collections"
interface Sendable
fun tag send(word: I64)
primitive Running
primitive Blocked
primitive Halted
primitive IllegalInstruction
@derrickturk
derrickturk / abstype.kk
Created Jul 29, 2022
"Abstract"-ish types in Koka (and module naming whatevers)
View abstype.kk
abstract type meat
Beef
pub Lamb(age: int)
@derrickturk
derrickturk / vecs.kk
Created Jul 29, 2022
Fun with heap and vector in Koka
View vecs.kk
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 Jul 29, 2022
Extensible variant types (I think? they're not documented except in the grammar) in Koka
View ext.kk
open type openvar
A
B
extend type openvar
C
fun do_it_try_it(v: openvar): console ()
match v
A -> println("got an A")
View Parsing PHDWin formulas with Lark.ipynb
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 Jul 23, 2022
now this is podracing
View save.eff
(* 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 ->