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 / marker.js
Last active June 25, 2026 11:42
DOM Marker Interface
//@ts-check
// ⚠️ UPDATED https://gist.github.com/WebReflection/291357aa6bbbd97d54a971ce5f5aae4e?permalink_comment_id=5952616#gistcomment-5952616
//@ts-ignore
import custom from 'https://cdn.jsdelivr.net/npm/custom-function/esm/factory.js';
/** @typedef {'marker' | 'start' | 'end'} MarkerType */
if (!('MARKER_NODE' in Node)) {
@WebReflection
WebReflection / Emoji Copy Shell Extension.md
Last active June 18, 2026 08:26
GNOME and Emoji Copy <Super>period

Given these preferences within the extension:

image

Be sure that IBus Preferences (ibus-setup) around Emoji won't intercept/override <Super>period

Screenshot From 2026-03-19 11-13-06

Remove the bindings that you don't prefer/need over the Emoji Copy picker and enjoy 👋

@WebReflection
WebReflection / fetchp.js
Last active June 12, 2026 09:30
The easiest way to fetch JSON data when CORS is not an option but JSONP is
let p = 0;
const fetchp = (url, ..._) => new Promise((resolve, reject) => {
const src = new URL(url);
const callback = `__json${p++}`.replace('-', '_');
src.searchParams.set('callback', callback);
document.head.appendChild(Object.assign(
document.createElement('script'),
{ async: true, onerror: reject, src }
));
globalThis[callback] = value => {
@WebReflection
WebReflection / my-libraries-in-bytes.md
Last active May 20, 2026 20:04
My libraries in bytes

Toward better libraries

I am recently re-branding my libraries as µ (micro), refactoring these when necessary, dropping IE < 11 support, improving the logic where possible, or providing a better, more robust, or faster, API.

In few words, on the right there is the modern version of libraries I've used for the last ~5 years in production or for side projects, and I suggest anyone having one of the earlier dependencies, to have a look at their modern, micro, counterpart.

How to read these tables

All sizes are minified, brotli compressed, and representing these two files, when possible:

@WebReflection
WebReflection / writeInGithub.js
Last active May 12, 2026 10:32
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 / proxy-traps-cheat-sheet.md
Last active April 18, 2026 18:40
Proxy Traps Cheat Sheet

Proxy Traps Cheat Sheet

There are various shenanigans around the Proxy API, including issues with Array.isArray and Object.ownKeys so that this gits purpose is to describe all the undocummented caveats to help anyone dealing with all possibilities this half-doomed API offers.

The 3 + 1 Proxy Types

  • object: any non primitive value can be proxied but apply and construct traps won't work with it. If the object somehow wants to represent an array without being one, it's impossible to survive Array.isArray brand check (it will be false) and with ownKeys the target needs to have a non configurable length property or it will also fails once reached
  • array: it's like object but it survives the `
@WebReflection
WebReflection / audio2speakers.md
Last active April 13, 2026 12:54
MS-S1 MAX Audio Output to Speakers via jack

Create a $HOME/.config/systemd/user/speakers.service file with the following content:

[Unit]
Description=Force Speakers Audio
After=pulseaudio.service

[Service]
Type=oneshot
ExecStart=/usr/bin/pactl set-card-profile alsa_card.pci-0000_bd_00.6 "output:analog-stereo"
@WebReflection
WebReflection / qt-promise.md
Last active March 28, 2026 11:00
Qt Promise VS last fn as arg

I've found it quite "disturbing" in 2026 there are APIs that wouldn't use Promise and accept a last argument as function to retrieve data, see: https://doc.qt.io/qt-6/qtwebchannel-javascript.html#interacting-with-qobjects

Here an easy way to workaround that, where equality of the method is preserved and things would look more modern or easier to reason about.

const { apply } = Reflect;
const { create } = Object;

const wm = new WeakMap;
@WebReflection
WebReflection / superposition.md
Last active February 9, 2026 15:20
How to run Unigine Superposition Benchmark in ArchLinux

OK, the amount of gotchas with unigine-superposition 1.1 benchmark is too damn high, which is a pity because it's awesome!!!

How to run Unigine Superposition Benchmark in ArchLinux

  • download the Linux (.run) version of Qt5.9, the latest version that works https://download.qt.io/official_releases/qt/5.9/5.9.0/
  • make it executable chmod a+x qt-opensource-linux-x64-5.9.0.run
  • run it ./qt-opensource-linux-x64-5.9.0.run
  • skip the registration bit and when prompt about what to install, check Qt5.9 too (top checkbox) and don't change the default path (or do it and adjust following commands). You migt try to not install the tools and see how that goes.
  • use yay, yaourt or pakku / pamac to install pakku -S --needed unigine-superposition and I suggest you do that after a sudo mount -o remount,size=20G,noatime /tmp. If it ends with an error, just sudo pacman -U the-big-tar-file-in-tmp
  • remove the Qt folder inside the unigine-super
@WebReflection
WebReflection / queue.md
Last active January 29, 2026 09:24
Refillable Generators: The Better Alternative

This gist comes after my comment left in the original post.

The pattern is great but the way it was presented not too great:

  • it's all about queue ownership
  • the queue cannot iterate in multiple loops because it would create forever pending promises all over
  • the queue is just an Array after all, so how about we treat it as such?

A class based approach