Skip to content

Instantly share code, notes, and snippets.

@msullivan
msullivan / microbench.py
Created June 8, 2018 01:07
microbenchmark
from typing import cast
class Tree:
def accept(self, v: 'TreeVisitor') -> object:
pass
class Leaf(Tree):
def accept(self, v: 'TreeVisitor') -> object:
return v.visit_leaf(self)
class Node(Tree):
def __init__(self, value: int, left: Tree, right: Tree) -> None:
self.value = value
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
/**
* @brief A list traversal field that can be embedded in objects.
*/
typedef struct list_node {
struct list_node *next;
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
/**
* @brief A list traversal field that can be embedded in objects.
*/
typedef struct list_node {
///////
/**
* @file variable_queue.h
*
* @brief Generalized queue module for data collection
*
* @author Michael Sullivan ([email protected])
**/
#include <stddef.h>
#include <stdlib.h>
@msullivan
msullivan / recursive-set.sml
Created March 28, 2017 21:29
a modification of smlnj-lib's BinarySetFn that lets sets contain sets
(* A modification of binary-set-fn.sml to be able to handle set elements
* that contain sets. *)
(* binary-set-fn.sml
*
* COPYRIGHT (c) 1993 by AT&T Bell Laboratories. See COPYRIGHT file for details.
*
* This code was adapted from Stephen Adams' binary tree implementation
* of applicative integer sets.
*
@msullivan
msullivan / Memo.hs
Last active February 8, 2017 00:50
automatic haskell function memoizing
{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveFoldable #-}
import Data.Foldable
import qualified Data.Set as Set
import qualified Data.Map as Map
class Memo a where
memo :: (a -> b) -> (a -> b)
memoFix :: ((a -> b) -> (a -> b)) -> (a -> b)
#!/usr/bin/env python3
def build_rgraph(graph):
rgraph = {k: set() for k in graph.keys()}
for u in graph.keys():
for v in graph[u]:
rgraph[v].add(u)
return rgraph
def dfs(graph, seen, val, start):
@msullivan
msullivan / lf.sml
Created November 29, 2016 19:29
Implementation of LF typechecking using canonical forms and hereditary substitution
(* uses some data structures from
* https://github.com/standardml/cmlib/ *)
(* also the pretty printer uses some hacked up versions of some stuff
* from tom7 that I don't actually include but will if anybody wants to
* actually run this *)
signature VARIABLE =
sig
@msullivan
msullivan / delegations
Created July 27, 2016 18:41
PR numbers
Alaska,1
Delaware,1
Montana,1
NorthDakota,1
SouthDakota,1
Vermont,1
Wyoming,1
Hawaii,2
Idaho,2
Maine,2
@msullivan
msullivan / reboot.c
Created June 20, 2016 22:18
code to reboot a pc using keyboard controller
void reboot(void)
{
while (1) { /* keep trying if it doesn't work */
/* wait for the output buffer to be empty */
while (inb(KEYBOARD_CMD_PORT) & KEYBOARD_OUTBUF_FULL_MASK)
;
/* send the command to have the keyboard controller reboot the machine.
* wtf. */
outb(KEYBOARD_CMD_PORT, KEYBOARD_CMD_REBOOT);