Skip to content

Instantly share code, notes, and snippets.

View rud's full-sized avatar

Laust Rud Jacobsen rud

View GitHub Profile
@rud
rud / milk-extract.rb
Created July 15, 2010 12:52
Tool for migrating tasks to The Hit List from Remember The Milk
# Simple script for reading all tasks from Remember The Milk and exporting them in a format usable
# with The Hit List.
#
# Migrating from http://www.rememberthemilk.com to http://www.potionfactory.com/thehitlist
#
# Create a config.yml file in the same folder, then simply run it with "ruby milk-extract.rb"
#
# Released under MIT License
#
# Written by Laust Rud Jacobsen, rud@personal-it.dk, 2010
def run_import_step step_name
report_progress "Running #{step_name}" do
ImportModel.transaction do
self.send(step_name)
end
end
//...
context "with a bit of state" do
let!(:user) { User.create! }
it "should be the latest user" do
User.last.should == user
end
# .. more examples reusing the user
end
@rud
rud / gist:1055675
Created June 30, 2011 05:11
Heroku Danish languate support
(heroku console)$ User.connection.execute("select to_tsvector('danish', 'vi kigger p\303\245 biler og huse')").to_set
=> #<Set: {{"to_tsvector"=>"'bil':4 'hus':6 'kig':2"}}>
(psql)$ \dF+ danish
Text search configuration "pg_catalog.danish"
Parser: "pg_catalog.default"
Token | Dictionaries
-----------------+--------------
asciihword | danish_stem
@rud
rud / Current console output (consistent)
Created October 5, 2011 08:20
Demonstrate queue unsubscribe bug
ruby demo-amqp-one-message-subscribers.rb
single-message consumer listening to rapid producer
> PUT msg 0
> PUT msg 1
> PUT msg 2
> PUT msg 3
< GET msg 2 [waited 0.05s][18.95 reqs/sec]
/Users/rud/.rvm/gems/ruby-1.9.2-head@bundler/gems/amq-client-0.8.3/lib/amq/client/async/consumer.rb:246:in `block in <class:Consumer>': undefined method `handle_delivery' for nil:NilClass (NoMethodError)
from /Users/rud/.rvm/gems/ruby-1.9.2-head@bundler/gems/amq-client-0.8.3/lib/amq/client/async/adapter.rb:535:in `call'
from /Users/rud/.rvm/gems/ruby-1.9.2-head@bundler/gems/amq-client-0.8.3/lib/amq/client/async/adapter.rb:535:in `receive_frameset'
@rud
rud / postgresql.rb
Created October 22, 2011 12:42
Postgresql 8.4.8 recipe for homebrew, lives in /usr/local/Library/Formula/postgresql.rb
require 'formula'
require 'hardware'
class Postgresql <Formula
homepage 'http://www.postgresql.org/'
url 'http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.8/postgresql-8.4.8.tar.bz2'
md5 '4603e8ea30cee97189b62b39022f2043'
depends_on 'readline'
depends_on 'libxml2' if MACOS_VERSION < 10.6 #system libxml is too old
listen 3000
worker_processes 1
timeout 30
preload_app true
after_fork do |server, worker|
require "amqp"
PATH
remote: .
specs:
em-postgresql-adapter (0.2)
activerecord (>= 3.1.0)
eventmachine
pg (>= 0.8.0)
GEM
remote: http://rubygems.org/
@rud
rud / gist:2988115
Created June 25, 2012 11:40
Rails 3.2.6 config.active_record.whitelist_attributes adds blank attribute to .accessible_attributes

If you use tests of the form: User.accessible_attributes.should =~ [:email, :password] you'll get an extra attribute called "" if you set config.active_record.whitelist_attributes = true, and thus a specfailure. Annoying.

Instead, you can add this to your config/application.rb:

# Require attr_accessible to be used on all models for mass-assignment to work
ActiveRecord::Base.instance_eval do
  attr_accessible # none - and this method doesn't whitelist an attribute with the name ""

end

class ToggleLogging
def self.setup
Signal.trap('USR1') do
toggle
end
end
def self.toggle
level_before = Rails.logger.level == Logger::DEBUG
Rails.logger.level = debug_before ? Logger::INFO : Logger::DEBUG