This file contains hidden or 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
| #!/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 |
This file contains hidden or 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
| 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| |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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 'set' | |
| class CleanedList | |
| def initialize | |
| @data = SortedSet.new | |
| end | |
| def to_a | |
| @data.to_a | |
| end |
This file contains hidden or 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 'fuzzystringmatch' | |
| class Phrase | |
| attr_reader :matches | |
| def initialize(str, match_score=0.8) | |
| @str = str | |
| @matches = [] | |
| @match_score = match_score | |
| @scorer = FuzzyStringMatch::JaroWinkler.create |
This file contains hidden or 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 FuzzyMatch | |
| class Matcher | |
| require 'singleton' | |
| require 'fuzzystringmatch' | |
| include Singleton | |
| JW = FuzzyStringMatch::JaroWinkler.create | |
| def self.get_score(str1,str2) | |
| JW.getDistance(str1,str2) | |
| end |
This file contains hidden or 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 '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 |
This file contains hidden or 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 'pinboard_api' | |
| require 'peach' | |
| require 'typhoeus' | |
| hydra = Typhoeus::Hydra.new | |
| PinboardApi.username = '' | |
| PinboardApi.password = '' | |
| pins = PinboardApi::Post.all |
This file contains hidden or 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
| <img src="foo.jpg" class="lowres" /><img src="foo2x.jpg" class="hires" /> |
This file contains hidden or 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
| source :rubygems | |
| gem 'mysql2' | |
| gem 'sqlite3' | |
| gem 'tiny_tds' | |
| gem 'sequel' | |
| gem 'progressbar' |