Skip to content

Instantly share code, notes, and snippets.

@SeijiEmery
SeijiEmery / arith.hs
Created April 6, 2019 19:03
Haskell Arith
data Expr
= Const Integer -- values (integers)
| Add Expr Expr -- addition
| Mul Expr Expr -- multiplication
| If Expr Expr Expr Expr -- conditional branching (If a == b then c else d)
-- Not turing complete, but should be capable of evaluating most functions.
deriving (Show, Eq)
eval :: Expr -> Integer
@SeijiEmery
SeijiEmery / 0 compile
Last active May 19, 2019 00:24
Compile-time Arith
g++ -std=c++11 Arith.cpp -S && cat Arith.S
g++ -std=c++11 Arith.cpp && ./a.out
@SeijiEmery
SeijiEmery / learn_decision_tree.py
Last active February 21, 2019 18:35
from-scratch decision trees (basic example from an AI lecture)
"""
Discrete decision tree impl, pretty basic. (works for this example)
No libraries :)
Copyright (C) Seiji Emery 2018
"""
# Setup our dataset
data = {
'Day': [ 'D%s'%i for i in range(1, 15) ],
@SeijiEmery
SeijiEmery / build
Last active April 7, 2019 21:51
Full serialization lib in 160 lines of code (D)
chmod +x serializer.d
./serializer.d
@SeijiEmery
SeijiEmery / shapenet_distributed_jobs.py
Created February 18, 2019 00:06
concept code for rewriting shapenet utils
from utils.jobs import *
@job("apply-subdivision")
class BpySubdivisionJob (BpyJob):
@describe('input', type='file', ext='.obj')
@describe('output', type='file', ext='.obj')
@describe('subdivisions', type=intrange(1,6))
def run (self, input, output, subdivisions = 2):
src_obj = self.load_obj(path=input)
cube = self.create_cube()
#!/usr/bin/env python3
# bpy-run-from-blender fix.
# Assumes that commandline arguments are
# sys.argv[0] = path-to-blender
# sys.argv[1] = '-b'
# sys.argv[2] = '-P'
# sys.argv[3] = path-to-this-script
import sys
import os
4cd.edu
aaaom.edu
aacc.edu
aacsb.edu
aakers.edu
aamu.edu
aau.edu
aauj.edu
aauni.edu
aaup.edu
@SeijiEmery
SeijiEmery / unittest.java
Last active November 2, 2018 02:20
Crappy, easy unittesting in java
public class YourTestClass {
public static void main (String[] args) {
expect("my tests", () -> {
expect("test arithmetic", () -> {
assertEquals(2 + 2, 4);
assertNotEquals(2 + 2, 5);
});
expect("test exceptions", () -> {
assertNoThrow(() -> { if (2 + 2 != 4) { throw new IllegalStateException("blarg!"); });
assertThrows(() -> { if (2 + 2 != 5) { throw new IllegalStateException("blarg!"); });
@SeijiEmery
SeijiEmery / nines.py
Last active August 18, 2018 06:03
Nine-digit problem
#!/usr/bin/env python3
nines = set(range(1, 10))
nines = [ (i, nines - set([ i ])) for i in range(1, 10) ]
print(1, len(nines), [ i for i, _ in nines ])
for k in range(2, 10):
nines = [
(d * 10 + i, rest - set([ i ]))
for d, rest in nines
@SeijiEmery
SeijiEmery / mintest.h
Created August 16, 2018 16:05
A minimalistic C unittesting library
//
// A minimalistic unittesting framework that uses signal handling +
// longjmp to detect + test assertions + segfaults.
//
// Will add to this if / as needed
//
#ifndef __SEMERY_C_MINTEST_FRAMEWORK__
#define __SEMERY_C_MINTEST_FRAMEWORK__