Skip to content

Instantly share code, notes, and snippets.

Michael J. Sullivan msullivan

View GitHub Profile
@msullivan
msullivan / callable_module.py
Created Apr 3, 2019
making a python module callable
View callable_module.py
# ... don't do this
import sys
from types import ModuleType
def callme():
print("lol I'm a module")
class CallableModule(ModuleType):
def __call__(self, *args, **kwargs):
@msullivan
msullivan / 110
Created Dec 15, 2018
some day 12 inputs
View 110
initial state: #
..... => .
....# => .
#.... => .
#...# => .
...#. => #
...## => #
#..#. => #
#..## => #
@msullivan
msullivan / static.py
Created Oct 25, 2018
python static methods that can't be called on objects
View static.py
from types import MethodType
class strict_staticmethod:
def __init__(self, f):
self.f = f
def __get__(self, obj, type=None):
if obj is not None:
raise AttributeError("strict_staticmethod can't be accessed through obj")
return self.f
View microbench.py
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
View list.h
#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;
View list.h
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
/**
* @brief A list traversal field that can be embedded in objects.
*/
typedef struct list_node {
///////
View variable_queue.h
/**
* @file variable_queue.h
*
* @brief Generalized queue module for data collection
*
* @author Michael Sullivan (sully@msully.net)
**/
#include <stddef.h>
#include <stdlib.h>
@msullivan
msullivan / recursive-set.sml
Created Mar 28, 2017
a modification of smlnj-lib's BinarySetFn that lets sets contain sets
View recursive-set.sml
(* 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 Feb 8, 2017
automatic haskell function memoizing
View Memo.hs
{-# 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)
View detours.py
#!/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):
You can’t perform that action at this time.