Skip to content

Instantly share code, notes, and snippets.

View chrismetcalf's full-sized avatar

Chris Metcalf chrismetcalf

View GitHub Profile

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
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 µ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 4X memory

@ttscoff
ttscoff / barchart.rb
Last active January 2, 2022 10:40
Command line bar chart from JSON data (for GeekTool, et al)
#!/usr/bin/env ruby
# encoding: utf-8
# Brett Terpstra 2013, WTF license <http://www.wtfpl.net/txt/copying/>
# Outputs a vertical bar chart from date-based JSON data
# Requires the JSON rubygem: `[sudo] gem install json`
require 'date'
require 'open-uri'
require 'rubygems'
require 'json'
@jkuroiwa
jkuroiwa / demobuild.php
Created July 27, 2012 00:37
Demo for Socrata API JSON import into MySQL
<?php
// Credentialing for MySQL server if you want the code to create table and load data automatically
$host = "localhost";
$user = "user";
$password = "password";
$base = "database";
$connection = mysql_connect($host,$user,$password) or die (mysql_error());
mysql_select_db($base,$connection);
// $id is the unique identifier for the Socrata data.
@trey
trey / getbundles.md
Created May 18, 2012 02:32
Installing GetBundles on a Fresh Copy of TextMate

Installing GetBundles on a Fresh Copy of TextMate

$ mkdir -p ~/Library/Application\ Support/TextMate/Bundles
$ cd !$
$ svn co http://svn.textmate.org/trunk/Review/Bundles/GetBundles.tmbundle/
$ osascript -e 'tell app "TextMate" to reload bundles'

Sources

@jlong
jlong / config.ru
Created June 23, 2011 19:56
Directory Index w/ Rack
# The project root directory
$root = ::File.dirname(__FILE__)
# Common Rack Middleware
use Rack::ShowStatus # Nice looking 404s and other messages
use Rack::ShowExceptions # Nice looking errors
#
# From Rack::DirectoryIndex:
# https://github.com/craigmarksmith/rack-directory-index/