Skip to content

Instantly share code, notes, and snippets.

@joe-sullivan
joe-sullivan / pandoc.css
Created February 28, 2018 23:41
Pandoc css for html output
/* TO COMPILE: */
/* pandoc -s --toc --css pandoc.css <IN>.md -o <OUT>.html */
/* NOTE: */
/* include % <TITLE> as first line of md file to set html title */
body {
font-size: 12px;
margin: auto;
max-width: 80ch;
letter-spacing: .05em;
@joe-sullivan
joe-sullivan / colorterm.sh
Last active March 1, 2024 05:28
Bash Tricks
#!/bin/sh
if [ "$1" == "prod" ]; then
printf '\033]11;#331C1F\007' # red
elif [ "$1" == "dev" ]; then
printf '\033]11;#192436\007' # blue
elif [ "$1" == "other" ]; then
printf '\033]11;#253320\007' # green
else
printf '\033]11;#282c34\007' # black
@joe-sullivan
joe-sullivan / digram_visualization.py
Created June 8, 2017 01:53
Digram based binary visualization
#!/usr/bin/env python3
from collections import Counter
from PIL import Image
import math, os, sys
def create_image(filename):
# build digram
digram = Counter()
with open(filename, 'rb') as f:
#!/usr/bin/env python3
from collections import *
from random import random
def train_char_lm(fname, order=4):
with open(fname, 'r') as f:
data = f.read()
lm = defaultdict(Counter)
pad = '~' * order
@joe-sullivan
joe-sullivan / timing.h
Last active April 10, 2017 18:55
Timing macro c
#include <stdio.h>
#include <time.h>
#define TIMING(func) {\
int start=clock();\
func;\
int diff = clock() - start;\
int msec = diff * 1000 / CLOCKS_PER_SEC;\
printf("ms: %d\n", msec);\
}
@joe-sullivan
joe-sullivan / debug.h
Created July 14, 2016 19:26
Debug macro C
#ifdef DEBUG
# define D if(1)
#else
# define D if(0)
#endif
@joe-sullivan
joe-sullivan / timeout.py
Last active May 3, 2019 20:45
Simple timeout decorator for python
import signal
from functools import wraps
__all__ = ['timeout', 'TimeoutError']
class TimeoutError(Exception): pass
# IMPORTANT: this is not thread-safe
def timeout(seconds, error_message='Function call timed out'):
def _handle_timeout(signum, frame):
@joe-sullivan
joe-sullivan / verbose.py
Last active March 1, 2024 00:13
Simple logging decorator for python
#!/usr/bin/env python3
# +------------------------------------------------------------------------------+
# | HOW TO USE: from verbose import Log |
# +=================================== Basics ===================================+
# | <Inputs> |
# | msg : used as the main message to output (this is the only required field) |
# | tag : used to conceptually group messages or add string identifier |
# | |
# | <Functions> |
@joe-sullivan
joe-sullivan / async.py
Last active December 5, 2017 15:24
Easily create asynchronous functions in python using a decorator
import sys
if sys.version[0] == '2':
from Queue import Queue
else:
from queue import Queue
from threading import Thread
class asynchronous(object):
def __init__(self, func):
self.func = func