Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
anonymous
anonymous / gist:5122217
Created March 9, 2013 02:29
data StartsWithA a b = StartsWithA a (StartsWithB a b)
| EmptyA
deriving Show
data StartsWithB a b = StartsWithB b (StartsWithA a b)
| EmptyB
deriving Show
infixr 7 <<<
infixr 7 >>>
#!/usr/bin/env python
# -*-coding: utf8-*-
# Title: chessboard.py
# Author: Gribouillis
# Created: 2012-05-19 22:18:09.909216 (isoformat date)
# License: Public Domain
# Use this code freely.
version_info = (0, 1)
version = ".".join(map(str, version_info))
@mtnygard
mtnygard / query.clj
Created February 8, 2013 22:19
Use Datomic queries as a source for RxJava pipes.
(ns rxjava-datomic.query
(:require [datomic.api :as d])
(:use [clojure.repl :only [pst]])
(:import [rx Observable]
datomic.Peer))
(defn query [qry & inputs]
(Observable/toObservable
(Peer/q qry (object-array inputs))))
@mislav
mislav / procs-vs-lambda.md
Last active March 26, 2021 18:34
Jim Weirich on the differences between procs and lambdas in Ruby

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@manuel
manuel / dyn-wind-commentary.scm
Created August 11, 2012 12:45
Commenting on Oleg's dyn-wind.scm
;; See http://okmij.org/ftp/continuations/implementations.html#dynamic-wind
;; and http://axisofeval.blogspot.com/2012/08/delimited-continuations-do-dynamic-wind.html
;; Slight trick here: use identity of yield-record-tag function as the actual tag
(define (yield-record-tag) yield-record-tag)
(define (make-yield-record v k)
(list yield-record-tag v k))
;; Yield simply aborts up to the generator's caller, delivering to it
;; the yielded value and the continuation for resuming after the call
@fogus
fogus / latency.txt
Created June 7, 2012 17:41 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@fogus
fogus / latency.markdown
Created June 7, 2012 17:41 — 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
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs