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
# shorten a URL | |
# curl -X POST --data "url=http://livingsocial.com" localhost:9292 | |
# | |
# --> returns the shortened url in the body | |
# | |
# to retrieve a shortened URL | |
# open http://localhost:9292/a723bae | |
# | |
require 'rubygems' |
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
curl -v http://www.nytimes.com | |
> GET / HTTP/1.1 | |
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 | |
> Host: www.nytimes.com | |
> Accept: */* | |
< Server: Sun-ONE-Web-Server/6.1 | |
< Date: Fri, 29 Apr 2011 20:25:26 GMT | |
< Content-type: text/html; charset=UTF-8 | |
< Expires: Thu, 01 Dec 1994 16:00:00 GMT |
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 Reservation | |
has_one :authorization, :as => :authorizable | |
has_one :capture, :as => :capturable | |
end | |
class CreditCardAuthorization | |
belongs_to :authorizable, :polymorphic => true | |
def capture | |
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
module TimeExtras | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def nearest_upcoming_hour | |
Time.at((Time.now.to_f / (60*60)).ceil * (60*60)) | |
end | |
end | |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<style> | |
* { | |
font-family: sans-serif; | |
} | |
h1 { | |
font-size: 48px; | |
letter-spacing: 0px; |
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://rubyquiz.com/quiz154.html | |
# | |
def make_change(amount, available_change, coins = []) | |
raise "not enough available change" if(amount > 0 && available_change.empty?) | |
return coins if amount == 0 | |
coin = available_change.shift | |
n = amount / coin |
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
Videos | |
+------+------------------+ | |
| id | uploaded_by_user | | |
+------+------------------+ | |
| 1 | tom | | |
| 2 | mark | | |
| 3 | tom | | |
| 4 | mark | | |
| 5 | tom | | |
| 6 | john | |
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
require 'pp' | |
def uniq_combos(set) | |
comb = [] | |
(set.size).times.each do |x| | |
comb.concat set.combination(x+1).entries | |
end | |
comb.sort {|x,y| y.size <=> x.size} | |
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
create table blogs | |
(id integer, | |
user_id integer); | |
insert into blogs values | |
(1,1), | |
(2,2), | |
(3,3); | |
create table entries |
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
customer_addresses | |
cust_id, address_id, preferred | |
-------------------------------- | |
1 1 true | |
1 2 false | |
2 3 true | |
3 4 false | |
find customers that only have preferred=false addresses |