Skip to content

Instantly share code, notes, and snippets.

View latompa's full-sized avatar

Thomas Olausson latompa

View GitHub Profile
@latompa
latompa / rlshrtnr.rb
Created September 27, 2011 02:02
rlshrtnr.rb
# 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'
@latompa
latompa / sample curl session
Created April 29, 2011 20:26
sample curl session
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
@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
@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 / 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;
#
# 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
Videos
+------+------------------+
| id | uploaded_by_user |
+------+------------------+
| 1 | tom |
| 2 | mark |
| 3 | tom |
| 4 | mark |
| 5 | tom |
| 6 | john |
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
create table blogs
(id integer,
user_id integer);
insert into blogs values
(1,1),
(2,2),
(3,3);
create table entries
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