Skip to content

Instantly share code, notes, and snippets.

View codatory's full-sized avatar

Alex Conner codatory

View GitHub Profile
#!/usr/bin/env ruby
QUEUE = Beanstalk::Pool.new(['127.0.0.1:11300'])
MAILR = Mailer.new
MAILR.deliver_digests
# Main program loop
counter = 0
loop do
module Sanity
module ActsAsSaneNestedAttributes
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_sane_nested_attributes(options = [])
puts 'Setting up child callbacks'
ActiveRecord::Callbacks::CALLBACKS.each do |callback|
# Date formats
Time::DATE_FORMATS.merge!(
:friendly_date => lambda {|d| "#{d.month}/#{d.mday}" }, # 4/25 (no leading zeroes)
:friendly_time => lambda {|t|
date = (t.at_midnight == Time.now.at_midnight) ? '' : "#{t.month}/#{t.mday}@" # 4/25@4PM on other days
"#{date}#{t.strftime('%I').to_i}#{t.strftime('%p')}" # 4PM on same day
},
:year => "%Y", # 2008
:month_year => "%b %Y", # Apr 2008
:ampm_time => "%I:%M %p", # 04:15 PM
@codatory
codatory / cleaned_list.rb
Created June 21, 2012 00:51
Ruby Class for creating a list of normalized strings
require 'set'
class CleanedList
def initialize
@data = SortedSet.new
end
def to_a
@data.to_a
end
@codatory
codatory / phrase.rb
Created June 21, 2012 03:32
Fuzzy string matching convenience class
require 'fuzzystringmatch'
class Phrase
attr_reader :matches
def initialize(str, match_score=0.8)
@str = str
@matches = []
@match_score = match_score
@scorer = FuzzyStringMatch::JaroWinkler.create
@codatory
codatory / fuzzy_match.rb
Created June 22, 2012 21:14
Fuzzy Matching Library
class FuzzyMatch
class Matcher
require 'singleton'
require 'fuzzystringmatch'
include Singleton
JW = FuzzyStringMatch::JaroWinkler.create
def self.get_score(str1,str2)
JW.getDistance(str1,str2)
end
require 'set'
my_data = %w(cat cat dog dog foo bar bin baz baz bin)
my_set = Set.new
my_data.each do |i|
if my_set.add?(i)
puts "#{i} is the first of its kind"
else
@codatory
codatory / pinboard_check.rb
Created July 14, 2012 14:34
Quick and Dirty tool for finding stale bookmarks on Pinboard
require 'pinboard_api'
require 'peach'
require 'typhoeus'
hydra = Typhoeus::Hydra.new
PinboardApi.username = ''
PinboardApi.password = ''
pins = PinboardApi::Post.all
<img src="foo.jpg" class="lowres" /><img src="foo2x.jpg" class="hires" />
source :rubygems
gem 'mysql2'
gem 'sqlite3'
gem 'tiny_tds'
gem 'sequel'
gem 'progressbar'