Skip to content

Instantly share code, notes, and snippets.

View ggoodale's full-sized avatar

Grant Goodale ggoodale

View GitHub Profile
@ggoodale
ggoodale / gist:3137
Created July 29, 2008 18:20
Using a helper method in both a controller and a view.
class ApplicationController
protected
def iphone?
request.class.to_s.include?("CgiRequest") && request.user_agent.include?('iPhone')
end
end
class ApplicationHelper
def iphone?
[3] <enki> [10:51 PM] ~>irb
>> x.blank?
NameError: undefined local variable or method `x' for main:Object
from (irb):1
>>
def foo(a=Time.now.utc)
puts a
end
foo(nil) #=> nil
foo #=> Tue Jan 13 03:22:44 -0800 2009
begin
user = User.find(:frist) #=> Bill Frist?
user.update_attribute(:alive_or_dead) #=> Care to be more specific?
rescue => e
logger.error "Something bad happened" #=> Yeah, but what?
end
begin
a = Account.find(8675309) #=> Sadly, Jenny's not a user.
rescue
# I'm so cool I don't need to do anything here.
end
# If I ever find that Tommy...
a.update_attribute(:location, "bathroom wall")
User.find(params[:id]) rescue nil #=> Don't even get me started.
>> class Session < ActiveRecord::Base; end # So we can access the sessions table directly
=> nil
>> s = Session.first
=> #<Session id: 1, session_id: "bd0568033d143fafaa1f9752c43b61d7", data: "BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g...", created_at: "2008-12-10 15:50:58", updated_at: "2008-12-10 17:50:47">
>> session_data = Marshal.load(Base64::decode64(s.data))
=> {"flash" => {}}
>> Rails.cache.write("rack:session:#{s.session_id}", session_data)
=> true
for repo in *
do
[ ! -d $repo ] && continue
[ ! -d $repo/.git ] && continue
cd $repo;
echo $repo;
git pull;
cd - > /dev/null
done
# Note that I have Rails 2.3.4 installed on this machine already.
[12] <ci> [01:17 PM] /opt/app>sudo gem install awesome_nested_set
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
Successfully installed awesome_nested_set-1.4.3
3 gems installed
Installing ri documentation for activesupport-2.3.5...
Installing ri documentation for activerecord-2.3.5...
Installing ri documentation for awesome_nested_set-1.4.3...