Skip to content

Instantly share code, notes, and snippets.

View plukevdh's full-sized avatar
🔥

Luke van der Hoeven plukevdh

🔥
View GitHub Profile
@plukevdh
plukevdh / prod-setup.sh
Last active August 29, 2015 14:01
Shell helpers for sharing setups between dev and prod .rvmrc files
setup_env() {
if [[ -f ".env" ]]; then
for line in `cat .env`; do export $line; done
echo "Loaded .env file from this directory"
fi
}
bundled_commands=(foreman rackup rake rspec ruby shotgun thin pry)
_bundler-installed() {
@plukevdh
plukevdh / result
Last active August 29, 2015 14:01
ips: uniq vs. reduce
Calculating -------------------------------------
reduce 23 i/100ms
uniq 743 i/100ms
-------------------------------------------------
reduce 234.9 (±4.7%) i/s - 1173 in 5.005499s
uniq 7456.4 (±9.8%) i/s - 37150 in 5.081748s
@plukevdh
plukevdh / conditiona_validations.rb
Last active August 29, 2015 14:04 — forked from ibanez270dx/ConditionalValidations.rb
conditional validations in Rails 4+
module ConditionalValidations
extend ActiveSupport::Concern
attr_accessor :conditional_validations
def conditional_validations
@conditional_validations || []
end
def conditionally_validate(attribute, options=nil)
@plukevdh
plukevdh / course_sortable.rb
Last active August 29, 2015 14:05
hiding strategies from external
class CourseSortable
InvalidSortType = Class.new(StandardError)
def initialize(params, courses)
@strategy = get_strategy(params[:sort_by]).new(courses)
@strategy.descending! if (params[:sort_direction] == 'descending')
end
def sort
# RSpec matcher to spec delegations.
# Forked from https://gist.github.com/ssimeonov/5942729 with fixes
# for arity + custom prefix.
#
# Usage:
#
# describe Post do
# it { is_expected.to delegate(:name).to(:author).with_prefix } # post.author_name
# it { is_expected.to delegate(:name).to(:author).with_prefix(:any) } # post.any_name
# it { is_expected.to delegate(:month).to(:created_at) }
@plukevdh
plukevdh / bubble_change_events.js.coffee
Created September 9, 2014 19:15
bubbleable events for backbone
BubbleChangeEvents =
bubbleCollectionEvents: (container, watchAttributes...) ->
_.each watchAttributes, (attr) =>
@bubbleChangeEvent(attr, container)
@bubbleDestroyEvent(container)
@bubbleAddEvent(container)
bubbleChangeEvent: (attribute, container) ->

Excerpt from The Death of Adulthood in American Culture

Y.A. fiction is the least of it. It is now possible to conceive of adulthood as the state of being forever young. Childhood, once a condition of limited autonomy and deferred pleasure (“wait until you’re older”), is now a zone of perpetual freedom and delight. Grown people feel no compulsion to put away childish things: We can live with our parents, go to summer camp, play dodge ball, collect dolls and action figures and watch cartoons to our hearts’ content. These symptoms of arrested development will also be signs that we are freer, more honest and happier than the uptight fools who let go of such pastimes.

@plukevdh
plukevdh / context_nested.rb
Last active August 29, 2015 14:06
This feels broken in Rails 4
class Article < ActiveRecord::Base
has_many :images
end
class Image
belongs_to :article
validates :url, on: :publish
end
article = Article.new title: "Testing nested contexts"
@plukevdh
plukevdh / result.txt
Last active August 29, 2015 14:07
Why do mocked objects not assume identity of the object type they're mocking?
$> rspec test_case.rb
F.
Failures:
1) a failing case expects success
Failure/Error: expect(production_code(response)).to eq 'success'
expected: "success"
got: "failure"
@plukevdh
plukevdh / Rakefile
Created November 2, 2014 18:06
migrations a la sequel
namespace :db do
desc "Run migrations"
task :migrate, [:version] do |t, args|
require "sequel"
Sequel.extension :migration
db = Sequel.connect(ENV.fetch("DATABASE_URL"))
if args[:version]
puts "Migrating to version #{args[:version]}"