Skip to content

Instantly share code, notes, and snippets.

View giuseppeg's full-sized avatar
🌊
All is well.

Giuseppe giuseppeg

🌊
All is well.
View GitHub Profile
@dgp1130
dgp1130 / LICENSE
Last active June 23, 2023 00:47
Better type inference of `querySelector()` via inferred Template Literal Types
Copyright (c) 2023 Douglas Parker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all

Preact: Progressive Hydration

Preact now supports seamless progressive hydration.

Any component can throw during hydration (or new tree creation like a route change!), and if a component somewhere higher in the tree catches that via componentDidCatch, hydration gets paused.

Re-rendering the tree (via setState, etc) simply resumes hydration where it left off.

@Rich-Harris
Rich-Harris / http-apis.md
Last active November 3, 2022 09:02
Next-gen Node HTTP APIs

I saw this poll on Twitter earlier and was surprised at the result, which at the time of writing overwhelmingly favours option 1:

Screen Shot 2020-09-10 at 10 19 22 AM

I've always been of the opinion that the (req, res, next) => {} API is the worst of all possible worlds, so one of two things is happening:

  • I'm an idiot with bad opinions (very possibly!)
  • People like familiarity
import tree from "./tree";
test("it should serialise the tree", () => {
expect(tree("path/to/folder")).toMatchInlineSnapshot(); // jest will fill this in automatically
});
@wesleytodd
wesleytodd / framework.js
Last active September 18, 2020 15:55
Just noodling on the future Node.js and http
'use strict'
// Notice no certs, one thing I have thought
// for a long time is that frameworks should
// directly have support for spinning up with
// a cert if none was provided.
require('h3xt')()
.get('/', (req) => {
// Access the associated session
// req.session
@threepointone
threepointone / feature-flags.md
Last active May 24, 2023 11:03
Feature flags: why, how, all that

(I'm enjoying doing these raw, barely edited writeups; I hope they're useful to you too)

Feature flags

This is my own writeup on feature flags; for a deep dive I'd recommend something like Martin Fowler's article (https://martinfowler.com/articles/feature-toggles.html).

So. Feature flags. The basic idea that you'll store configuration/values on a database/service somewhere, and by changing those values, you can change the user experience/features for a user on the fly.

Let's say that you're building a new feature, called 'new-button' which changes the color of buttons, which is currently red, to blue. Then you'd change code that looks like this -

const cwd = process.cwd()
module.exports = function requireResolve(moduleName) {
const resolveOpts = {
paths: [
// will prefer this folder:
path.resolve(cwd, '..', 'some-dep', 'node_modules'),
// over this folder:
path.resolve(cwd, 'node_modules'),
],
/*
Proof of concept: Writing dual-mode (sync and async) code via generators
Recommendation: start by reading the example (at the end).
API:
– The API object is called `def`.
– Dual-mode `await`: const unwrapped = yield wrapped;
– Dual-mode `yield`: yield def.$one(singleValue)
– Dual-mode `yield*`: yield def.$all(iterable)

Zero-knowledge Auth

The modern email/password authentication does not protect users from bad practices and, in the secure version (with 2FA), is difficult to use.

The IT world needs more discussion about authentication mechanisms to find more convenient and secure options.

This proposal contains an unusual authentication for a small subset of use cases. What problems does it have in terms of security and usability?

Task

I was drawn to programming, science, technology and science fiction
ever since I was a little kid. I can't say it's because I wanted to
make the world a better place. Not really. I was simply drawn to it
because I was drawn to it. Writing programs was fun. Figuring out how
nature works was fascinating. Science fiction felt like a grand
adventure.
Then I started a software company and poured every ounce of energy
into it. It failed. That hurt, but that part is ok. I made a lot of
mistakes and learned from them. This experience made me much, much