Skip to content

Instantly share code, notes, and snippets.

@uinz
uinz / getArr.ts
Created July 25, 2018 09:46
实现0和1的排列组合
function getArr(size: number) {
const result: number[][] = [];
(function loop(arr: number[] = []) {
if (arr.length < size) {
loop([...arr, 0]);
loop([...arr, 1]);
} else {
result.push(arr);
}
})();
<input pattern="[0-9]*" />
@uinz
uinz / omnisharp.json
Created September 17, 2018 03:13
vscode - c# format (Omnisharp: Restart Omnisharp)
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInAccessors": false,
@uinz
uinz / polygonArea.ts
Last active April 1, 2019 09:45
calculate polygon area
function polygonArea(points: { x: number; y: number }[]) {
let i = 0;
let s = 0;
while (points[i + 1]) {
const p1 = points[i];
const p2 = points[i + 1];
s += p1.x * p2.y - p2.x * p1.y;
i += 1;
}
return Math.abs(s / 2);
// yarn add fs-extra glob
const { promisify } = require('util');
const glob = promisify(require('glob'));
const fse = require('fs-extra');
const path = require('path');
async function replace(ext, newExt) {
const pattern = path.resolve(__dirname, `**/*.${ext}`);
const filenames = await glob(pattern);
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.20312860608100891</real>
@uinz
uinz / http-api.ts
Last active May 7, 2021 06:24
http
// 基于 ctx, 类型好友的 js HTTP 设计尝试
type IncomingMessage = object;
type Prettier<T> = T extends object ? { [K in keyof T]: T[K] } : T;
type Middle = (ctx: BaseCtx) => unknown;
type BaseCtx = { readonly _: IncomingMessage };
type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;
type NextCtx<T extends Middle> = Awaited<ReturnType<T>>;
type KV<P> = P extends `${infer K}=${infer V}` ? { [k in K]: VType<V> } : {};