Skip to content

Instantly share code, notes, and snippets.

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
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)
# 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)
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"
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def explicit
return 1
end
def implicit
1
end
remove_constant(:JavaScriptHelper)
Kernel.expects(:require).with('action_view/helpers/javascript_helper')
JavaScriptHelper
# 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