Skip to content

Instantly share code, notes, and snippets.

function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@actsasflinn
actsasflinn / WSAppender.java
Created June 2, 2011 05:13
Web Service Log4j Appender, loosely based on SMTPAppender
package client;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.helpers.CyclicBuffer;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.ErrorCode;
import org.apache.log4j.spi.LoggingEvent;
@actsasflinn
actsasflinn / kyoto_cabinet_099_snow_leopard_compatibility.patch
Created April 2, 2010 03:16
Kyoto Cabinet patch fix compatibility on Mac OSX Snow Leopard (Kyoto Cabinet 0.9.9)
--- kcthread.cc.orig 2010-04-01 22:59:17.000000000 -0400
+++ kcthread.cc 2010-04-01 23:04:41.000000000 -0400
@@ -178,12 +178,12 @@ Mutex::Mutex(Type type) {
break;
}
case ERRORCHECK: {
- if (::pthread_mutexattr_settype(&attr, ::PTHREAD_MUTEX_ERRORCHECK) != 0)
+ if (::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) != 0)
throw std::runtime_error("pthread_mutexattr_settype");
break;
@actsasflinn
actsasflinn / macosx_snow_leopard_socket_fix.patch
Created March 30, 2010 01:04
Tokyo Tyrant patch fix unix sockets on Mac OSX Snow Leopard
--- ttutil.c.orig 2010-03-13 00:33:29.000000000 -0500
+++ ttutil.c 2010-03-13 00:34:05.000000000 -0500
@@ -127,7 +127,7 @@ int ttopensockunix(const char *path){
struct sockaddr_un saun;
memset(&saun, 0, sizeof(saun));
saun.sun_family = AF_UNIX;
- snprintf(saun.sun_path, SOCKPATHBUFSIZ, "%s", path);
+ strncpy(saun.sun_path, path, sizeof(saun.sun_path)-1);
int fd = socket(PF_UNIX, SOCK_STREAM, 0);
if(fd == -1) return -1;
@actsasflinn
actsasflinn / tcadb_misc_iterrec_iterout_for_bdb.patch
Created March 30, 2010 00:46
Tokyo Cabinet patch adds iterrec and iterout to tcadbmisc
--- tcadb.c.orig 2010-03-11 09:55:29.000000000 -0500
+++ tcadb.c 2010-03-13 15:34:13.000000000 -0500
@@ -2423,6 +2423,25 @@ TCLIST *tcadbmisc(TCADB *adb, const char
tclistdel(rv);
rv = NULL;
}
+ } else if(!strcmp(name, "iterrec")){
+ rv = tclistnew2(1);
+ int ksiz;
+ const char *kbuf = tcbdbcurkey3(adb->cur, &ksiz);
@actsasflinn
actsasflinn / msgpack_benchmark.rb
Created January 30, 2010 05:07
Message Pack vs similar utilities
=begin
Message Pack vs similar utilities
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.0.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
Packing
user system total real
pack: bert 18.320000 0.770000 19.090000 ( 19.101583)
pack: bson_ext 0.850000 0.030000 0.880000 ( 0.878398)
pack: json_ext 2.540000 0.040000 2.580000 ( 2.582495)
# nginx with memcache module... after a request the connection to memcached closes, what gives?
http {
upstream memcache {
server 127.0.0.1:11211;
keepalive 1024 single; # with this or without http://mdounin.ru/hg/ngx_http_upstream_keepalive/
}
server {
listen 80;
scopes[:your_composite_scope_name] = proc{ Scope.new(your.combined.scopes.here, {}) }
def self.your_composite_scope_name(*args)
scopes[:your_composite_scope_name].call(self, *args)
end
@actsasflinn
actsasflinn / FastHashRing_Benchmark.rb
Created November 15, 2009 06:55
FastHashRing (Ruby C Extension) vs HashRing (pure Ruby)
# Spoiler...
# user system total real
# Hash Ring 4.580000 0.040000 4.620000 ( 4.785069)
# Fash Hash Ring 0.080000 0.000000 0.080000 ( 0.087039)
#
require 'benchmark'
require 'rubygems'
require 'faker'
require 'hash_ring'
require 'fast_hash_ring'
@actsasflinn
actsasflinn / TokyoTyrant Balancer Benchmark
Created November 15, 2009 06:13
Experimental Tokyo Tyrant Balancer Benchmark
TokyoTyrant Single Node
user system total real
inserting data 0.320000 0.170000 0.490000 ( 1.415912)
reading data 0.310000 0.170000 0.480000 ( 1.394186)
TokyoTyrant Balanced 3 nodes using Ruby C Fast Hash Ring
user system total real
inserting data 0.300000 0.170000 0.470000 ( 1.464022)
reading data 0.350000 0.170000 0.520000 ( 1.489997)