Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
joeyAghion / haproxy.sh
Created November 21, 2013 21:05
Update Haproxy's config to allow management commands via socket, then connect and disable/enable some servers.
sudo yum install socat # if not already installed
sudo nano -w /etc/haproxy/haproxy.cfg # add ..."level admin" to stats socket line
sudo /etc/init.d/haproxy reload # reload config
sudo socat readline /tmp/haproxy.sock
prompt
> set timeout cli 1d
> help
> disable server rails_app_servers/rails-app1
> disable server rails_app_servers_ssl/rails-app1
> enable server rails_app_servers/rails-app1
@joeyAghion
joeyAghion / mongodb_collection_sizes.js
Last active February 9, 2024 22:37
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
@joeyAghion
joeyAghion / points.coffee
Created August 15, 2013 14:48
Hubot script for storing the "points" accumulated by different users. E.g. "+10 John". Adapted from https://github.com/github/hubot-scripts/blob/master/src/scripts/plusplus.coffee in order to add new "+N <name>" syntax.
# Adapted from https://raw.github.com/github/hubot-scripts/master/src/scripts/plusplus.coffee
#
# Description:
# Give or take away points. Keeps track and even prints out graphs.
#
# Dependencies:
# "underscore": ">= 1.0.0"
# "clark": "0.0.6"
#
# Configuration:
#!/usr/bin/env ruby
# I don't remember where I found this, but all credit goes to them.
require 'rubygems'
gem 'term-ansicolor', '=1.0.3'
require 'term/ansicolor'
class GitCommit
attr_reader :content
@joeyAghion
joeyAghion / benchmark_bundle.rb
Created December 3, 2012 00:28 — forked from bdurand/benchmark_bundle.rb
Benchmark Your Bundle
#!/usr/bin/env ruby
# Set the CHECK_RAILTIE environment variable to star (*) gems without Railties (warning: SLOW).
require 'bundler'
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
@joeyAghion
joeyAghion / benchmark.rb
Created November 30, 2012 19:45 — forked from panthomakos/benchmark.rb
Benchmark Your Bundle
#!/usr/bin/env ruby
# Set the CHECK_RAILTIE environment variable to star (*) gems without Railties (warning: SLOW).
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
@joeyAghion
joeyAghion / app.rb
Created July 9, 2012 02:40
Example files implementing the log-driven slideshow described in "Spend time with your site" post (http://artsy.github.io/blog/2012/07/05/spend-time-with-your-site/).
require 'rubygems'
require 'sinatra'
require 'json'
get '/latest' do
# This is where the [ugly] magic happens. Grep an appropriate path from the _end_ of the incoming log file,
# excluding office IP range and paying special attention to escaping...
line = `tac /var/log/heroku.log | grep ".*GET [^\?]*/home\/[^/ \\"]*" | grep -v "controls\\|pending\\|99\\.99\\." -m 1`
if match = line.match(/\/home\/([a-z0-9\-]*)/i)
return match[1].to_json
@joeyAghion
joeyAghion / cpi_historical.json
Last active July 11, 2017 19:05
Historical Consumer Price Index (CPI) data, by month. Originally sourced from http://www.alyz.com/oldrates/cpiu.data. Updates borrowed from http://www.inflationdata.com/Inflation/Consumer_Price_Index/HistoricalCPI.aspx.
[
[1913,1,9.8],
[1913,2,9.8],
[1913,3,9.8],
[1913,4,9.8],
[1913,5,9.7],
[1913,6,9.8],
[1913,7,9.9],
[1913,8,9.9],
[1913,9,10.0],
@joeyAghion
joeyAghion / git-unmerged
Created May 30, 2012 20:34
Script for reporting what local branches haven't been merged into master. Slightly adapted from http://www.mutuallyhuman.com/blog/2009/07/02/finding-unmerged-commits-with-git-unmerged/
#!/usr/bin/env ruby
require 'rubygems'
gem 'term-ansicolor', '=1.0.3'
require 'term/ansicolor'
class GitCommit
attr_reader :content
[cache]
LOCAL_DATA_DIR = /opt/graphite/storage/whisper/
# Specify the user to drop privileges to
# If this is blank carbon runs as the user that invokes it
# This user must have write access to the local data directory
USER = www-data
# Limit the size of the cache to avoid swapping or becoming CPU bound.
# Sorts and serving cache queries gets more expensive as the cache grows.