Skip to content

Instantly share code, notes, and snippets.

# Three things to add:
# * before_filter call
# * action_has_layout? method (if you have one, combine them)
# * adjust_for_inline
#
class ApplicationController < ActionController::Base
# ...
before_filter :adjust_for_inline
@hughevans
hughevans / gist:161109
Created August 4, 2009 08:33
Convert your Pivotal Tracker iterations to a textile table
require 'rubygems'
require 'activeresource'
PROJECT_ID = 123
TOKEN = 'token'
class Iteration < ActiveResource::Base
self.site = "http://www.pivotaltracker.com/services/v2/projects/#{PROJECT_ID}"
headers['X-TrackerToken'] = TOKEN
end
chruby () {
v=`ruby -e "puts RUBY_VERSION.split('.')[0,2].join('.')"`
if [ $v = "1.9" ]; then
cv="1.8"
else
cv="1.9"
fi
rubyexes=(erb gem irb rake rdoc ri ruby testrb)
for i in ${rubyexes[*]}; do
sudo unlink "/opt/local/bin/${i}"
@hughevans
hughevans / gist:191062
Created September 22, 2009 13:26
My first Arduino sketch
// Knobber
// Hook up a potentiometer to tri-color LED
int redPin = 9; // red LED, digital pin 9
int greenPin = 10; // green LED, digital pin 10
int bluePin = 11; // blue LED, digital pin 11
int potPin = 0; // potentiometer, analog pin 0
int redVal = 1;
int greenVal = 1;
# An experiment at using typhoeus with ActiveResource. It's currently not very
# useful (in fact it seems slower). Somehow using the queueing will be the trick
require 'typhoeus'
module ActiveResource
class Connection
def get(path, headers = {})
format.decode(Typhoeus::Request.get(@site.host + path, :headers => authorization_header).body)
end
@hughevans
hughevans / Results
Created March 16, 2012 05:31
String concat speed.
user system total real
0.050000 0.000000 0.050000 ( 0.043481)
0.100000 0.010000 0.110000 ( 0.107440)
0.060000 0.000000 0.060000 ( 0.062976)
@hughevans
hughevans / gist:2048694
Created March 16, 2012 05:39
Reject blank/empty strings before joining with a space.
[' ', 'Evans'].reject(&:blank?).join ' '
@hughevans
hughevans / 404.html.erb
Created May 7, 2012 08:39
A rake task to bake out a 404.html and 500.html into your public directory when doing a `rake assets:precompile`.
<!-- this goes in app/assets/html/404.html.erb -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<%= stylesheet_link_tag 'application', :media => 'all' %>
<%= javascript_include_tag 'modernizr' %>
</head>
<body>
var showBody = function() {
return $.Deferred(function(def) {
$("body").fadeIn(1000, def.resolve);
});
};
showBody().then(function() {
console.log("body faded in now, let’s dance.");
});
@hughevans
hughevans / gist:3082625
Created July 10, 2012 10:47 — forked from mtcmorris/gist:3082609
20 top films in the past 5 years
The Artist
Senna
Hanna
Headhunters (Hodejegerne)
The Help
Best Exotic Marigold Hotel
District 9 <- Fookin’ prawns!
Crazy Stupid Love
The Social Network
Black Swan