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
# UPDATE: I benchmarked parsing JSON and it's way way faster. I'm going to transition to requesting | |
# JSON from flickr and store the cached data as JSON too. | |
# | |
# With Rreset (http://github.com/javan/rreset/tree/master), I am caching some of the XML | |
# returned from Flickr API calls. Then, on subsequent hits, the cached XML is loaded and parsed | |
# using Hash.from_xml which is an implementation of XmlSimple. I was curious if it would be | |
# faster to first convert the XML to Yaml and parse that on cached hits instead. Yaml was the | |
# obvious winner. There are probably way faster XML parsing libraries out there, | |
# but I wanted to stick with the Rails defaults. | |
# |
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
sudo port install ruby | |
# Install rubygems 1.2.0 because the memcached gem requires it (macport installs 1.3.0) | |
curl -O http://files.rubyforge.mmmultiworks.com/rubygems/rubygems-1.2.0.tgz | |
tar xzvf rubygems-1.2.0.tgz | |
cd rubygems-1.2.0 | |
sudo ruby setup.rb | |
#memcached | |
wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz |
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
<% if 1 == 1 # some comment %> | |
In ruby 1.8.6 you'll see me. In 1.8.7 you won't. It seems 1.8.7 doesn't like comments in erb tags like the one above. | |
<% 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
class User < ActiveRecord::Base | |
# These are all boolean fields defined for this User model. | |
# As we add more email columns, and add them to this array, | |
# the named_scope below keeps up. | |
EMAIL_COLUMNS = [:email_new_market_alerts, :email_new_announcements, :email_stock_notices] | |
named_scope :unsubscribed, lambda { { :conditions => EMAIL_COLUMNS.inject({}) { |conditions, column| conditions[column] = false; conditions } } } | |
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
# Takes a collection of Stocks and moves the closed ones to the end | |
def closed_stocks_last(stocks) | |
open, closed = [], [] | |
stocks.each do |stock| | |
if stock.closed? | |
closed << stock | |
else | |
open << stock | |
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
# Sorry for the confusing stock names. Their name does not indicate the order they should be in. "second" is the only closed stock. | |
# The original ordering | |
>> stocks.map(&:name) | |
=> ["second", "third", "first"] | |
# Ordering from #sort_by | |
>> stocks.sort_by { |s| s.closed? ? 1 : 0 }.map(&:name) | |
=> ["first", "third", "second"] |
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
irb(main):007:0> 0 / 0 | |
ZeroDivisionError: divided by 0 | |
from (irb):7:in `/' | |
from (irb):7 | |
from :0 | |
irb(main):006:0> 0.0 / 0 | |
=> NaN | |
irb(main):014:0> 0.0 == 0 |
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
<link href="jbar.css" media="screen" rel="stylesheet" type="text/css" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> | |
<script src="jquery.jbar.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
jQuery(function(){ | |
jQuery('.jbar').jbar(); | |
}); | |
</script> | |
<ul class="jbar"> |
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
# Tweet::OAuth::CONSUMER_KEY and Tweet::OAuth::CONSUMER_SECRET are strings I stored locally. | |
class OauthTwitterController < ApplicationController | |
# Will redirect to authorize with twitter | |
def show | |
oauth.set_callback_url(new_oauth_twitter_url) | |
session[:twitter_oauth_request_token] = oauth.request_token.token | |
session[:twitter_oauth_request_token_secret] = oauth.request_token.secret | |
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
every 1.day, :at => '2:30pm' do | |
runner 'Company.grow' | |
end | |
every 20.minutes do | |
command 'cd /home/fetch/fetches && wget http://example.com/latest_file.txt' | |
end | |
every :reboot do | |
rake 'memcached:start' |
OlderNewer