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
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 |
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
#!/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) |
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
#!/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 |
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 'xmpp4r-simple' | |
module ActiveMessaging | |
module Adapters | |
module Xmpp | |
class Connection | |
include ActiveMessaging::Adapter | |
register :xmpp | |
def initialize(cfg) |
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
# 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 |
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
$(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) { |
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 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 |
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
#!/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))} |
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 'sinatra' | |
require 'dm-core' | |
require 'dm-validations' | |
require 'dm-timestamps' | |
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/messages.sqlite3") | |
class Message | |
include DataMapper::Resource |
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
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] |
OlderNewer