Skip to content

Instantly share code, notes, and snippets.

" Vim syntax file
"
" Modification of vims Haskell syntax file:
" - match types using regular expression
" - highlight toplevel functions
" - use "syntax keyword" instead of "syntax match" where appropriate
" - functions and types in import and module declarations are matched
" - removed hs_highlight_more_types (just not needed anymore)
" - enable spell checking in comments and strings only
" - FFI highlighting
#include <stdio.h>
#include <unistd.h>
#include <string.h> /* for strncpy */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
@johntyree
johntyree / typed_functions.py
Created January 24, 2014 20:15
A not so great hack to check types at runtime.
#!/usr/bin/env python
# coding: utf8
# GistID: 8605391
""" Add type checking decorators to functions.
@in_types(int, str)
@out_types(str)
def mul(a, b):
return a * b
@johntyree
johntyree / dups.py
Last active January 3, 2016 09:59
Find bit-exact duplicate files.
#!/usr/bin/env python2
# coding: utf8
# GistID: 8446782
import hashlib
import os
import sys
def get_size(path):
@johntyree
johntyree / mem.py
Created January 7, 2014 16:25
Memory profile of numpy array access
# GistID: 8301919
import numpy as np
import gc
from memory_profiler import profile
n = 30
m = 1000000
@profile
@johntyree
johntyree / scrot-shot.sh
Created January 3, 2014 19:40
Screenshot with scrot for hotkeys
#!/bin/bash
#GistID: 8245054
# By default we take a full screen shot and name it the current time
# If -s is passed as first argument, we do window/selection mode
DATETIME=$(date +%F_%T.%N | rev | cut -c 8- | rev)
OUTPUTDIR="~/Pictures/Screenshots/"
#!/usr/bin/env python
# coding: utf8
import sys
from numpy import loadtxt
from matplotlib.pyplot import matshow, show
mat = loadtxt(sys.stdin, dtype=bool, delimiter=',')
matshow(mat)
show()
// GistID: 7920541
//
//
// In this exercise you should get familiar with closures and
// implement an elementary cellular automaton (CA)
// [http://en.wikipedia.org/wiki/Elementary_cellular_automaton]. Read
// the article before proceeding. Then study closures from
// https://developer.mozilla.org/en/JavaScript/Guide/Closures and make
// sure you understand "Emulating private methods with closures" part
@johntyree
johntyree / jpp.py
Created December 10, 2013 16:01
Generic preprocessor
#!/usr/bin/env python
# coding: utf8
# GistID: 7893054
""" A generic preprocessor.
Replace `#include "<file>"` lines with file contents.
If the line starts with '//' then leave the include line in the output
for reference.
#!/usr/bin/env python3
# coding: utf-8
# GistID: 7799767
from __future__ import print_function
# import cStringIO
import itertools
import os
import re