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
-- members | |
create table members (id integer, age integer); | |
insert into members (id,age) values | |
(1,10) ,(2,20) ,(3,30) ,(4,25) ,(5,28) ,(6,37) ,(7,38) ,(8,68) ,(9,9) | |
-- posts | |
create table posts (id integer, user_id integer, title varchar(32)) | |
insert into posts (id,user_id,title) values |
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
SELECT name, | |
COUNT(name) | |
FROM users | |
GROUP BY name | |
HAVING ( COUNT(name) > 1 ) |
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 |
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
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
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
# | |
# 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
<!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
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
class Reservation | |
has_one :authorization, :as => :authorizable | |
has_one :capture, :as => :capturable | |
end | |
class CreditCardAuthorization | |
belongs_to :authorizable, :polymorphic => true | |
def capture | |
end |