Skip to content

Instantly share code, notes, and snippets.

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);
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"
@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
{
// 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.)
function orderByProperty(prop) {
var args = [].slice.call(arguments, 1);
return function (a, b) {
var propA = a[prop];
var propB = b[prop];
var result;
if (typeof propA == 'string' || typeof propB == 'string') {
result = String(propA).localeCompare(propB);
} else {
function humanizeBytes(bytes, si) {
unit = si ? 1e3 : 1024;
var byteSuffix = (si ? 'b' : 'B');
if (bytes < unit) {
return bytes + byteSuffix;
}
var modifier = Math.floor(Math.log(bytes) / Math.log(unit));
var prefix = (si ? 'kMGTPEZ' : 'KMGTPEZ')[modifier - 1];
if (!si) {
function demethodize(fn) {
if (typeof fn === "function") {
return Function.bind.bind(Function.call)(fn);
}
return null;
}
_.mixin((function() {
return {
demethodize: function(fn) {
(function(I18n) {
if (!I18n) {
throw new Error('Missing dependency: I18n');
}
var translate = I18n.translate;
var slice = [].slice;
/**
* // en.js
Object.prototype[Symbol.iterator] = function() {
let self = this;
let keys = null;
let length = 0;
let index = -1;
return {
next() {
if (keys === null) {
keys = Object.keys(self);
@lamchau
lamchau / __components_inline-edit.js
Last active August 29, 2015 14:25
{{inline-edit}} for Ember
/**
* Inline Edit Component
*
* @author lamchau
*/
import Ember from "ember";
import KeyCodes from "utils/key-codes";
const DOUBLE_CLICK_COUNT = 2;
const SINGLE_CLICK_COUNT = 1;