Skip to content

Instantly share code, notes, and snippets.

require "hmac"
require "hmac-sha2"
# reference:
# http://docs.amazonwebservices.com/AWSECommerceService/2009-07-01/DG/index.html?BasicAuthProcess.html
# http://docs.amazonwebservices.com/AWSECommerceService/2009-07-01/DG/index.html?Query_QueryAuth.html
module AmazonSignature
def sign_request(params)
params.reverse_merge!(:Timestamp => timestamp, :Version => "2009-07-01")
params.merge!(:Signature => build_signature(params, "GET"))
desc 'partition photo ids'
task :partition_photo_ids => :environment do
for p in Photo.all
base_path = p.data.path.split(p.id.to_s).first
orig_path = base_path + p.id.to_s
if FileTest.directory?( orig_path )
new_path = base_path + ("%09d" % p.id).scan(/\d{3}/).join("/")
`mkdir -p #{new_path} && mv #{orig_path}/* #{new_path} && rmdir #{orig_path}`
else
p.destroy
@briandunn
briandunn / gist:513318
Created August 7, 2010 23:29
/etc/firewall.user
# This assumes your gateway is an OpenWRT box at 192.168.1.1,
# your lan is 192.168.1.0/24,
# and your OpenWRT stock chains are intact.
# It is different than the built in /etc/config/firewall rules in that it allows you to address
# your linux box at example.com, whether your request originates from within your lan, or from outside.
WIN_XP_HOST=192.168.1.184
LINUX_HOST=192.168.1.202
WWW_NAME=example.com
@briandunn
briandunn / embacon.js
Created June 16, 2011 22:26
Insert some meaty dummy text
(function(){
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.type='text/javascript';
script.src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
script.onload = function() {
var $active = $(document.activeElement)
$active.css({cursor: 'wait'})
$.getScript('http://baconipsum.com/wp-includes/js/l10n.js', function() {
$.get('http://baconipsum.com/?paras=1&type=all-meat', function(data) {
@briandunn
briandunn / rip_longest.rb
Created February 7, 2012 16:25
Returns the location of the 10 longest methods. 1.9 only
require 'pathname'
require 'ripper'
module LongestMethod
class Method < Struct.new(:location, :size)
def self.add(line_number, token_count)
(@methods ||= []).push new(line_number, token_count)
end
def to_s
@briandunn
briandunn / gist:1903192
Created February 24, 2012 19:36
Lothesome Nokogiri xmlns
xml = %|<?xml version="1.0" ?><foo xmlns="http://www.github.com"><bar/></foo>|
doc = Nokogiri xml
# Namespace is making me sad :(
doc.xpath '//bar'
# => []
# I can introduce a new name for a namespace and use it in my query
doc.xpath '//corprate-douche:bar', 'corprate-douche' => 'http://www.github.com'
# => [#<Nokogiri::XML::Element name="bar" namespace=#<Nokogiri::XML::Namespace href="http://www.google.com">>]
@briandunn
briandunn / hdb.rake
Created August 10, 2012 19:21
Heroku database tasks
# Tasks for working with your heroku database.
#
# These won't work until you enable the (free) pgbackups addon:
#
# heroku addons:add pgbackups
#
#
# Examples:
#
# Replace development DB with a fresh capture from Heroku
@briandunn
briandunn / QuickFix notes
Last active December 28, 2015 08:29
Notes on my QuickFix talk at VimChi
QuickFix
--------
Overview:
rational: Vim has a lot of great ways to navigate a project. But if your computer already knows where the problem is, we should be able to jump straight there without searching again.
:help quickfix
Supports "edit-compile-edit"
Inspired by an Amega compiler
def get_step_name(scenario)
if Cucumber::Ast::OutlineTable::ExampleRow === scenario
outline = scenario
return outline.backtrace_line
else
scenario.instance_variable_get :@current_step
visitor = scenario.instance_variable_get :@current_visitor
listeners = visitor.instance_variable_get :@listeners
formatter = listeners.first
step = formatter.instance_variable_get :@current_step
# project Ardour3 (3.5.357) configured on Fri Apr 4 11:02:56 2014 by
# waf 1.6.11 (abi 98, python 20706f0 on darwin)
# using ./waf configure
#
----------------------------------------
Setting top to
/Users/brian/src/ardour
----------------------------------------
Setting out to
/Users/brian/src/ardour/build