This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a number "rounded" to the nearest multiple of `amount`. | |
* | |
* @param {number} num - The number to quantize | |
* @param {number} amount - the quantization factor | |
* @return {number} The multiple of `amount` that is nearest to `number`. | |
*/ | |
quantize(num, amount) { | |
const halfway = Math.round(amount / 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My Awesome Sketch | |
Normal State* | |
hover -> Hover State | |
click -> Selected State | |
Hover State | |
unhover -> Normal State | |
click -> HoverSelected State | |
Selected State | |
hover -> HoverSelected State | |
clickanyother -> Normal State |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://plainjs.com/javascript/utilities/merge-two-javascript-objects-19/ | |
function extend(obj, src) { | |
Object.keys(src).forEach(function(key) { obj[key] = src[key]; }); | |
return obj; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Event Delegation with Plain Javascript | |
// from Adam Beres-Deak | |
// http://bdadam.com/blog/plain-javascript-event-delegation.html | |
function on(elSelector, eventName, selector, fn) { | |
var element = document.querySelector(elSelector); | |
element.addEventListener(eventName, function(event) { | |
var possibleTargets = element.querySelectorAll(selector); | |
var target = event.target; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('form').on('submit', function(evt) { | |
$('a, button:not([type]), [type="submit"]', this) | |
.prop('disabled', true); | |
$('a').addClass('is-disabled'); | |
}); | |
/* | |
The `is-disabled` class is added for the rare case that a link might | |
be set up to submit a form, since some browsers won't disable a link. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Jasmine sample code | |
This file is called a spec. | |
describe() groups related tests within a spec. | |
it() contains a single test. | |
The outer describe() matches the name of the module being tested. | |
Select elements only via test-foo classes! | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Markup in React | |
Javascript: | |
return React.createElement("p", {className: "foo"}, "Hello, world!"); | |
JSX: | |
return (<p className="foo">Hello, world!</p>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Merging objects via jQuery | |
var defaults = { validate: false, limit: 5, name: "foo" }; | |
var options = { validate: true, name: "bar" }; | |
// merged objects not modified -- creates new object `settings` | |
var settings = $.extend( {}, defaults, options ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ditto -c -k --rsrc --keepParent ~/Documents/ Docs.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DATE="`date +%Y%m%d"-"%H%M`" |
NewerOlder