Skip to content

Instantly share code, notes, and snippets.

View matthewrudy's full-sized avatar

Matthew Rudy Jacobs matthewrudy

View GitHub Profile
@matthewrudy
matthewrudy / loginable.rb
Last active June 26, 2019 22:30
Example of a module that expects the classes including it to have certain methods implemented
# typed: true
class AdminLogin
include Loginable
def email
'[email protected]'
end
end
@matthewrudy
matthewrudy / competitive_eater.rb
Created June 25, 2019 15:55
Example of using Protected methods for comparisons
class CompetitiveEater
include Comparable
def <=>(other)
spicy_tolerance <=> other.spicy_tolerance
end
def initialize(spicy_tolerance)
@spicy_tolerance = spicy_tolerance
end
module Refillable
extend ActiveSupport::Concern
include do
attr_reader :store
end
def refill!
@store = 100
end
@matthewrudy
matthewrudy / errors.out
Last active March 25, 2019 16:10
Changes required to make rspec-rails work with Rails 6
# this is what the errors looked like before
ActionView::Template::Error:
wrong number of arguments (given 2, expected 1)
@matthewrudy
matthewrudy / output.sh
Last active January 21, 2019 18:38
Heroku fails to release with bundler 2.0
$ cd /tmp
$ git clone https://github.com/matthewrudy/bundler2-heroku-example.git
Cloning into 'bundler2-heroku-example'...
remote: Enumerating objects: 94, done.
remote: Counting objects: 100% (94/94), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 94 (delta 5), reused 94 (delta 5), pack-reused 0
Unpacking objects: 100% (94/94), done.
@matthewrudy
matthewrudy / bundler2.diff
Last active January 22, 2020 15:08
Diff to make bundler 2 work on circleci.
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 37e192c..d639500 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -15,6 +15,7 @@ jobs:
ENABLE_REVIEW_APPS: true
BASIC_AUTH_USER: user
BASIC_AUTH_PASSWORD: password
+ BUNDLER_VERSION: 2.0.0
- image: circleci/postgres:11-alpine # 11
@matthewrudy
matthewrudy / add-update-then-null.rb
Created December 18, 2018 16:56
An example of adding a column as nullable, setting the default, then making it not null.
class AddTimestampsToRegions < ActiveRecord::Migration[4.2]
def up
add_timestamps :regions, null: true
execute "UPDATE regions SET created_at = NOW(), updated_at = NOW()"
change_column_null :regions, :created_at, false
change_column_null :regions, :updated_at, false
end
def down
remove_column :regions, :created_at
@matthewrudy
matthewrudy / example.sh
Created December 3, 2018 12:31
Compiling sass to css adds back in the leading zero
$ echo 'p { margin: .5em }' > /tmp/in.scss
$ sass --style compressed /tmp/in.scss /tmp/out.css
$ cat /tmp/out.css
p{margin:0.5em}
/*# sourceMappingURL=out.css.map */
@matthewrudy
matthewrudy / humans_are_hard
Last active November 23, 2018 20:09
Humans are Hard - talk blurb
When I started coding, everything was easy.
I went to our scrum board,
I took a card,
It had acceptance criteria,
maybe I had to ask a few questions,
but more or less I was left to code in peace.
Everything was simple.
I could be the 10x engineer everyone talks about.
@matthewrudy
matthewrudy / multi_counter.rb
Created August 29, 2018 11:27
A way of counting multiple values at once
class MultiCounter
def initialize(n)
@counters = [0]*n
end
def add(*values)
values.each_with_index do |v, i|
@counters[i] += v
end
end