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
-- 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
-- table | |
create table members (id integer, age integer); | |
-- data | |
insert into members (id,age) values | |
(1,10), (2,20), (3,30), (4,25), (5,28), (6,37), (7,38), (8,68), (9,9); | |
-- query | |
select | |
SUM(case when age between 1 and 20 then 1 else 0 end) as "1-20", |
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
You have an audit table | |
created | action | |
---------------------+-------- | |
2009-01-01 00:00:00 | create | |
2009-01-02 00:00:00 | delete | |
2009-01-15 00:00:00 | create | |
2009-01-16 00:00:00 | create | |
and you want a report with two counts, created and deleted for each week |
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 the following test, the setup is supposed to create a variable, | |
# but fails because of a missing method | |
# | |
# If you run this test, you wont see the setup error, | |
# it's being masked by teardown, because @some_object is nil | |
# | |
require 'test/unit' | |
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
require 'rubygems' | |
require 'lib/fleakr' | |
Fleakr.api_key = 'API_KEY' | |
Fleakr.shared_secret = 'SECRET' | |
MAX_TRIES = 100 | |
user_list = [{:auth_token => "TOKEN_1", :owner_id => "USER_1"}, | |
{:auth_token => "TOKEN_2", :owner_id => "USER_2"}] |
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 'rubygems' | |
require 'activesupport' | |
module Fleykr | |
mattr_accessor :token | |
def self.search_photos | |
p "searching, and my token is #{Fleykr.token}" | |
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 Account < ActiveRecord::Base | |
has_many :balance_transfers | |
has_many :orders | |
def purchase_order(description, cost) | |
begin | |
transaction do | |
balance_transfers.create! :change=>cost | |
orders.create! :description=>description | |
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
-- You have a products table, and want to show the ones a user can afford first sorted on price | |
-- followed by the products he can't afford, also sorted | |
create table products(id integer, name varchar(32), price integer) | |
insert into products values | |
(1,"teddy bear",10), | |
(2,"red fire engine",5), | |
(3,"doll house",50), | |
(4,"lego castle",190), |
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
You are using attachment_fu and have a database like so | |
id product_id parent_id content_type thumbnail filename | |
1 500 (null) image/png (null) ipod.png | |
2 (null) 1 image/png medium ipod_medium.png | |
3 (null) 1 image/png large ipod_large.png | |
and you want to produce a list of all your s3 urls (for copying a bucket maybe) | |
product_images/1/ipod.jpg |