Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@terrainoob
terrainoob / custom_steps.rb
Created May 6, 2009 14:20
Cucumber subdomain testing
Given /^I visit subdomain (.+)$/ do |sub|
host! "#{sub}.#{TEST_DOMAIN}" #TEST_DOMAIN is defined in test.rb. In my case TEST_DOMAIN = 'example.com'
end
class ApplicationController < ActionController::Base
include Intercession
before_filter :load_skin
before_filter :require_user
before_filter :require_matching_skin
before_filter :require_admin
def load_skin
session.skin = Skin.for_request(request)
@airblade
airblade / html.rb
Created May 12, 2010 09:02 — forked from mislav/html.rb
require 'nokogiri'
ugly = Nokogiri::HTML ARGF
tidy = Nokogiri::XSLT File.open('tidy.xsl')
nice = tidy.transform(ugly).to_html
puts nice
# Rackup file for serving up a static site from a "public" directory
#
# Useful for chucking a static site on Heroku
class IndexRewriter
def initialize(app) @app = app end
def call(env)
env["PATH_INFO"].gsub! /\/$/, '/index.html'
@app.call(env)
end
@pwim
pwim / dateinput_converter.js
Created November 19, 2010 06:21
Convert Rails style date input to jQuery Tools' dateinput
// Based on http://snipt.net/boriscy/datetime-jquery-formtastic/
$.tools.dateinput.localize("ja", {
months: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
shortMonths: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
days: '日曜日,月曜日,火曜日,水曜日,木曜日,金曜日,土曜日',
shortDays: '日,月,火,水,木,金,土'
});
$.tools.dateinput.conf.format = 'yyyy-mm-dd';
@caged
caged / stale.rb
Created January 4, 2011 20:11
Quick script to help you find and deal with old watched repos, forks and owned repos.
#!/usr/bin/env ruby
#
# Quick hack to help you find and deal with old watched repos, forks and owned repos.
#
# It will ask you to confirm once if you want to unwatch a repo.
#
# You can't unwatch your own repos, so they will need to be deleted.
# THIS SCRIPT WILL ASK YOU FOR CONFIRMATION TWICE BEFORE IT DELETES A REPO.
#
require 'rubygems'
Object.class_eval do
def self.method_added(name)
raise "You forgot to spell initialize the American way, again." if :initialise == name
end
end
class A
def initialise
<<-LRUG Hola El Rug,
Here's a little teaser for you...
I have two sets of photos; we'll call them urban and nature. Both sets contain about 6-9 photos, but not necessarily the same number.
I also have about 15-20 pages on a site, spread more or less evenly across three sections. Each page has a title unique to its section (and, if it helps, we can assume unique across all the pages).
On each page I want to display one photo from each set.
@namxam
namxam / gist:970361
Created May 13, 2011 11:11
typhoeus example
require 'rubygems'
require 'typhoeus'
hydra = Typhoeus::Hydra.new
# Create all your requests
request = Typhoeus::Request.new("http://your_image_url")
request.on_complete do |response|
# Check if the returned data really is an image