Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Clayton joshuaclayton

View GitHub Profile
@joshuaclayton
joshuaclayton / 0_reuse_code.js
Created Sep 22, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@joshuaclayton
joshuaclayton / README.md
Last active Jun 1, 2018
RSpec custom matchers for Segment.io tracking
View README.md
View lists-broken.scss
$tablet: new-breakpoint(max-width 768px 8);
$mobile: new-breakpoint(max-width 480px 8);
li.location {
@include span-columns(4);
@include omega(3n);
@include media($tablet) {
@include span-columns(4);
@include omega(2n);
View 3.2 test output
[ ~/dev/gems/factory_girl master ] ✔ rake appraisal:3.2 spec:acceptance ☺ 1.9.3-p429
>> BUNDLE_GEMFILE=/Users/joshuaclayton/dev/gems/factory_girl/gemfiles/3.2.gemfile bundle exec /Users/joshuaclayton/.rbenv/versions/1.9.3-p429/bin/rake spec:acceptance
/Users/joshuaclayton/.rbenv/versions/1.9.3-p429/bin/ruby -S rspec spec/acceptance/activesupport_instrumentation_spec.rb spec/acceptance/aliases_spec.rb spec/acceptance/attribute_aliases_spec.rb spec/acceptance/attribute_existing_on_object_spec.rb spec/acceptance/attributes_for_spec.rb spec/acceptance/attributes_from_instance_spec.rb spec/acceptance/attributes_ordered_spec.rb spec/acceptance/build_list_spec.rb spec/acceptance/build_spec.rb spec/acceptance/build_stubbed_spec.rb spec/acceptance/callbacks_spec.rb spec/acceptance/create_list_spec.rb spec/acceptance/create_spec.rb spec/acceptance/define_child_before_parent_spec.rb spec/acceptance/defining_methods_inside_a_factory_spec.rb spec/acceptance/definitio
View demo_spec.rb
describe 'Page without plans' do
it 'passes unless a second assertion is made that .plans li contains at least one element' do
visit root_path
all('.plans li').each do |node|
expect(node.text).to match /\$\d{1,2}/
end
end
end
View gist:4019160
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.joshuaclayton.tmux_copy</string>
<key>ProgramArguments</key>
<array>
<string>/Users/joshuaclayton/.dotfiles/bin/tmux_copy</string>
</array>
@joshuaclayton
joshuaclayton / backtrace
Created Oct 2, 2012
Attempt at ensuring a test takes at most four seconds before failing
View backtrace
/Users/joshuaclayton/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/formatters/base_text_formatter.rb:181:in `dump_failure_info': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
View good-burgers.md
  • 1 1/3 lb grass-fed beef
  • 2 tbsp Worcestershire sauce
  • 3/4 tsp ground coriander seed
  • 1/2 tsp garlic powder
  • 1/4 tsp ground cumin
  • 4 tbsp softened butter
  • 1/2 tsp freshly ground pepper
  • 1/2 tsp freshly ground sea salt
  • 4 pieces of fresh cheese (Muenster or sharp cheddar are best)
View post_factory.rb
factory :post do
title "Example Post"
body "This is the body of the example post"
meta { { version: 2 } }
# or
meta({ version: 2 })
created_at "2012-06-01 17:53:13"
end
View explanation.md

There's ways to do cleaner SRP that allow moving email delivery out of a model and controller and still be flexible for emailing different things based on type of user, etc.; it's merely a matter of how you solve the problem. simple.rb is the simplest thing that'll do basically the same exact thing that the original author intended - separate object, fast to test, blah blah blah. Introducing DI to override delivery is super simple and can be a lambda/Proc or method; WithDeliveryEmail doesn't give a shit, as long as it has a call method accepting the user to deliver the email to.

Is the solution of moving email delivery outside the callback of the user sensible? Can other developers figure out what the side effects of saving a user from the controller immediately? Does creating a user always ensure that an email is delivered? If the system does what it needs to do and all those can be answered with yes, I think it