Skip to content

Instantly share code, notes, and snippets.

@NYKevin
NYKevin / trie.py
Last active December 23, 2015 00:19
A quick-and-dirty Trie implementation
import collections
class Trie(collections.MutableSet):
def __init__(self, iterable=None):
self.children = {}
self.accepting = False
if iterable is not None:
for item in iterable:
self.add(item)
@NYKevin
NYKevin / fractal.py
Created September 29, 2013 16:53
Branching spiral
#!/usr/bin/python3
import turtle
import math
MIN_LENGTH = 2
#FACTOR = (3/2) + math.sqrt(5)/2
@NYKevin
NYKevin / accounting.sql
Last active April 3, 2024 15:46
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@NYKevin
NYKevin / signal.c
Last active August 29, 2015 14:06
What signal am I receiving?
#define _POSIX_C_SOURCE 1
#include <signal.h>
#include <sys/signalfd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
sigset_t sig_mask;