Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
# make your repos on github
git clone git@github.com:YOU/NEW_REPOS.git
# 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
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)
else
instance_variable_set('@' + key, val)
@timruffles
timruffles / build_report.html.erb
Created November 2, 2010 13:10
Makes commit hashes and pivotal ids clickable - only need to pull in project github url
# cruisecontrol/app/views/build_mailer/build_report.html.erb
<% if Configuration.dashboard_url -%>
<%= @message %>
CHANGES
-------
<%
require 'uri'
repos = URI.parse(@build.project.source_control.repository)
for_viewing_url = "https://#{repos.host}#{repos.path.gsub(/\.git\/?$/,'')}"
div#comwrapper{
position:relative;
height: 70px;
overflow: hidden;
zoom: 1;
background: $main_bg;
color: #fff;
font-size: 12px;
margin-bottom: 10px;
# 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
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."
redirect_to(new_account_idcheck_path)
else
default.call
end
end
end
@timruffles
timruffles / bonus_confusion_smell.rb
Created November 30, 2010 18:11
this is fattening for our controllers, and should be encapsulated
end
end
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."
end
@timruffles
timruffles / switchy_views.rb
Created November 30, 2010 18:14
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 :(
<%=
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
end
elsif current_user.has_enough_funds_to_bet?
@timruffles
timruffles / runnable_cuke_failers.sh
Created December 8, 2010 11:54
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 STDIN.read.split("cucumber").map {|l| l.gsub(/^ (\S*):\d*.*/,"\\1")}.uniq.join(" ")'
@timruffles
timruffles / sinatra_awesome_css_js_html.rb
Created December 12, 2010 13:59
Lets you use haml, sass and coffee script from Sinatra by compiling on demand
# sass handler
get /\/(.*)\.css/ do |stylesheet|
headers 'Content-Type' => 'text/css; charset=utf-8'
sass stylesheet.to_sym
end
# coffee script handler
get %r{/(.*)\.js} do |js|
# compile coffee script and place in respective JS folder
coffee = "#{ROOT_DIR}/js/#{js}.coffee"