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 / type.js
Created January 17, 2013 05:42
All JSON compatible (and incompatible thanks to "function") types in a simple cross platform function
var type = function (isArray, type){
return function(object) {
type = typeof object;
return type === "object" ? (
object ? (
isArray(object) ? "array" : type
) : "null"
) : type;
};
}(Array.isArray || function(Array, toString, array){
@WebReflection
WebReflection / writeInGithub.js
Last active January 13, 2021 04:33
a silly script to write in your github timeline
/**
* so here the thing ... you go in your github page
* as example I go here: https://github.com/WebReflection
* you open your console
* you copy and paste this shit
* then you write and execute in the console
* write("Hi There!");
* NOTE: Pixel Font from a 2006 project of mine :-) http://devpro.it/pixelfont/
*/
function write(text, color, start) {
@WebReflection
WebReflection / JSLintWTF.js
Created February 6, 2013 20:36
JUST LOL JSLINT
var a, b; // JUST LOL JSLINT !
// tell me how less confusing this is ^_^
// a can do async stuff
// then b is needed
function a() {
setTimeout(b, 1);
}
// b can be used regardless a()
@WebReflection
WebReflection / gist:4983340
Created February 19, 2013 05:28
How to install node.js in Ubuntu 12.10 via terminal
# Ubuntu 12.10 via VirtualBox Image
# go in the user dir
cd ~/
# install git CL tool and g++
sudo apt-get install git
sudo apt-get install g++
# clone node.js git repo
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@WebReflection
WebReflection / gist:5084045
Last active January 15, 2018 22:52
Boot to node: An Arch Linux on Raspberry PI + WiFi + node.js quick guide through
# these info are valid today
# 4th March 2013
# flush latest Arch for Pi dist
# via dd or other ways
# With A DHCPed Network Cable
pacman -Syu
sync
reboot
@WebReflection
WebReflection / gist:5167299
Last active June 8, 2021 08:29
Array.prototype.find and Array.prototype.findIndex quick and dirty polyfill
// WebReflection quick and dirty polyfill
(function(AP){
if ('find' in AP) return;
// quick size/safe version
// if predicate is not a function, call will throw
// if this is not array like, throws or nothing happens
function find(value) {
return function (predicate, thisArg) {
for(var
k = 0,
@WebReflection
WebReflection / gist:5238782
Last active December 15, 2015 09:29
In current ES5 (all mobile browsers and all desktops but IE < 9) is possible to somehow simulate Harmony Symbol constructor.
var Symbol;
if (!Symbol) {
Symbol = (function(Object){
var defineProperty = Object.defineProperty,
prefix = '__simbol' + Math.random() + '__',
id = 0;
function Symbol() {
var self = this;
defineProperty(
Object.prototype,
@WebReflection
WebReflection / Object.setPrototypeOf.md
Last active December 15, 2015 10:39
A possible Object.setPrototypeOf(object, proto) polyfill from the unknown future of JS
@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};