Skip to content

Instantly share code, notes, and snippets.

@hashchange
hashchange / marionette.handlebars.js
Last active Aug 29, 2015 — forked from funkjedi/marionette.handlebars.js
Handlebars for Marionette. -- No longer maintained. Instead, please use https://github.com/hashchange/marionette.handlebars
View marionette.handlebars.js
/**
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* This gist is no longer updated. Please use
*
* https://github.com/hashchange/marionette.handlebars
*
* instead.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@hashchange
hashchange / debounce.js
Last active Jun 28, 2016
Stand-alone, straightforward debounce function. Executes the callback at the end (no option for executing at start).
View debounce.js
function debounce( callback, delay, context ) {
var timer;
return function () {
var _this = context || this,
args = arguments;
// Clear a timer which has been created earlier in the sequence of calls.
timer && clearTimeout( timer );
@hashchange
hashchange / custom_error.js
Last active Jul 4, 2016
Patterns for creating custom error types.
View custom_error.js
// Pattern for creating a custom error type.
//
// Based on Zakas, Professional Javascript for Web Developers, 3rd Ed., p. 619,
// See also http://stackoverflow.com/a/5251506/508355, including comments.
function MyCustomError ( message ) {
this.message = message;
if ( Error.captureStackTrace ) {
Error.captureStackTrace( this, this.constructor );
@hashchange
hashchange / precompiled.declarative.handlebars.templates.js
Last active Sep 7, 2016
Precompiled.Declarative.Handlebars.Templates – a plug-in for Backbone.Declarative.Views, enabling the use of precompiled Handlebars templates.
View precompiled.declarative.handlebars.templates.js
/**
* Precompiled.Declarative.Handlebars.Templates
*
* Plug-in for Backbone.Declarative.Views, enabling the use of precompiled Handlebars templates.
*
* For defining `el`-related properties along with a precompiled template, modify the template source. Add a special
* comment to the source, just as you would in a template string. An example:
*
* <!-- data-tag-name="ul" data-class-name="list" -->
*
@hashchange
hashchange / rounding.js
Created Jul 26, 2015
Floating-point versions of Math.round, Math.floor, Math.ceil
View rounding.js
/**
* Adjusts a number to a given precision, working around the buggy floating-point math of Javascript. Works for
* round, floor, ceil operations.
*
* Lifted from the Math.round entry of MDN. Minor changes without effect on the algorithm.
*
* @param {string} operation "round", "floor", "ceil"
* @param {number} value
* @param {number} [precision=0] can be negative: round( 104,-1 ) => 100
* @returns {number}
@hashchange
hashchange / scrollTargetPosition.js
Created Aug 17, 2015
Returns the scroll target position for scrolling to the top of an element.
View scrollTargetPosition.js
/**
* Returns the scroll target position for scrolling to the top of an element.
*
* Pass the result to a scrollTo method:
*
* - $scrollContainer.scrollTop( result ) for instant scrolling
* - $scrollContainer.scrollTo( result ) for animated scrolling with jQuery.scrollable
*
* @param {jQuery} $target the target element
* @param {jQuery} $scrollContainer either $(window), or a scrollable HTML element
View _map-sort.scss
/// map-sort
/// Sort map by keys
/// @param $map - A SASS map
/// @returns A SASS map sorted by keys
/// @requires function list-sort
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function map-sort($map) {
$keys: list-sort(map-keys($map));
$sortedMap: ();
@each $key in $keys {
@hashchange
hashchange / README.md
Created Mar 22, 2018 — forked from barneycarroll/README.md
Lock and unlock a page's scroll position.
View README.md

jquery.scrollLock.js

Useful for when a blocking user experience is needed (in my case, didn't want people unwittingly loosing their place by scrolling while a modal required their attention): $.scrollLock() locks the body in place, preventing scroll until it is unlocked.

// Locks the page if it's currently unlocked
$.scrollLock();

// ...or vice versa
@hashchange
hashchange / export-custom-packages
Created Nov 30, 2021
Creates and maintains a list of all manually-installed packages in a Ubuntu distro.
View export-custom-packages
#!/usr/bin/env bash
# Script name
PROGNAME=$(basename "$0")
if [[ "$1" == '--help' || "$1" == '-h' ]]; then
fmt -s <<- HELP_TEXT
Writes and updates a list of all manually-installed packages in a Ubuntu distro.
@hashchange
hashchange / wsl-windows-path
Last active May 10, 2022
Safely converts a WSL (Linux) path to a Windows path. Does not suffer from the limitations of `wslpath -w`.
View wsl-windows-path
#!/usr/bin/env bash
# Script name
PROGNAME="$(basename "$BASH_SOURCE")"
if [[ "$1" == '--version' || "$1" == '-v' ]]; then
fmt -s <<- VERSION_TEXT
$PROGNAME 1.1.2
(c) 2022 Michael Heim
License: MIT