This file contains 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
namespace :haml do | |
desc "Convert all .erb views to .haml" | |
task :assimilate => :environment do | |
git = File.exist?( Rails.root.join('.git') ) | |
chdir Rails.root do | |
Dir["app/views/**/*.erb"].map do |file| | |
[ file, file.gsub(/\.erb$/, '.haml') ] | |
end.each do |(erb, haml)| | |
sh "bundle exec html2haml #{erb} #{haml}" |
This file contains 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
# http://dontmindthelanguage.wordpress.com/2009/12/09/groovy-delegate-annotation/ | |
# class Cleaner { | |
# def doWork() { "clean" } | |
# } | |
# | |
# class Employee { | |
# def doWork() { "work!" } | |
# } | |
# | |
# class Manager { |
This file contains 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
#!/bin/bash | |
# | |
# Install virtualbox: | |
# - http://www.virtualbox.org/wiki/Downloads | |
# - Download iso: http://releases.ubuntu.com/10.10/ | |
# - Create a new virtualbox using the iso as the install media | |
# - Change network adapter to bridged | |
# - Use ifconfig to get ip address | |
# | |
# Once you have a clean install of ubuntu... |
This file contains 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
# Making a large class modular | |
# * Put core functionality into Base module inside your class | |
# * Split other functionality into modules and include them at the bottom of the | |
# your class | |
# * Now it is easy to reuse or recreate custom versions of the class by creating | |
# new classes, including only some modules, swapping modules out for others, etc. | |
class MainClass | |
module Base | |
attr_accessor :name | |
def initialize(name) |
This file contains 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
# Goal: Demonstrate the building blocks for creating a DSL in ruby, based on | |
# bundler's Gemfile DSL implementation | |
module Remote | |
# Responsible for evaluating the specification. This will transform the | |
# specification into meaningful data structures that can be acted on. | |
class Dsl | |
# Given a string of dsl code, create a new instance of dsl and evaluate | |
# the code within the context of the instance. |
This file contains 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
# Create our own log subscriber that logs a little more | |
class VerboseLogSubscriber < ActiveSupport::LogSubscriber | |
def request(event) | |
result = event.payload[:result] | |
info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}" | |
info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration] | |
info result.body | |
end | |
end |
This file contains 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
curl -sOL https://github.com/nathansmith/960-Grid-System/raw/master/code/css/uncompressed/960.css | |
curl -sOL https://github.com/nathansmith/960-grid-system/raw/master/code/css/uncompressed/reset.css | |
curl -sOL https://github.com/nathansmith/960-grid-system/raw/master/code/css/uncompressed/text.css |
This file contains 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 'active_record' | |
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" | |
ActiveRecord::Schema.define do | |
create_table :authors do |t| | |
t.string :name, :null => false | |
end | |
add_index :authors, :name, :unique |
This file contains 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
# This module follows best practices for daemonizing processes in a UNIX | |
# environment with as little fluff as possible. Forks once, calls `setsid`, | |
# and forks again. STDIN, STDOUT, STDERR are all redirected to /dev/null by | |
# default. We'll even manage the pidfile | |
# | |
# `chdir` and `umask` are optional precautions: | |
# | |
# * `chdir` is a safeguard against problems that would occur is you tried to | |
# launch a daemon process on a mounted filesystem | |
# * `umask` gives your daemon process more control over file creation |
This file contains 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 self.save | |
super | |
rescue ActiveRecord::StatementInvalid => e | |
if e.message =~ /Mysql::Error: Duplicate entry/ | |
errors.add(...) | |
else | |
raise | |
end | |
end |