Skip to content

Instantly share code, notes, and snippets.

View jasonkarns's full-sized avatar
🏠
Working from home

Jason Karns jasonkarns

🏠
Working from home
View GitHub Profile
@jasonkarns
jasonkarns / rubocop-ruby.rake
Last active October 9, 2024 18:32
Print the target ruby version derived by rubocop
namespace :rubocop do
task :ruby do
require "rubocop"
config = RuboCop::ConfigStore.new.for_dir Dir.pwd
target = RuboCop::TargetRuby.new(config)
if Rake.application.options.trace || verbose == true
rake_output_message "derived target ruby version (last wins):"
rake_output_message target.class.const_get(:SOURCES).reverse.map { |s| s.new config }
<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by NetNewsWire -->
<opml version="1.1">
<head>
<title>Subscriptions.opml</title>
</head>
<body>
<outline text="0X404DEAD" title="0X404DEAD">
<outline text="Andy Budd" title="Andy Budd" description="" type="rss" version="RSS" htmlUrl="http://www.andybudd.com/" xmlUrl="http://www.andybudd.com/index.rdf"/>
<outline text="Ben Alman » News" title="Ben Alman » News" description="" type="rss" version="RSS" htmlUrl="http://pipes.yahoo.com/pipes/pipe.info?_id=7pC7HRAi3RGGdfjlMlrX_Q" xmlUrl="http://feeds.benalman.com/benalman/"/>
class BitInquirer
def self.[](mask_map)
Class.new(SimpleDelegator) do
mask_map.each do |name, mask|
define_method name do
allbits?(mask)
end
end
end
end
@jasonkarns
jasonkarns / mailer_preview_helper.rb
Last active May 27, 2021 15:23
A helper to generate mailer previews automatically (or more easily) for each action that exists on the mailer.
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
jasonkarns / npm_package.txt
Created August 26, 2020 02:53
npm_package environs
$ grep -RIho -E '\$npm_package_[_0-9a-z]*' . 2>/dev/null | sort -u
$npm_package_
$npm_package_actions
$npm_package_bin_brew_publish
$npm_package_bin_node_build
$npm_package_bin_packfiles
$npm_package_bin_validate_analytics_data
$npm_package_browser
$npm_package_config_
$npm_package_config_app
@jasonkarns
jasonkarns / npx.bash
Created January 4, 2019 22:19
nodenv exec hook to make npx happy
[ "$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

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 June 2, 2017 15:09 — forked from chrmoritz/issue.md
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
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);
}
require 'axe/configuration'
module Axe
class FindsPage
WEBDRIVER_NAMES = [ :page, :browser, :driver, :webdriver ]
class << self
alias :in :new
end