Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View klochner's full-sized avatar

kevin lochner klochner

View GitHub Profile
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,
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?
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']
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,
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
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 "
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)
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
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, . .
@foo.connection.execute("delete from foos_bars where foo_id = #{@foo.id}")}