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 / switchless-4x-sparks.md
Last active November 1, 2026 20:01
Switch-less 4X Sparks

Current ports diagram:


┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━┓
┃ Spark3                 ┃  A  ┃  B  ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━┻━━┳━━┻━━┳━━┛
                            ┃     ┗━━━━━━┓
                            ┗━━━━━┓      ┃
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━┳━━┻━━┓ ┃
@WebReflection
WebReflection / pyscript-goes-maintenance.md
Created August 20, 2026 13:07
PyScript is entering maintenance mode

👋 PyScript is entering maintenance mode

Background

I joined the team more than three years ago, and the challenge was clear:

  • allow as many people as possible to use Python on the Web without even thinking about it
  • also let them use MicroPython for simpler tasks that should run as soon as possible
  • give kids, students, professionals, and universities a way into Python through the Web, with no OS or local configuration ceremony 🥳
@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 / 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 / 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

@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 / 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 / ten-tdec.md
Last active August 2, 2025 10:14
TextEncoder & TextDecoder shenanigans

TextEncoder & TextDecoder shenanigans

This gist is to remind developers that resizable or growable buffers don't play nice with TextEncoder or TextDecoder instances.

Setup

// setup
const ref = new TextEncoder().encode("hello");
@WebReflection
WebReflection / sqlite-as.md
Last active January 25, 2025 15:12
Bun sqlite `.as(Class)` alternative

This is a simple demo of how latest Bun could've implemented .as(Class) instead of using the quite jurassic Object.create which is slow, bloated due descriptors logic, if used at all, and incapable to play nicely with features introduced after Object.create was even specified.

// what `as(Class)` should return
const { assign } = Object;
const asClass = new WeakMap;
const setAsClass = Class => {
  class As extends Class {
    constructor(fields) {
      assign(super(), fields);