Skip to content

Instantly share code, notes, and snippets.

@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);
@msullivan
msullivan / clang-crash.cpp
Created April 13, 2016 20:02
clang parser segfault - I got it to crash on 3.6 and 3.7 on my machine
// clang++ --std=c++11 clang-crash.cpp
template<typename F>
auto foo(F f) -> decltype(f()) { }
void bar() {
foo([&]() { return *bogus; });
}
@msullivan
msullivan / notionstartup.sh
Created November 6, 2015 05:30
my notion startup script
#!/bin/sh
if pgrep unity-settings > /dev/null; then
exit
fi
xsetroot -solid black
# sleeps: evade, don't solve, concurrency problems
unity-settings-daemon& sleep 1;
wmdocker & sleep 1
@msullivan
msullivan / borrow-regression.rs
Created October 9, 2015 21:39
What seems to be a borrowchecker regression
// This compiles without error on stable and beta but gives a borrow
// error on nightly. It worked as of nightly 6e5a32547.
// Replacing the .by_ref() with explicitly taking a &mut ref fixes it.
// Other more dubious things fix it also.
pub type Session = i32;
pub struct StreamParser<'a, T: Iterator<Item=i32>> {
_tokens: T,
@msullivan
msullivan / fake-panel.py
Created September 17, 2015 03:16
Script to register a dummy panel so that multimedia keys work properly when using weirdo WMs
#!/usr/bin/env python3
# Michael J. Sullivan (http://www.msully.net/)
# Stupid little script to make gnome/unity media keys work when running
# weirdo window managers like xmonad and notion.
# Directions:
# With unity-settings-daemon running, run this script in the background.
# Tested on Ubuntu 15.04 using notion.