Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile
@dbrady
dbrady / ps1.bash
Created March 22, 2011 20:39
Dave Brady's PS1
# ALARM: production/master RED: stage YELLOW: next CYAN: everybody else
export PS1="\D{%H:%M:%S} \[\033[37m\]\u@\h\[\033[32m\]:\w \$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\\033[36m(\1)/' | sed -e 's/(production)/\\033[1;37m\\033[41m(production)\\033[m/' | sed -e 's/(master)/\\033[1;37m\\033[41m(master)\\033[m/' | sed -e 's/(stage)/\\033[31m(stage)/' | sed -e 's/(next)/\\033[33m(next)/')\[\033[37m\]\[\033[0m\] \n∫ "
@dbrady
dbrady / backup_dir.el
Created April 4, 2011 21:01
Potty-train emacs to stop littering the fs tree with ~ files
;; Do civilized backup names. Added by dbrady 2003-03-07, taken from
;; http://emacswiki.wikiwikiweb.de/cgi-bin/wiki.pl?BackupDirectory
;;
;; Don't forget to mkdir ~/saves
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
@dbrady
dbrady / about_scoring_projects.rb
Created April 13, 2011 23:36
Dice Scoring in a single expression
def score(dice)
(1..6).map {|i| (dice.count(i)/3) * i * 100 }.inject {|a,b| a+b} + (dice.count(1)/3) * 900 + (dice.count(1)%3)*100 + (dice.count(5)%3)*50
end
# Wait, what? Back that shit up a minute.
#
# Reconsider the rules of Greed as follows:
# 1. Score each triple of value k as k*100. This gives a correct score for all triples EXCEPT 1's--we're 900 points short.
# 2. Add in a 900-point bonus for each triple of 1's
# 3. Add 100 points for each 1 NOT in a triple
@dbrady
dbrady / tourbus.bash
Created May 4, 2011 21:40
tourbus in 3 steps
# Crush your website in 3 easy steps with TourBus!
# 1. get tourbus. Latest isn't in rubygems yet.
# If you don't have bundler, make sure you have the reqs.
git clone https://github.com/dbrady/tourbus.git &&
cd tourbus &&
bundle install &&
gem build tourbus.gemspec &&
gem install tourbus-2.0.0.gem
@dbrady
dbrady / Gemfile
Created May 17, 2011 17:55
Crashy Gemfile
source :rubygems
gem "rails", "2.2.2"
gem "rspec-rails", "1.1.12"
gem "rspec", "1.1.12"
gem "rspec-rails", "1.1.12"
gem "trollop", "1.12"
gem "utility_belt", "1.1.0"
gem "will_paginate", "2.3.14"
gem "wirble", "0.1.3"
@dbrady
dbrady / reports_controller.rb
Created May 18, 2011 04:05
ReportsController - Rails 1.2, circa 2008
class ReportsController < ApplicationController
layout 'home'
def last_login
if current_user.can_view_login_report?
@execs = Acl.find(:all, :include => :user, :conditions => ["access_type='Airport' AND access_id=#{current_airport_id}"]).map { |a| a.user }
operators = Operator.find_all_by_airport_id(current_airport[:id])
@opers = Acl.find(:all, :include => :user, :conditions => ["access_type='Operator' AND access_id IN (?)", operators]).map { |a| a.user }
stores = Store.find_all_by_airport_id(current_airport[:id])
@vendors = Acl.find(:all, :include => :user, :conditions => ["access_type='Store' AND access_id IN (?)", stores]).map { |a| a.user }
@users = @execs + @opers + @vendors
@dbrady
dbrady / snip.sh
Created May 21, 2011 18:44
Rails 3.1 edge nonworky?
# We did a bundle install, and rails seems to install, but weirdness then happens...
# Note that it is in the path, but doesn't run, and gem list doesn't show it as installed.
#
# Halp?
12:40:13 dbrady@shinything:~/shiny_systems/1on1/ian ruby-1.9.2-p180@ian
∫ which rails
/Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/bin/rails
12:40:36 dbrady@shinything:~/shiny_systems/1on1/ian ruby-1.9.2-p180@ian
@dbrady
dbrady / error.log
Created May 21, 2011 22:52
devise install error
# THIS IS FIXED! TL;DR: Sprockets has a bug in betas 3, 4, and 5, roll back to beta 2.
#
# See: http://umwhatnow.com/rails-fix-your-3-1-beta-1-sprockets-problem/
#
# Wots of wuv, Dave and Bwandon
∫ rails g devise_install
/Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/actionpack-3.1.0.beta1/lib/sprockets/railtie.rb:37:in `block (2 levels) in <class:Railtie>': undefined method `context' for #<Sprockets::Environment:0x0000010098f840> (NoMethodError)
from /Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/activesupport-3.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/activesupport-3.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
@dbrady
dbrady / csv_tests.rb
Created May 26, 2011 06:05
Unit Tests for CSV demonstrating that Enumerable is supported only at the whim of the underlying StringIO seek position
#!/usr/bin/env ruby
unless RUBY_VERSION.start_with? "1.9"
puts "This test file is for Ruby 1.9.x"
exit -1
end
require 'csv'
require 'test/unit'
@dbrady
dbrady / gist:1021248
Created June 12, 2011 04:17
FizzBuzz!
Transcript clear.
(1 to: 100) do: [ :i | (i \\ 15 = 0)
ifTrue: [Transcript show: 'FizzBuzz']
ifFalse: [
(i \\ 3 = 0)
ifTrue: [ Transcript show: 'Fizz']
ifFalse: [
(i \\ 5 = 0)
ifTrue: [ Transcript show: 'Buzz' ]
ifFalse: [Transcript show: i].