Skip to content

Instantly share code, notes, and snippets.

Michael J. Sullivan msullivan

Block or report user

Report or block msullivan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
msullivan /
Created Apr 3, 2019
making a python module callable
# ... 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 / 110
Created Dec 15, 2018
some day 12 inputs
View 110
initial state: #
..... => .
....# => .
#.... => .
#...# => .
...#. => #
...## => #
#..#. => #
#..## => #
msullivan /
Created Oct 25, 2018
python static methods that can't be called on objects
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
from typing import cast
class Tree:
def accept(self, v: 'TreeVisitor') -> object:
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 (
#include <stddef.h>
#include <stdlib.h>
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 / 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)
#!/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]:
return rgraph
def dfs(graph, seen, val, start):
You can’t perform that action at this time.