Skip to content

Instantly share code, notes, and snippets.

@jboner
jboner / latency.txt
Last active May 18, 2024 15:58
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
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 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@timmc
timmc / fact.swear.clj
Last active July 5, 2022 13:34
Factorial in Clojure without using alphanumeric characters
;; It all started here: http://clojure-log.n01se.net/date/2011-04-06.html#19:04
(#((% (+(*))) %) ;; call arg 1 with all args
[;; data
(+ (*)(*)(*)(*)(*)(*)(*))
;; main fn -- simulate 'if' with map lookup and closures
#(({(+) (% (+(*)(*)))} ;; if zero return 'then' clause
(% (+)) ;; dispatch on first arg
(% (+(*)(*)(*)))) ;; call 'else' clause (n not found in map)
%)
@cqfd
cqfd / ring.erl
Created July 20, 2012 16:07
Grow your own Erlang process ring
-module(ring).
-export([chain/0, chain/1, start/3]).
chain() ->
chain(self()).
chain(Neighbor) ->
receive
stop ->
io:format("stopping ~p...~n", [self()]),
@noahlz
noahlz / clojure-nyc-meetup-notes-20120718.md
Created July 20, 2012 17:28
Rough Notes from the July 18 Clojure NYC Meetup

Organizing Clojure Projects

Presented by @stuartsierra

Stuart presented using a deck created with org-html-slideshow, a Clojure library for formatting org-mode notes as HTML slides.

General Code Structure / Organization
  1. Be careful not to make function calls across component boundaries.
  2. Protocols should be minimalistic. They should have the fundamental operations of your component.

Here's some erlang.

-module(mini_chat).
-compile(export_all).

-define(ACTIVE_OPTIONS, [{reuseaddr, true}]).

% Commands start with "/", char 47
@zerokarmaleft
zerokarmaleft / family-trees.txt
Created July 31, 2012 18:53
Game of Thrones Challenge #65
AA = Rickard Stark (M) AB = Eddard Stark (M) AC = Catelyn Tully (F)
AD = Brandon Stark (M) AE = Benjen Stark (M) AF = Jon Snow (M)
AG = Robb Stark (M) AH = Sansa Stark (F) AI = Arya Stark (F)
AJ = Bran Stark (M) AK = Rickon Stark (M) AL = Hoster Tully (M)
AM = Minisa Whent (F) AN = Edmure Tully (M) AO = Lysa Tully (F)
AP = Jon Arryn (M) AQ = Robert Arryn (M) AR = Tytos Lannister (M)
AS = Tywin Lannister (M) AT = Joanna Lannister (F) AU = Kevan Lannister (M)
AV = Cersei Lannister (F) AW = Jamie Lannister (M) AX = Tyrion Lannister (M)
AY = Robert Baratheon (M) AZ = Joffrey Baratheon (M) BA = Myrcella Baratheon (F)
BB = Tommen Baratheon (M) BC = Lancel Lannister (M) BD = Steffon Baratheon (M)
@ngocdaothanh
ngocdaothanh / gist:3764694
Created September 22, 2012 00:43
Scala Assignment: Recursion
package recfun
import scala.collection.mutable.ListBuffer
import common._
/** https://class.coursera.org/progfun-2012-001/assignment/view?assignment_id=4 */
object Main {
def main(args: Array[String]) {
println("Pascal's Triangle")
for (row <- 0 to 10) {
@phedders
phedders / mosh-wrapper-simple
Created December 9, 2012 22:18
Very Simple shell mosh-{client,server} wrapper
h=1.2.3.4;
read a b port MOSH_KEY < <(ssh $h -t mosh-server 2>/dev/null|tr -d "\r"|grep MOSH); mosh-client $h $port
or
eval `ssh $h -t mosh-server 2>/dev/null|tr -d "\r"|awk '/^MOSH CONNECT/{print "MOSH_KEY=" $4,"mosh-client $h",$3}'`
@gtrak
gtrak / gist:4548456
Last active December 11, 2015 04:58
(ns xml.test
(:require [clojure.java.io :as io]
[clojure.data.xml :as xml]))
;; wget
;; download.geofabrik.de/openstreetmap/north-america/us/maryland.osm.bz2
(def xml-seq
#(-> (io/file "/home/gary/dev/maryland.osm")
io/input-stream
@jordanorelli
jordanorelli / gif_example.pde
Created February 20, 2013 02:38
make an animated gif with Processing
import gifAnimation.*;
GifMaker gifExport;
int frames = 0;
int totalFrames = 120;
public void setup() {
smooth();
size(400, 400);