Skip to content

Instantly share code, notes, and snippets.

@guest271314
guest271314 / harmony.md
Last active November 8, 2024 18:30
Why I use node, deno, bun, qjs, tjs at the same time

Why I use node, deno, bun, qjs, tjs at the same time.

Winds up being a (not the) rather comprehensive JavaScript toolbox. The idea being for the modern JavaScript programmer can use all of the tools available for a given requirement, task or job, without preference for any. No external bundlers or compilers are needed. No frameworks are needed. I can use qjs or tjs for systems with minimal RAM and disk space; and when I want to use Web API's deno makes an effort to provide those interfaces. In some cases I can run the exact same code in bun, deno, and node, which provides a means to perform 1:1 testing as to performance.

There's probably a few things I am unintentionally omitting below. These are just a brief synposis. I'll update accordingly.

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@sindresorhus
sindresorhus / esm-package.md
Last active November 17, 2024 22:07
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.
@zerobias
zerobias / safe-padding.css
Last active May 29, 2024 05:51
Safe body paddings with env() and max() support
/* size variables */
:root {
--md: 8px;
--md-2: calc(var(--md) * 2);
--md-3: calc(var(--md) * 3);
--md-4: calc(var(--md) * 4);
}
/* safe area defaults */
@zhuziyi1989
zhuziyi1989 / URL Schemes.md
Last active November 18, 2024 09:13
常用 URL Schemes 收集。

** 由于此文年事已久,可能某些 URL Schemes 已失效,可在评论区留言指出!(最后更新于 2024.10.28)

关于 URL Scheme 你知道多少?

iOS 系统中

由于苹果的各应用都是在沙盒中,不能够互相之间访问或共享数据。但是苹果还是给出了一个可以在 APP 之间跳转的方法:URL Scheme。简单的说,URL Scheme 就是一个可以让 APP 相互之间可以跳转的协议。每个 APP 的 URL Scheme 都是不一样的,如果存在一样的 URL Scheme,那么系统就会响应先安装那个 APP 的 URL Scheme,因为后安装的 APP 的 URL Scheme 被覆盖掉了,是不能被调用的。

Android 系统中

@hjkcai
hjkcai / parallel.ts
Last active March 5, 2020 15:06
2018-3-2 面试题
// 实现一个方法 parallel(tasks, concurrency),让 tasks 并发执行(并控制并发数为 concurrency)
// 其中 tasks 为一个数组,每一个元素都是一个方法返回一个 promise
// 当所有 tasks 执行完成时,resolve 一个数组保存所有的结果
// 当任意一个 task 执行失败时,reject 这个错误
// 运行方法:
// $ tsc parallel.ts --target esnext && mocha parallel
declare const require
declare const describe
@egmontkob
egmontkob / Hyperlinks_in_Terminal_Emulators.md
Last active November 13, 2024 14:50
Hyperlinks in Terminal Emulators
@akmandev
akmandev / Nginx - Disable Cache.conf
Created February 12, 2017 20:40
Nginx disabling static file cache for local development
location / {
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;
}
@paulirish
paulirish / what-forces-layout.md
Last active November 15, 2024 16:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent

Angular2 + JSPM cheat sheet

First time setup

  • install jspm beta: npm install -g jspm@beta
  • set up your project: jspm init
  • install dependencies: jspm install angular2 reflect-metadata zone.js es6-shim

This will create a jspm_packages folder, and a config.js file.

Open the config.js file - this file manages options for the System.js loader - tweak it as appropriate