Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Jason Karns jasonkarns

🏠
Working from home
Block or report user

Report or block jasonkarns

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jasonkarns
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
path_before="$result"
result="${result//:$path_to_remove:/:}"
done
View nodenv.md

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
jasonkarns / issue.md
Last active Jun 2, 2017 — forked from chrmoritz/issue.md
3 undocumented breaking changes we encountered while upgarding npm to v5.0.1 in homebrew
View issue.md

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
end
@jasonkarns
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)
attributes.map.each do |k,v|
self.class.instance.instance_variable_set(:"@#{k}", v)
end
end
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(Regexp.new("(?<num>123)")).to match("a123a").with_captures("123")
end
# 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 = @a11y_check.call Page.new page
::RSpec::Expectations::FailureAggregator.new(@audit.invocation, nil).aggregate do
@audit.results.violations.each {|v| ::RSpec::Expectations.fail_with v.failure_message }
end
@audit.passed?
end
@jasonkarns
jasonkarns / capturing_matcher.rb
Created Jul 29, 2015
Custom Matcher that extends RSpec::Matchers::BuiltIn::Match to also enable specifying capture groups.
View capturing_matcher.rb
module CustomMatchers
class Match < RSpec::Matchers::BuiltIn::Match
def matches?(actual)
# first ensure the regex matched
return false unless result = super
# only continue if specifying captures
return result unless expected_captures = @captures
actual_captures = to_hash result
@jasonkarns
jasonkarns / kill-domcontentloaded.js
Created May 8, 2015
Kills DOMContentLoaded in Opera when executed prior to jquery
View kill-domcontentloaded.js
var DOMContentLoaded = function() {
document.removeEventListener('DOMContentLoaded', DOMContentLoaded);
document.body.appendChild(document.createElement('iframe'));
};
document.addEventListener('DOMContentLoaded', DOMContentLoaded);
You can’t perform that action at this time.