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
#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
#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
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) |
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
FB.init({ | |
appId : 'YOUR_APP_ID', | |
status : true, // check login status | |
cookie : true, // enable cookies to allow the server to access the session | |
xfbml : true // parse XFBML | |
}); | |
FB.getLoginStatus(function(response) { | |
if (response.session) { | |
// logged in and connected user, someone you know |
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
#try this data set: | |
ARR = [[1, "red"], [1, "green"], | |
[2, "red"], | |
[3, "yellow"], | |
[4, "red"], [4, "green"], [4, "yellow"], | |
[5, "green"], [5, "red"], | |
[6, "black"], | |
[7, "foo"], | |
[8, "bar"], | |
[9, "baz"], |
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
Join Table Columns (2.3ms) SHOW FIELDS FROM `foos_bars` | |
Bar Load (18.7ms) SELECT * FROM `bars` INNER JOIN `foos_bars` ON `bars`.id = `foos_bars`.bar_id WHERE (`foos_bars`.foo_id = 1327 ) | |
SQL (0.1ms) BEGIN | |
SQL (51.2ms) DELETE FROM `foos_bars` WHERE foo_id = 1327 AND bar_id in (117261,117262,117263, . . | |