Skip to content

Instantly share code, notes, and snippets.

Working from home

Jason Karns jasonkarns

Working from home
View GitHub Profile
jasonkarns / mailer_preview_helper.rb
Last active May 27, 2021
A helper to generate mailer previews automatically (or more easily) for each action that exists on the mailer.
View mailer_preview_helper.rb
module MailerPreviewHelper
extend ActiveSupport::Concern
included do
# Allows a mailer preview to override `params` method (either class or instance level)
# to define the hash that will be passed to the mailer by default by the `preview` helper.
class_attribute :params, default: {}, instance_accessor: false
mailer.instance_methods(false).each do |action|
define_method(action) { mailer.with(**params).send action }
jasonkarns / npm_package.txt
Created Aug 26, 2020
npm_package environs
View npm_package.txt
$ grep -RIho -E '\$npm_package_[_0-9a-z]*' . 2>/dev/null | sort -u
jasonkarns / npx.bash
Created Jan 4, 2019
nodenv exec hook to make npx happy
View npx.bash
[ "$NODENV_COMMAND" = npx ] || return 0
remove_from_path() {
local path_to_remove="$1"
local path_before
local result=":${PATH//\~/$HOME}:"
while [ "$path_before" != "$result" ]; do

Why choose nodenv?

Because nodenv was forked from rbenv, many of the reasons to choose nodenv over others are similar to why one would choose rbenv over rvm. (Nodenv also inherits a much longer battle-tested history than others.)

Auto switching

One of the biggest reasons to choose nodenv over the others is that nodenv can automatically select the appropriate node version for a given project. Neither nvm nor n have auto-switching capabilities out of the box. They both require some form of 'use' command to activate a given version; which lasts for the lifetime of the shell (or until another version is activated).

jasonkarns /
Last active Jun 2, 2017 — forked from chrmoritz/
3 undocumented breaking changes we encountered while upgarding npm to v5.0.1 in homebrew

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

supporting information:

  • npm -v prints: 5.0.1
View maxJSDate.js
module.exports = function findMaxValidDate(min, max) {
var next = Math.floor((min+max)/2);
if(min == next) return min;
if(new Date(next) == "Invalid Date") {
return findMaxValidDate(min, next);
} else {
return findMaxValidDate(next, max);
View finds_page.rb
require 'axe/configuration'
module Axe
class FindsPage
WEBDRIVER_NAMES = [ :page, :browser, :driver, :webdriver ]
class << self
alias :in :new
jasonkarns / singleton_yaml.rb
Created Mar 8, 2016
Deserialize YAML config file into a singleton instance
View singleton_yaml.rb
require 'singleton'
class Configuration
include Singleton
def init_with(attributes) do |k,v|
self.class.instance.instance_variable_set(:"@#{k}", v)
View match_with_captures_spec.rb
# named captures shouldn't *have* to be compared as a hash;
# MatchData still returns the captures as a plain indexed array,
# so matching against the indexed captures should still be allowed
it "matches indexed captures against named captures" do
expect("(?<num>123)")).to match("a123a").with_captures("123")
# doesn't make sense to show the expected captures if the match itself fails; they're irrelevant at that point
it "shows plain match failure message if match itself fails" do
expect {
View multiple_errors.rb
def matches?(page)
@audit = page, nil).aggregate do
@audit.results.violations.each {|v| ::RSpec::Expectations.fail_with v.failure_message }