Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
@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

I feel the need to have a little rant about MooTools and ES7 and the whole 'Array.contains' hoo-hah.

When MooTools came out in 2006, the most popular framework was Prototype. As the name suggests, it extended prototypes, as did MooTools. People still referred to making websites with JavaScript as 'DHTML', there was no trim method on strings, there wasn't even a forEach method on arrays. JavaScript was a crippled language. IE6 ruled the waves.

MooTools, Prototype, Dojo, Base2 - they made the language usable, even fun, to work with. By using an incredible feature of JavaScript, prototypical inheritance, we were able to add features to the language that made it palatable.

Be it simple methods like number.toInt, string.trim, array.forEach, or familiar programming constructs such as Class, MooTools and its ilk took JavaScript from something impossible to work with to something that you could properly use to build awesome sites, and even apps - Microsoft, IE and desktop ruled everything, and the concept of a 'we

@cortesben
cortesben / hg-commands.md
Last active March 6, 2025 14:58
Mercurial command cheat sheet

Mercurial Commands

Commands Description
hg pull get latest changes like git pull use flags like -u IDK why yet
hg add only for new files
hg commit add changes to commit with -m for message just like git
hg addremove adds new files and removes file not in your file system
hg incoming see changes commited by others
hg outgoing see local commits
@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 / certificate.sh
Last active July 1, 2020 18:08
A basic Self Signed SSL Certificate utility
#!/usr/bin/env bash
# A basic Self Signed SSL Certificate utility
# by Andrea Giammarchi @WebReflection
# https://www.webreflection.co.uk/blog/2015/08/08/bringing-ssl-to-your-private-network
# # to make it executable and use it
# $ chmod +x certificate
# $ ./certificate # to read the how-to
@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 / 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 .");
@WebReflection
WebReflection / object-mix.js
Last active March 27, 2021 18:38
"Real" Mixins with JavaScript Objects
let mix = (object) => ({
with: (...mixins) => mixins.reduce(
(c, mixin) => Object.create(
c, Object.getOwnPropertyDescriptors(mixin)
), object)
});

Basic utility to launch a python 2 or python 3 simple http server.

#!/usr/bin/env bash

if [ "$1" != "" ]; then
  PORT="$1"
elif [ "$PORT" = "" ]; then
  PORT=8000
fi