Skip to content

Instantly share code, notes, and snippets.

View lenqwang's full-sized avatar
🏠
Working from home

lenq lenqwang

🏠
Working from home
  • In job search
  • GuangZhou or FoShan, China
  • 08:42 (UTC +08:00)
  • X @lenq
View GitHub Profile
@lenqwang
lenqwang / crc32.js
Created May 6, 2022 12:58
crc32 implementation
const makeCRCTable = () => {
let c;
const crcTable = [];
for (let n = 0; n < 256; n++) {
c = n;
for (let k = 0; k < 8; k++) {
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
}
crcTable[n] = c;
}
@lenqwang
lenqwang / tiny-date.js
Last active April 26, 2022 02:23
tinydate
// copied from https://github.com/lukeed/tinydate
var RGX = /([^{]*?)\w(?=\})/g;
var MAP = {
YYYY: 'getFullYear',
YY: 'getYear',
MM: function (d) {
return d.getMonth() + 1;
},
DD: 'getDate',
@lenqwang
lenqwang / csv2ts.ts
Last active November 3, 2021 14:09
convert json to csv file
#!/usr/bin/env ts-node
import path from 'path'
import glob from 'glob'
import csv from 'csv-parser'
// @ts-ignore
import { writeFile, readFile } from 'fs/promises'
import fs from 'fs'
async function main() {
@lenqwang
lenqwang / repos.json
Last active September 24, 2021 07:40
批量应用patch到指定仓库(支持多个)
{
"repos": [
{ "repoName": "AA", "targetBranchName": "feature/v1" },
{ "repoName": "BB", "originBranchName": "master", "targetBranchName": "feature/v2" },
{ "repoName": "CC", "originBranchName": "feature/v1", "alias": "folder Name of CC in your locale", "targetBranchName": "feature/xxx/sync-patch" }
],
"patch": "DD/*.patch"
}
@lenqwang
lenqwang / short_url.sh
Created July 9, 2021 02:56
自定义缩短 github url
#!/bin/bash
set -eo pipefail
# 缩短 url,自定义短网址
api="https://git.io"
short_url() {
# 防御编程
# 无参数输入
@lenqwang
lenqwang / png2svg.sh
Created November 19, 2020 10:31
png to svg (png must be png 24)
#!/bin/bash
# 在转换之前先确保 png 是否为 png24 位,否则跳去 [Photopea | Online Photo Editor](https://www.photopea.com/) 先导出为png格式文件,再进行如下操作
# 确保是否有安装 potrace
# HOMEBREW_NO_AUTO_UPDATE=1 brew install potrace
# 确保是否有安装 convert
# HOMEBREW_NO_AUTO_UPDATE=1 brew install imagemagick
File_png="${1?:Usage: $0 file.png}"
@lenqwang
lenqwang / findItem.js
Last active August 1, 2019 06:54
查找过滤符合条件的深度嵌套对象及其top项
function findItem (data, filterFn, childrenKey = 'children', targetTopLevel = 1) {
let resultItem
let resultTopLevelItem
let topLevelItem
function findNestItem (d, filter, level) {
if (!d || !d.length) {
return
}
@lenqwang
lenqwang / resize-detector.js
Created February 15, 2019 06:15
window resize detector
let raf = null;
function requestAnimationFrame(callback) {
if (!raf) {
raf = (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function (callback) {
return setTimeout(callback, 16)
}