Skip to content

Instantly share code, notes, and snippets.

View shantanuo's full-sized avatar

Shantanu Oak shantanuo

  • oksoft
  • mumbai
View GitHub Profile
@diosmosis
diosmosis / example.py
Created August 15, 2011 22:41
Python decorator that catches exceptions and logs a traceback that includes every local variable of each frame.
import os
from log_exceptions import log_exceptions
def throw_something(a1, a2):
raise Exception('Whoops!')
@log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None)
def my_function(arg1, arg2):
throw_something(arg1 + 24, arg2 - 24)
@shantanuo
shantanuo / dumper.pl
Created September 20, 2011 09:12
MySQLdump filter. Removes or replaces the DEFINER clauses from a dump
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case );
my $replace = undef;
my $delete = undef;
my $help = 0;
GetOptions (
@adampatterson
adampatterson / git_pull
Created October 17, 2011 20:27
Git pull Helper
/**
* Git Pull
*
* @author Adam Patterson
* http://www.adampatterson.ca/blog/2011/10/diy-simple-staging-server/
*
* Use: echo pull();
*/
function pull ( )
@cpatni
cpatni / app.rb
Created November 21, 2011 22:39
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@ambroff
ambroff / patch-keep-slave-data.diff
Created December 21, 2011 23:25
Allow setting up replication without purging data in the slave first.
diff --git a/redis.conf b/redis.conf
index 44fb536..505cb6e 100644
--- a/redis.conf
+++ b/redis.conf
@@ -150,6 +150,13 @@ slave-serve-stale-data yes
#
# repl-timeout 60
+# When setting up replication, the slave will purge the current data set before
+# loading the data sync from the master. Setting this will prevent that from
@ambroff
ambroff / gist:1509153
Created December 22, 2011 06:05
Collapsing a redis cluster from 6 nodes into 2.
1.) [1] [2] [3] Six node cluster
[4] [5] [6]
2.) [1] [2] <= [3] Hosts 2 and 5 replicate from 3 and 6 respectively.
[4] [5] <= [6] Once caught up, the clients are updated to point
to 2 and 5 instead, and 3 and 6 are terminated.
3.) [1] <= [2] Repeat.
[4] <= [5]
unsigned long zslGetRank(zskiplist *zsl, double score, robj *o) {
zskiplistNode *x;
unsigned long rank = 0;
int i;
x = zsl->header;
for (i = zsl->level-1; i >= 0; i--) {
while (x->level[i].forward &&
(x->level[i].forward->score < score ||
(x->level[i].forward->score == score &&
Program received signal SIGSEGV, Segmentation fault.
zslGetRank (zsl=0x7f3d8d71c360, score=19.498544884710096, o=0x7f3d4cab5760) at t_zset.c:335
335 (x->level[i].forward->score < score ||
(gdb) bt
#0 zslGetRank (zsl=0x7f3d8d71c360, score=19.498544884710096, o=0x7f3d4cab5760) at t_zset.c:335
#1 0x000000000042818b in zrankGenericCommand (c=0x7f3d9dcdc000, reverse=1) at t_zset.c:2046
#2 0x00000000004108d4 in call (c=0x7f3d9dcdc000) at redis.c:1024
#3 0x0000000000410c1c in processCommand (c=0x7f3d9dcdc000) at redis.c:1130
#4 0x0000000000419d3f in processInputBuffer (c=0x7f3d9dcdc000) at networking.c:865
#5 0x0000000000419e1c in readQueryFromClient (el=<value optimized out>, fd=<value optimized out>, privdata=0x7f3d9dcdc000, mask=<value optimized out>) at networking.c:908
@tlossen
tlossen / diskstore_inspector.rb
Created January 24, 2012 15:33
parse redis diskstore files (which contain hashes)
# encoding: UTF-8
# dependencies:
# - wget http://dist.schmorp.de/liblzf/liblzf-3.6.tar.gz
# - gem install lzfruby
require 'lzfruby'
require 'stringio'
class DiskstoreInspector
@misaka
misaka / Gemfile
Created January 27, 2012 11:29
Guardfile for py.test
source "http://rubygems.org"
group :development do
gem 'guard'
gem 'ruby_gntp'
gem 'growl'
end