Skip to content

Instantly share code, notes, and snippets.

@zyf0330
zyf0330 / fillTriangle
Last active April 16, 2024 05:57
给定直角边长,从左上角以逆时针螺旋路径,填充该等腰三角形内的每个整数坐标点
function fillTriangle(N) {
const lines = [];
function makeRound() {
let x = round - 1;
let y = round - 1;
let step = 1;
try {
(lines[y] ??= [])[x] = n;
canFinishFill();
@zyf0330
zyf0330 / add-override.js
Created April 27, 2023 07:39
fix noImplicitOverride error
const cp = require("child_process")
const fs = require("fs/promises")
const path = require("path")
try {
cp.execSync("npx tsc --noEmit")
} catch (e) {
const output = e.stdout.toString()
const regexp = /^(.+\.ts)\((\d+?),(\d+?)\): error TS411(4|6):.+/
const overrideFiles = output.split("\n").reduce((m, line) => {
const result = line.match(regexp)
@zyf0330
zyf0330 / two-way-dependency-map.txt
Last active July 6, 2021 10:09
construct two-way dependency map to execute by order
'use strict'
function resolver(o) {
return new Promise((res) => {
setTimeout(() => {
console.log(Date.now(), 'prepare end', o.service)
res()
}, 1000)
})
}
@zyf0330
zyf0330 / quanping-to-shuangpin.js
Created December 13, 2020 09:25
转换搜狗拼音txt词库为 Gboard 微软双拼词库
/**
* dic.txt 内每行类似 'a'ba 阿巴
* 先组合声母韵母,然后再完整替换
* 对于零声母音节,声母当作空字符
**/
const fs = require('fs')
// 声母
const shengmu = {
@zyf0330
zyf0330 / openInstagramImg.js
Last active February 24, 2022 02:31
open img of current focus at Instagram
javascript:var multiEle=document.getElementsByClassName('MreMs')[0];var i=(multiEle!=null)?multiEle.style.transform.slice(12, -3)/480:0; var img=document.getElementsByClassName('ZyFrc')[0].getElementsByClassName('FFVAD')[i];window.open(img.src)
class TaskList {
constructor(tasks) {
this.tasks = tasks
this.promise = null
this.index = 0
this.fowarding = false
}
async start() {
this.fowarding = true
@zyf0330
zyf0330 / logrotate.sh
Created February 12, 2018 02:42
logrotate for nginx log hourly
#!/bin/env bash
set -euo pipefail
function _d() {
echo `date +%Y%m%d-`$1
}
cd /var/log/nginx
h=$((`date +%H`-1))
if [ $h = -1 ]; then
h=23
@zyf0330
zyf0330 / Promise.js
Last active July 2, 2017 06:02
My Promise implement. Must run in Node.js. 只是一个没有按照标准实现的残次品
let id = 1
function Promise(executor) {
this.id = id++
this.status = 'pending'
this.value = null
this._next = null
const response = (status, v) => {
if (this.status != 'pending') {
return
}
const numsNum = 10
const nums = '0'.repeat(numsNum).split('').map(() => parseInt(Math.random() * 100) + 1)
console.log('before sort', nums)
const arrs = []
let push = 0
// 这里的循环说明了空间使用是 O(n2)
for (const num of nums) {
@zyf0330
zyf0330 / wrapGenerator
Last active June 15, 2017 06:31
Wrap generator returns promise. Got by myself
const wrapGenerator = function (Generator) {
const promise = new Promise(function (resolve, reject) {
const g = Generator()
let r = g.next()
const nextYield = function (r) {
if (r.done == true) {
resolve(r.value)
return
}
r.value.then(function (x) {