Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
@rwaldron
rwaldron / endianness.js
Created September 1, 2015 00:49
Endianness
function endian() {
var a32 = new Uint32Array([0x12345678]);
var a8 = new Uint8Array(a32.buffer);
return a8[1] === 0x12 && a8[2] === 0x78 ? 'MIDDLE' :
(a8[0] === 0x12 ? 'BIG' : 'LITTLE');
}
console.log(endian())
@WebReflection
WebReflection / lie.js
Last active September 4, 2015 11:02
Optionally resolvable, rejectable, and cancelable Promises through abort.
function Lie(callback) {'use strict';
// (C) Andrea Giammarchi - MIT Style License
// this is now an official npm module https://github.com/WebReflection/dodgy#dodgy-
var
resolve, reject, abort,
lie = new Promise(function (res, rej) {
callback(res, rej, function onAbort(callback) {
resolve = res;
reject = rej; // feel free to use or ignore arguments
abort = function abort() { reject(callback.apply(null, arguments)); };
@WebReflection
WebReflection / mutations.js
Created January 13, 2012 07:09
DOM MutationEvent Feature Detection
var mutations = (function (document) {
// (C) WebReflection - Mit Style License
var
type = [
"DOMSubtreeModified",
"DOMNodeInserted",
"DOMNodeRemoved",
"DOMNodeRemovedFromDocument",
"DOMNodeInsertedIntoDocument",
"DOMAttrModified",
@WebReflection
WebReflection / gjs.js
Created November 25, 2015 09:56
GJS Linux compatible imports with the current path without needing to push its searchPath
#!/usr/bin/env sh
imports=imports// "exec" "gjs" "-I" "$(dirname $0)" "$0" "$@"
log("I've found a valid GJS hack to auto import from .");
@dfkaye
dfkaye / es6-timeout.md
Last active December 15, 2015 14:49
ES6 needs a timeout - I reserve the right to change my mind about this

2013-3-30

Some recent activity from active contributors regarding ES6 proposals threaten to undermine its acceptance from the community at large.

ES6 proposals include the fat arrow, destructured assignment, splat args, let/block scope, class syntax, class-based inheritance, setters/getters with export, the module loader syntax, weak maps, weak events, @symbols, and so forth.

That is a lot for a community user of the language to comprehend. It is a lot for a single iteration of any project.

The sheer amount of change is at root of the confusion apparent even among the es-discuss mailing list ~ [see this conversation for an example] (https://twitter.com/kangax/status/315863525899780096 ""that was removed from the spec", "I thought it was back in", "it's on the table", "'on the table' does not mean 'in the spec'"").

@WebReflection
WebReflection / gist:5282385
Last active December 15, 2015 15:29
`__proto__` is dangerous

Object.setPrototypeOf() polyfills

Non greedy in 95 bytes (function(O,P){P in O||(O[P]=function(o,p){o.__proto__=p;return o})})(Object,'setPrototypeOf');

Or via self reassignment in 91 bytes (function(O,P){O[P]=O[P]||function(o,p){o.__proto__=p;return o}})(Object,"setPrototypeOf");

Or direct call, 65 bytes, for you closure! var p=Object.setPrototypeOf||function(o,p){o.__proto__=p;return o};

@WebReflection
WebReflection / slice.js
Last active March 8, 2016 11:06
How to slice arguments without leaking them
// Andrea Giammarchi, WTFPL
function slice() {'use strict';
for (var
o = +this, // offset
i = o, // start index
l = arguments.length, // length
n = l - o, // new length
a = Array(n < 0 ? 0 : n); // new Array
i < l; i++
) a[i - o] = arguments[i];
@WebReflection
WebReflection / __proto__.js
Last active August 18, 2016 16:41
just __proto__ and all shenanigans it can bring to any environment
// all IE < 11 browsers:
// there is no __proto__
if (!('__proto__' in {})) {
console.log('you gonna have hard time');
// we need extra logic to be able to work
// as meant in IE too. IE9 ain't disappearing
// any time soon in both desktop and mobile
// neither will IE10
}
// all Mobile WebKit browsers:
@WebReflection
WebReflection / Object.prototype.watch.js
Last active September 15, 2016 15:38
There is a reason Firefox still uses `Object.prototype.watch` … it's freaking useful if you know how to use it.
(function(Object){
/*! (C) Andrea Giammarchi - Mit Style License */
/////////////////////////////////////////////////////////////////
//
// compatibility
// native: Firefox Desktop and Mobile
// partial: IE8 works with DOM nodes only
// simulated: all other browsers except IE < 8
@WebReflection
WebReflection / packages-info.md
Last active September 20, 2016 10:03
A simple way to understand multiple dependencies between different NodeJS projects.

This snippet helps understanding packages dependencies and versions across different projects/folders.

You can pass 2 or more folders to compare their package.json

You can also pass just one fodler to check all modules in it (example: a node_modules folder)

You can pass nothing to analize the current list of packages.

#!/usr/bin/env node