Skip to content

Instantly share code, notes, and snippets.

named_scope :matches, lambda { |value| {
:select => sanitize_sql(["addresses.*, match(value) against(? in boolean mode) as relevancy", wildcardize(value)]),
:conditions => ["match(value) against(? in boolean mode)", wildcardize(value)],
# truncates html text to the desired text length.
# Like the Rails _truncate_ helper but doesn't break HTML tags or entities.
#
# accepts options:
# :link_to => url
def truncate_html(text, max_length = 400, options = {})
elipsis = '…'
tag_delimiter_count = 0
in_html_entity = false
character_count = 0
@ddollar
ddollar / template.rb
Created July 20, 2009 15:51
Rails Template
# Rails Template
require 'open-uri'
def download(from, to = from.split("/").last)
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
end
# :PUBLISHER: markdown, shell, { command: 'rdiscount' }
# :BRACKET_CODE: '[ruby]', '[/ruby]'
# :TEXT:
#
# Have you ever started a long operation and walked away from the computer, and
# come back half an hour later only to find that the process is hung up waiting
# for some user input? It's a sub-optimal user experience, and in many cases it
# can be avoided by having the program choose a default if the user doesn't
# respond within a certain amount of time. One example of this UI technique in
# the wild is powering off your computer - most modern operating systems will
desc "Migrate all of the databases"
task :migrate_all => :environment do
Customer.connect_each do |customer|
puts "Migrating #{customer.environment}"
ActiveRecord::Migrator.migrate "db/migrate/"
end
end
@ddollar
ddollar / test.pl
Created July 23, 2008 15:07 — forked from maio/test.pl
use strict;
print "Hello World!\n";