This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
NewerOlder