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 / dom.js
Last active March 27, 2021 18:37
Basic Proxy usage compatible with Custom Elements, using `append` DOM.next entry
// https://jsbin.com/tebevak/edit?js,output
// .append via https://github.com/WebReflection/dom4/#dom4
const dom = new Proxy({}, {
get(target, property) {
return function (attrs = {}, ...children) {
const el = document.createElement(
property.replace(/[a-z][A-Z]/g, '$1-$2'));
for (let prop of Object.keys(attrs))
el.setAttribute(prop, attrs[prop]);
el.append(...children);
@WebReflection
WebReflection / gist:d2281cd858e7666ed5d9
Last active February 1, 2016 12:12
Object.getOwnPropertyDescriptors V8 diff
diff --git a/src/js/v8natives.js b/src/js/v8natives.js
index c14f9f2..fa4e710 100644
--- a/src/js/v8natives.js
+++ b/src/js/v8natives.js
@@ -777,6 +777,18 @@ function ObjectGetOwnPropertyDescriptor(obj, p) {
return %GetOwnProperty(obj, p);
}
+// ES proposal https://github.com/tc39/proposal-object-getownpropertydescriptors
+function ObjectGetOwnPropertyDescriptors(obj) {
@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)
});
@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 / noswear.js
Last active November 10, 2015 22:56
no swear
var terms = ['shit', 'fuck'];
var re = RegExp('\\b(?:' + terms.join('|') + ')\\b', 'i');
var hasBadWords = function (str) { return re.test(str); };
hasBadWords("hit me duck"); // false
hasBadWords("holy shit"); // true
hasBadWords("My assistant couldn't find shitake mushrooms."); // false
@WebReflection
WebReflection / requestIdleCallback.md
Last active September 29, 2015 19:38
A rAF and busy-time based attempt to polyfill requestIdleCallback

TL;DR this polyfill might poorly perform on already slow devices. It might be convenient to just test the API but it won't exactly produce the expected result.

Hint: use with care, not suggested for prod.

// please read this conversation before making any decision
// https://twitter.com/WebReflection/status/648925435120734208
var requestIdleCallback = requestIdleCallback || (function (rAF) {
  // (C) Andrea Giammarchi - @WebReflection - Mit Style
  function Deadline(timemout) {
@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 / scroll-smoother.js
Last active December 9, 2015 06:21
A simple solution to a common scrolling problem
(function (global) {'use strict';
// (C) Andrea Giammarchi @WebReflection
// https://gist.github.com/WebReflection/ea3e833b4de07d877479
var
tick = false,
rAF = global.requestAnimationFrame ||
global.webkitRequestAnimationFrame ||
global.mozRequestAnimationFrame ||
global.msRequestAnimationFrame ||
global.oRequestAnimationFrame ||
@WebReflection
WebReflection / ai2svg.md
Last active August 6, 2025 20:29
Transform AI to SVG, requires Inkscape

Save this file as ai2svg, make it executable via chmod +x ai2svg then run it optionally passing the folder to look for.

It will convert in that folder, or the current one, all .ai files into .svg

#!/usr/bin/bash

createsvg() {
  local margin="$1"
 local d
@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