Skip to content

Instantly share code, notes, and snippets.

FactoryGirl.define do
factory :user do
email 'myuser@test.com'
password 'this IS a BAd passowrds1234!!'
trait :confirmed do
confirmed_at { Time.now }
confirmation_token nil
end
@cupakromer
cupakromer / gist:8851663
Last active August 29, 2015 13:56
On Open Classes and Message Passing in Ruby #retroruby
"Words" * 2
# => "WordsWords"
2 * "Words"
# TypeError: String can't be coerced into Fixnum
# Oops what just happened?
# In Ruby, virtually everything is a message to another object.
# Above we would say:
@cupakromer
cupakromer / hilong.rb
Created February 14, 2014 17:51 — forked from jstorimer/hilong.rb
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile
@cupakromer
cupakromer / gist:9144881
Created February 21, 2014 22:24
😧 Mongo BSON dump restore script
#!/usr/bin/env ruby
#
# Little ditty to untar a bunch of mongo bson dumps,
# and then restore them.
#
# Remembers if something was processed before and doesn't
# process it again. (Though mongo will basically due this
# for you 😬)
#
# I'm a bad person and I should feel bad for writing this
@cupakromer
cupakromer / gist:9149496
Last active August 29, 2015 13:56
Advanced RSpec Hook Inclusion

Check the Metadata

Say you normally use the great database_cleaner gem. Per the README the standard setup is:

RSpec.configure do |config|

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
@cupakromer
cupakromer / gist:9214777
Last active August 29, 2015 13:56
Check log script
cat_with_name() { for i in $* ; do echo ; echo "=== $i ===" ; cat $i ; done }
@cupakromer
cupakromer / chruby.sh
Last active August 29, 2015 13:56
Patch local binstubs into chruby
CHRUBY_VERSION="0.3.8"
RUBIES=()
for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
[[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
done
unset dir
function chruby_reset()
{
@cupakromer
cupakromer / flatten_map_bm.rb
Last active August 29, 2015 13:56
If you may have an array of arrays, `flat_map` is probably the way to go
require "benchmark"
require "benchmark/ips"
def arr
Array.new(1_000, 1)
end
def arr_of_arrs
Array.new(1_000){ (1..1000).to_a }
end
@cupakromer
cupakromer / gist:9414554
Created March 7, 2014 16:19
Command Line Tricks

Command Line Tricks

  • !! Repeat Previous Command
  • !-1 Repeat Previous Command
  • !-2 Repeat 2nd Previous Command
  • !ps Execute Previous Command STARTING WITH ps
  • !^ First Argument From Previous Command
  • !:2 2nd Argument From Previous Command
  • !$ Last Argument From Previous Command
  • !!:$ Last Argument From Previous Command
@cupakromer
cupakromer / gist:9934026
Created April 2, 2014 13:25
RelishApp Syntax Formatting Test
Feature: Testing Code Blocks
In the feature description.
Only indent to specify code block:
No indent:
/a regex/
a_string = "foo"