Skip to content

Instantly share code, notes, and snippets.

View willemt's full-sized avatar
💣
focusing.

Willem willemt

💣
focusing.
View GitHub Profile
@willemt
willemt / raft_backoff.c
Last active November 9, 2015 14:42
Raft with backoff throttling
#include <sys/time.h>
#include <math.h>
#define min(a,b) ((a) < (b) ? (a) : (b))
int expboff(int n, int lmin, int lmax)
{
return min(lmin + (pow(n + 1, 2) - 1) / 2, lmax);
}
@willemt
willemt / gist:833d1766a4638db46a51
Created October 15, 2015 02:57
pickle anything
import pickle
class TolerantPickler(pickle.Pickler):
def save(self, obj):
try:
pickle.Pickler.save( self, obj )
except (TypeError, pickle.PicklingError, RuntimeError):
pickle.Pickler.save( self, None )
from StringIO import StringIO
def dumps(obj, protocol=None):
df <- read.csv("myRandomFile.csv", header=TRUE)
@willemt
willemt / gist:5573af8b7365f6bfe77c
Created January 28, 2015 12:04
Uploading a pip package to pypi
python setup.py bdist_wheel
python setup.py sdist bdist_wheel upload
vim (COMMAND git diff --name-only xxx)
@willemt
willemt / gist:a4e45eb64e2d9100a68b
Created October 25, 2014 04:14
hexdump -v -e '/32 "%05_ad |"' -e '/1 "%3_c"' -e '/32 "|\n"' tmp.queue
hexdump -v -e '/32 "%05_ad |"' -e '/1 "%3_c"' -e '/32 "|\n"' tmp.queue
@willemt
willemt / gist:0438fbb47189e970353a
Last active August 29, 2015 14:06
Python/Django profiling/debugging
# Django database checking
from django.db import connection; connection.queries
from django.db import connection; print "\n\n".join([v.values()[1] for v in connection.queries])
# Profiling
import cProfile, StringIO
pr = cProfile.Profile()
pr.enable()
# ... do something ...
library(reshape)
library(ggplot2)
library(scales)
library(cairoDevice)
data <- read.csv("birds.csv", head=TRUE, sep=",")
Cairo_png("Birds.png", width=10, height=7)
ggplot(data, aes(x=Letter,y=Frequency,fill=Frequency)) +