Skip to content

Instantly share code, notes, and snippets.

@msullivan
msullivan / knot_solve.py
Created January 3, 2021 05:07
not really working black knot solver for 2006 icfp
#!/usr/bin/env python3.8
import sys
import re
def extract(s):
return [int(x) for x in re.findall(r'-?\d+', s)]
from z3 import Bool, Int, If, Not, Solver, And
"""Fixer for six.iterkeys() -> .keys(), and similarly for iteritems and itervalues."""
from lib2to3 import fixer_util, fixer_base
from lib2to3 import pytree
from lib2to3.fixes import fix_dict
from lib2to3.fixer_util import Call, Name
import libpostmodernize
class FixDict(fix_dict.FixDict):
@msullivan
msullivan / unlambda_selfify.sml
Created August 20, 2019 04:19
lulz, mankangulisk, cps, nub manufacturer
signature UNLAMBDA_REPR =
sig
type F
val ap : F * F -> F
val ul_I : F
val ul_K : F
val ul_S : F
val ul_V : F
val ul_Dot : char -> F
val ul_C : F
@msullivan
msullivan / callable_module.py
Created April 3, 2019 21:15
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
msullivan / 110
Created December 15, 2018 20:34
some day 12 inputs
initial state: #
..... => .
....# => .
#.... => .
#...# => .
...#. => #
...## => #
#..#. => #
#..## => #
@msullivan
msullivan / static.py
Created October 25, 2018 00:53
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
@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 (sully@msully.net)
**/
#include <stddef.h>
#include <stdlib.h>