Skip to content

Instantly share code, notes, and snippets.

View Cairnarvon's full-sized avatar

Koen Crolla Cairnarvon

View GitHub Profile
#!/usr/bin/python
import re
import signal
import sys
import time
from requests.exceptions import ConnectionError
from kol.Session import Session
@Cairnarvon
Cairnarvon / kolcaps.py
Created July 30, 2014 19:07
List all words that can be formed by capitalising letters in a given word.
#!/usr/bin/python3
import sys
DICT = '/usr/share/dict/words'
def subs(s):
for i in range(len(s)):
for s2 in subs(s[i + 1:]):
yield s[i] + s2
@Cairnarvon
Cairnarvon / astar.py
Created June 3, 2013 06:54
A* is easier than you think.
#!/usr/bin/env python3
# coding=utf8
import heapq
class Node(object):
def __init__(self, path, state, h, g):
self.path = path
self.state = state
@Cairnarvon
Cairnarvon / crypt.py
Created March 3, 2013 11:20
Pure-Python implementation of crypt(3).
#!/usr/bin/env python
# Initial permutation
IP = (
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
@Cairnarvon
Cairnarvon / pypistats.py
Created February 5, 2013 15:17
Graphs downloads per day for PyPI packages using gnuplot, because vanity. Usage: ./pypistats.py packagename
#!/usr/bin/env python
import bz2
import datetime
import os
import sys
import time
import urllib2
import warnings
@Cairnarvon
Cairnarvon / stego.py
Created October 24, 2012 01:54
Stegosaurus — let's steganograpy together.
#!/usr/bin/python
import argparse
import hashlib
import itertools
import struct
import sys
import zlib
from PIL import Image
@Cairnarvon
Cairnarvon / codan.py
Created October 4, 2012 01:30
The original Codan compiler (because Sprunge deletes old pastes).
#!/usr/bin/python2.5
# coding=utf8
"""
Copyright © 2010 Codan Working Group
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
@Cairnarvon
Cairnarvon / banned.py
Created September 21, 2012 22:51
Web service that keeps track of bad images using perceptual hashes and a bloom filter, to be used by imageboards and the like. (Proof of concept.)
#!/usr/bin/python
import argparse
import cgi
import math
import os
import sys
from PIL import Image
import pybloomfilter # https://github.com/axiak/pybloomfiltermmap
@Cairnarvon
Cairnarvon / Makefile
Created August 20, 2012 01:55
Variations on a theme.
MW = `MagickWand-config --cflags --ldflags --libs`
WARNS = -Wall -Wextra -pedantic -std=c99
.PHONY: all
all: imgcat
imgcat: imgcat.c
$(CC) -o $@ $(MW) $(WARNS) $(CFLAGS) $^
.PHONY: clean
@Cairnarvon
Cairnarvon / Makefile
Created August 18, 2012 22:50
imgcat, a cat in an image^W^W^Wfor images
MW = `MagickWand-config --cflags --ldflags --libs`
WARNS = -Wall -Wextra -pedantic -std=c99
.PHONY: all
all: imgcat
imgcat: imgcat.c
$(CC) -o $@ $(MW) $(WARNS) $(CFLAGS) $^
.PHONY: clean