Skip to content

Instantly share code, notes, and snippets.

View klochner's full-sized avatar

kevin lochner klochner

View GitHub Profile
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
#!/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 = []
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
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
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}}
#models/user.rb
def user_city
read_attribute(:user_city) || address && address.city || ""
end
#locations.html.erb
<%= render :partial=>"user", :collection=>@users %>
#_user.html.erb
<%=h user.name %> lives in <%=h user.user_city %>
#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
#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
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)