Skip to content

Instantly share code, notes, and snippets.

require "rubygems"
require "mongo_mapper"
MongoMapper.database = 'test_db'
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
@dce
dce / url_dsl.rb
Created December 15, 2009 03:48 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@dce
dce / after-use
Created August 27, 2009 18:52 — forked from defunkt/after-use
#!/usr/bin/osascript
run_command("cd ~/Projects/resque")
run_command("redis-server redis.conf")
open_tab()
run_command("cd ~/Projects/resque")
run_command("shotgun config.ru")
open_tab()
dups = Notification.undelivered.all(:select => "user_id, about_id, about_type, COUNT(*) AS dup_count",
:group => "user_id, about_id, about_type HAVING dup_count > 1")
dups.each do |dup|
notes = Notification.find_all_by_user_id_and_about_id_and_about_type(dup.user_id, dup.about_id, dup.about_type)
notes[1..-1].each(&:destroy)
end
Activity.record_timestamps = false
Post.all.each do |post|
if post.published?
post.create_activity(:updated_at => post.updated_at)
end
end
Comment.all.each do |comment|
obj = comment.commentable
#!/usr/bin/ruby
# Download all MP3 files linked from a given URL
require "open-uri"
url = ARGV.first
data = open(url)
data.read.scan(/href="(.*mp3)"/).each do |filename|
class Test::Unit::TestCase
def self.should_sum_total_ratings
klass = model_class
context "finding total ratings" do
setup do
@ratable = Factory(klass.to_s.downcase)
end
should "have zero total ratings if no rated talks" do
@dce
dce / gitlog.rb
Created April 2, 2009 20:01
gitlog.rb
#!/usr/bin/ruby
require 'rubygems'
require 'activesupport'
require 'git'
AUTHORS = ['deisinger', 'David Eisinger']
Git.open('.').log(300).select { |commit|
AUTHORS.include?(commit.author.name) and commit.message.strip.match(/^(Merge|git-svn)/).nil?
@dce
dce / gist:54714
Created January 29, 2009 20:11
SpeakerRate User Activity Report
User.find(:all, :conditions => ["created_at >= ?", Time.local(2009, 1, 26)]).each do |u|
if u.speaker
puts "#{u.created_at.to_date} #{u.speaker.name}"
end
end
Speaker.all.last(20).map {|s| s.talks.any? && s.talks.first.creator.speaker.name }
Speaker.all.each do |s|
puts s.name + "\t\t" + s.claim_code unless s.claim_code.blank?
#!/usr/bin/ruby
require 'rubygems'
require 'git'
log = "~/gitlog.txt"
tmp = "/tmp/gitlog"
commit = Git.open('.').log.first
message = [
commit.date.strftime('%D'),