Skip to content

Instantly share code, notes, and snippets.

View shhider's full-sized avatar

Shi Haohong shhider

  • DingTalk Docs / 钉钉文档
  • Hangzhou / 杭州
View GitHub Profile
@shhider
shhider / brew-lite-doc.sh
Created March 27, 2023 02:55
[Homebrew Lite Docs] #litedoc #brew
# show installed formulae and casks
brew list
# list installed formulae that are not dependencies of another installed formula.
brew leaves
@shhider
shhider / console-save.js
Last active May 4, 2023 07:43
[console.save] download console output to file
((console) => {
console.save = (data, filename) => {
if (!data) {
console.error('Console.save: No data');
return;
}
if (!filename) filename = 'console.json';
if (typeof data === "object") {
@shhider
shhider / lazy-nvm.sh
Created January 30, 2023 08:21
[NVM lazy Loading] #node #nvm
# from: https://blog.yo1.dog/better-nvm-lazy-loading/
export NVM_DIR="$HOME/.nvm"
# This lazy loads nvm
nvm() {
unset -f nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
nvm $@
}
@shhider
shhider / esm-package.md
Created June 22, 2022 08:32 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from 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.
@shhider
shhider / class-initialization.md
Created December 28, 2021 09:01
[The order of class initialization] #javascript

The order of class initialization, as defined by JavaScript, is:

  1. The base class fields are initialized
  2. The base class constructor runs
  3. The derived class fields are initialized
  4. The derived class constructor runs
@shhider
shhider / javascript-binary-data.md
Last active November 19, 2021 01:48
[JavaScript Binary Data: ArrayBuffer, Uint8Array...]

ArrayBuffer 是一个基本的二进制对象 —— 对固定长度的连续内存空间的引用。

Uint8Array, Uint16Array, Uint32Array, Float64Array 等是 View,通过这些对象来「解释」二进制数据,统称为TypedArray.

@shhider
shhider / ts-utils.ts
Created October 28, 2021 06:47
[TypeScript Utility Types] #typescript
/**
* Mapped Type
* - Omit
* - Pick
* - Required
* - Partial
*
* Function
* - Parameters
* - ReturnType
@shhider
shhider / built-in variables.md
Last active August 25, 2021 11:18
[VSCode things] #vscode
Variable description example
${workspaceFolder} the path of the folder opened in VS Code /home/your-username/your-project
${workspaceFolderBasename} the name of the folder opened in VS Code without any slashes (/) your-project
${file} the current opened file /home/your-username/your-project/folder/file.ext
${fileWorkspaceFolder} the current opened file's workspace folder /home/your-username/your-project
${relativeFile} the current opened file relative to workspaceFolder folder/file.ext
${relativeFileDirname} the current opened file's dirname relative to workspaceFolder folder
${fileBasename} the current opened file's basename file.ext
${fileBasenameNoExtension} the current opened file's basename with no file extension file
@shhider
shhider / isNumberOverPrecison.ts
Created April 15, 2021 09:01
[isNumberOverPrecison]
function isNumberOverPrecison(num: number, precision = 15) {
if (!isFinite(num)) {
return false;
}
let numStr = num.toString().toLowerCase();
if (numStr.length <= 15) {
return false;
}
@shhider
shhider / merge-files.js
Last active November 18, 2021 09:42
[merge files by nodejs stream] #nodejs #stream #fs
async function mergeFiles(output, files) {
const outputStream = fs.createWriteStream(output, {
encoding: 'utf8',
flags: 'w+',
});
const merge = (fileToMerge) => new Promise((resolve, reject) => {
const fileStream = fs.createReadStream(fileToMerge, { encoding: 'utf8' });
fileStream.on('end', () => {
fileStream.close();