Skip to content

Instantly share code, notes, and snippets.

View Sort the Ruby files in your project by LOC
#Sort the Ruby files in your project by LOC
find . -iname "*.rb" -type f -exec wc -l {} \; | sort -rn
View Count the lines of Ruby code in your app
#Count the lines of Ruby code in your app
find . -iname "*.rb" -type f -exec cat {} \; | wc -l
shageman / application.js
Created Sep 1, 2012
Rails environment indicator
View application.js
<% if Rails.env != 'production' %>
document.addEventListener("DOMContentLoaded", function() {
display: 'block',
position: 'fixed',
left: '20px',
top: '500px',
'-webkit-transform': 'rotate(-90deg)',
'-moz-transform': 'rotate(-90deg)',
'-o-transform': 'rotate(-90deg)',
shageman / object_creation_methods.rb
Last active Oct 6, 2015
ObjectCreationMethods a la Jeff Dean
View object_creation_methods.rb
#lives in spec/support/object_creation_methods.rb
# Source:
module ObjectCreationMethods
def new_post(overrides = {})
defaults = {:title => "Some title #{counter}"} { |post| apply(post, defaults, overrides) }
shageman / the_class_that_is_true_but_never_in_the_same_way.rb
Created Mar 9, 2012
Why a question mark method should return the true object or the false object
View the_class_that_is_true_but_never_in_the_same_way.rb
require 'rspec/core'
class TheClassThatIsTrueButNeverInTheSameWay
def initialize(truthiness)
@truthiness = truthiness
def truthy?
@truthiness ? : false
shageman / predicate_matchers.rb
Created Mar 8, 2012
The problem of rspec predicate matchers
View predicate_matchers.rb
require 'rspec/core'
class VeryImportantQuestions
def self.really?(answer)
answer == 'Yes. I am telling you.'
def self.really_really?(answer)
answer == 'Yes. I am telling you.' ? 42 : nil
shageman / bar.rake
Created Feb 8, 2012
Testing rake tasks
View bar.rake
File: lib/tasks/bar.rake
class BarOutput
def self.banner text
puts '*' * 60
puts " #{text}"
puts '*' * 60
def self.puts string
puts string
shageman / .ideamodules.xml
Created Feb 8, 2012
InetlliJ Modules in Rubymine
View .ideamodules.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<module fileurl="file://$PROJECT_DIR$/custom_engine1/module1.iml" filepath="$PROJECT_DIR$/custom_engine1/custom_engine1.iml" />
<module fileurl="file://$PROJECT_DIR$/custom_engine2/module2.iml" filepath="$PROJECT_DIR$/custom_engine2/custom_engine2.iml" />
View sign_up_page.rb
class SignUpPage
def initialize
current_path.should == sign_up_path
def with_email(email)
fill_in "Login", :with => email
def with_password(password, confirmation = password)
View conductor.rb
class Conductor
include ActiveModel::Conversion
extend ActiveModel::Naming
include ActiveModel::Validations
class_attribute :object_names
def self.presents(*object_names)
self.object_names = object_names
object_names.each do |object_name|