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
# worker model | |
belongs_to :project1, :class_name => "Project", :foreign_key => "project1_foreign_key_name_in_workers_table" | |
belongs_to :project2, :class_name => "Project", :foreign_key => "project2_foreign_key_name_in_workers_table" | |
belongs_to :project3, :class_name => "Project", :foreign_key => "project3_foreign_key_name_in_workers_table" | |
# The project model is going to be harder, and you're not going to be | |
# able to intuitively assign workers to projects, but you can at least | |
# fudge-together some helper methods to make it look like you're | |
# leveraging the power of Rails! :-) |
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
>> a1 = [3, 1, 2] | |
=> [3, 1, 2] | |
>> a2 = [2, 3, 4] | |
=> [2, 3, 4] | |
>> (a1 - a2) + (a2 - a1) | |
=> [1, 4] |
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
# monkey patch gleaned from http://dev.rubyonrails.org/attachment/ticket/11394/merge_bang_errors.patch | |
module ActiveRecord | |
class Errors | |
def merge!(errors, options={}) | |
fields_to_merge = if only=options[:only] | |
only | |
elsif except=options[:except] | |
except = [except] unless except.is_a?(Array) | |
except.map!(&:to_sym) |
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
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()) |
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 'rspec/autorun' | |
def get_indexes(needle, haystack) | |
(0...haystack.length).find_all { |i| haystack[i,1] == needle } | |
end | |
def map_indexes(needle, haystack) | |
needle.split('').map do |nee| | |
get_indexes nee, haystack | |
end |