Skip to content

Instantly share code, notes, and snippets.

View manjuraj's full-sized avatar

Manju Rajashekhar manjuraj

View GitHub Profile
@manjuraj
manjuraj / struct_hack.c
Created October 18, 2011 23:36
C struct hack
#include <stdlib.h>
#include <stddef.h>
/*
* C struct hack - the last member of the struct is of variable length
*
* C99 however introduces the concept of a flexible array member, which
* allows the size of an array to be omitted if it is the last member
* in a structure
*/
@manjuraj
manjuraj / comprehension.py
Created January 6, 2012 08:17
List Comprehension in Python (listcomps)
# Notes:
# List comprehension (listcomps) is an expression.
# With list comprehension, you get back a list, not a generator.
# With generator expression, you get back an iterator that computes values as an when needed.
# prints [1, 2, 3, 4]
[x for x in (1, 2, 3, 4)]
# prints [2, 4]
[x for x in (1, 2, 3, 4) if x % 2 == 0]
@manjuraj
manjuraj / generator.py
Created January 6, 2012 08:20
Generators in Python (genexps)
def gen(num):
n = 0
while n < num:
yield n
n += 1
# returns a generator object
g = gen(3)
# returns 0
@manjuraj
manjuraj / iterators.py
Created February 12, 2012 02:22
Iterators in Python
items = [1, 2, 3]
it = iter(items)
# prints 1
print it.next()
# prints 2
print it.next()
# prints 3
@manjuraj
manjuraj / latency.txt
Created May 31, 2012 17:35 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@manjuraj
manjuraj / twemproxy_redis.perf
Created August 2, 2012 08:10
twemproxy with redis_benchmark
branch = redis_unstable on github.com/twitter/twemproxy
## redis-benchmark through a local twemproxy (nutcracker)
$ ./redis-benchmark -q -p 22121
SET: 63291.14 requests per second
GET: 65359.48 requests per second
INCR: 64935.07 requests per second
LPUSH: 67114.09 requests per second
LPOP: 68493.15 requests per second
SADD: 66225.16 requests per second
@manjuraj
manjuraj / throughput_vs_latency.md
Created December 5, 2012 18:38
Throughput vs Latency

IP Header = 20 TCP Header = 20 Ethernet = 20

Loopback RTT = 0.01 msec Datacenter RTT = 0.250 msec

1 Gbps = 128 MBps Assume 40% overhead, 600 Gps = 75 MBps

// my response to https://groups.google.com/forum/?fromgroups#!searchin/play-framework/cake/play-framework/LQ2y40QNZaE/qvRFw5of-rQJ
import play.api._
import play.api.mvc._
// Domain object
case class User(id: String, name: String)
// Trait defining the service component
trait UserServiceComponent {
@manjuraj
manjuraj / Monad.scala
Last active December 29, 2015 20:49 — forked from johnynek/Monad.scala
// (1). Simplified - A Thing[A] to compute another Thing[B]
// Thing[A] is like a simplest posssible container for a value and the
// pattern, given a Thing[A], and a function flatMap, pulls a value of
// type A out of the Thing[A] and applies the function flatMap() on this
// value of type A and returns another new Thing[B] with a value of
// type B injected into it by the constructor (apply() method here)
// encapsulates a monad in loose sense
case class Thing[+A](value: A) {
def flatMap[B](f: A => Thing[B]) = f(value)
}
@manjuraj
manjuraj / cake_di.scala
Last active December 30, 2015 02:39
DI using cake
// from: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di
// (1).
case class User(username: String, password: String)
trait UserRepositoryComponent {
val userRepository: UserRepository
class UserRepository {