Skip to content

Instantly share code, notes, and snippets.

@yurial
yurial / reshard.py
Created March 24, 2018 19:35
consistent sharding
def generate_keysets(n_shards, keys):
n_keys = len(keys)
shards = []
shards.append(keys)
elements_required = n_keys
shard_to_pop = 0
for step in xrange(1,n_shards):
need_count = n_keys // (step+1)
new_shard = []
for i in xrange(0,need_count):
@apsun
apsun / hax.c
Last active April 22, 2024 05:49
Hook main() using LD_PRELOAD
/*
* Hook main() using LD_PRELOAD, because why not?
* Obviously, this code is not portable. Use at your own risk.
*
* Compile using 'gcc hax.c -o hax.so -fPIC -shared -ldl'
* Then run your program as 'LD_PRELOAD=$PWD/hax.so ./a.out'
*/
#define _GNU_SOURCE
#include <stdio.h>
fluid-let
@lonnen
lonnen / author_stats.sh
Created November 10, 2011 00:25
Git repo summary stats for a particular author
git log --shortstat --author "AUTHOR NAME" | grep "files changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed: ", files, "\nlines inserted: ", inserted, "\nlines deleted: ", deleted}'