Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
# after $ mysql -u ''adminusername'' -p
CREATE DATABASE ''databasename'';
GRANT ALL PRIVILEGES ON ''databasename''.* TO "''username''"@"''hostname''" IDENTIFIED BY "''password''";
FLUSH PRIVILEGES;
EXIT
def fields_for_work_experience(work_experience, &block)
prefix = work_experience.new_record? ? 'new' : 'existing'
# uses the fields_for helper with a block that gives an extra option to the form fields preventing hash and array param clashes (also for date_selects) which
# would otherwise cause a server error.
fields_for("candidate[#{prefix}_work_experience_attributes][]", work_experience) { |wef| wef.with_options :index => "", &block }
end
# Helper for work experience fields, adopted from Advanced Rails recipes 13 and railscasts 73-75 from Ryan Bates.
def fields_for_work_experience(work_experience, &block)
unless work_experience.new_record?
prefix = 'existing'
fields_for("candidate[#{prefix}_work_experience_attributes][]", work_experience, &block)
else
prefix = 'new'
# uses the fields_for helper with a block that gives an extra option to the form fields preventing hash and array param clashes (also for date_selects) which
# would otherwise cause a server error.
fields_for("candidate[#{prefix}_work_experience_attributes][]", work_experience) { |we| we.with_options :index => "", &block }
require 'autotest/redgreen'
module Autotest::Growl
def self.growl title, msg, img, pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{ msg.inspect} #{title} #{stick}"
end
Autotest.add_hook :ran_command do |autotest|
# We could both use test-unit and rspec which use respectively 'examples' and 'tests' as prefix.
# More info on http://www.jeevidee.nl/instant_rails_application
# template.rb
in_root { run("rm public/index.html") }
# My plugins
plugin "dm_generator", :git => "git://github.com/jeroenvandijk/dm_generator.git -r amsterdam.rb"
plugin "dm_templates", :git => "git://github.com/jeroenvandijk/dm_templates.git -r amsterdam.rb"
plugin "dm_designs", :git => "git://github.com/jeroenvandijk/dm_designs.git"
# template.rb
in_root { run("rm public/index.html") }
# Finalize
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
# TODO divide examples into groups
# one assertion at a time, so more intelligence to interpretation of comments
# TODO define state
# Think further of how to exploit this
module ObjectHooks
def inherited(*args)
# puts preceding_comments
class ResourceController < ApplicationController
acts_as_resource
# Set flashes to I18n
create.flash { translate_flash :create }
create.fails.flash { translate_flash :create_fails }
update.flash { translate_flash :update }
update.fails.flash { translate_flash :update_fails }
destroy.flash { translate_flash :destroy }