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
module Mustache | |
class << self | |
import com.github.mustachejava.DefaultMustacheFactory | |
import com.github.mustachejava.jruby.JRubyObjectHandler | |
def template_dir | |
Rails.root.join('app', 'templates') | |
end | |
def factory |
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
module UserHelper | |
attr_accessor :current_user | |
class Credentials < Struct.new(:email, :password) | |
def self.parse(arg) | |
return arg if arg.is_a?(Credentials) | |
new(arg) | |
end | |
def initialize(credentials) |
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
# After reading this comment | |
# http://avdi.org/devblog/2010/08/02/using-and-and-or-in-ruby/#comment-1098 , | |
# | |
# I became aware of a cool idiom for Ruby. | |
# | |
# I've seen this in a lot of cases: | |
if (variable = expression_or_method(options)) | |
variable.calculate_something | |
do_other_stuff(variable) |
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 :vlad do | |
desc "installs Bundler if it is not already installed" | |
remote_task :install_bundler do | |
run "sh -c 'if [ -z `which bundle` ]; then echo Installing Bundler; sudo gem install bundler --pre; fi'" | |
end | |
desc "run 'bundle install' to install Bundler's packaged gems for the current deploy and cache the config and lock files for the next releases" | |
remote_task :bundle_install do | |
run "cd #{latest_release} && bundle install #{shared_path}/bundle --without development test" |
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
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return | |
require 'benchmark' | |
def explicit | |
return 1 | |
end | |
def implicit | |
1 | |
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
remove_constant(:JavaScriptHelper) | |
Kernel.expects(:require).with('action_view/helpers/javascript_helper') | |
JavaScriptHelper |
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
# I hear that aliasing lambda is bad, but this is | |
# much more readable... | |
alias :this_block :lambda | |
this_block{ @this.destroy }.should change(Thing, :count).by(-1) | |
# (tomafro) I've done this for ages, only using doing rather than this_block: | |
alias :doing, :lambda |