Skip to content

Instantly share code, notes, and snippets.

def similar(n = 10)
other_tags = Tag.find(:all, :conditions => ['tags.id != ?', self.id], :include => :bookmarks)
other_tags.map do |b|
[b, tanimoto(b.bookmarks, self.bookmarks)] # compare tag listings
end.select do |b|
b.last > 0 # select only those which have a tanimoto greater than 0, ie. some shared tags
end.sort do |x,y|
y.last <=> x.last # sort on tanimoto
end[0..n].map(&:first) # return only 0..10 bookmarks
@tomtaylor
tomtaylor / flickr-geo-munge.rb
Created August 10, 2008 19:17
Munge Flickr to find yourself in photos.
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'activesupport'
require 'uri'
# Set the longitude, latitude and radius of your search in here. And your api key.
def get_uri(from, to)
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'activesupport'
require 'uri'
# Set the longitude, latitude and radius of your search in here. And your api key.
def get_uri
require 'xmpp4r-simple'
module ActiveMessaging
module Adapters
module Xmpp
class Connection
include ActiveMessaging::Adapter
register :xmpp
def initialize(cfg)
# For what I have done, please forgive me.
# This monkey patch adds in the HttpOnly support for the session cookie
# This is present and accepted into Rails 2.2 at the time of writing, but not in Rails 2.1.
# You can remove this and set HttpOnly properly when moving to Rails 2.2
module ActionController
class RackRequest
DEFAULT_SESSION_OPTIONS = {
:database_manager => CGI::Session::CookieStore, # store data in cookie
:prefix => "ruby_sess.", # prefix session file names
$(document).ready(function() {
var gmap = new GMap2(document.getElementById("map"));
gmap.addControl(new GSmallMapControl());
var startingPoint = new GLatLng(51.506325,-0.127144);
gmap.setCenter(startingPoint, 13);
var bounds = new GLatLngBounds();
function displayPolygon(woeid, borderColor, fillColor) {
$.getJSON('http://api.flickr.com/services/rest/?method=flickr.places.getInfo&api_key=get_your_own&woe_id=' + woeid + '&format=json&jsoncallback=?', function(data) {
class String
require 'rexml/parsers/pullparser'
def truncate_html(len = 30)
p = REXML::Parsers::PullParser.new(self)
tags = []
new_len = len
results = ''
while p.has_next? && new_len > 0
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'rio'
body = Net::HTTP.get 'minneapolisfuckingrocks.blogspot.com', '/2009/01/diplo-remix-collection.html'
body.scan(/http:\/\/[a-zA-Z0-9_\.\/]*mp3{1}/).each {|link| rio(link) > rio(File.basename(link))}
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/messages.sqlite3")
class Message
include DataMapper::Resource
mu:inception tom$ make
gcc -g -Wall -m32 -c -o inception.o inception.c
gcc -g -Wall -m32 -g -o inception inception.o -lpthread
mu:inception tom$ ./inception
Dreamer [Fischer], level [1], priority [19], policy [OTHER]
Dreamer [Cobb], level [1], priority [19], policy [OTHER]
Dreamer [Ariadne], level [1], priority [19], policy [OTHER]
Dreamer [Arthur], level [1], priority [19], policy [OTHER]
Dreamer [Eames], level [1], priority [19], policy [OTHER]
Dreamer [Saito], level [1], priority [19], policy [OTHER]