Skip to content

Instantly share code, notes, and snippets.

@alanwei43
alanwei43 / logger.ts
Created February 12, 2020 12:18
logger module
import { appendFile, existsSync, mkdirSync } from "fs";
import { join } from "path";
let GLOBAL_COUNT = 0;
export class Log {
private dir: string
constructor(private name: string) {
this.dir = join(process.cwd(), "logs");
this.checkDir();
}
@alanwei43
alanwei43 / typescript-import-json.md
Created January 8, 2020 14:28
import json by typescript

How to import *.json ?

As already answered you need Typescript >= 2.9 and the following settings in tsconfig.json:

{
  "resolveJsonModule": true,
  "esModuleInterop": true,
  "module": "commonjs"
}
@alanwei43
alanwei43 / pipe.js
Created December 29, 2019 01:06
Node HTTP pipe
const http = require("http"),
url = require("url");
http.createServer((proxyReq, proxyRes) => {
console.log(proxyReq.url);
const options = url.parse(proxyReq.url);
const svr = http.request(options, svrRes => {
svrRes.pipe(proxyRes, { end: true });
});
proxyReq.pipe(svr, {
@alanwei43
alanwei43 / windows-port-proxy.md
Last active April 18, 2024 11:19
windows powershell port forward
netsh interface portproxy add v4tov4 protocol=tcp connectaddress=192.168.67.128 connectport=9091 listenport=9091
@alanwei43
alanwei43 / ChainResponse.js
Created September 21, 2019 04:41
ChainResponse.js
const fs = require("fs"), path = require("path");
let debugMode = false;
//#region 日志函数
function log(txt) {
if (debugMode) {
console.log(`[${new Date().toLocaleString()}] ${txt}`);
}
}
function warn(txt) {
@alanwei43
alanwei43 / Promise.whenAllSettled.js
Created September 18, 2019 12:02
Promise.whenAllSettled
/**
* 所有Promise都被 settled
* @param {[{promise: function():Promise, data: {}}]} promises
* @retu {Promise<[{isResolve: boolean, isReject: boolean, error: {}, result: {}, data: {}}]>}
*/
Promise.whenAllSettled = function (promises) {
const isPromise = function (obj) {
return obj && typeof obj.then === "function" && typeof obj.catch === "function";
};
@alanwei43
alanwei43 / repositories.md
Created August 4, 2019 08:03
Alpine Linux 镜像源

编辑 /etc/apk/repositories,然后在文件的最顶端添加(注意将 3.3 换成需要的版本)

http://mirrors.ustc.edu.cn/alpine/v3.3/main/

参考wiki

@alanwei43
alanwei43 / profiles.json
Created July 24, 2019 08:00
Microsoft Terminal Preview default configurations
{
"globals" :
{
"alwaysShowTabs" : true,
"defaultProfile" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{
@alanwei43
alanwei43 / push-to-gist.sh
Last active May 21, 2019 11:49
Push to gist 读取文件并发布到gist上
# 0. Your file name
FNAME="$2"
# 1. Somehow sanitize the file content
# Remove \r (from Windows end-of-lines),
# Replace tabs by \t
# Replace " by \"
# Replace EOL by \n
CONTENT=$(sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' "${FNAME}" | awk '{ printf($0 "\\n") }')
@alanwei43
alanwei43 / dwz.csx
Last active May 18, 2019 07:58
百度短网址生成脚本
#r "nuget: Newtonsoft.Json, 12.0.2"
using System.Net.Http;
using static System.Console;
using Newtonsoft.Json;
using static Newtonsoft.Json.JsonConvert;
if (Args.Count == 0)
{
Console.WriteLine($@"