Skip to content

Instantly share code, notes, and snippets.

@codeslinger
codeslinger / latency.txt
Created June 1, 2012 19:33 — 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 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
SSD random read 150,000 ns
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
@codeslinger
codeslinger / example.rb
Created April 25, 2012 13:17 — forked from erikeldridge/example.rb
A utility for signing an url using OAuth in a way that's convenient for debugging
require 'oauth_util.rb'
require 'net/http'
o = OauthUtil.new
o.consumer_key = 'examplek9SGJUTUpocjZ5QjBJmQ9WVdrOVVFNHdSR2x1TkhFbWNHbzlNQS0tJnM9Y29uc3VtkZXJzZWNyZXQmeD0yYg--';
o.consumer_secret = 'exampled88d4109c63e778dsadcdd5c1875814977';
url = 'http://query.yahooapis.com/v1/yql?q=select%20*%20from%20social.updates.search%20where%20query%3D%22search%20terms%22&diagnostics=true';
@codeslinger
codeslinger / gist:2371012
Created April 12, 2012 21:10 — forked from mikeyk/gist:2307647
Run PGFouine for 30 seconds, logging all queries and analyzing the logs
def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
time.sleep(30)
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
@codeslinger
codeslinger / hack.sh
Created March 31, 2012 13:25 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@codeslinger
codeslinger / Rationale.md
Created March 19, 2012 18:27 — forked from leegao/Rationale.md
JIT for dummies: JIT compiling RPN in python

If you don't care about the explanation, scroll down to find the code, it's 50 some odd lines and written by someone who doesn't know any better. You have been warned.

What it does

This is a very simple proof of concept jitting RPN calculator implemented in python. Basically, it takes the source code, tokenizes it via whitespace, and asks itself one simple question: am I looking at a number or not?

First, let's talk about the underlying program flow. Pretend that you are a shoe connoisseur with a tiny desk. You may only have two individual shoes on that desk at any one time, but should you ever purchase a new one or get harassed by an unruly shoe salesman without realizing that you have the power to say no (or even maybe?), you can always sweep aside one of the two shoes on the desk (the one on the right, because you're a lefty and you feel that the left side is always superior) onto the messy floor, put the other shoe on the right hand side, and then place your newly acquired shoe in

@codeslinger
codeslinger / gist:2122256
Created March 19, 2012 18:11 — forked from marcel/gist:2100703
giftube – Generates an animated gif from a YouTube url.
#!/usr/bin/env ruby
# giftube – Generates an animated gif from a YouTube url.
#
# Usage:
#
# giftube [youtube url] [minute:second] [duration]
#
# ex.
#
@codeslinger
codeslinger / ctf_mpetrov.c
Created February 26, 2012 15:28 — forked from michaelpetrov/ctf_mpetrov.c
Stripe CTF Challenge Level 06 Solution
//
// Created by Michael Petrov on 12-02-23.
// Copyright (c) 2012 TenthBit Inc. All rights reserved.
// http://michaelpetrov.com (petrov.michael@gmail.com)
//
//
// This solution performs a timing attack on the fork system call. By monitoring the process closely
// it is possible to discover where the fork likely happened. With some basic heuristics, it's possible
// to infer where the wrong character is. With very minor brute force searching it becomes very easy
// to find the password one letter at a time.
@codeslinger
codeslinger / gist:1917396
Created February 26, 2012 15:28 — forked from evandrix/gist:1901352
Stripe CTF Challenge - Solutions to all Levels
Stripe CTF - Work Notes
mpetrov (petrov.michael@gmail.com)
These notes are very rough. They should give a general idea of how each level was solved.
---- LEVEL 01 (login: e9gx26YEb2) -----
Solution: modifying PATH env variable
Password: kxlVXUvzv
date.c
@codeslinger
codeslinger / DisruptorTest.java
Created January 10, 2012 20:15 — forked from jbrisbin/DisruptorTest.java
Disruptor RingBuffer-based simplistic NIO HTTP test server
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@codeslinger
codeslinger / Migration-Syntax.clj
Created November 8, 2011 17:42 — forked from RickMoynihan/Migration-Syntax.clj
Rails like Database Migrations in Clojure... Using clojure.contrib.sql
(def migrations (sorted-map
;; Migrations are numbered by integer values to explicitly document them
1 {
:doc "Foo Table"
:up (fn []
(create-table
:Foo
[:id :int "PRIMARY KEY" "NOT NULL GENERATED ALWAYS AS IDENTITY"]
; store a JSON blob in here for the screening record