Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
# http://railscasts.com/episodes/126-populating-a-database
# http://github.com/ryanb/populator/tree/master
namespace :db do
task :populate => :environment do
require 'populator' # http://populator.rubyforge.org/
require 'faker' # http://faker.rubyforge.org/rdoc/
[User, Event, Link].each(&:delete_all)
def random(model)
# config/initializers/log_protected_attribute_removal.rb
# raises an exception in test environment when trying to mass assign protected attributes
# detail: http://railspikes.com/2008/9/22/is-your-rails-application-safe-from-mass-assignment
if RAILS_ENV == 'test'
ActiveRecord::Base.class_eval do
def log_protected_attribute_removal(*attributes)
raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}"
end
# Time zone issues with BJ, Rails, and UTC/local times?
# http://codeforpeople.rubyforge.org/svn/bj/trunk/README
# http://twitter.com/rubyist/statuses/957131155
# http://twitter.com/technoweenie/statuses/957156761
# config/initializers/bj_table_hack.rb
Bj::Table.class_eval do
def self.time_zone_aware_attributes
false
~ $ sudo gem install merb
Password:
Building native extensions. This could take a while...
Successfully installed extlib-0.9.8
Successfully installed thor-0.9.7
Successfully installed merb-core-0.9.9
Successfully installed merb-action-args-0.9.9
Successfully installed merb-assets-0.9.9
Successfully installed merb-auth-core-0.9.9
Successfully installed merb-auth-more-0.9.9
~ $ sudo gem install rails
Password:
Successfully installed rails-2.1.1
1 gem installed
class Foo
attr_accessor :bar
def initialize(bar)
@bar = bar
end
def doit
puts bar
bar = "*** #{bar} ***"
require 'etc'
class Group
def foo
"hello"
end
end
class WTF < Struct.new(:var)
def foo
# http://github.com/jnunemaker/httparty/
require 'rubygems'
require 'httparty'
class Delicious
include HTTParty
base_uri 'https://api.del.icio.us/v1'
def initialize(u, p)
@auth = {:username => u, :password => p}
@trevorturk
trevorturk / gist:34895
Created December 11, 2008 21:56
Allow "uploads via url" with Rails and Paperclip
#
# See also: http://almosteffortless.com/2008/12/11/easy-upload-via-url-with-paperclip/
#
# Allow "uploads via url" with Rails and Paperclip
#
# http://www.thoughtbot.com/projects/paperclip
# http://github.com/thoughtbot/paperclip/tree/master
# http://groups.google.com/group/paperclip-plugin/browse_thread/thread/456401eb93135095
#
# This example is designed to work with a "Photo" model that has an "Image" attachment