Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar

Andrea Giammarchi WebReflection

View GitHub Profile
WebReflection /
Last active June 20, 2024 20:54
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);
WebReflection /
Last active November 23, 2023 19:35
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 /
Created October 23, 2023 14:54
WSL open a new TAB (not window) on the same folder

I've saved this file as /usr/local/bin/new-tab but I think there is a way to configure it as Ctrl+Shift+T shortcut somehow, yet I really wanted to write this down as I've lost 20 minutes of my life to have WSL behaving just like any regular Linux distro in a console/terminal.

#!/usr/bin/env sh

cmd.exe /c wt.exe wt -w 0 nt -d "$(pwd)" -p "$WSL_DISTRO_NAME"

If you have better tips, hints, or follow ups, you're more than welcome to share, thank you!

This gist is a simple no-brainer description of the 3 ways (actually 2.5) the Web handle events.

<tag onclick />

The declarative inline HTML event listener is mostly an indirection of DOM Level 0 events, meaning this simply uses the equivalent of tag.onclick = listener behind the scene.


click me
WebReflection /
Last active July 3, 2024 05:50
Builtin Extends Only

Builtin Extends Only

This gist simply lists all elements that can't be extended on "the platform" if not through the Custom Elements builtin extends feature.

This list does not focus on the "why would you?" rather on the "why can't you?" (on Safari) question out there, using the Permitted Parent section out of MDN Element Reference.

WebReflection /
Last active May 26, 2024 02:33
Proposal: an ESX for JS implementation
WebReflection /
Last active August 31, 2023 09:52
Brainstorming a smarter JSX

Brainstorming a smarter JSX


The new proposal and hopefully the new transformer will be out soon.

This gist tries to narrow down all features and complexity hidden behind a smarter JSX, something landed already as @ungap/babel-plugin-transform-hinted-jsx module but not yet concretely, or efficiently, implemented.

EllyLoel / reset.css
Last active June 28, 2024 04:00
CSS Reset
Made by Elly Loel -
With inspiration from:
- Josh W Comeau -
- Andy Bell -
- Adam Argyle - /
- `:where()` is used to lower specificity for easy overriding.
huytd /
Last active May 16, 2024 20:39
Wordle in less than 50 lines of Bash


How to use:


Or try the unlimit mode:

WebReflection /
Last active January 21, 2022 11:31
Create wordle report

Apparently there's no share button after wordling in my browsers, so I created this copy/paste JS to put in console, which will produce an output like:

Wordle 212 4/6