Skip to content

Instantly share code, notes, and snippets.

@mheffner
mheffner / emspawn.rb
Created October 18, 2011 00:01
How to spawn sub-procs with EM and capture all output (stdout and stderr)
module Spawner
class SpawnedJob < EventMachine::Connection
def initialize(params)
@output = ""
@dfr = params[:deferrable]
super
end
def notify_readable
begin
@mheffner
mheffner / gist:1211868
Created September 12, 2011 17:39
Setting Monitoring Tags with Passenger and Librato Silverline
# See this article for how to tag processes:
# http://support.silverline.librato.com/kb/monitoring-tags/using-monitoring-tags
#
####
# Apache config option:
# See: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerRuby
#
PassengerRuby /path/to/ruby_wrapper.sh
@mheffner
mheffner / silverline.conf
Created August 5, 2011 18:01
Librato Silverline upstart config
# silverline - start the Librato Silverline agent
#
# The Librato Silverline agent collects monitoring statistics
# from Silverlined processes, dynamically rebalances capacity
# based on registered SLAs and process demand, and pushes limits
# to managed Silverlined processes.
#
# Librato Silverline is provided as a SaaS platform, see:
# http://www.librato.com
#
@mheffner
mheffner / README.md
Created June 20, 2011 23:06
Setting up syslog logging on Heroku with Sinatra 1.2.x

Setting up syslog logging on Heroku with Sinatra 1.2.x

1. Update your Gemfile to include:

gem 'remote_syslog_logger'

2. Add the file remote_syslog.rb below to your Sinatra app as lib/remote_syslog.rb.

3. Modify your config.ru to match the example one below.

@mheffner
mheffner / gist:1004610
Created June 2, 2011 15:09
digicert on Fedora 14
$ grep -i digicert /etc/pki/tls/cert.pem
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA
@mheffner
mheffner / readtsc.c
Created May 13, 2011 19:21
Report gettimeofday, TSC and getrusage(self) periodically while performing I/O workload.
/*
* Dumps the value of gettimeofday(), the TSC, and
* getrusage(RUSAGE_SELF) every two seconds while performing some fake
* I/O workload on a /tmp file.
*
* Build: gcc -o readtsc readtsc.c -lrt
*/
#include <stdio.h>
@mheffner
mheffner / cleanup_snapshots
Created April 16, 2010 19:10
Cleanup old EBS snapshots
#!/usr/bin/env ruby
#
#
# Cleanup EC2 EBS snapshots.
#
# Originally from: http://www.elastdream.com/2009/04/snapshots.html
#
require 'rubygems'
require 'right_aws'
function traildir()
{
local n=$1 dir=$2
local sl tildedir homelen shifted traildir
local oldifs=$IFS
tildedir=${dir#$HOME}
if ! [[ "$tildedir" == "$dir" ]]; then
# Special break out case
[[ -z "$tildedir" ]] && { echo "~"; return 0; }
$ make libab.so
gcc -Wall -fPIC -fvisibility=hidden -c -o filea.o filea.c
gcc -Wall -fPIC -fvisibility=hidden -c -o fileb.o fileb.c
gcc -Wall -fPIC -fvisibility=hidden -shared -o libab.so filea.o fileb.o
$ strip --strip-all --discard-all libab.so
$ objdump -T libab.so | grep get
0000000000000587 g DF .text 000000000000004a Base ab_get_string
/* filea.c */
#include <stdio.h>
/* Include public API definitions. */
#include "ab.h"
/* Function provided by fileb.c */
int b_getval_super_secret(void);
/* Simple function internal to this file only. */