Skip to content

Instantly share code, notes, and snippets.

View insane-dreamer's full-sized avatar

Sean Mullen insane-dreamer

  • Intheon
  • San Diego
View GitHub Profile
@insane-dreamer
insane-dreamer / convert_links_to_html.rb
Created August 24, 2010 23:07
Convert links in plain text to html
@insane-dreamer
insane-dreamer / gist:523774
Created August 14, 2010 00:26
access current_user in an Observer
class ApplicationController < ActionController::Base
before_filter :set_current_user
private
def set_current_user
UserActionObserver.current_user = current_user
end
end
class UserActionObserver < ActiveRecord::Observer
# assuming these all have created_by_id and updated_by_id
We couldn’t find that file to show.
@insane-dreamer
insane-dreamer / gist:513339
Created August 7, 2010 23:49
find a random Item (that exists)
def self.random
photos = Photo.all.collect(&:id)
Photo.find(photos[rand(photos.length)])
end
@insane-dreamer
insane-dreamer / rake to delete attachments created with tests.rb
Created August 7, 2010 23:15
rake to delete attachments created with tests
namespace :paperclip do
desc 'deletes stale attachments (i.e., created by tests)'
task :stale => :environment do
Dir.chdir('public/system/items')
dirs = Dir.glob("[^\.]*")
items = Asset.all.collect(&:id)
count = 0
dirs.each { |d|
unless items.include?(d.to_i)
print '.'
@insane-dreamer
insane-dreamer / pastie script
Created August 4, 2010 14:26
send to pastie.org script
#!/usr/bin/ruby
# can be called with two optional arguments:
# 1. name of file to paste
# 2. programming language / parser
#
# in the absence of 1., the clipboard will be read
# in the absence of 2., the default_language (below) will be used
#
# the returning URL will be copied to the clipboard and opened in browser
@insane-dreamer
insane-dreamer / rails1_to_rails2.rake
Created April 22, 2009 01:52
Rake task to check code for upgrading from rails 1 to 2.2
# upgrading from rails 1 to 2.2
# original script by technoweenie
# additions taken from other sources including:
# http://rubythis.blogspot.com/2006/12/ruby-on-rails-deprecations-part-2.html
# http://mentalized.net/journal/2007/03/13/rails_20_deprecations/
# http://www.slashdotdash.net/2007/12/03/rails-2-upgrade-notes/
# http://www.akuaku.org/archives/2008/04/upgrading_to_ra.shtml
# Does not include checks for Rails 2.3 changes.
namespace :rails2 do