Skip to content

Instantly share code, notes, and snippets.

@codeslinger
codeslinger / gist:5100109
Last active December 14, 2015 14:19
x.js
/*
* items -- array of objects with a 'location' field
* userPrefs -- array of user-specified location labels, in user-specified order
*/
function sortByLocation(items, userPrefs) {
return sortBy(items, userPrefs, 'location');
}
function sortBy(items, userPrefs, column) {
items.sort(function(a,b) {
@codeslinger
codeslinger / README.md
Created November 8, 2015 01:49 — forked from Dr-Nikson/README.md
Auth example (react + redux + react-router)
@codeslinger
codeslinger / recipe.rb
Created June 29, 2012 20:15 — forked from peplin/recipe.rb
S3 File Resource for Chef
# Source accepts the protocol s3:// with the host as the bucket
# access_key_id and secret_access_key are just that
s3_file "/var/bulk/the_file.tar.gz" do
source "s3://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
group "root"
mode 0644
end
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')