Skip to content

Instantly share code, notes, and snippets.

View eczn's full-sized avatar
Star

eczn* eczn

Star
View GitHub Profile
@eczn
eczn / gist:808b6e0edea8118bbee8c73f757b35e7
Last active July 18, 2023 22:23 — forked from lomomike/gist:770dd7df03bb951fac4e
linux 内核代码里利用宏实现的链表 list,值得观赏/收藏
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
struct birthday {
int day;
int month;
int year;
@eczn
eczn / install-chromium.md
Created July 24, 2022 23:26
how to install chromium on arm-mac

install chromium

$ brew install chromium
$ xattr -cr /Applications/Chromium.app

env settings

@eczn
eczn / optional.ts
Last active August 14, 2022 07:45
serveral ways of optional chaining for unknown values
// use Optional instead unknown
type Optional = (undefined | null | number | string | Function | Optional[]) & {
[key: string]: Optional;
}
declare const value: Optional;
const d = value?.a?.b?.c?.d;
if (typeof d === 'number') d.toFixed(2);
@eczn
eczn / union-to-tuple.md
Last active May 9, 2022 12:28
UnionToTuple<T>
// T ====> [...T, E]
type Concat<T, E> = T extends any[] ? [...T, E] : [];


// union to intersection of functions
// UnionToIoFn<'a' | 'b'>
// ====> ((x: 'a') => void) & ((x: 'b') => void)
// ====> that equal to { (x: 'a'): void; (x: 'b'): void }
type UnionToIoFn =
@eczn
eczn / one package with different version in the one package.json.md
Created May 9, 2022 08:31
one package with different version in the one package.json
$ npm i gg@latest
$ npm i gg-1.0.0@npm:[email protected]
import ggOld from 'gg-1.0';
import gg from 'gg';
@eczn
eczn / VvV.md
Last active April 4, 2023 21:49
-v --verbose | -V --version
$ [command] -v --verbose
$ [command] -V --version
@eczn
eczn / reinstall-cleaning-nvm-node-npm.md
Last active April 26, 2022 13:08
reinstal / cleanning your nvm / node / npm in ways of abcdefg

a) remove .nvm dir

$ cd ~
$ rm -rf ./.nvm  # !! danger, be careful to delete with -rf

b) check node/npm removed or not

@eczn
eczn / thistype.md
Last active April 24, 2022 08:38
TypeScript ThisType

sometimes we need to change context's type in function

const f1 = {
  data: {
    i: 0,
  },
  methods: {
 inc() {
@eczn
eczn / person.ts
Last active March 15, 2022 14:54
someone's js artworks
const wait = (t = 0) => new Promise(r => setTimeout(r, t));
class Person {
name: string;
promise: Promise<any>;
constructor(name: string) {
this.name = name;
this.promise = new Promise((resolve) => {
resolve(undefined);
});
}
@eczn
eczn / textboard.ts
Last active July 27, 2022 02:01
clipboard copy
class TextBoard {
/**
* 文字复制至剪切板
* @param data 需要复制的文本
*/
public copy = async (data: string) => {
if (window.navigator.clipboard) {
try {
await window.navigator.clipboard.writeText(data)
} catch (err) {