Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
label {
position: relative;
}
label:after {
content: '☰';
@WebReflection
WebReflection / extensible.js
Last active April 4, 2021 00:34
A simple way to create objects usable to extends other objects or classes.
function extensible(object) {
// usable to extend a class
function descriptors() {}
// get rid of name, length, and the rest
Reflect.ownKeys(descriptors).forEach(function (k) {
delete descriptors[k];
});
// clean up the constructor too
descriptors.prototype = {};
// per each property in object
@WebReflection
WebReflection / on.js
Last active March 27, 2021 19:10
The smallest, cross browser, DOM chainable `.on()` shortcut for `addEventListener`
(function (F, I, X, DOM, on) {
DOM = (F.Node || F.Element).prototype;
on = F.Object.defineProperty ||
function (t, k, d) {
t[k] = d.value;
};
I in F || on(F, I, X);
I in DOM || on(DOM, I, X);
I in F.document || on(F.document, I, X);
}(
@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
@WebReflection
WebReflection / transpiled-class.md
Last active October 25, 2016 16:45
Babel is broken, let's fix it.

Current Babel transform, when it comes to call the parent

function _possibleConstructorReturn(self, call) {
  if (!self) {
    throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  }
  return call && (typeof call === "object" || typeof call === "function") ? call : self;
}

It's a way too poor implementation.

@WebReflection
WebReflection / 2gif.sh
Created September 1, 2016 11:36
simple ffmpeg based script to convert a generic video file to a gif
#!/usr/bin/env bash
#$ 2gif video.mp4 # creates video.gif
#$ 2gif video.mp4 out.gif # creates out.gif
extension2gif() {
local name="$1"
echo "${name%.*}.gif"
}
@WebReflection
WebReflection / days-since.js
Last active January 12, 2022 02:50
Days since another date
function date(year, month, day, hours, minutes, seconds, ms) {
var today = new Date();
today.setYear(year);
today.setMonth(month - 1);
today.setDate(day);
today.setHours(hours || 0);
today.setMinutes(minutes || 0);
today.setSeconds(seconds || 0);
today.setMilliseconds(ms || 0);
return today;
@WebReflection
WebReflection / sw.md
Created July 26, 2016 22:12
How SW is being advocated

This is just a small list of links that used Desktop browsers/machines to test or demonstrate how SW are good for offline, something most of the time still tested on Desktop machines only simulating the real case.

If performance is your main concern and you still want to obtain the best from your Web App, use published links as a reference and test for real on your target devices.

@WebReflection
WebReflection / super.js
Last active April 4, 2021 00:33
Using `this.super()` and `this.super.method()` via any kind of object or prototype (proof of concept)
var withSuperContext = (function (Object) {
//! (c) Andrea Giammarchi
var
defineProperty = Object.defineProperty,
getPrototypeOf = Object.getPrototypeOf,
setPrototypeOf = Object.setPrototypeOf ||
function (o, p) { o.__proto__ = p; },
handler = {
get: function get(target, property, receiver) {
return function () {
@WebReflection
WebReflection / index.html
Last active July 30, 2017 12:57
BENJA Raspberry Pi alpha ISO live demo
<!DOCTYPE html>
<html>
<head>
<!-- to have access to local or global scripts -->
<script>
require('module').globalPaths.push(
process.cwd() + '/node_modules',
process.env.NODE_PATH
);
</script>