Skip to content

Instantly share code, notes, and snippets.

@dspezia
dspezia / t.go
Created Jul 22, 2020
Example Go frequency measurement
View t.go
package main
import "bytes"
import "time"
import "fmt"
func ClusterSlot(key []byte) uint16 {
if start := bytes.IndexByte(key, '{'); start >= 0 {
if end := bytes.IndexByte(key[start+1:], '}'); end > 0 {
View GC1
Sun Jun 14 18:23:12 CEST 2015
stkbarPos=0 len(stkbar)=1 goid=1025 gcphase=2
fatal error: g already has stack barriers
runtime stack:
runtime.throw(0x7403d0, 0x1c)
/data2/ds/local/go/src/runtime/panic.go:527 +0x96
runtime.scanstack(0xc209a40840)
/data2/ds/local/go/src/runtime/mgcmark.go:334 +0x4f4
runtime.gcphasework(0xc209a40840)
View Test1
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x80 addr=0x0 pc=0x41be2a]
runtime stack:
runtime.throw(0x7586d0, 0x2a)
/data2/ds/local/go/src/runtime/panic.go:527 +0x96
runtime.sigpanic()
/data2/ds/local/go/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.mSpan_Sweep(0x7f9a7c0b8c00, 0xa1900000a00, 0xc01)
/data2/ds/local/go/src/runtime/mgcsweep.go:182 +0x1ba
@dspezia
dspezia / example.c
Created Apr 25, 2013
Example if hiredis subscribe with libevent
View example.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/libevent.h"
void subCallback(redisAsyncContext *c, void *r, void *priv) {
redisReply *reply = r;
@dspezia
dspezia / example.c
Created Nov 26, 2012
Example of Redis zset polling daemon
View example.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/ae.h"
#include "sha1.h"
@dspezia
dspezia / entropy.c
Created Oct 4, 2012
Dead simple (unsafe) entropy generator for Linux /dev/random
View entropy.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@dspezia
dspezia / db.c
Created Aug 4, 2012
Redis hack to get notified when a key expire
View db.c
// Change propagateExpire function in db.c as follows:
void propagateExpire(redisDb *db, robj *key) {
/* HORRIBLE HACK STARTS HERE */
/* robj *argv[2]; */
robj *argv[3];
/* HORRIBLE HACK ENDS HERE */
argv[0] = shared.del;
@dspezia
dspezia / intset.js
Created Jun 19, 2012
Evaluating memory consumption of 1M targeted tag sets
View intset.js
var redis = require('redis')
var rc = redis.createClient(6379, 'localhost');
function create( target, callback )
{
x = []
for ( var i=0; i<40; ++i )
{
// Only 100K entries in the reverse index
var n = 1000*Math.round(Math.random()*100000);
@dspezia
dspezia / ha.cfg
Created May 10, 2012
haproxy to target redis
View ha.cfg
global
daemon
maxconn 256
defaults
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
@dspezia
dspezia / ex3.rb
Created May 3, 2012
Ruby example of pipelining with the distributed client
View ex3.rb
require 'rubygems'
gem 'redis', '3.0.0.rc1'
require 'redis'
require 'redis/distributed'
# Create a client for 3 distributed Redis instances
$r = Redis::Distributed.new %w[redis://localhost:6380 redis://localhost:6381 redis://localhost:6382]
# Set 1000 items in distributed Redis