Skip to content

Instantly share code, notes, and snippets.


Tim Ruffles timruffles

View GitHub Profile
View quicker github repos init
# make your repos on github
git clone
# Initialized empty Git repository in /Users/timruffles/Development/CapistranoLearning/.git/
# warning: You appear to have cloned an empty repository.
touch README
nano README # add readme
git add .
git commit -m 'Initial import'
git push origin master
View Configable.rb
require 'net/http'
require 'yaml'
module Configable
def configure(setup)
setup.each_pair do |key,val|
if self.respond_to? key + '='
self.send(key + '=', val)
instance_variable_set('@' + key, val)
timruffles / build_report.html.erb
Created Nov 2, 2010
Makes commit hashes and pivotal ids clickable - only need to pull in project github url
View build_report.html.erb
# cruisecontrol/app/views/build_mailer/build_report.html.erb
<% if Configuration.dashboard_url -%>
<%= @message %>
require 'uri'
repos = URI.parse(@build.project.source_control.repository)
for_viewing_url = "https://#{}#{repos.path.gsub(/\.git\/?$/,'')}"
View gist:706738
height: 70px;
overflow: hidden;
zoom: 1;
background: $main_bg;
color: #fff;
font-size: 12px;
margin-bottom: 10px;
View application_controller.rb
# To specify custom behavior that will be taken if the validation fails, pass a block to this method.
# It'll be called with |reason, default_action_as_proc|
def validate_rights(action, object = nil, message = nil)
@validate_rights_has_been_called = true
return true if action == :unprotected
take_action = false
respond_to do |format|
if !logged_in?
reason = :not_logged_in
format.html do
View useage_example.rb
def user_allowed_to_deposit?
validate_rights :deposit do |reason, default|
if reason == :acl_failed
flash[:notice] = "We need to verify your identity before you can deposit."
timruffles / bonus_confusion_smell.rb
Created Nov 30, 2010
this is fattening for our controllers, and should be encapsulated
View bonus_confusion_smell.rb
previous_last_bonus = @user.bonuses.any? && @user.bonuses.last
if !problems && @user.save_with_identity(@identity)
flash[:notice] = "The user has been updated."
if @user.bonuses.any? && @user.bonuses.last.bonus_offer.is_bet_for_free? && @user.bonuses.last != previous_last_bonus
flash[:notice] += " We have awarded the bet for free bonus for the user."
timruffles / switchy_views.rb
Created Nov 30, 2010
This view is way too smart... It'd be great to remove it all to helpers and plugins, but most important is BonusOffer.signup.enabled? && ! current_user.identity_verified?, buiz logic that is in the view :(
View switchy_views.rb
if not logged_in?
# Log in
# A button for each stake
@real_game.stake_amounts.sum do |stake_amount|
render 'games/buttons/login_to_play_stake', :stake_amount => stake_amount
elsif current_user.has_enough_funds_to_bet?
timruffles /
Created Dec 8, 2010
Have a lot of failing things from cuce and can't be bothered to re-run? Copy this out of terminal, paste into a variable, and run this one liner'
# assign failers via export FAILERS = '
# paste after opening the quote, and close after the pasted contents
echo $FAILERS | ruby -e 'puts"cucumber").map {|l| l.gsub(/^ (\S*):\d*.*/,"\\1")}.uniq.join(" ")'
timruffles / sinatra_awesome_css_js_html.rb
Created Dec 12, 2010
Lets you use haml, sass and coffee script from Sinatra by compiling on demand
View sinatra_awesome_css_js_html.rb
# sass handler
get /\/(.*)\.css/ do |stylesheet|
headers 'Content-Type' => 'text/css; charset=utf-8'
sass stylesheet.to_sym
# coffee script handler
get %r{/(.*)\.js} do |js|
# compile coffee script and place in respective JS folder
coffee = "#{ROOT_DIR}/js/#{js}.coffee"
You can’t perform that action at this time.