Skip to content

Instantly share code, notes, and snippets.

samg / custom-resource-log.js
Last active September 3, 2019 20:53
example logging curl command for CFN custom resources
View custom-resource-log.js
module.exports = async message => {
/* Custom resources have timeouts on the order of hours. If a resource fails
* to deploy, we can look at the logs to at least be able to manually fail the
* resource action so we can try again quickly. */
const failureResponse = {
Status: 'FAILED',
Reason: 'Manually cancelled',
PhysicalResourceId: message.PhysicalResourceId || 'resource',
StackId: message.StackId,
RequestId: message.RequestId,
# recompile all rbenv versions of ruby to avoid CVE-2013-6393 pwnage
# curl | bash
set -x
cd ~/.rbenv/plugins/ruby-build/
git pull
samg / earth.rb
Last active December 30, 2015 05:29
View earth.rb
module Earth
extend self
def meters_between_two_points(p1, p2)
( 6378.0 * Math.acos([
Math.cos(p1.lat_in_radians) * Math.cos(p2.lat_in_radians) *
Math.cos(p2.lng_in_radians - p1.lng_in_radians) +
Math.sin(p1.lat_in_radians) * Math.sin(p2.lat_in_radians),
].min)) * 1000
samg / notes
Created October 23, 2013 16:33
Advanced Multithreading talk at Cascadia Ruby
View notes
Jerry D'Antonio (all code, slides, and notes in a repo on github)
From Ohio
Works at a Ruby and Erlang shop.
View gist:5406046
raise 'example'
rescue Exception => exception
if defined? ::NewRelic
samg /
Created April 4, 2012 04:41 — forked from rfunduk/
OSX For Hackers
#!/usr/bin/env sh
# This is script with useful tips taken from:
# install it:
# curl -sL | sh
samg / dont_rescue_exception.rb
Created February 1, 2012 19:17
Doing it wrong
View dont_rescue_exception.rb
puts "Try ^C, or any kill signal, but I'll survive."
puts "You're going to have to kill -9 me. (Unlike other signals the kernal handles kill -9)"
loop do
sleep 1e6
rescue Exception => e
puts "Caught #{[, e].join}"
View gist:1483512
class SteelController < ActionController::Metal
include ActionController::Rendering
def show
render :text => { :data => 1 }.to_json
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :show
samg / lockfile.rb
Last active September 28, 2015 11:18
Implement a lockfile in ruby
View lockfile.rb
require 'fileutils'
path_to_lock_file = '/tmp/lock.lock', File::CREAT|File::EXCL) # raise if file already exits
system *ARGV
FileUtils.rm path_to_lock_file
View gist:1348988
self.class.trace_execution_scoped(['External/servicename/all', 'External/allWeb']) do
#your service call code here
# "External/allWeb" will cause the calls to be included in the
# green "Web External" stripe of your response time graph.
# "External/servicename/all" will enable you to see specific
# metrics in the "External services" tab, such as calls per minute and average call time.