Skip to content

Instantly share code, notes, and snippets.

View latompa's full-sized avatar

Thomas Olausson latompa

View GitHub Profile
@latompa
latompa / gist:217325
Created October 24, 2009 01:38
find users with no activity
-- 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
@latompa
latompa / find duplicate records
Created October 30, 2009 02:29
find duplicate records
SELECT name,
COUNT(name)
FROM users
GROUP BY name
HAVING ( COUNT(name) > 1 )
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
create table blogs
(id integer,
user_id integer);
insert into blogs values
(1,1),
(2,2),
(3,3);
create table entries
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
Videos
+------+------------------+
| id | uploaded_by_user |
+------+------------------+
| 1 | tom |
| 2 | mark |
| 3 | tom |
| 4 | mark |
| 5 | tom |
| 6 | john |
#
# 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
@latompa
latompa / gist:753930
Created December 24, 2010 05:24
slider with letter-spacing
<!DOCTYPE HTML>
<html>
<head>
<style>
* {
font-family: sans-serif;
}
h1 {
font-size: 48px;
letter-spacing: 0px;
@latompa
latompa / nearest_upcoming_hour.rb
Created March 17, 2011 17:38
nearest_upcoming_hour.rb
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
@latompa
latompa / poly.rb
Created April 27, 2011 17:59
poly.rb
class Reservation
has_one :authorization, :as => :authorizable
has_one :capture, :as => :capturable
end
class CreditCardAuthorization
belongs_to :authorizable, :polymorphic => true
def capture
end