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 / i18n-noop.js
Created October 22, 2017 15:49
A template literal tag function that does nothing.
function i18n(t) {
for (var o = [t[0]], i = 1, l = arguments.length; i < l; i++)
o.push(arguments[i], t[i]);
return o.join('');
}
@WebReflection
WebReflection / es.mjs
Last active February 15, 2018 08:31
A loader for both `.mjs` and `.m.js` extension.
import _url from 'url';
const builtins = new Set(
Object.keys(process.binding('natives')).filter(str =>
/^(?!(?:internal|node|v8)\/)/.test(str))
);
const esmIfExplicit = url => {
const eof = url.slice(-5);
return {
@WebReflection
WebReflection / camelPatched.js
Created October 11, 2017 16:15
A camelCase GJS Class methods patch
const camelPatched = (() => {'use strict';
/*! (c) 2017 Andrea Giammarchi - @WebReflection (ISC) */
const GIRepository = imports.gi.GIRepository;
const rep = GIRepository.Repository.get_default();
const patched = new Set;
return Class => {
if (!patched.has(Class)) {
patched.add(Class);
const path = Class.name.split('_');
if (path.length === 2) {
function hash(str) {
var hval = 0x811c9dc5, i = 0, length = str.length;
while (i < length) {
hval ^= str.charCodeAt(i++);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
}
@WebReflection
WebReflection / template-content.js
Created August 30, 2017 08:30
micro shim for template content
(function (document, TEMPLATE) {
var container = document.createElement(TEMPLATE);
if ('content' in container) return;
var createElement = document.createElement;
var descriptor = {
get: function () { return this.content ? this.content.innerHTML : ''; },
set: function (html) {
var el = createElement.call(document, TEMPLATE);
if (/^[^\S]*?<(t(?:head|body|foot|r|d|h))/i.test(html)) {
var selector = RegExp.$1;
@WebReflection
WebReflection / hyper-without-literals.js
Last active June 13, 2018 07:41
Simulating Template Literals arguments without Template Literals
// this is now part of hyperHTML package
// https://github.com/WebReflection/hyperHTML/blob/master/no.js
@WebReflection
WebReflection / hyperhtml-firebase.html
Last active December 16, 2019 08:15
A basic hyperHTML + Firebase example. 100% client side.
<!doctype html>
<html lang="en">
<head>
<title>hyperHTML &amp; Firebase</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>
html { font-family: sans-serif; }
html, body, ul, p { padding: 0; margin: 0; }
ul, li { list-style: none; }
@WebReflection
WebReflection / hyper-element.js
Created July 27, 2017 15:31
One possible way to simplify hyperHTML components.
const borrowedState = require('flatstate').setState;
class HyperElement extends HTMLElement {
constructor(...args) {
super(...args);
this.html = hyperHTML.bind(this);
}
render() {}
const any = $ => new Promise((D, E, A, L) => {
A = [];
L = $.map(($, i) => Promise
.resolve($)
.then(D, O => (((A[i] = O), --L) || E(A)))
).length;
});
// a slightly modified DelegatedListener
// it sends itself while triggering the event
class DelegatedListener {
constructor(delegated) {
this.delegated = delegated;
}
handleEvent(event) {
this.delegated['on' + event.type](event, this);