Skip to content

Instantly share code, notes, and snippets.

@dvirsky
dvirsky / gist:dfdfd4066c70e8391dc5
Created Dec 24, 2014
Checking is a function was deferred or not
View gist:dfdfd4066c70e8391dc5
package main
import(
"fmt"
"runtime"
"io/ioutil"
"bytes"
"strings"
)
View gist:16411e335531aef6c5bf
package redis
import (
"fmt"
"github.com/garyburd/redigo/redis"
)
// Batch represents a set of batched results, either a transaction or just send/receive.
//
View README.md

Distributed Read-Write Mutex in Go

The default Go implementation of sync.RWMutex does not scale well to multiple cores, as all readers contend on the same memory location when they all try to atomically increment it. This gist explores an n-way RWMutex, also known as a "big reader" lock, which gives each CPU core its own RWMutex. Readers take only a read lock local to their core, whereas writers must take all locks in order.

@dvirsky
dvirsky / disque_example.go
Created May 3, 2015
Disque Usage example
View disque_example.go
package main
import(
"fmt"
"time"
"github.com/EverythingMe/go-disque/disque"
"github.com/garyburd/redigo/redis"
)
View filter.go
package main
import (
"fmt"
"github.com/EverythingMe/inbloom/go/inbloom"
"net/http"
)
var vocabulary = []string{"foo", "bar", "baz", "hey", "yo", "go"}
View foo_test.go
package foo
import (
"testing"
)
type Foo struct {
a string
b int
c float32
@dvirsky
dvirsky / gist:f9ebf6f66f763a356d4a
Created Nov 19, 2014
Long running Python Parent/Child communication via pipes
View gist:f9ebf6f66f763a356d4a
import subprocess
import time
import sys
def parent():
p = subprocess.Popen(['python', './testp.py', '--child'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
View serialization.c
// A serializer prototype - you serialize by calling Write N times.
// the key type is determined on registration so not needed here
// the list size will be determined by redis when you exit, based on the number of times you called write()
int (*Serialize)(RedisModuleCtx *ctx, RedisModuleObjectWriter *out, RedisModuleKey *k)
// you deserialize by calling Read and reading one object at a time.
// numElements is passed so the user can preallocate stuff in advance
int (*Deserialize)(RedisModuleCtx *ctx, RedisModuleObjectReader *in, RedisModuleString *keyName, size_t numElements)
@dvirsky
dvirsky / tasks.json
Created Sep 20, 2016
tasks.json for building and testing generic go projects in vscode
View tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"options": {
"cwd": "${fileDirname}"
},
"tasks": [
@dvirsky
dvirsky / example.txt
Last active Sep 26, 2016
index example
View example.txt
# creating an index:
127.0.0.1:6379> IDX.CREATE users TYPE HASH SCHEMA name STRING age INT32
OK
# running HASH commands while indexing them:
127.0.0.1:6379> IDX.INTO users HMSET user1 name "alice" age 24
OK
127.0.0.1:6379> IDX.INTO users HMSET user2 name "bob" age 19