Skip to content

Instantly share code, notes, and snippets.

def check_for_outdated_homebrew
HOMEBREW_REPOSITORY.cd do
timestamp = if File.directory? ".git"
`git log -1 --format="%ct" HEAD`.to_i
else
(HOMEBREW_REPOSITORY/"Library").mtime.to_i
end
if Time.now.to_i - timestamp > 60 * 60 * 24 then <<-EOS.undent
Your Homebrew is outdated
@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:2394780
Created April 15, 2012 20:58
config.log from brew install -v collectd using Clang 3.1 on Lion w/Xcode 4.3.2
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by collectd configure 5.0.2, which was
generated by GNU Autoconf 2.67. Invocation command line was
$ ./configure --disable-debug --disable-dependency-tracking -C --with-python=/usr/bin --prefix=/usr/local/Cellar/collectd/5.0.2 --localstatedir=/usr/local/var
## --------- ##
## Platform. ##
@codeslinger
codeslinger / gist:2389148
Created April 15, 2012 01:15
brew install -v collectd (with Clang 3.1Xcode 4.3.2)
==> Downloading http://collectd.org/files/collectd-5.0.2.tar.bz2
Already downloaded: /Users/toby/Library/Caches/Homebrew/collectd-5.0.2.tar.bz2
/usr/bin/tar xf /Users/toby/Library/Caches/Homebrew/collectd-5.0.2.tar.bz2
==> ./configure --disable-debug --disable-dependency-tracking -C --with-python=/usr/bin --prefix=/usr/local/Cellar/collectd/5.0.2 --localstatedir=/usr/local/var
./configure --disable-debug --disable-dependency-tracking -C --with-python=/usr/bin --prefix=/usr/local/Cellar/collectd/5.0.2 --localstatedir=/usr/local/var
configure: creating cache config.cache
checking build system type... x86_64-apple-darwin11.3.0
checking host system type... x86_64-apple-darwin11.3.0
checking for gcc... /usr/bin/clang
checking whether the C compiler works... yes
@codeslinger
codeslinger / brew doctor
Created April 14, 2012 14:12
Attempted build of collectd 5.0.2 on Lion with Homebrew (Xcode 4.3.2 installed)
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python-config
@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.
#