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 history(num=100) | |
h = Readline::HISTORY.to_a | |
start = [0,h.size-num-1].max | |
h.zip((0..h.size).to_a)[start...h.size].each do |e,i| | |
puts " #{(i).to_s.rjust(4)} #{e}" | |
end;nil | |
end | |
def hg(term) | |
num=500 | |
h = Readline::HISTORY.to_a |
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/ruby | |
require 'rubygems' | |
leads = File.read('archstone_leads.csv').lines.collect {|x| x.strip} | |
closed = File.read('archstone_closed.csv').lines.collect {|x| x.strip} | |
leads_by_name_hash = [] | |
leads_by_email_hash = [] |
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
leads_by_email_hash.each_with_index do |hash, index| | |
by_name = leads_by_name_hash[index] | |
if closes_by_email_hash.include?(hash) | |
out += "#{hash[:community]},#{by_name[:name]},#{hash[:email]},#{sources[index]},X\n" | |
elsif closes_by_name_hash.include?(by_name) | |
out += "#{hash[:community]},#{by_name[:name]},#{hash[:email]},#{sources[index]},X\n" | |
end | |
end | |
puts out |
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 chart(chds,chxr,data) | |
str=%Q{http://chart.apis.google.com/chart?chxt=y,r&chbh=a&chs=200x200&cht=bvg&chf=bg,s,efefef} | |
str+= %Q{&chds=0,#{chds}&chxr=0,0,#{chxr}} | |
str += %Q{&chd=t:#{data}} | |
str | |
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
def distribution_chart_helper(width,height,sent,click) | |
data = [sent,click].map{|d| [d,0.01].max}.join("|") | |
legend = "sent|clicks" | |
data_labels = (0..1).map{|i| "N*f0*,000000,#{i},-1,11"}.join("|") | |
max_val = [sent,click,1].max | |
series_colors = %Q{76a4fb,405887} | |
url = %Q{http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=#{width}x#{height}&cht=bvg&chf=bg,s,efefef} | |
url += %Q{&chds=0,#{max_val*1.1}&chxr=0,0,#{max_val}} | |
url += %Q{&chco=#{series_colors}} | |
url += %Q{&chd=t:#{data}&&chdl=#{legend}} |
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
#models/user.rb | |
def user_city | |
read_attribute(:user_city) || address && address.city || "" | |
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
#locations.html.erb | |
<%= render :partial=>"user", :collection=>@users %> | |
#_user.html.erb | |
<%=h user.name %> lives in <%=h user.user_city %> |
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
#models/user.rb | |
named_scope :with_city_info, | |
:joins=>:address, | |
:select="users.*, addresses.city as user_city" | |
#controllers/users_controller.b | |
def locations | |
@users = User.with_city_info | |
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
#models/user.rb | |
class User < ActiveRecord::Base | |
has_one :address | |
named_scope :with_city_info, | |
:joins=>:address, | |
:select="users.*, addresses.city as user_city" | |
end | |
#models/address.rb | |
class Address < ActiveRecord::Base |
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 history(num=100) | |
h = Readline::HISTORY.to_a | |
start = [0,h.size-num-1].max | |
h.zip((0..h.size).to_a)[start...h.size].each do |e,i| | |
puts " #{(i).to_s.rjust(4)} #{e}" | |
end;nil | |
end | |
>> history(7) | |
483 def history(num=100) |