Skip to content

Instantly share code, notes, and snippets.

mheffner / gauge.cpp
Created Dec 14, 2015
c++ functional interface
View gauge.cpp
#include <functional>
#include <iostream>
class Foo {
Foo(std::function<double()> gauge) {
this->_gauge = gauge;
void invoke() {
mheffner /
Created Feb 15, 2015
USB thermometer to Librato measure
# Submit USB thermometer temperature to Librato
# Use with:
View gist:9dd3edf7f5ebbb629730
# this script will attempt to detect any ephemeral drives on an EC2 node and create a RAID-0 stripe
# mounted at /mnt. It should be run early on the first boot of the system.
# Beware, This script is NOT fully idempotent.
mheffner / gist:c3671966d50d69909af1
Created Jul 19, 2014
Base packages for ruby on ubuntu
View gist:c3671966d50d69909af1
apt-get -y install ruby git xutils-dev ruby-dev make g++ libssl-dev autoconf libsasl2-dev libmysqlclient-dev scons

Hacking a Twine

I got a Twine the other week because I was interested in tracking temperature and moisture readings from my house, particularly to know if something is flooding.

Once setup, the Twine sends periodic readings of its temperature sensor and any external probes (moisture sensor) to the Supermechanical site. I was disappointed to find that there isn't currently a way to access those periodic readings. You can set rules

View gist:3880063
# This module provides build platform lookup in the form qaweb requires.
module BuildPlatform
def self.get_platform(env)
def self.get_os
mheffner /
Created Oct 3, 2012
Upload Travis CI builds to S3

Upload Travis CI builds to S3

This will demonstrate how to upload build files from Travis CI to S3.

NOTE: Keys have been changed to protect the innocent.

Step 1: Create an S3 policy.

Create an S3 ACL policy, see s3_policy.json for an example.

View simple ps1
# Prompt
function getwintitle()
case $TERM in
# Set icon title
mheffner / gist:1296089
Created Oct 18, 2011
Chef roles ruby->json rake task
View gist:1296089
ROLE_DIR = File.expand_path('../roles', __FILE__)
namespace :roles do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :to_json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role =
json_file = rb_file.sub(/\.rb$/,'.json'), 'w'){|f| f.write(JSON.pretty_generate(role))}
mheffner / emspawn.rb
Created Oct 18, 2011
How to spawn sub-procs with EM and capture all output (stdout and stderr)
View emspawn.rb
module Spawner
class SpawnedJob < EventMachine::Connection
def initialize(params)
@output = ""
@dfr = params[:deferrable]
def notify_readable