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
### Basic routes ### | |
Rails 2: | |
# singular resource | |
map.resource :account | |
# resources with addition member & collection actions | |
map.resources :games, :member => { :download => :get }, :collection => { :favourites => :get } | |
Rails 3: |
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
# Factory girl, relaxed. | |
# | |
# Factory.define :user do |f| | |
# f.login 'johndoe%d' # Sequence. | |
# f.email '%{login}@example.com' # Interpolate. | |
# f.password f.password_confirmation('foobar') # Chain. | |
# end | |
# | |
# Factory.define :post do |f| | |
# f.user { Factory :user } # Blocks, if you must. |
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
class ImageMagick | |
def self.palette(image_file, number_of_colours = 5) | |
image_details = %x(convert #{image_file} +dither -depth 8 -colors #{number_of_colours} -unique-colors txt:-) | |
image_details.scan(/#[a-z0-9]{6}/i) | |
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
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config |
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
# Rails 3 generator for miniskirt | |
# Add the factory_girl gem | |
append_file 'Gemfile', <<-GEMS | |
group :test do | |
gem 'miniskirt' | |
end | |
GEMS | |
# touch the file for storing factories |
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
MVIM Cheat Sheet: | |
* auto complete | |
ctrl+n | |
or | |
ctrl+p | |
* Running Rake for test | |
:Rake |
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 the javascripts dir | |
run 'mkdir public/javascripts' | |
# pull down jquery, jquery-ui and the appropriate rails driver | |
run 'curl -L http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js > public/javascripts/jquery.js' | |
run 'curl -L http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js > public/javascripts/jquery-ui.js' | |
run 'curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js > public/javascripts/rails.js' |
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 a fresh git repo | |
git :init | |
git :add => "." | |
git :commit => "-m 'Initial commit.'" | |
# Create the javascripts dir | |
run 'mkdir public/javascripts' |
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
<link rel="apple-touch-icon" media="screen and (resolution: 163dpi)" href="57px.png" /> | |
<link rel="apple-touch-icon" media="screen and (resolution: 132dpi)" href="72px.png" /> | |
<link rel="apple-touch-icon" media="screen and (resolution: 326dpi)" href="114px.png" /> |
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
# divide an array with one pint too many | |
class Array | |
def /(divider) | |
divider = divider.to_i | |
collection_size = size / divider | |
array = [] | |
each_with_index do |element, index| | |
index % collection_size == 0 && divider != array.size ? array << [element] : array.last.push(element) | |
end | |
array.size == 1 ? array.flatten! : array |
OlderNewer