Skip to content

Instantly share code, notes, and snippets.

View mcmire's full-sized avatar
🎯
Not a lot of time for side projects these days, so ping me if I'm unresponsive!

Elliot Winkler mcmire

🎯
Not a lot of time for side projects these days, so ping me if I'm unresponsive!
View GitHub Profile
@mcmire
mcmire / bypass_broken_images_middleware.rb
Last active October 16, 2021 11:09
Ignore requests for broken images in Capybara tests
# Instructions
# ------------
#
# * Save this as app/middlewares/bypass_broken_images_middleware.rb
# * Add the following inside of the Rails.application.configure block
# in config/environments/test.rb:
#
# config.middleware.insert_before(
#  ActionDispatch::DebugExceptions,
#  BypassBrokenImagesMiddleware,
@mcmire
mcmire / time_zones.txt
Created March 22, 2017 16:16
Time zone identifiers in Rails
[1] pry(main)> ActiveSupport::TimeZone.us_zones.map { |zone| puts "#{zone.name.inspect} => #{zone.tzinfo.name.inspect} (#{zone.utc_offset / 3600} from UTC)" }; nil
"Hawaii" => "Pacific/Honolulu" (-10 from UTC)
"Alaska" => "America/Juneau" (-9 from UTC)
"Pacific Time (US & Canada)" => "America/Los_Angeles" (-8 from UTC)
"Arizona" => "America/Phoenix" (-7 from UTC)
"Mountain Time (US & Canada)" => "America/Denver" (-7 from UTC)
"Central Time (US & Canada)" => "America/Chicago" (-6 from UTC)
"Eastern Time (US & Canada)" => "America/New_York" (-5 from UTC)
"Indiana (East)" => "America/Indiana/Indianapolis" (-5 from UTC)
@mcmire
mcmire / .eslintrc.yml
Last active January 9, 2019 01:34
My ESLint configuration
---
env:
browser: true
node: true
es6: true
extends: eslint:recommended
globals:
module: true
require: true
parserOptions:
@mcmire
mcmire / _css_overrides.html.erb
Created November 11, 2016 22:19
Disable transitions and animations in tests
<% if Rails.env.test? %>
<style type="text/css">
* {
transition-duration: 0s !important;
animation-duration: 0s !important;
}
</style>
<% end %>
@mcmire
mcmire / have_body_including.rb
Created November 2, 2016 01:53
Matcher for testing an email's body using Markdown
# You'll need to install the `reverse_markdown` gem in order for this to work.
module Matchers
def have_body_including(expected_inner_body)
HaveBodyIncludingMatcher.new(expected_inner_body)
end
class HaveBodyIncludingMatcher
def initialize(expected_inner_body)
@expected_inner_body = expected_inner_body.rstrip.gsub(/»\s+/, "")
@mcmire
mcmire / .rubocop.yml
Last active April 16, 2021 03:23
My Rubocop settings
---
AllCops:
Exclude:
- db/schema.rb
TargetRubyVersion: 3.0
Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation
Layout/ClassStructure:
Enabled: true
Layout/DotPosition:
@mcmire
mcmire / youtube.com.js
Last active May 30, 2016 20:56
How to make YouTube 100x better
// This script requires dotjs.
// You can install it here: <https://github.com/defunkt/dotjs>
// After you've done that, create a file, ~/.js/youtube.com.js, with these contents in it.
(function () {
var playerWidth = $("#placeholder-player > div").width();
// Remove "up next". It sucks you in, and turns a two-minute YouTube session
// into a two-hour one.
$("#watch7-sidebar").remove()
@mcmire
mcmire / 00_README.md
Last active May 24, 2016 19:05
Making a page object class for use in feature tests

Feature tests can oftentimes get long, complicated, and hard to maintain. One common strategy that I use to break them apart is to use "page object classes". These classes may contain methods to find elements on the page, methods to interact with those elements, and methods to make assertions about what the user sees after those interactions are made.

This gist demonstrates what these page object classes look like. One thing to note is that Capybara methods like find and RSpec methods such as expect are automatically available in the class. This is made possible by having the class inherit from SimpleDelegator and then having the test pass self to the class initializer when an object is created. self is the context in which the test is running, and by receiving it, the page object can access method that the feature test can access. Now, there's a second way you could accomplish this: you could include RSpec::Matchers and Capybara::DSL instead of inheriting from SimpleDelegator. But this approach has

@mcmire
mcmire / elixir.md
Last active March 17, 2017 11:10
Elixir notes

Elixir notes

Things I picked up while reading the getting started guide:

  • You can sort two arbitrary data types: 1 < atom evaluates to true.
  • + isn't overloaded like it is in Ruby -- it's only used for arithmetic. If you want to add two arrays together, use ++; two strings, use <>.
  • Single-quoted strings are character lists, and lists that are composed of ASCII character codes will be represented as single-quoted strings
  • Double-quotes strings are actually a different data type than single-quoted strings so 'foo' != "foo"
  • Lists are linked lists, tuples are stored contiguously in memory.
  • If you see "size" it's a performant operation, if you see "length" then you know it will scale as the data structure grows.
@mcmire
mcmire / react_ecosystem.md
Last active August 14, 2016 02:28
Notes on the React ecosystem: Flux, Reflux, Nuclear.js, and more

Following are notes I've compiled while researching the React ecosystems and frameworks/tools that people use within it.