Skip to content

Instantly share code, notes, and snippets.

it "requires a password if the crypted password isn't set" do
account.password = ' '
account.crypted_password = nil; account.valid?
account.errors.must_include :password
end
@biscuitvile
biscuitvile / factory-tips.md
Last active August 29, 2015 14:07
Ryan Bates on Factories

I found the following comment on a blog from @ryanb in 2012, and to this day it is still a spot on, comprehensive list of everything I see people do wrong with factories to make their lives unintentionally harder:

While factories can get you in trouble, the key is to use them correctly. Here are some suggestions.

  • The base factory should be just enough to get validations passing and never contain specific data that is used by a test.
  • If you need an association, make a separate factory for it (such as comment_with_article) but keep the base factories free of associations unless they are required to make a valid record.
  • Don't attempt to get fancy, such as building has_many associations with factories. Any factory overly complex should be moved up into the test so it is clear what it is doing.
@biscuitvile
biscuitvile / batteries.md
Created September 23, 2014 13:11
Batteries

Trojan L-16RE-B Batteries (Not AGM?) $350.00

2 in series          =  370 amp hour @ 12 volts
4 in series parallel =  740 amp hour @ 12 volts
6 in series parallel = 1110 amp hour @ 12 volts

11-5/8" x 7" x 17-11/16"

class FormBuilder < ActionView::Helpers::FormBuilder
EMAIL_OPTIONS = {autocapitalize: 'off', autocomplete: 'off', autocorrect: 'off'}
def label(method, text = nil, options = {}, &block)
text = (text || method.to_s.humanize.titleize)
unless object.nil?
errors = object.errors[method.to_sym]
if errors.present?
text += " <small>#{errors.is_a?(Array) ? errors.first : errors}</small>"
options[:class] ||= 'error'
class EmojiMatcher
def self.match?(string)
new.match? string
end
def match?(string)
matchers.any? { |matcher| matcher.match string }
end
\u{2600}
\u{2614}
\u{2601}
\u{2744}
\u{26C4}
\u{26A1}
\u{1F300}
\u{1F301}
\u{1F30A}
\u{1F431}
@biscuitvile
biscuitvile / nacho-cheese.md
Created September 12, 2014 13:23
Insane Vegan Nacho Cheese Dip

Blow Yo Mind Nacho Dip

This is a modified version of one of recipes in the artisan vegan cheese book. Mine omits onion, increases adobo, decreases tapioca starch, and adds ume plum vinegar for more cheddary tang.

  • 1 cup cooked butternut squash
  • 1/4 cup cashews (you know they be soakin')
  • 3/4 cup water
  • 3/4 cup unsweetened nondairy yogurt
  • 5 tbs nutritional yeast
  • 2 tbs tapioca starch
bind c new-window -c '#{pane_current_path}'
bind | split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
@biscuitvile
biscuitvile / README.md
Last active August 29, 2015 14:02
Custom Minitest Assertion

Custom Minitest Assertions

It doesn't have to be like this:

-> { ShippingOption.find(shipping_option.id) }.must_raise ActiveRecord::RecordNotFound

I'm aware some feel assert_nothing_raised is an anti-pattern, but I think for finding ActiveRecord models it has value.

Mars Rover

Explanation

  • Develop an api that moves a rover around a grid.
  • You are given the initial starting point (x,y) of a rover and the direction (N,S,E,W) it is facing.
  • The rover receives a character array of commands.
  • Implement commands that move the rover forward/backward (f,b).
  • Implement commands that turn the rover left/right (l,r).
  • The only commands you can give the rover are f,b,l, and r.