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
def freq(letter) | |
freq_dict = {"a" => 8.167, | |
"b" => 1.492, | |
"c" => 2.782, | |
"d" => 4.253, | |
"e" => 12.702, | |
"f" => 2.228, | |
"g" => 2.015, | |
"h" => 6.094, | |
"i" => 6.966, |
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
class ActionMailer::Base | |
@@name_regex = '[\w\.%\+\-]+'.freeze | |
@@dom_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze | |
@@dom_tld_regex = '(?:com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum|[A-Z]{2})'.freeze | |
@@carated_regex = /\A.*<\s*(#{@@name_regex}@#{@@dom_head_regex}#{@@dom_tld_regex})\s*>.*\z/i | |
@@uncarated_regex = /\A\s*(#{@@name_regex}@#{@@dom_head_regex}#{@@dom_tld_regex})\s*\z/i | |
def valid_recipient(s) | |
addr = $1 if s=~@@carated_regex || s=~@@uncarated_regex | |
addr && Unsubscribe.find_by_email(addr).nil? |
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
def get_public_action_urls(controller) | |
controller_name = (/(\S+)_controller/).match(controller.name.underscore)[1] | |
controller.action_methods.select { |m| | |
url_for(:controller= >controller_name, | |
:action=>m, | |
:method=>:get, | |
:host=>APP_CONFIG['settings']['domain'] | |
) rescue nil}.collect do |m| | |
url_for :controller=>controller_name, | |
:action=>m,:host=>APP_CONFIG['settings']['domain'] |
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
def send_to_sales_force(info_request) | |
sf_url = "www.salesforce.com" | |
sfhash = {"oid"=>"GET_THIS_FROM_SALES_FORCE", | |
"retURL"=>"http://www.mycompany.com", | |
"first_name"=>info_request.first_name, | |
"last_name"=>info_request.last_name, | |
"email"=>info_request.email, | |
"company"=>info_request.company, |
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 'optparse' | |
require 'yaml' | |
options = {} | |
ARGV.options do |opts| | |
opts.on( "-c", "--configfile ENVIRONMENT", String, | |
"mongrel cluster config file." ) do |config_file| | |
options[:config_file] = config_file | |
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
def sanitize_for_filename | |
#strip the string | |
ret = self.strip | |
#blow away apostrophes | |
ret.gsub! /['`]/,"" | |
# @ --> at, & --> and | |
ret.gsub! /\s*@\s*/, " at " | |
ret.gsub! /\s*&\s*/, " and " |
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
class Foo < ActiveRecord::Base | |
has_and_belongs_to_many :bars | |
end | |
class Bar < ActiveRecord::Base | |
has_and_belongs_to_many :foos | |
end | |
@foo = Foo.create | |
@bars = Bar.find_all_by_some_attribute(:a) |
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
class << Foo | |
def mass_habtm(attr_array) | |
attr_str = attr_array.map{|a| %Q{'#{a}'} }.uniq.join(",") | |
self.connection.execute(%Q{insert into foos_bars (foo_id,bar_id) | |
select distinct foos.id,bars.id from foos,bars | |
where foos.id = #{self.id} | |
and bars.some_attribute in (#{attr_str})}) | |
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
Join Table Columns (2.3ms) SHOW FIELDS FROM `foos_bars` | |
Resident Load (18.7ms) SELECT * FROM `bars` INNER JOIN `foos_bars` ON `bars`.id = `foos_bars`.bar_id WHERE (`foos_bars`.foo_id = 1327 ) | |
SQL (0.1ms) BEGIN | |
SQL (51.2ms) DELETE FROM `foos_bars` WHERE foo_id = 1327 AND bar_id in (117261,117262,117263, . . |
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
@foo.connection.execute("delete from foos_bars where foo_id = #{@foo.id}")} |
OlderNewer