Skip to content

Instantly share code, notes, and snippets.

{
// Synced with https://github.com/jshint/jshint/blob/master/examples/.jshintrc
// comments/etc retained to enable diff'ing
// Detailed explanation of options:
// - http://www.jshint.com/docs/options/
"maxerr" : 10000, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
@lamchau
lamchau / sinon-test-helper.js
Created May 16, 2015 01:06
sinon + ic.ajax
function fakeServer(method, url, response) {
response = response || {
"data": "default"
};
var server = sinon.fakeServer.create(),
// force a server pass through to enable response delays
forceServer = sinon.stub(App, "isApiEndpoint").returns(false),
// ic.ajax will always do an internal lookup before passing it on
windows:
todo = "!f() { git diff $1 -STODO | grep -E '\\+\\+\\+|TODO' | sed 's/+++ b\\//\\n/' | sed 's/\\+\\s*\\/\\// */'; }; f"
unix:
todo = "!f() { git diff $1 -STODO | grep -E '\+\+\+|TODO' | sed 's/+++ b\//\n/' | sed 's/+\s*\/\// */'; }; f"
var woot = document.querySelector('#woot');
var song = document.querySelector('#now-playing-media');
var date = function () {
return new Date().toLocaleString().replace(',', '');
};
var observer = new MutationObserver(function(mutation) {
var wootable = woot.querySelector('.icon-woot');
if (wootable) {
console.log('autowoot @ %s: %s', date(), song.innerText);
function pad(n, count) {
// http://stackoverflow.com/a/15398371
var length = (Math.log(Math.abs(n + 1)) * 0.43429448190325176 | 0) + 1;
count = Math.max(count - length, 0);
if (n < 10) {
return n;
}
// http://stackoverflow.com/a/5450113
@lamchau
lamchau / logging.js
Created April 21, 2015 00:31
simple pretty log4j-like logging (requires chalk for color)
var util = require('util');
var chalk = require('chalk');
var LOG_TYPE = chalk.bold.black('[') + '%s' + chalk.bold.black(']') + ':';
var ALL = {
type: 'ALL'
};
var TRACE = {
type: 'TRACE',
fn: console.log,
@lamchau
lamchau / youtube-repeat.js
Created April 19, 2015 09:28
youtube infinite repeater
(function() {
if (!/youtube.com$/i.test(location.host)) {
alert("hostname does not match 'youtube.com'");
return;
}
var timeout;
var resume;
var repeat = function repeat() {
clearTimeout(timeout);
describe('filterObject', function () {
it('should filter out falsey values', function () {
var actual = filterObject({
empty: '',
depth: 0,
nested: {
empty: '',
depth: 1,
nested: {
empty: '',
(function(History) {
if (!Ember.Object.detectInstance(History)) {
throw new Error("Native `Ember.History` is already defined.");
}
if (Ember.Evented.detect(History)) {
return;
} else {
History.reopen(Ember.Evented);
}
@lamchau
lamchau / controllers__command.js
Created April 2, 2015 20:25
ember.js: command pattern with browser history for undo/redo
/**
* Command Dispatcher for managing {@code App.Command}.
*
* {@link http://en.wikipedia.org/wiki/Command_pattern|Command Pattern}
*/
App.CommandController = Ember.Controller.extend({
commands: null,
result: null,
position: 0,
maxRedo: 0,