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 / filey.rs
Created March 22, 2023 19:25
sometimes Python objects are "filey"
View filey.rs
use std::{
io::{self, Read, Seek, SeekFrom, Write},
fs::File,
};
use pyo3::{
prelude::{Python, PyObject},
};
pub enum Filey {
@derrickturk
derrickturk / plot_petra.rs
Last active March 21, 2023 17:20
Using plotters and petra_grid to half-ass something
View plot_petra.rs
use std::{
env,
error::Error,
fs::File,
process::ExitCode,
};
use plotters::prelude::*;
use petra_grid::{Grid, GridData};
@derrickturk
derrickturk / petra_grid.map
Created March 6, 2023 17:27
An experiment with GNU Poke
View petra_grid.map
load petra_grid;
%%
%entry
%name header
%type Header
%offset 0x0#B
%entry
@derrickturk
derrickturk / pop_char.rs
Created January 22, 2023 20:12
"Uncons" a char from a Rust &str
View pop_char.rs
#[inline]
fn pop_char(s: &str) -> Option<(char, &str)> {
let mut chars = s.chars();
chars.next().map(|c| (c, chars.as_str()))
}
@derrickturk
derrickturk / ziptree.py
Last active December 8, 2022 21:15
zippin' zippers in Python
View ziptree.py
# Language path: Haskell->Ocaml->Python, mypy typesystem [semantic loss ~31%]
# Subject: Zippers as the key insight
# what great fun! since mypy ~0.991 (?) we can finally, finally work with
# recursive types. this opens up Python to some traditional functional
# programming practices with a minimum of bullshit.
from typing import NamedTuple, TypeAlias
# let's walk amongst the trees for a bit.
@derrickturk
derrickturk / queue.awk
Last active December 11, 2022 15:36
SICKOS: hahahahah, yes
View queue.awk
function push(q, val) {
if (empty(q)) {
q["head"] = 0
q["tail"] = 0
q[0] = val
} else {
q[q["tail"] + 1] = val
q["tail"] = q["tail"] + 1
}
}
@derrickturk
derrickturk / good.hs
Last active November 30, 2022 22:04
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 November 21, 2022 20:53
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 October 26, 2022 14:49
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 September 18, 2022 17:42
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