Skip to content

Instantly share code, notes, and snippets.

@samg
samg / custom-resource-log.js
Last active Sep 3, 2019
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,
View fix-rubies.sh
#!/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
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),
1
].min)) * 1000
@samg
samg / notes
Created Oct 23, 2013
Advanced Multithreading talk at Cascadia Ruby
View notes
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.
View gist:5406046
begin
raise 'example'
rescue Exception => exception
if defined? ::NewRelic
::NewRelic::Agent.notice_error(exception)
end
end
@samg
samg / osx.sh
Created Apr 4, 2012 — forked from rfunduk/osx.sh
OSX For Hackers
View osx.sh
#!/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
#
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
begin
sleep 1e6
rescue Exception => e
puts "Caught #{[e.class.name, e].join}"
end
end
View gist:1483512
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 Sep 28, 2015
Implement a lockfile in ruby
View lockfile.rb
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
View gist:1348988
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.