Skip to content

Instantly share code, notes, and snippets.

我的翻译内容基于 CC BY-NC-SA 3.0 协议
https://creativecommons.org/licenses/by-nc-sa/3.0/cn/deed.zh
launchd.plist(5) BSD File Formats Manual launchd.plist(5)
NAME
launchd.plist -- System wide and per-user daemon/agent configuration
files
launchd.plist -- 系统范围和用户级的守护进程/代理程序配置文件。
#!/usr/bin/env ts-node
/**
* Usage:
*
* pnpm ts-node scripts/generate-btc-ordinal-addresses.ts 'mainnet | testnet' 'mnemonic' 0 1000 | jq -r 'map(.address) | join("\n")' > /save/to/some/file
*/
import { BIP32Factory } from 'bip32';
import * as bip39 from 'bip39';
type UnknownObject = Record<string, unknown>
/**
* 一个 EventEmitter ,当注册事件的对象(`gcTarget`)被 GC 时,会自动取消注册事件
*
* WARNING: 使用这个 EventEmitter 时需要注意,为了避免 `callback` 里可能会引用
* `gcTarget` 导致 `gcTarget` 本身不被回收,所以代码实现中对 `callback` 是持有的弱引用,
* 因此 `gcTarget` 本身需要持有 `callback` 的强引用
*
* @example
@bolasblack
bolasblack / ocserv.init
Last active June 11, 2020 14:53
/etc/init.d/ocserv
#!/sbin/runscript
DAEMON=/usr/local/sbin/ocserv
PIDFILE=/var/run/ocserv.pid
LOGFILE=/var/log/ocserv.log
DAEMON_ARGS="-f -d 1"
extra_commands="debug"
depend() {
@bolasblack
bolasblack / test.js
Last active April 17, 2020 03:57
break lines in html5 canvas
import { textBreakLinesInCanvas } from "./textBreakLinesInCanvas"
const maxWidth = 300
const lineHeight = 24
document.querySelectorAll('canvas').forEach((e) => e.remove())
const canvas = document.createElement('canvas')
canvas.width = maxWidth
canvas.height = 300
canvas.style.lineHeight = `${lineHeight}px`
@bolasblack
bolasblack / nodejs unlimited console.log.js
Last active October 5, 2018 04:45
nodejs unlimited console.log
const util = require('util')
module.exports.global = () => {
util.inspect.defaultOptions.maxArrayLength = null
util.inspect.defaultOptions.depth = null
}
module.exports.consoleJson = () =>
console.json = (...args) =>
console.log.apply(console, args.map(arg =>
# 1
curl -o yarn -L `curl -s 'https://api.github.com/repos/yarnpkg/yarn/releases/latest' | jq -r '.assets | map(select(.name | test("legacy.*js$")) | .browser_download_url) | .[0] | tostring'` && chmod u+x yarn
# 2
VERSION=$(curl https://yarnpkg.com/latest-version)
curl -L -o yarn https://github.com/yarnpkg/yarn/releases/download/v$VERSION/yarn-legacy-$VERSION.js

Promise.race

const result = await Promise.race([promise1, promise2])
(go (let [[result chan] ;; result the value and while chan won
          (<! (alts! [chan1
 [value chan2] ;; even can wait a value &gt;! chan
@bolasblack
bolasblack / bfcache-test.js
Last active September 19, 2018 08:24
how to prevent bfcache
// modified from https://mixmax.com/blog/chrome-back-button-cache-no-store
/**
* Run this by downloading this script to your computer, then:
* 1. $ npm install express
* 2. $ node thisscript.js
* 3. Open localhost:8030/nocache and then localhost:8030/nostore
*/
const app = require('express')()
@bolasblack
bolasblack / export.scpt
Last active September 10, 2018 09:14
Export OS X Reminder
on format_time(currTime as date)
set stamp to the time of currTime
set h to text -2 thru -1 of ("00" & (stamp div (60 * 60)))
set m to text -2 thru -1 of ("00" & (stamp - (60 * 60) * h) div 60)
set s to text -2 thru -1 of ("00" & (stamp - ((60 * 60) * h + 60 * m)))
return h & ":" & m & ":" & s
end format_time
-- from http://henrysmac.org/blog/2014/1/4/formatting-short-dates-in-applescript.html
on format_date(currTime as date)