Skip to content

Instantly share code, notes, and snippets.

@lh3
lh3 / inthash.c
Last active November 5, 2024 21:04
Invertible integer hash functions
/*
For any 1<k<=64, let mask=(1<<k)-1. hash_64() is a bijection on [0,1<<k), which means
hash_64(x, mask)==hash_64(y, mask) if and only if x==y. hash_64i() is the inversion of
hash_64(): hash_64i(hash_64(x, mask), mask) == hash_64(hash_64i(x, mask), mask) == x.
*/
// Thomas Wang's integer hash functions. See <https://gist.github.com/lh3/59882d6b96166dfc3d8d> for a snapshot.
uint64_t hash_64(uint64_t key, uint64_t mask)
{
key = (~key + (key << 21)) & mask; // key = (key << 21) - key - 1;
@vincentdavis
vincentdavis / gist:8588879
Last active January 4, 2016 07:29
De Bruijn sequence
def debruijn(k, n):
"""
De Bruijn sequence for alphabet size k (0,1,2...k-1)
and subsequences of length n.
From wikipedia Sep 22 2013
"""
a = [0] * k * n
sequence = []
def db(t, p,):
if t > n:
@teh
teh / grind_coarseness.py
Created June 8, 2013 14:39
Measure average grind coarseness from a picture.
from PIL import Image
import numpy
from skimage.filter import sobel
from skimage.morphology import watershed
from scipy import ndimage as nd
grind = numpy.asarray(Image.open('grind.png')).mean(axis=2)
edges = sobel(grind)
markers = numpy.zeros_like(grind)
@imiric
imiric / PKGBUILD
Last active December 16, 2015 10:59
PKGBUILD for Vagrant 1.2.1
pkgname=vagrant
pkgver=1.2.1
pkgrel=4
pkgdesc="Tool for building and distributing virtualized development environments"
arch=('i686' 'x86_64')
url='http://vagrantup.com/'
license=('MIT')
depends=('ruby' 'virtualbox>=4.0' 'ruby-net-ssh>=2.6.6' \
'ruby-net-scp>=1.1.0' 'ruby-erubis>=2.7.0' 'ruby-i18n>=0.6.0' \
'ruby-log4r>=1.1.9' 'ruby-childprocess>=0.3.7')