Skip to content

Instantly share code, notes, and snippets.

View mikehale's full-sized avatar

Michael Hale mikehale

  • Heroku
  • Holly Springs, NC
View GitHub Profile
@mikehale
mikehale / deploy.rb
Created July 22, 2008 19:55
capistrano recipe for working with slicehost dns api
load 'config/dns'
set :ip, '127.0.0.1'
set :domains, %w(example.net. example.com. example.org.)
@mikehale
mikehale / app.rb
Created April 22, 2014 20:43
Workaround for sinatra-assetpack with SSL
require 'sinatra'
require 'rack-test-ext'
configure :production do
use Rack::SSL
Rack::Test::Session.custom_env['HTTPS'] = 'on'
end
assets do
css :application, [ '/css/app.css' ]
@mikehale
mikehale / cloud.cfg
Created August 7, 2014 14:15
Commented cloud.cfg
$ cat cloud-init_0.7.5/etc/cloud/cloud.cfg
# The top level settings are used as module
# and system configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
- default
@mikehale
mikehale / backoff_when_throtted.rb
Created September 17, 2014 04:16
Excon middleware to exponentially backoff when throttled by AWS APIs
require 'fog'
class BackoffWhenThrottled < Excon::Middleware::Base
def error_call(datum)
datum[:throttle] ||= {}
datum[:throttle][:max_retries] ||= 0
datum[:throttle][:max_delay] ||= 30
datum[:throttle][:retry_count] = 0
if throttled?(datum)
#!/usr/bin/env ruby
require "excon"
require "active_support"
require "active_support/subscriber"
# Translates excon instrumentation events into rails style with
# namespace last. Yuck!
class ExconToRailsInstrumentor
def self.instrument(name, datum, &block)
$ ruby
loop {
begin
begin
exit 1
ensure
p $!
raise "foo"
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.jasf.beamoff</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/beamoff.app/Contents/MacOS/beamoff</string>
</array>
#!/usr/bin/env ruby
# Shows the physical location of each disk
DEVICE_NAME = "sata_sil24"
FORMAT = {
:scsi_id => 0..12,
:media => 13..20,
:bus => 21..29,
:model => 30..46,
@mikehale
mikehale / gist:7a66ba17ba9f074046d9
Last active August 29, 2015 14:22
restore old syncthing versions
# Specific dir
cd ~/Sync/.stversions
cp foo ~/Sync/foo
cd ~/Sync/foo
find . -name '*~20150604*' -type f |ruby -rfileutils -e 'mappings = STDIN.read.split($/).map{|s| s =~ /^(.+)~\d{8}-\d{6}(.*)/; d = [$1, $2].join; [s,d]}; mappings.each{|s,d| FileUtils.mv(s,d, noop: false, verbose: true)}'
# Scan for version files
cd ~/Sync
find . ! -path './.stversions/*' -name '*~20150604*' -type f
#This can be used as a sake task
desc "Install a database.yml if non exists"
task :add_database_yml do
database_yml = %(env: &env
adapter: sqlite3
timeout: 5000
development: