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 / Cargo.toml
Created Sep 22, 2020
A minimal Python module in Rust (move lib.rs to src/lib.rs); rename target/{profile}/rustpy.dll to rustpy.pyd.
View Cargo.toml
[package]
name = "rustpy"
version = "0.1.0"
authors = ["Derrick W. Turk <dwt@terminusdatascience.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@derrickturk
derrickturk / Makefile
Last active Sep 22, 2020
A minimal(?) Python module in C++, with MinGW makefile
View Makefile
CXX=g++
CXXOPTS=-Wall -pedantic -std=c++2a -O2 -static
PYROOT=C:/Users/Derrick/local
PYVER=36
PYINCLUDEDIR=$(PYROOT)/Python$(PYVER)/include
PYLIBDIR=$(PYROOT)/Python$(PYVER)/libs
ALL: cpppytest.pyd cpppyobj.pyd
%.pyd: %.cpp
@derrickturk
derrickturk / Makefile
Last active Sep 22, 2020
A minimal Python module in C, with MinGW makefile
View Makefile
CC=gcc
COPTS=-Wall -pedantic -std=c99 -O2 -static
PYROOT=C:/Users/Derrick/local
PYVER=36
PYINCLUDEDIR=$(PYROOT)/Python$(PYVER)/include
PYLIBDIR=$(PYROOT)/Python$(PYVER)/libs
cpytest.pyd: cpytest.c
$(CC) $(COPTS) -shared -I$(PYINCLUDEDIR) -L$(PYLIBDIR) -o $@ $^ -lpython$(PYVER)
@derrickturk
derrickturk / model_context.py
Created Sep 12, 2020
A simpler version of PyMC3's questionable idea
View model_context.py
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
derrickturk / ex1.jl
Created Aug 5, 2020
Coursera ML course, exercise 1, ported to Julia
View ex1.jl
using LinearAlgebra
using DelimitedFiles
using Plots
gr()
warmup() = I
J(X, y, θ) = sum((X * θ - y) .^ 2) / (2 * length(y))
@derrickturk
derrickturk / typestate.py
Last active Jul 24, 2020
"typestate" with Literal types in Python 3.8
View typestate.py
# check with mypy typestate.py --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
derrickturk / cata.py
Last active Jun 26, 2020
Base functors and a type-level fixed point in Python, for no good reason
View cata.py
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
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
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@derrickturk
derrickturk / uplink.cs
Created Jun 10, 2020
Excel regex link rewriter
View uplink.cs
You can’t perform that action at this time.