Skip to content

Instantly share code, notes, and snippets.

@bmaland
bmaland / tjeld-app.rb
Created May 7, 2009 17:16
Small desktop app for viewing the webcam at http://tjeld.uib.no/
#!/usr/bin/env ruby
# Small desktop app for viewing the webcam at http://tjeld.uib.no/
# Written in Shoes. Works on at least Linux and OSX,
# should be fine on Windows as well.
require "open-uri"
INTERVAL = 10
WIDTH = 240
# In Ruby 1.8
irb(main):008:0> "" + Errno::ENOENT.new
=> "No such file or directory"
irb(main):009:0> "" + Errno::ENOENT.new.to_s
=> "No such file or directory"
# In Ruby 1.9
irb(main):002:0> "" + Errno::ENOENT.new
TypeError: can't convert Errno::ENOENT into String
@bmaland
bmaland / manifest.rake
Created May 10, 2009 20:36
Rake task for building .gems
namespace :heroku do
desc "Populates the .gems manifest file, to be used with Heroku"
task :gems => :environment do
File.open(File.join(RAILS_ROOT, ".gems"), "w") do |f|
Rails.configuration.gems.each do |dep|
f.puts dep.send(:install_command)[1..-1].join(' ')
end
end
end
end
@bmaland
bmaland / heroku-db-backup.sh
Created May 14, 2009 18:23
Backup script for Heroku db's - created for crantastic.org
#!/usr/bin/zsh
# -*- Abstract -*-
# Backup the database from your Heroku webapp. 7 day rotating daily backup,
# stores a weekly copy every week (on sundays).
#
# The latest version of this script is available from http://gist.github.com/111804
# Code by Bjørn Arild Mæland [github.com/Chrononaut]
#
# -*- Requirements and usage -*-
#!/usr/bin/env python
# Simple algorithm for clustering WordNet synsets. Requires Python 2.5 or 2.6,
# in addition to the NLTK toolkit which is available at http://www.nltk.org/.
import nltk
from nltk.corpus import wordnet as wn
from nltk.corpus import wordnet_ic
def cluster_senses(word, treshold = 0.30,
require "yaml"
# Parser for Debian Control Files (http://www.debian.org/doc/debian-policy/ch-controlfields.html)
# Piggybacks on the stdlib YAML parser, so this only works as long as there is a
# space after the field names (this is a stated DCF convention). You'll encounter problems if
# there are unescaped colons in the values.
#
# I've also built a full Treetop grammar for DCF: http://github.com/Chrononaut/treetop-dcf
module Dcf
# Copy `n Paste from IRB, based on http://judofyr.net/posts/copy-paste-irb.html
# Requires xclip for clipboard interaction. Stick in .irbrc:
def copy(str)
IO.popen('xclip -i', 'w') { |f| f << str.to_s }
end
def paste
`xclip -o`
end
# lib/github_gem.rb
module Rails
class Configuration
def github_gem(name, options = {})
options[:source] = 'http://gems.github.com'
options[:lib] = name.sub(/[^-]+-/, '') unless options.has_key?(:lib)
self.gem(name, options)
end
end
end
#!/usr/bin/env python
import nltk
## Tom Sawyer, by Mark Twain.
## Available from the Gutenberg Project:
## http://www.gutenberg.org/files/74/74.txt
reader = nltk.corpus.reader.PlaintextCorpusReader('.', 'twain-tomsawyer.txt')
words = reader.words('twain-tomsawyer.txt') # List of all the words in the text
## Usage:
## db <- Database("http://208.78.99.54:5984/", "packages")
##
## Insert(key, value, db)
##
## Note that values are automatically converted to JSON.
source("curr.R")
# The DB is created if it doesnt exist