This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
print "Hello World!\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# :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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment" | |
class Rails::Boot | |
def run | |
load_initializer | |
extend_environment | |
Rails::Initializer.run(:set_load_path) | |
end | |
def extend_environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/spec_helper' | |
describe "The library itself" do | |
Spec::Matchers.define :have_no_tab_characters do | |
match do |filename| | |
@failing_lines = [] | |
File.readlines(filename).each_with_index do |line,number| | |
@failing_lines << number + 1 if line =~ /\t/ | |
end | |
@failing_lines.empty? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rack' | |
require 'ruby-debug' | |
class Rack::Nest | |
attr_reader :app | |
def initialize(app, options={}, &block) | |
@path = options[:path] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Person has_many cards has_many transaction_feeds. | |
# I would like to find all of the people with at least one transaction feed with the is_ach bool set to true: | |
SELECT DISTINCT(people.id) AS person_id FROM `people` | |
INNER JOIN `cards` ON cards.person_id = people.id | |
LEFT JOIN `transaction_feeds` ON transaction_feeds.card_id = cards.id | |
WHERE (transaction_feeds.is_ach = 1) | |
GROUP BY person_id | |
HAVING COUNT(transaction_feeds.id) = 0; | |
# This works. |
OlderNewer