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 / hyper-lit.md
Last active November 8, 2022 03:55
lit-html is awesome, but it came afterwards

The history of hyperHTML followed by lit-html

While many remember the epic hyperHTML: A Virtual DOM Alternative post I've published the 5th of March 2017, the first official implementation of the library was working as hyperHTML.bind(node) function for tagged literals the day before, and it's been in my experiments folder already for a little while.

The hilarious reaction from the skeptical community

At first glance people couldn't believe performance of the DBMonster demo shown in that article,

if(JSON.stringify('\u2028').length<4)JSON.stringify=function(s,r,f){return function() {return s.apply(null,arguments).replace(r,f)}}(JSON.stringify,/\u2028|\u2029/g,function(c){return'\u2028'==c?'\\u2028':'\\u2029'});
@WebReflection
WebReflection / irc.js
Created February 15, 2018 08:27
Transform IRC logs into Markdown
#!/usr/bin/env node
require('fs').readFile(process.argv[2], (err, data) => {
if (err) return;
const content = data.toString().trim();
const re = /^\[(.+?)\]\s+<(.+?)>\s(.*)$/gm;
const chat = [];
let current = {};
while (match = re.exec(content)) {
if (match[2] !== current.name) {
@WebReflection
WebReflection / ama.md
Created February 14, 2018 21:25
AMA (Ask Me Anything) session with WebReflection (2018-Feb-14)

[12:58] @icebox

ANNOUNCE: in two minutes "Wed, Feb 14th, at 13.00 CET (GMT+1) a 1 hour #angularjs (Freenode) AMA (Ask Me Anything) with me about hyperHTML, standards, transpilers, bundlers, esm modules, and the meaning of keyed VS non keyed JS benchmarks + your questions. See you there" - https://twitter.com/WebReflection/status/961352362962059264


[12:59] Pyrrhus666

welcome webreflection


@WebReflection
WebReflection / paint.js
Last active February 11, 2018 17:15
Grants UI setup and future state through rAF
var paint = function(rAF){ 'use strict';
return function paint(before) {
before();
return rAF(before), {
then: function (after) {
return rAF(rAF.bind(null, after)), this;
}
};
};
}(
@WebReflection
WebReflection / jsc
Last active October 2, 2024 23:49
JavaScriptCore for macOS and Linux
#!/usr/bin/env bash
if [ -f /usr/lib/jsc ]; then
/usr/lib/jsc "$@"
elif [ -f /System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc ]; then
/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc "$@"
fi
@WebReflection
WebReflection / primitive.md
Last active February 15, 2018 08:29
Wrapping primitives keeping control of the exposed value and lazily defining every accessor

Two ways to do it, via Symbol

const Primitive = (() => {
  const secret = Symbol();
  const update = (obj, value) => {
    Object.defineProperty(obj, secret, {configurable: true, value});
  };

  function Primitive(value) {'use strict';
const clone = (() => {
/*! (c) Andrea Giammarchi - WTFPL */
const toString = {}.toString;
const flags = ['global', 'ignoreCase', 'multiline', 'sticky', 'unicode'];
const prime = obj => typeof obj === 'object' ? new obj.constructor(obj.valueOf()) : obj;
const through = obj => {
const descriptors = Object.getOwnPropertyDescriptors(obj);
Reflect.ownKeys(descriptors).forEach(key => {
const descriptor = descriptors[key];
if ('value' in descriptor) {
@WebReflection
WebReflection / caniuse
Last active July 12, 2019 15:16
A simple script that tells you if a feature is available for a list of browsers
#!/usr/bin/env node
var browsers = [
'chrome 49',
'edge 16',
'firefox 51',
'opera 36'
].join(', ');
var caniuse = require('caniuse-api');
@WebReflection
WebReflection / fixEslintAllman.js
Created January 16, 2018 11:07
fix allman style with brackets losing initial padding
function fixEslintAllman(code) {
return code.replace(/^{/mg, function ($0, $1) {
var newLine = code.lastIndexOf('\n', $1 - 2);
var spaces = code.slice(newLine + 1, $1 - 1).match(/^(\s*)/)[1];
return spaces + '{';
});
}