This file contains hidden or 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
# Add .format in your path specification, like this: | |
map.profile '/:profile.:format', :controller => 'users', :action => 'show' | |
# Then you'll end up with: | |
profile /:profile(.:format) {:action=>"show", :controller=>"users"} |
This file contains hidden or 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
create_table "messages", :force => true do |t| | |
t.string "subject" | |
t.text "body" | |
t.datetime "created_at" | |
t.datetime "updated_at" | |
t.string "message_type" | |
t.integer "user_id" | |
t.boolean "deleted", :default => false | |
end |
This file contains hidden or 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 CreateCustomers < ActiveRecord::Migration | |
def self.up | |
create_table :customers do |t| | |
t.string :name | |
t.timestamps | |
end | |
execute "ALTER TABLE customers AUTO_INCREMENT = 1000;" | |
end |
This file contains hidden or 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
month_dict = {"Jan":1,"Feb":2,"Mar":3,"Apr":4, "May":5, "Jun":6, | |
"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12} | |
def to_dict(name): | |
return month_dict[name] |
This file contains hidden or 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
#http://docs.python.org/library/time.html#time.strptime | |
time.strptime('Sat Mar 20', '%a %b %d') | |
time.struct_time(tm_year=1900, tm_mon=3, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=79, tm_isdst=-1) | |
time.strptime('3pm', '%I%p') | |
time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=15, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1) | |
In [19]: dts = 'Sat Mar 20 2010 5pm' |
This file contains hidden or 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
In [1]: from geopy import geocoders | |
In [2]: us = geocoders.GeocoderDotUS() | |
In [3]: print us.geocode("314 W 77th St #4B, New York NY 10024")[0] | |
------> print(us.geocode("314 W 77th St #4B, New York NY 10024")[0]) | |
314 W 77th St, New York, NY 10024 |
This file contains hidden or 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
<% for item in @all_items %> | |
<li><%= link_to item.content_type + item.content_id.to_s, :controller => item.content_type.tableize, :action => "edit", :id => item.content_id %></li> | |
<% end %> | |
eval(key.to_s + "_path") |
This file contains hidden or 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 timer(end_time) | |
d = (end_time - Time.now).to_i | |
return "#{(d/60)%60}:#{d%60}" | |
end | |
>> timer(10.minutes.from_now) | |
=> "9:59" |
This file contains hidden or 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
counts = Users.count(:group => :country) | |
counts.each |country, count| do | |
p "#{country} - #{count}" | |
end | |
# Prints | |
US 123 | |
UK 54 | |
DE 33 |
This file contains hidden or 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
# http://www.tmtm.org/en/mysql/ruby/ | |
apt-get install libmysqlclient16-dev | |
wget http://rubyforge.org/frs/download.php/69181/mysql-ruby-2.8.2.tar.gz | |
tar zxvf mysql-ruby-2.8.2.tar.gz | |
cd mysql-ruby-2.8.2/ | |
ruby extconf.rb --with-mysql-dir=/usr/local/mysql | |
make | |
make install |