Skip to content

Instantly share code, notes, and snippets.

View ngryman's full-sized avatar

Nicolas Gryman ngryman

View GitHub Profile
@ngryman
ngryman / expose.js
Last active February 1, 2018 10:16
expose pattern for global, commonjs & amd.
(function(expose) {
var foo = 'bar';
// expose
expose(foo);
})(function(name, export) {
if ('object' == typeof module && module.exports) module.exports = export;
else if ('function' == typeof define && define.amd) define(name, [], function() { return export; });
else if ('object' == typeof window) window[name] = export;
@ngryman
ngryman / usleep.c
Created September 8, 2013 07:07
usleep for Windows.
void usleep(DWORD waitTime){
LARGE_INTEGER perfCnt, start, now;
QueryPerformanceFrequency(&perfCnt);
QueryPerformanceCounter(&start);
do {
QueryPerformanceCounter((LARGE_INTEGER*) &now);
} while ((now.QuadPart - start.QuadPart) / float(perfCnt.QuadPart) * 1000 * 1000 < waitTime);
}
@ngryman
ngryman / _sprites.scss
Created September 14, 2013 00:15
normal and retinized spirte sass mixin
$ui-sprites: sprite-map('ui/*.png');
$ui-2x-sprites: sprite-map('ui-2x/*.png');
@mixin ui($item) {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
background-image: sprite-url($ui-sprites);
background-position: sprite-position($ui-sprites, $item);
@ngryman
ngryman / parallel.js
Last active February 1, 2018 10:11
jQuery parallel script loading keeping execution order.
/**
* Load scripts in parallel keeping execution order.
* @param {array} An array of script urls. They will parsed in the order of the array.
* @returns {$.Deferred}
*/
function getScripts(scripts) {
var xhrs = scripts.map(function(url) {
return $.ajax({
url: url,
dataType: 'text',
@ngryman
ngryman / 0_reuse_code.js
Created January 22, 2014 19:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ngryman
ngryman / art.md
Created April 7, 2014 22:46
An awesome pixel art chef d'oeuvre
@ngryman
ngryman / package.json
Created June 27, 2014 22:12
Scrapper for Jerem
{
"name": "grabber",
"version": "0.0.0",
"description": "Jeremy se lance dans le bis",
"main": "grabber.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@ngryman
ngryman / without-diatrics.js
Created August 22, 2014 21:33
Strip diatrics from a string.
var withoutDiatrics = function() {
var diatrics = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var stripped = 'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
return function(str) {
var len = str.length, out = '';
for (var i = 0; i < len; i++) {
var index = diatrics.indexOf(str[i]);
out += (-1 != index ? stripped[index] : str[i]);
@ngryman
ngryman / waterfall-metrics.js
Created March 21, 2015 23:57
Waterfall with promises.
function waterfall(tasks, callback) {
var firstTask = tasks.shift();
return tasks.reduce(function(prevPromise, task) {
return prevPromise.then(function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(task);
return makePromise.apply(null, args);
});
}, makePromise(firstTask));
@ngryman
ngryman / gulp+browserify.js
Created May 26, 2015 18:51
gulp + browserify
var browserify = require('browserify')
, gulp = require('gulp')
, gutil = require('gulp-util')
, mocha = require('gulp-mocha')
, source = require('vinyl-source-stream')
, watchify = require('watchify');
var b = watchify(browserify({
entries: ['./app/index.js'],
debug: true