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 self.parent_select_options | |
options = [['-- No Parent --', nil]] | |
Tag.recurse_for_parent_select_options(Tag.roots,options) | |
return options | |
end | |
def self.recurse_for_parent_select_options(nodes,options) | |
nodes.each do |node| | |
prefix = node.depth > 0 ? ' -' * node.depth + ' ' : '' | |
options << [ prefix + node.title, node.id] |
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
" Fuzzy Finder Mappings | |
map <C-t> :FuzzyFinderFileWithCurrentBufferDir |
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 FreemailerCampaign < ActiveRecord::Base | |
belongs_to :sender, :class_name => 'User' | |
has_many :freemailer_campaign_contacts, :dependent => :destroy | |
has_many :contacts, :through => :freemailer_campaign_contacts | |
validates_uniqueness_of :title, :scope => :sender_id, :on => :create, :message => "must be unique" #JS me | |
attr_accessible :title, :subject | |
before_destroy :remove_active_campaign | |
def contact_names |
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 self.ranking_sort(results,query) | |
results.sort { |a,b| ranking_score(a,query) <=> ranking_score(b,query) } | |
end | |
# Compute the two-ordered score for sorting | |
# Score is of the form [ 1 / # of matches, average distance ] | |
# This arises because we may have 1 or more query parts that aren't matched at all | |
# Since those elements return nil we can't exactly set them to 0 or MAX and expect reliable results | |
# e.g. "Carrot Soup" === ["carrot","soup"] = (0 + 8) / 2 = 4 # Clearly the best result | |
# "Carrot's, raw" === ["carr...soup"] = (0 + 0?) / 2 = 0 # but setting to 0 breaks this |
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 ham_dist(word) | |
a = SHA1.hexdigest(word).to_i(16) | |
b = "6cac827bae250971a8b1fb6e2a96676f7a077b60".to_i(16) | |
(a ^ b).to_s(2).split('').inject(0) {|sum,i| sum + i.to_i } | |
end | |
def permute(sentence) | |
non_space_chars = sentence.scan(/\S/).count | |
(0...(2**non_space_chars)).each do |mask| | |
yield apply_mask(sentence,mask) |
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 'digest/sha1' | |
def suffix(seqnum) | |
o = "" | |
5.times do | |
o << (33 + (seqnum % 93)).chr | |
seqnum /= 93 | |
end | |
return o | |
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
>> smtp = Net::SMTP.new('oz.law.harvard.edu', 465) | |
=> #<Net::SMTP oz.law.harvard.edu:465 started=false> | |
>> smtp.set_debug_output $stderr | |
=> #<IO:0x126dbc> | |
>> smtp.start( 'oz.law.harvard.edu', 'rneufeld', MY_PASS, :login) | |
Connection opened: oz.law.harvard.edu:465 | |
Timeout::Error: execution expired | |
from /opt/local/lib/ruby/1.8/timeout.rb:60:in `rbuf_fill' | |
from /opt/local/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill' | |
from /opt/local/lib/ruby/1.8/net/protocol.rb:116:in `readuntil' |
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
# Code Golf: Text Area Tag Edition | |
# Ladies and Gentlemen here is the function | |
# Smallest (and least legible) rewrite wins! | |
def size_for_text_area_tag(string, cols = 40) | |
lines = string.split("\n") | |
rows = lines.map(&:length).inject(0) do |sum,len| | |
sum + if len/cols > 0 | |
len/cols | |
else |
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
#!/usr/bin/env ruby | |
puts `./simulator ./test/test#{ARGV[0]}.o ./test/test#{ARGV[0]}.dat` |