Skip to content

Instantly share code, notes, and snippets.

View fabiospampinato's full-sized avatar

Fabio Spampinato fabiospampinato

View GitHub Profile
@cometkim
cometkim / README.md
Last active November 21, 2024 03:20
There are too many LRU implementations in JS...

JavaScript LRU library benchmark

There are too many LRU(Least Recently Used) implementations in JS.

I recommend to use [flru] which is the smallest one and fast enough. Unless you need more rich functionality.

However, it's performance is vary depend on the host environment. For example, flru loses on Bun.

If you need micro-optimization on it, measure it yourself in your environment.

Optional chaining assignment proposal

Basically, allow this:

foo?.bar = value;

which is equivalent to

foo == null ? undefined : (foo.bar = value);
@rsms
rsms / example.txt
Last active March 11, 2023 23:00
source line-length histogram script
./linelen_hist.sh src '*.c'
COLS COUNT
2 1317 ████████████████████████████████████████████████████████████▌
4 583 ██████████████████████████▏
6 500 ██████████████████████▎
8 253 ███████████▊
10 264 ████████████▊
12 448 ████████████████████▋
14 417 ███████████████████▌
16 476 █████████████████████▍
@ymoslem
ymoslem / M2M-100-example.py
Last active September 1, 2024 13:23
Example of translating a file with M2M-100 using CTranslate2
# This example uses M2M-100 models converted to the CTranslate2 format.
# Download CTranslate2 models:
# • M2M-100 418M-parameter model: https://bit.ly/33fM1AO
# • M2M-100 1.2B-parameter model: https://bit.ly/3GYiaed
import ctranslate2
import sentencepiece as spm
@jonlabelle
jonlabelle / npm_version_cheatsheet.md
Last active December 21, 2024 03:34
npm version cheatsheet

npm version cheatsheet

npm uses Semantic Versioning

npm uses Semantic Versioning. Given a version number MAJOR.MINOR.PATCH, increment the:

  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.
@sindresorhus
sindresorhus / esm-package.md
Last active December 20, 2024 10:06
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@marcan2020
marcan2020 / notable.md
Last active December 29, 2021 05:01
Dockerized version of Notable with no network access
@pesterhazy
pesterhazy / indexeddb-problems.md
Last active December 16, 2024 03:50
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

@smhanov
smhanov / OpenType.ts
Last active December 15, 2024 13:42
Here is my implementation of a TrueType font reader in Typescript. You can read a font directly from an ArrayBuffer, and then call drawText() to draw it. See my article http://stevehanov.ca/blog/index.php?id=143. The second file, OpenType.ts is the same thing but it handles more TrueType files. It is also more coplex
// To see this run, you first stub out these imports. Then put the file in a Uint8Array.
// let slice = new Slice(array);
// let font = new OTFFont(slice);
// Then you can call methods like font.drawText(canvasContext, )
//
//
import { ICanvasContext } from "./ICanvasContext"
import { log as Log } from "./log"
const log = Log.create("OPENTYPE");
@WebReflection
WebReflection / dom-libraries.md
Last active November 19, 2024 03:24
A recap of my FE / DOM related libraries

My FE/DOM Libraries

a gist to recap the current status, also available as library picker!

Minimalistic Libraries

do one thing only and do it well

  • µhtml (HTML/SVG auto-keyed and manual keyed render)
  • augmentor (hooks for anything)
  • wickedElements (custom elements without custom elements ... wait, what?)