Skip to content

Instantly share code, notes, and snippets.

@samg
samg / custom-resource-log.js
Last active January 31, 2024 23:34
example logging curl command for CFN custom resources
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,
#!/bin/bash
# recompile all rbenv versions of ruby to avoid CVE-2013-6393 pwnage
# https://groups.google.com/forum/#!topic/rubysec-announce/3sx25iR7yHQ
#
# curl https://gist.github.com/samg/9098647/raw | bash
set -x
cd ~/.rbenv/plugins/ruby-build/
git pull
@samg
samg / earth.rb
Last active December 30, 2015 05:29
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),
1
].min)) * 1000
@samg
samg / notes
Created October 23, 2013 16:33
Advanced Multithreading talk at Cascadia Ruby
Jerry D'Antonio
github.com/jdantonio (all code, slides, and notes in a repo on github)
@jerrydantonio
From Ohio
Works at a Ruby and Erlang shop.
begin
raise 'example'
rescue Exception => exception
if defined? ::NewRelic
::NewRelic::Agent.notice_error(exception)
end
end
@samg
samg / osx.sh
Created April 4, 2012 04:41 — forked from rfunduk/osx.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with useful tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2263406/osx.sh | sh
#
@samg
samg / dont_rescue_exception.rb
Created February 1, 2012 19:17
Doing it wrong
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
begin
sleep 1e6
rescue Exception => e
puts "Caught #{[e.class.name, e].join}"
end
end
class SteelController < ActionController::Metal
include ActionController::Rendering
def show
render :text => { :data => 1 }.to_json
end
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :show
end
@samg
samg / lockfile.rb
Last active September 28, 2015 11:18
Implement a lockfile in ruby
require 'fileutils'
begin
path_to_lock_file = '/tmp/lock.lock'
File.new(path_to_lock_file, File::CREAT|File::EXCL) # raise if file already exits
begin
system *ARGV
ensure
FileUtils.rm path_to_lock_file
end
self.class.trace_execution_scoped(['External/servicename/all', 'External/allWeb']) do
#your service call code here
end
# "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.