Skip to content

Instantly share code, notes, and snippets.

View trak3r's full-sized avatar

Thomas "Teflon Ted" Davis trak3r

View GitHub Profile
Dear Git experts,
The other day I had made a change to my code and committed it then realized I was in an unrelated branch; I had intended to commit the change to master.
I switched to master and attempted to merge just the errant commit (by the long hash key) from the branch but that ended up merging the entire branch into master.
I blame this faux pas on my still-ingrained Subversion mentality.
Where did I go wrong? How should I have handled correcting the mistake?
$ port list | grep ruby
ruby @1.8.7-p72 lang/ruby
$ sudo port install ruby @1.8.7-p72
---> Installing ruby @1.8.6-p114_0+darwin_9+thread_hooks
WTF!?
= link_to_remote(image_tag(video.thumbnail_url, :alt => h(video.title)), :update => 'main', :url => { :action => 'wtf', :id => video.id })
# produces "/videos/wtf/77"
= link_to_remote(image_tag(video.thumbnail_url, :alt => h(video.title)), :update => 'main', :url => { :action => 'show', :id => video.id })
# produces "/videos/77"
# notice how it *removed* the 'show' action from the url!?
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
def has_role?(role)    
# if list isn't already assigned to something, create an array of the names of my roles
list ||= self.roles.map(&:name)    
# if list includes the string representation of the passed-in role [assumed to be the name] or if the list includes the string 'admin' [assumed to be the administrative role] return true
list.include?(role.to_s) || list.include?('admin')  
end
# from: http://pivotallabs.com/users/alex/blog/articles/865-monkey-patch-du-jour
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
def log_info(sql, name, ms)
if @logger && @logger.debug?
@logger.debug("#{sql}, #{name}, #{ms}")
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i}
c.gsub!("#{File.expand_path(File.dirname(RAILS_ROOT))}/", '') if defined?(RAILS_ROOT)
name = '%s (%.1fms) %s' % [name || 'SQL', ms, c]
def self.included(receiver)
receiver.class_eval <<-RUBY
named_scope :latest_before, lambda {|time| {:conditions => ['created_at < ?', time]}}
RUBY
end
@trak3r
trak3r / gist:134143
Created June 22, 2009 19:29
assert_close_enough
def assert_close_enough(target, actual, message = nil)
lower = (0.9 * target.to_f).floor
upper = (1.1 * target.to_f).ceil
full_message = build_message(message,
"<?-?> expected but was\n<?>.\n", lower, upper, actual)
assert_block(full_message) { actual >= lower and actual <= upper }
end
@trak3r
trak3r / gist:140552
Created July 4, 2009 12:17
all my gems
sudo gem install ZenTest actionmailer actionpack activerecord activeresource activesupport autotest-fsevent autotest-rails beanstalk-client capistrano capistrano-ext columnize ctran-annotate curb engineyard-eycap fastercsv fastthread highline hoe httpclient libxml-ruby linecache mysql net-scp net-sftp net-ssh net-ssh-gateway nokogiri passenger plist rack rails rake redgreen rspec rspec-rails ruby-debug ruby-debug-base rubyforge rubyist-aasm sevenwire-forgery soap4r sys-uname taf2-curb taf2-rmem thoughtbot-factory_girl
@trak3r
trak3r / gist:143349
Created July 9, 2009 01:24
where ruby hides on os x
lrwxr-xr-x 1 root wheel 76 May 21 05:31 /usr/bin/ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby