Skip to content

Instantly share code, notes, and snippets.

View nightire's full-sized avatar
Looking for new opportunities

余凡 nightire

Looking for new opportunities
View GitHub Profile
@guest271314
guest271314 / javascript_engines_and_runtimes.md
Last active April 15, 2024 02:03
A list of JavaScript engines, runtimes, interpreters

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

SpiderMonkey is Mozilla’s JavaScript and WebAssembly Engine, used in Firefox, Servo and various other projects. It is written in C++, Rust and JavaScript. You can embed it into C++ and Rust projects, and it can be run as a stand-alone shell. It can also be [compiled](https://bytecodealliance.org/articles/making-javascript-run-fast-on

@khalidx
khalidx / node-typescript-esm.md
Last active April 17, 2024 12:32
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@cassus
cassus / i18n-ts-with-namespaces.ts
Created October 7, 2023 07:52
i18n-ts-with-namespaces.ts
import type { Paths, I18n, Translate } from "next-translate"
type Tail<T> = T extends [unknown, ...infer Rest] ? Rest : never
export type TranslationsKeys = {
common: Paths<typeof import("./locales/en/common.json")>
["feat-analytics"]: Paths<typeof import("./locales/en/feat-analytics.json")>
["feat-participate"]: Paths<
typeof import("./locales/en/feat-participate.json")
>
const AudioPrimitiveContext = React.createContext<InterpreterFrom<
typeof audioMachine
> | null>(null);
export const AudioPrimitiveProvider = ({
children,
}: {
children?: React.ReactNode;
}) => {
const [machine] = React.useState(() => {
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active October 6, 2023 18:39
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"resolveSourceMapLocations": null,
"sourceMaps": true,

Cheat sheet: modules

Named exports, named imports, namespace imports

If we put export in front of a named entity inside a module, it becomes a named export of that module. All other entities are private to the module.

//===== lib1.mjs =====
// Named exports
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { cached } from 'tracked-toolbox';
import { scheduleOnce } from '@ember/runloop';
const Observers = [];
class Observer {
tags = [];
cb = null;
@lifeart
lifeart / ember-cli-build.js
Last active January 28, 2022 18:57
Minimal Ember 3.28 app with runtime-defined components
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function (defaults) {
let app = new EmberApp(defaults, {});
// we need to add emebr-template-compiler into runtime
app.import('node_modules/ember-source/dist/ember-template-compiler.js');
@maxfierke
maxfierke / cancelable-fetch.js
Last active April 21, 2022 18:15
cancelableFetch Yieldable ember-concurrency
import { Yieldable } from 'ember-concurrency';
import fetch from 'fetch'; // i.e. ember-fetch. could also use native fetch too.
class FetchYieldable extends Yieldable {
constructor(url, opts = {}) {
super(...arguments);
this.url = url;
this.opts = opts;
}