Skip to content

Instantly share code, notes, and snippets.

View eczn's full-sized avatar
Star

eczn* eczn

Star
View GitHub Profile
@eczn
eczn / ListNode.ts
Last active April 23, 2019 11:06
ListNode in TypeScript (a generic example)
export class ListNode<T> {
val: T;
next: ListNode<T> | null;
constructor(val: T, next: ListNode<T> | null = null) {
this.val = val;
this.next = next;
}
/**
@eczn
eczn / getRandomId.ts
Last active May 16, 2019 07:23
JS Get A Short Random Id
export function getRandomId() {
return Date.now().toString(36);
}
export function getRandomId2() {
return Math.random().toString(36).slice(2);
}
@eczn
eczn / resolve-utf8-base64.md
Last active April 27, 2022 08:33
解决 utf-8 base64 编码乱码

乱码不是乱码 而是二进制 base64

https://git.coolaj86.com/coolaj86/unibabel.js/src/branch/master/index.js

base64 解中文会乱码,原因是解出来的东西是一个 8 位整数,你得对这个整数进行 .toString(8) 并在前面加上 % 变成形如 %E5%B1%8E 这样的字符串,再进行 decodeComponentURI

那么反过来呢?

汉字转 binary bytes (base64-expression)

@eczn
eczn / set-nodejs-timezone.sh
Created September 13, 2019 07:04
设置 nodejs 运行的时候的系统时区
# https://www.viafitness.com/files/viafit_time_zones.pdf
env TZ='Asia/Shanghai' node
@eczn
eczn / mac-look-dir-size.sh
Created October 8, 2019 03:41
Mac 查看文件夹大小
# 查看当前文件夹大小
du -h -d 0
# 查看当前文件夹下各个子目录的大小
du -h -d 1
# 等价于 du -h -d 0
du -h -s
@eczn
eczn / MergeDeepType.ts
Last active November 19, 2019 08:33
MergeDeep Type
/**
* object skin copy
* e.g: SkinMerge<{ a: 1, c: 1 }, { a: 2, b: 2 }> ==> { a: 2, b: 2, c: 1 }
*/
type SkinMerge<O1, O2> = {
[k in (keyof O1 | keyof O2)]: k extends keyof O2 ? O2[k] : (k extends keyof O1 ? O1[k] : never)
}
/**
* get keys from O where the value is object
@eczn
eczn / git-clone-big-repo.sh
Last active December 20, 2019 06:06
command-line-notebook
# clone git repo without the repo's full history:
$ git clone --depth=1
@eczn
eczn / x5-video-z-index.md
Created November 15, 2019 07:17
安卓 X5 内核浏览器 Video 元素层级问题
@eczn
eczn / postfix-calc.hs
Last active November 18, 2019 08:21
ts / hs 实现后缀计算式
-- by @W-46ec
-- a4.hs
-- Token data type
data Token = Num Double | Op String | Err String
deriving (Eq, Show)
-- Stack operations
@eczn
eczn / git-set-unset-proxy.sh
Last active August 12, 2023 07:37 — forked from laispace/git 设置和取消代理
git 设置和取消代理
# 设置
git config --global https.proxy http://127.0.0.1:1080
git config --global http.proxy https://127.0.0.1:1080
# 取消
git config --global --unset http.proxy
git config --global --unset https.proxy
# 删除 npm proxy 配置
npm config delete proxy