Skip to content

Instantly share code, notes, and snippets.

View tjh's full-sized avatar

Tim Harvey tjh

View GitHub Profile
# Monkeypatch paperclip to handle local file attachment. Didn't add this to
# the class itself as we only need local loading during the population
AssetItem.class_eval do
require 'open-uri'
attr_accessor :source_filename, :source_url, :source_path, :existing_cache_file, :new_cache_file
before_validation :import_source_file, :if => :source_filename_provided?
private
Order.class_eval do
def has_site_approvals?
line_items.each do |item|
return true if item.approval && item.approval.approved?
end
false
end
end
Approval.class_eval do
#
# EC2 / Chef command cheat sheet
#
# Uses cookbooks and templates from:
# http://github.com/tjh/chef-repo
# Fire up a new instance on EC2
# - Super-fast large instance
# - Uses a template that uses RVM/REE for the system ruby (optional)
var delay = 5000;
var transition = 40;
var imageContainer = 'jw-sir';
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
function init() {
if(!d.getElementById || !d.createElement)return;
imgs = d.getElementById(imageContainer).getElementsByTagName("img");
for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
imgs[0].style.display = "block";
# -----------------------------------------
# Cucumber formatter that outputs the file
# and line number for each test.
#
# Useful for Hudson CI which only flushes
# the output to the log after a line return
# so that you can see what's failed before
# a long build finishes.
# -----------------------------------------
#
# This method allows the app to figure out what username and password were passed
# via basic http auth. Because calling #authenticate_or_request_with_http_basic will
# fail if no password was sent, I had to hack in my own check (taken from the Rails
# source) to make sure that they tried to auth.
def get_credentials
log_it
# Grabbed from the rails source...if the user sent auth data...
if ( request.env['HTTP_AUTHORIZATION'] ||
set autolist
set autoeval
set autoreload
Comment styles
comh1
# #######################################################
#
#
#
# #######################################################
class Tweet < ActiveRecord::Base
def self.latest_text
if Tweet.first.nil? || Tweet.first.created_at < ENV['CACHE_TIMEOUT'].to_i.minute.ago
begin
httpauth = Twitter::HTTPAuth.new(ENV['TWITTER_USR'], ENV['TWITTER_PWD'])
client = Twitter::Base.new(httpauth)
Tweet.delete_all
client.user_timeline.each do |tweet|
# -----------------------------------------
# Oh My Zsh theme
# -----------------------------------------
# Inspired by "xiong-chiamiov" and "robbyrussell"
# Looks like:
# ┌─[tharvey@macbook] - [~/code/test_project] - [git:master ✗ Changed ✗]
# └─[$]>➜