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
/** | |
* 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
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
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
// 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
/** | |
* 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
#!/bin/bash | |
pgr="most" | |
tmpFile="/tmp/pager_$(uuidgen)" | |
cat - /dev/stdin > $tmpFile; | |
nblines=$(wc -l $tmpFile |awk '{print($1)}'); | |
if [ "$nblines" -gt "$(tput lines)" ]; then | |
$pgr $tmpFile | |
else | |
cat $tmpFile && echo "" |
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 | |
# get user step on command line or default to 1 | |
USERSTEP=${1:-1} | |
# get max and current values of brightness | |
MAX=`/usr/lib/gnome-settings-daemon/gsd-backlight-helper --get-max-brightness` | |
CUR=`/usr/lib/gnome-settings-daemon/gsd-backlight-helper --get-brightness` | |
# define step and min to apply regarding the max value to have approximatively ten levels of settings | |
STEP=$(($MAX/10)) | |
MIN=$((STEP/2)) | |
# calc new user wanted 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>jsonFilter test suite</title> | |
<link type="text/css" rel="stylesheet" href="qunit-1.10.0.css" media="all" /> | |
</head> | |
<body> | |
<div id="qunit"></div> |
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
/** | |
* minimal jquery/zepto compatibility layer | |
* be aware that won't mimic jquery/zepto at all but offer a similar api for basic stuffs as querySelectorAll and addEventListener ... | |
* @author jgotti at modedemploi dot fr for agence-modedemploi.com | |
* @licence Dual licence LGPL / MIT | |
* @changelog | |
* - 2012-11-28 - more jquery like syntax and some events related stuffs | |
*/ | |
(function($){ | |
"use strict"; |