Skip to content

Instantly share code, notes, and snippets.

@Bamco
Bamco / nn.h
Created September 23, 2016 13:50 — forked from antirez/nn.h
#ifndef __NN_H
#define __NN_H
/* Data structures.
* Nets are not so 'dynamic', but enough to support
* an arbitrary number of layers, with arbitrary units for layer.
* Only fully connected feed-forward networks are supported. */
struct AnnLayer {
int units;
double *output; /* output[i], output of i-th unit */
@Bamco
Bamco / permutations.ml
Created August 4, 2013 21:08
Ocaml list permutations
(* interleave 1 [2;3] = [ [1;2;3]; [2;1;3]; [2;3;1] ] *)
let rec interleave x lst =
match lst with
| [] -> [[x]]
| hd::tl -> (x::lst) :: (List.map (fun y -> hd::y) (interleave x tl))
(*permutations [1; 2; 3] = [[1; 2; 3]; [2; 1; 3]; [2; 3; 1]; [1; 3; 2]; [3; 1; 2]; [3; 2; 1]] *)
let rec permutations lst =
match lst with
| hd::tl -> List.concat (List.map (interleave hd) (permutations tl))
def concat(separator, lst):
"""
Takes string separator and list of strings and retuns one big string with
all the string elements of lst concatenated together, but separated by the
string separator.
This implementation is kinda *functional*.
Examples:
concat('...', []) -> ""
concat('...', ["Test"]) -> "Test"
concat('+', ["One", "Two", "Three"]) -> "One+Two+Three"
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@Bamco
Bamco / latency.markdown
Created June 1, 2012 09:08 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

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  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
Read 1 MB sequentially from memory ..... 250,000 ns  = 250 µs

Round trip within same datacenter ...... 500,000 ns = 0.5 ms