Skip to content

Instantly share code, notes, and snippets.

@brettz9
brettz9 / .eslintignore
Last active February 26, 2020 09:14
Disabling of mostly stylistic rules when applying eslint-config-ash-nazg (for linting other projects or node_modules); should split these out within ash-nazg; also has overrides used for linting others' projects
# dist
# very unfortunately, it seems this can't be overridden apparently
# per https://eslint.org/docs/user-guide/configuring
# "ESLint always ignores files in /node_modules/* and /bower_components/*"
!node_modules
!.eslintrc.js
!.eslintrc-script.js
@brettz9
brettz9 / pug-i18n.js
Created January 19, 2020 11:51
pug i18n
'use strict';
// Todo: Move to own repo
const {i18n} = require('intl-dom');
const walk = require('pug-walk');
const fileFetch = require('file-fetch');
global.fetch = fileFetch; // For `intl-dom`
@brettz9
brettz9 / jamilih-lite.js
Last active January 11, 2020 02:37
Jamilih Lite (see also https://github.com/brettz9/jamilih ); for adaptation and inclusion in stand-alone libraries which still wish to build the DOM in an attractive, pure JS, and syntax-highlighting/JS-friendly manner. For the string-building equivalent, see https://gist.github.com/brettz9/72bb6a460212d9350f67
function jml (elName, atts, children) {'use strict';
var el = typeof elName === 'string' ? document.createElement(elName) : elName;
if (atts && Array.isArray(atts)) {
children = atts;
}
else if (atts) {
Object.keys(atts).forEach(function (att) {
var attVal = atts[att];
if (att === '$on') {
return Object.keys(attVal).forEach(function (ev) {
jq -r '.dependencies,.devDependencies|keys[]' package.json | while read line; do \
printf "$line: "
[ "$(npm show "$line" | grep -ic 'DEPRECATED')" != "0" ] && \
printf "\e[1;31m""DEPRECATED\n""\e[0m" || \
printf "\e[1;32m""not deprecated.\n""\e[0m"
done
@brettz9
brettz9 / set.js
Last active December 10, 2019 23:18
Simple JS equivalent of the Python set() constructor (without the methods)
/**
* Simple JS equivalent of the Python set() constructor (without the methods)
* @requires shim: Array.prototype.indexOf
* @param {array} arr The array to turn into a set
* @example
* var mySet = set(['red', 'yellow', 'black', 'yellow']);
* mySet.length; // 3
* JSON.stringify(mySet); // ["red","yellow","black"]
* @see For a fuller version, see {@link https://npmjs.org/package/set}
*/
@brettz9
brettz9 / .npmrc
Last active September 28, 2019 10:24
My current npmrc config
; Can get this file by `npm config edit` but doing so causes loss of some comments; better go get at `/Users/brett/.npmrc`
; Filed https://npm.community/t/npm-config-edit-reformats-file-stripping-user-comments/10287
; Off topic, but good info on migrating global npm for nvm:
; https://github.com/nvm-sh/nvm#migrating-global-packages-while-installing
; Also off topic: `npm star` not working
; https://npm.community/t/npm-star-shows-a-star-but-npm-stars-doesnt-list-any-stars-thereafter/10284
; Let\'s just try this and disable if ends up too oppressive (useful to
@brettz9
brettz9 / atom-edit-command.md
Last active September 27, 2019 02:11
Set up and use Atom as npm editor for `npm edit` command

Use -a flag to add project without opening new window:

npm config set editor 'atom -a'

Use npm edit . to open the current project (just a lightly better habit than calling atom -a directly in case changing editor).

Also allows adding, e.g., npm edit depOfCurrentPackage into Atom.

@brettz9
brettz9 / HTMLSelectElement.prototype.selectedOptions.js
Last active July 25, 2019 16:04
selectedOptions shim (multiple select) with IE8 support
/**
* Polyfill for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects are implementation-dependent,
* IE doesn't need to work this way). Also works on strings,
* fixes IE to allow an explicit undefined for the 2nd argument
* (as in Firefox), and prevents errors when called on other
* DOM objects.
* @license MIT, GPL, do whatever you want
-* @see https://gist.github.com/brettz9/6093105
@brettz9
brettz9 / OpenInTerminalTab.sh
Last active May 12, 2019 00:18
Sourcetree Custom action to open in Terminal *tab*; need `chmod 0755 OpenInTerminalTab.sh` enable SourceTree in `System Preferences->Security & Privacy->Privacy->Accessibility`; note: implementing as an application did not seem to work from within Sourcetree
#!/bin/sh
dir=$(dirname "$1")
scr=$(cat <<EOF
on run {}
set directory to "$dir"
set newTab to (application "Terminal" is running)
tell application "Terminal"
activate
@brettz9
brettz9 / sourcetree.md
Last active May 12, 2019 00:18
Sourcetree Custom Actions (right-click)

ATOM:

  • Menu Caption: Open in Atom
  • Script to run: /usr/local/bin/atom
  • Parameters: -n false -a $REPO

Terminal:

  • Menu Caption: Open in Terminal Tab
  • Script to run: /Applications/TerminalTab.sh
  • Parameters: Parameters: $REPO/$FILE