Skip to content

Instantly share code, notes, and snippets.

@charsyam
charsyam / gen-lua.py
Last active December 17, 2015 16:20
generate set-tx script.
import os,sys
f = open(sys.argv[1], "w")
for i in xrange(100000):
key = "a%s"%(str(i))
data = "\"local ts = redis.call('lindex', KEYS[1], 1) or -1\\r\\nif tonumber(ARGV[2]) > tonumber(ts) then\\r\\nredis.call('del', KEYS[1])\\r\\nredis.call('rpush', KEYS[1], ARGV[1], ARGV[2])\\r\\nreturn ARGV[1]\\r\\nelse\\r\\nreturn {err='Stale'}\\r\\nend\""
cmd = "EVAL %s %s %s %s %s\n"%(data, 1, key, i, i);
f.write(cmd)
cmd = "EVAL %s %s %s %s %s\n"%(data, 1, key, i, i+100);
f.write(cmd)
@charsyam
charsyam / redis-proto-test.cc
Created July 17, 2013 10:59
redis protocol parsing code and test.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#define CR '\r'
#define LF '\n'
class message {
@charsyam
charsyam / MyList.java
Created August 3, 2013 02:58
Java Generic LIst
public class MyList<Element> {
public class ElementNode<Element> {
Element node;
ElementNode<Element> prev,next;
public ElementNode() {
clear();
}
@charsyam
charsyam / list_max.erl
Created August 8, 2013 08:52
get max number in list.
-module(list_max).
-export([list_max/1]).
list_max([Head|Rest]) ->
list_max(Head, Rest).
list_max(Res, []) ->
Res;
list_max(Result_so_far, [Head|Rest]) when Head > Result_so_far ->
-module(mylist).
-export([append/2, sum/1]).
append([H|T], Tail) ->
[H] ++ append(T, Tail);
append([], Tail) ->
[Tail].
sum([H|T]) -> H + sum(T);
package main
import (
"fmt"
"./tree"
)
func main() {
tree := tree.New()
tree.Add(4)
public class MarketUnknownSourceInformation {
public static boolean getMarketUnknownSourceInformation() {
boolean unknownSource = false;
if (Build.VERSION.SDK_INT < 3) {
unknownSource = Settings.System.getInt(getContentResolver(),
Settings.System.INSTALL_NON_MARKET_APPS, 0) == 1;
} else if (Build.VERSION.SDK_INT < 17) {
unknownSource = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.INSTALL_NON_MARKET_APPS, 0) == 1;
} else {
@charsyam
charsyam / redis-stat.py
Created August 26, 2013 15:44
redis-stat.py
import redis
import time
r = redis.StrictRedis('127.0.0.1', 6379)
last_total = 0
while(True):
ret = r.info()
if (last_total > 0):
print "command: ", int(ret["total_commands_processed"]) - last_total
print "clients: ", ret["connected_clients"]
@charsyam
charsyam / skiplist.go
Created September 8, 2013 17:02
go-skiplist example
package main
import (
"fmt"
"math/rand"
"time"
)
type SkipListNode struct {
level int
@charsyam
charsyam / universalhash.go
Created September 28, 2013 15:36
Simple Universalhash
package main
import (
"fmt"
"math/rand"
"time"
)
type UniversalHash struct {
table [] byte