Skip to content

Instantly share code, notes, and snippets.

@swindsor
swindsor / fizzbuzz.js
Created January 11, 2012 20:20
FizzBuzz
function cat(a,b,c){
return c ? (a + b) : (a);
}
function fizz(i,s){
return cat(s,"Fizz", (i%5===0));
}
function buzz(i,s){
return cat(s,"Buzz", (i%3===0));
function foo(){
alert("I'm Awesome!");
}
foo();
@swindsor
swindsor / chompy_chompy.rb
Created November 4, 2011 01:04
Best on-liner of the day.
Hash[*(doc/"/b").map{|e| [e.inner_html.squeeze(" ").chomp(" ").chomp(":"), e.next.to_s.squeeze(" ").chomp(" ")] }.flatten]
@swindsor
swindsor / teacher.json
Created June 22, 2011 20:56
Test Teacher
{
"teacher": {
"rating": 4.66666666666667,
"listings_count": 5,
"mediumImageUrl": "http://images3.teachstreet.com:80/image/view?e=cr-75-75&id=im-d0rg2h1ldc&reference_id=ir-19f7mu9xnvk",
"about_me": "<p>This is my amazing description.This is my amazing description&nbsp;This is my amazing descriptionThis is my amazing description&nbsp;This is my amazing description&nbsp;This is my amazing descriptionThis is my amazing description.</p>\r\n<p><a href=\"http://www.teachstreet.com/teacher-requests/create\" class=\"\" target=\"_blank\">foo</a></p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
"location": {
"name": "Seattle, WA",
"city": "Seattle",
"lon": -122.333139770975,
#!/usr/bin/env ruby
require 'netflix'
File.open('catalog_titles_index.xml', 'w') do |f|
f.write(Netflix.catalog_titles_index)
end
#!/usr/bin/env ruby
require 'rubygems'
require 'ruby_odata'
svc = OData::Service.new "http://odata.netflix.com/Catalog/"
puts "DVD:"
svc.Titles.filter("AverageRating le 2 and Type eq 'Movie' and Dvd/Available eq true").order_by("AverageRating asc").top(100)
movies = svc.execute
@swindsor
swindsor / worst_movies.rb
Created February 7, 2011 16:24
find the worst movies from the redis sorted set
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
redis = Redis.new
ratings = redis.zrangebyscore("netflix_ratings", 0, 5, :with_scores => true, :limit => [0, 100])
counter = 0
index = 1
@swindsor
swindsor / add_all_movies.rb
Created February 7, 2011 16:23
Add all netflix movies (from text file) to a redis sorted set
#!/usr/bin/env ruby
require 'netflix'
require 'redis'
redis = Redis.new
File.open("movies.txt", "r") do |f|
f.each_line do |line|
id = line.chomp
@swindsor
swindsor / netflix.rb
Created February 7, 2011 16:17
simple quick netflix client using oauth & crack
#!/usr/bin/env ruby
require 'rubygems'
require 'oauth'
require 'crack'
class Netflix
class CatalogTitle
attr_accessor :average_rating, :release_year, :category, :short_title, :title, :id, :runtime, :box_art, :link
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /opt/local/var/mongodb/data
# Only accept local connections
bind_ip = 127.0.0.1