Skip to content

Instantly share code, notes, and snippets.

@moos
moos / serve-wsl.js
Created January 14, 2021 20:46
Hot reload and do full builds with `esbuild` for WSL
const { build } = require('esbuild');
const liveServer = require('live-server');
var watch = require('node-watch');
async function fullBuild() {
const builder = await build({
color: true,
entryPoints: ['./src/index.js'],
outfile: './build/app.js',
minify: false,
// per https://docs.npmjs.com/misc/scripts, npm exposes a bunch of variables to
// the environment prefixed with npm_config_*, npm_package_* and npm_lifecycle_*.
// Here's a list of all variables exposed in my setup.
npm_config_access=
npm_config_allow_same_version=
npm_config_also=
npm_config_always_auth=
npm_config_argv='{"remain":[],"cooked":["run","foo"],"original":["run","foo"]}'
npm_config_auth_type=legacy
@moos
moos / gist:34645e0468578c416469
Last active September 17, 2015 17:37
Backbone.Model.prototype.reset(attrs, options)
/**
* add reset() to Backbone.Model. Note 'id' attribute is kept.
*
* Unlike Backbone.Collection's native reset, no 'reset' event is fired.
*
* @param attrs {object} - hash of any new attributes to set, otherwise set to defaults
* @param options {object} - options to pass to set()
*/
Backbone.Model.prototype.reset = function(attrs, options) {
var opts = _.defaults(options || {}, {silent: true}),
@moos
moos / mousetrap.numbers.js
Last active December 10, 2021 23:03
Number sequence handler for Mousetrap
/**
* Mousetrap numbers plugin -- add support for 'number' and 'numbers' keywords
*
* Usage:
*
* Mousetrap.bind('number', callback) - handle any single number
*
* Mousetrap.bind('numbers', callback) - handle a sequence of 1+ numbers
*
* // pre sequence
@moos
moos / backbone.view.rAF.js
Created March 18, 2014 22:59
A handy method for Backbone views to execute an update method on requestAnimationFrame, eg. this.requestFrame('render');
/**
* Execute a Backbone View method or function at next animation frame, while
* correctly handling multiple requests.
*
* Caveat: only one anonymous function can be used at a time. Use a named function or method name.
*
* @example (from a Backbone view):
*
* this.requestFrame('render') // execute method render of current object
* this.requestFrame(this.render) // same as above