Skip to content

Instantly share code, notes, and snippets.

View dln's full-sized avatar
🚀

Daniel Lundin dln

🚀
View GitHub Profile
; This is ~/.clojure/repl-init.clj
;
; I start a clojure repl something like:
;
; rlwrap --remember --complete-filenames \
; --history-filename ~/.clojure/history \
; --break-chars "\"\\'(){}[],^%$#@;:|" \
; java -server -cp 'src/:lib/*' clojure.main \
; -i ~/.clojure/repl-init.clj
@dln
dln / uuid_bench.md
Created May 26, 2010 08:23
Quick benchmark of time-based UUID generation in python, clojure/java and C.

TimeUUIDs in Python are slow. Clojure (Java) is fast.

Python

85 >>> def test():
    for _ in xrange(1000000):
        uuid.uuid1()

...:

data = {
1 : {1.1: "data",
1.2: "data",
1.3: "data",
1.4: "data",
1.5: "data"},
2 : {2.1: "data",
2.2: "data",
2.3: "data",
2.4: "data",
MyObjs(Standard)
----------------
row_key => {ts: 1234,
host: "kremvax",
attr1: data,
attr2: data,
attr2: data}
MyObjsIndices(Super)
--------------------
Simple string
-------------
>>> s='foo bar baz'
>>> %timeit str(s)
1000000 loops, best of 3: 214 ns per loop
@dln
dln / ttldict.py
Created August 14, 2010 11:32
Implementaion a dictionary with timed expiration of values.
import time
class TtlDict(dict):
"""A dict where values expire after a set time.
Expiration is done on access, or using `prune` (linear)"""
ttl = 5
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
@dln
dln / time_space.py
Created September 5, 2010 16:03
Measure time between pressing 'space' key twice.
import sys
import termios
import time
import tty
def wait_space():
if sys.stdin.read(1) == ' ':
return time.time()
return wait_space()
First revision (Secondary Index)
==================================
Store objects in one CF, and index in another.
Note: In Cassandra 0.7, using a secondary index for columns id:google, id:fb, id:myspace would eliminate the need for UserIndex.
Users
------
"e0ee3406d83c11dfa47e002219990fd7": {
"""
$ cat testar.thrift
struct Testar {
1: i32 heltal = 42,
2: optional string texten,
3: optional string mertext = 'foo',
4: optional map<string,string> properties
}
@dln
dln / java.env
Created December 28, 2010 11:02
Zookeeper RPM spec for CentOS 5.x, including python bindings
ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
ZOO_LOG_DIR="/var/log/zookeeper/"