Skip to content

Instantly share code, notes, and snippets.

View joelr's full-sized avatar

Joel Richards joelr

View GitHub Profile
anonymous
anonymous / auto_orient.rb
Created May 10, 2010 19:27
module Paperclip
class AutoOrient < Paperclip::Processor
def initialize(file, options = {}, *args)
@file = file
end
def make( *args )
dst = Tempfile.new([@basename, @format].compact.join("."))
dst.binmode
@jamiew
jamiew / Unicorn capistrano deploy.rb
Created October 6, 2010 07:36
bundler, memcached, chef, log tailing and delayed job workers
# capistrano deployment
require "bundler/capistrano"
require "capistrano/ext/multistage"
set :stages, %w(canary production)
set :default_stage, "canary"
set :application, "lolcats"
set :deploy_to, "/srv/#{application}"
@anolson
anolson / sendfile.rb
Created August 26, 2011 21:01
Upload a file to Strava
#!/usr/bin/env ruby
require 'net/smtp'
require 'optparse'
module SendFile
class CommandlineOptions
attr_accessor :options
@bkayser
bkayser / account.rb
Created May 10, 2012 00:05
Example of monitoring a ruby background job with New Relic
class Account
include NewRelic::Agent::MethodTracer
def check_usage
end
def send_invoice
end
add_method_tracer :check_usage
require "securerandom"
class RollingCounter
# :call-seq: RollingCounter.new(redis_client, max_window_seconds) -> counter
#
# Create a new counter instance, that will store/retrieve counts with
# +redis_client+ and return counts within the last +max_window_seconds+
# seconds.
#
config.jobs = ActiveSupport::OrderedOptions.new
# Controls whether or not workers report heartbeats
config.jobs.heartbeat_enabled = true
# How often workers should send heartbeats
config.jobs.heartbeat_interval_seconds = 60
# How long a worker can go without sending a heartbeat before they're considered dead
config.jobs.heartbeat_timeout_seconds = 3 * 60
# How often to check for dead workers
config.jobs.dead_worker_polling_interval_seconds = 60
@gljeremy
gljeremy / disconnect.rb
Created September 21, 2011 14:03 — forked from tmcw/disconnect.rb
bulk-export run data from Garmin Connect
#!/usr/bin/env ruby
## disconnect
# ./disconnect.rb -u yourusername [-o /your/path] [-p yourhttpproxyserver]
#
# This is a command-line utility for the bulk-downloading of run data from
# the connect.garmin.com web application, which has lackluster export
# capabilities.
#
#!/bin/bash
# ansible-vault-git-diff -- show what changed in a vaulted file at a specific commit
commit="$1"
file="$2"
if [ -z "$2" ]; then
echo "Usage: $0 <commit> <file>"
exit 1
fi
@joost
joost / change_s3_metadata.rb
Last active August 26, 2016 01:40
Change metadata on existing S3 files
# Using v1 of Ruby aws-sdk as currently v2 seems not able to do this (broken?).
require 'aws-sdk-v1'
key = YOUR_AWS_KEY
secret = YOUR_AWS_SECRET
region = YOUR_AWS_REGION
AWS.config(access_key_id: key, secret_access_key: secret, region: region)
s3 = AWS::S3.new
bucket = s3.buckets[bucket_name]
@timblair
timblair / gist:942151
Created April 26, 2011 12:09
National Rail really is run by a bunch of monkeys...
$ curl --silent -i http://ojp.nationalrail.co.uk/ | grep 'Powered-By'
X-Powered-By: An infinite number of monkeys