Public Gists by danielharan

Gravatar
Wed Aug 26 14:33:44 -0700 2009
1
2
3
  has_many :connections, :foreign_key => "from_id"
  has_many :favorites, :through => :connections, :source => :to
  
Gravatar
Wed Aug 12 11:13:43 -0700 2009
1
2
3
$ gem list aslak
 
*** LOCAL GEMS ***
gist: 148102 Refactoring an example from...
Gravatar
Wed Jul 15 18:43:12 -0700 2009
1
2
3
#!/usr/bin/env ruby
 
maxima = Hash.new(0)
Gravatar
Tue Jun 30 17:24:03 -0700 2009
1
2
3
# http://svn.facebook.com/svnroot/platform/samples/packages/
# therunaround.tar.gz / core.php
/**
Gravatar
Thu Mar 26 14:41:33 -0700 2009
1
2
3
# FAIL
value = compute_value
value = (value > CONSTANT) ? value : CONSTANT
Gravatar
Thu Mar 26 13:58:19 -0700 2009
1
2
3
# Script written a year ago to get SAQ wines...
#
# first, get all search pages
Gravatar
Tue Mar 03 14:57:32 -0800 2009
1
2
3
class ApplicationController < ActionController::Base
  def set_time_zone
    if current_user
Gravatar
Thu Feb 19 16:26:21 -0800 2009
1
2
3
#!/usr/bin/env ruby
 
require 'rubygems'
Gravatar
Tue Feb 17 10:54:06 -0800 2009
1
2
3
$ time thor scraper:extract cbc_scraper postal_codes.txt > codes_to_edids.csv
real 193m57.176s
user 0m39.874s
Gravatar
Wed Jan 28 09:58:58 -0800 2009
1
2
3
# We order a LOT of pizza at GiraffeSoft
# (there are 14 empty boxes on the table, and 3 more on the way)
# So, what's the cheapest way to buy them?
Gravatar
Tue Dec 30 10:34:49 -0800 2008
1
2
3
$ rake stats
(in /Users/danielharan/projects/giraffesoft/SEEKRIT)
+----------------------+-------+-------+---------+---------+-----+-------+
Gravatar
Wed Dec 17 18:18:27 -0800 2008
1
2
3
class Euclidean
  class << self
 
Gravatar
Thu Nov 20 12:38:46 -0800 2008
1
2
3
# > {1 => 'a', 2 => 'b', 3 => 'a'}.values.histogram
# => {"a"=>2, "b"=>1}
class Array
Gravatar
Wed Nov 19 14:22:33 -0800 2008
1
2
3
class Jaccard
  def self.coefficient(a,b)
    result = (a & b).length / (a + b).uniq.length.to_f
Gravatar
Wed Nov 12 19:34:22 -0800 2008
1
2
3
# Example use:
# weigh_by_relative_importance(@report.items, :cell_value, [2,4,6,8,10]) do |item,weight|
# xml.movie :lat => item.latitude, :long => item.longitude, :title => item.city,
Gravatar
Tue Oct 14 15:25:58 -0700 2008
1
2
3
require 'rubygems'
require 'mechanize'
 
Gravatar
Fri Oct 10 10:34:07 -0700 2008
1
2
3
class KeyValuePairs
  # Take a file like:
  # G6C=24034
Gravatar
Fri Oct 10 07:04:14 -0700 2008
1
2
3
class String
  def starts_with?(str)
    self =~ /#{str}/
Gravatar
Mon Oct 06 09:18:03 -0700 2008
1
2
3
class Hash
  def +(other)
    (self.keys + other.keys).uniq.each do |key|
Gravatar
Sun Oct 05 09:17:18 -0700 2008
1
2
3
Dir.glob("*").each do |pc|
  File.open(pc).read =~ /aug08cpocRidingProfileTitle>([^<]*)</
  puts "#{pc},#{$1}"