Skip to content

Instantly share code, notes, and snippets.

(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 / Cargo.toml
Created Sep 22, 2020
A minimal Python module in Rust (move to src/; rename target/{profile}/rustpy.dll to rustpy.pyd.
View Cargo.toml
name = "rustpy"
version = "0.1.0"
authors = ["Derrick W. Turk <>"]
edition = "2018"
crate-type = ["cdylib"]
# See more keys and their definitions at
derrickturk / Makefile
Last active Sep 22, 2020
A minimal(?) Python module in C++, with MinGW makefile
View Makefile
CXXOPTS=-Wall -pedantic -std=c++2a -O2 -static
ALL: cpppytest.pyd cpppyobj.pyd
%.pyd: %.cpp
derrickturk / Makefile
Last active Sep 22, 2020
A minimal Python module in C, with MinGW makefile
View Makefile
COPTS=-Wall -pedantic -std=c99 -O2 -static
cpytest.pyd: cpytest.c
$(CC) $(COPTS) -shared -I$(PYINCLUDEDIR) -L$(PYLIBDIR) -o $@ $^ -lpython$(PYVER)
derrickturk /
Created Sep 12, 2020
A simpler version of PyMC3's questionable idea
import sys
from typing import ClassVar, Dict, List, Type
class Model:
_ctx: 'ClassVar[List[Model]]' = list()
def __init__(self):
self.nodes: 'Dict[Node]' = dict()
def __enter__(self):
derrickturk / ex1.jl
Created Aug 5, 2020
Coursera ML course, exercise 1, ported to Julia
View ex1.jl
using LinearAlgebra
using DelimitedFiles
using Plots
warmup() = I
J(X, y, θ) = sum((X * θ - y) .^ 2) / (2 * length(y))
derrickturk /
Last active Jul 24, 2020
"typestate" with Literal types in Python 3.8
# check with mypy --allow-redefinition
# (this option should be called --no-demented-nazi-mode)
from enum import Enum, auto
from typing import cast, Generic, Literal, TypeVar
class DoorState(Enum):
CLOSED = auto()
LOCKED = auto()
OPEN = auto()
derrickturk /
Last active Jun 26, 2020
Base functors and a type-level fixed point in Python, for no good reason
from typing import Callable, Dict, Generic, List, TypeVar, Union
_T = TypeVar('_T')
JsonF = Union[str, Dict[str, Union[str, _T]], List[_T]]
class Fix(Generic[_T]):
def __init__(self, val: 'Union[_T, Fix[_T]]'):
self.val = val
derrickturk / veccy.idr
Created Jun 19, 2020
ad-hoc overloading with interfaces
View veccy.idr
import Data.Vect
%hide List.Nil
interface Addable (a : Type) (b : Type) (c : Type) | a, b where
add : a -> b -> c
-- it's redundant to case-split this for vectors, but just for example
Addable (Vect n a) (Vect Z a) (Vect n a) where
add xs _ = xs
derrickturk / oban.ebnf
Last active Jun 24, 2020
Parsing OBAN, the Obviously Bogus Abject Notation
View oban.ebnf
(* Copyright 2020 Derrick W. Turk / terminus data science, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
derrickturk / uplink.cs
Created Jun 10, 2020
Excel regex link rewriter
View uplink.cs
You can’t perform that action at this time.