- churn script:
git log --name-only | grep *.rb | sort | uniq -c | sort -nr | head
- Bread recipe for Jeff: http://www.youtube.com/watch?v=13Ah9ES2yTU
- Conway's law - Sarah Mei's RubyConf 2012 keynote http://www.confreaks.com/videos/1304-rubyconf2012-the-insufficiency-of-good-design
- Make smaller things (it's hard to err in the direction of too small, and you can always merge things together). Fred George,
This file contains hidden or 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 UsersController < ApplicationController | |
def create | |
@user = User.new params[:user] | |
return render 'new' unless @user.save | |
flash[:notice] = "The user was created succesfully" | |
redirect_to :index | |
end |
This file contains hidden or 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
s/\([^.a-zA-Z_-]\)stub\>/\1double/g | |
s/\([^.a-zA-Z_-]\)mock\>/\1double/g | |
s/\.returns\>/.and_return/g | |
s/\.yields\>/.and_yield/g | |
s/\(\S\+\)\.stubs(/allow(\1).to receive(/g | |
s/\(\S\+\)\.expects(/expect(\1).to receive(/g | |
s/at_least_once/at_least(:once)/g | |
s/at_most_once/at_most(:once)/g | |
s/\.raises\>/.and_raise/g | |
s/\(allow\|expect\)(\(\S\+\)\.any_instance).to receive/\1_any_instance_of(\2).to receive/g |
This file contains hidden or 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
# You will need the pygments and xclip packages | |
# This example highlights some Bash source code | |
# '-O noclasses=true' tells pygments to embed colors inline in the source | |
# the '-t text/html' option tells xclip what "target" to specify for the selection | |
pygmentize -l bash -f html -O noclasses=true mysource.sh | xclip -selection clipboard -t text/html |
Command Line
pry -r ./config/app_init_file.rb
- load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb
- load your rails into a pry session
Debugger
This file contains hidden or 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
find . -name "*.[mh]" | while read line; do expand -t 4 $line > $line.new; mv $line.new $line; done | |
find . -name "*.[mh]" | while read line; do git stripspace < $line > $line.new; mv $line.new $line; done |
This file contains hidden or 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 'capybara' | |
require 'capybara/dsl' | |
require 'capybara/poltergeist' | |
require 'awesome_print' | |
Capybara.run_server = false | |
Capybara.current_driver = :poltergeist | |
class Oyster |
This file contains hidden or 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
# Original Rails controller and action | |
class EmployeesController < ApplicationController | |
def create | |
@employee = Employee.new(employee_params) | |
if @employee.save | |
redirect_to @employee, notice: "Employee #{@employee.name} created" | |
else | |
render :new | |
end |
This file contains hidden or 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
drop table if exists target_homes; | |
with | |
supermarket_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from osm_polygons where osm_polygons.shop='supermarket'), | |
rail_stop_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from trimet_rail_stops), | |
park_zones as (select st_expand(geom, 0.0045) as zone, 2 as score from osm_polygons where osm_polygons.leisure='park'), | |
target_buildings as ( | |
select * from supermarket_zones inner join buildings on st_intersects(supermarket_zones.zone, buildings.geom) where buildings.subarea='City of Portland' | |
union select * from rail_stop_zones inner join buildings on st_intersects(rail_stop_zones.zone, buildings.geom) where buildings.subarea='City of Portland' | |
) |