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 selector to use with document.querySelector to retrieve given node | |
* @param {DOMElement} node | |
* @returns {string} | |
*/ | |
function getSelector(node){ | |
// check for node.id avoiding autogenerated ids by ignoring any ids containing numeric values | |
// and checking that the id is unique in the document. | |
if (node.id && node.id.match(/^\D+$/) && document.querySelectorAll(node.id).length === 1) { | |
return '#' + node.id; |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
60 failing | |
1) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is a thenable that tries to fulfill twice for an asynchronously-fulfilled custom thenable `then` calls `resolvePromise` synchronously via return from a fulfilled promise: | |
Error: timeout of 200ms exceeded | |
at null.<anonymous> (/tmp/D.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/runnable.js:165:14) | |
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15) | |
2) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a then |
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
function npmMonthlyStats(pkgName){ | |
var xhr=new XMLHttpRequest() | |
, rows | |
, obj={} | |
; | |
xhr.open('GET','https://isaacs.iriscouch.com/downloads/_design/app/_view/pkg?group_level=2&start_key=%5B%22' + pkgName + '%22%5D&end_key=%5B%22' + pkgName + '%22,%7B%7D%5D', false); | |
xhr.send(); | |
rows=JSON.parse(xhr.responseText).rows; | |
rows.forEach(function(v,k){ | |
var d = v.key[1].slice(0,7); |
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
/** | |
* very poor (but short and easy) cross platform implementation to detect dom readiness | |
*/ | |
function onReady(fn){ | |
document.body ? fn() : setTimeout(function(){ onReady(fn);},50); | |
}; |
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 comparator to use in Array.sort method context. | |
* take a list of properties (array or string delimited by pipe or comma) which you want to use for sort | |
* @param {(string|string[])) fields list of properties names (array or string delimited by pipe or comma) which you want to use for sort | |
* each field name may be prefixed by an < or > to sort on ascending or descending order | |
* you can use n< or n> as prefix for a natural order sorting | |
* @returns {function(object, object)} | |
*/ | |
function propertyComparator(compareConfig) { | |
if (typeof compareConfig === 'string') { |
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
/** By J.louis */ | |
function parseExprAttr($parse, $scope, $attrs, name) { | |
var fn = $parse($attrs[name]), | |
res | |
; | |
res = function (locals) { | |
return fn($scope, locals); | |
}; | |
res.assign = fn.assign && function (value) { | |
fn.assign($scope, value); |
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
// ==UserScript== | |
// @name Confluence fancybox enhance navigation | |
// @version 0.0.1 | |
// @description add navigation through image previews | |
// @author Jonathan Gotti | |
// @match http://*/* | |
// @match https://*/* | |
// ==/UserScript== | |
// update match rules for your domain | |
(function(){ |
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
/** | |
Tim Down reply at | |
http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div/6691294#6691294 | |
*/ | |
function pasteHtmlAtCaret(html) { | |
var sel, range; | |
if (window.getSelection) { | |
// IE9 and non-IE | |
sel = window.getSelection(); | |
if (sel.getRangeAt && sel.rangeCount) { |
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
/* | |
* Copyright (C) 2004 Baron Schwartz <baron at sequent dot org> | |
* | |
* This program is free software; you can redistribute it and/or modify it | |
* under the terms of the GNU Lesser General Public License as published by the | |
* Free Software Foundation, version 2.1. | |
* | |
* This program is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |