Skip to content

Instantly share code, notes, and snippets.

@mheffner
mheffner / gauge.cpp
Created Dec 14, 2015
c++ functional interface
View gauge.cpp
#include <functional>
#include <iostream>
class Foo {
public:
Foo(std::function<double()> gauge) {
this->_gauge = gauge;
}
void invoke() {
@mheffner
mheffner / measure.sh
Created Feb 15, 2015
USB thermometer to Librato measure
View measure.sh
#!/bin/bash
# Submit USB thermometer temperature to Librato
#
# Use with: https://github.com/petechap/usb-thermometer
#
#
# FILL OUT:
#
View gist:9dd3edf7f5ebbb629730
#!/bin/bash
#
# 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.
#
METADATA_URL_BASE="http://169.254.169.254/2012-01-12"
@mheffner
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
View twine.md

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)
"#{BuildPlatform.get_os}.#{BuildPlatform.get_arch(env)}"
end
def self.get_os
@mheffner
mheffner / README.md
Created Oct 3, 2012
Upload Travis CI builds to S3
View README.md

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
export PROMPT_DIRTRIM=3
function getwintitle()
{
case $TERM in
xterm*|rxvt|Eterm|eterm)
# Set icon title
@mheffner
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 = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(role))}
@mheffner
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]
super
end
def notify_readable
begin