Skip to content

Instantly share code, notes, and snippets.

function omitDeep(collection, excludeKeys) {
function omitFn(value) {
if (value && typeof value === 'object') {
excludeKeys.forEach((key) => {
delete value[key];
});
}
}
@bytemain
bytemain / notion_proxy.js
Created November 7, 2021 06:37
A serverless function that reverse proxy notion
const MY_DOMAIN = "example.com"
const START_PAGE = "https://www.notion.so/xxxx/xxxxx"
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, HEAD, POST,PUT, OPTIONS",
@bytemain
bytemain / delete_tag.mjs
Created September 11, 2021 13:28
use zx delete git tag
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('请输入要删除的 tag');
process.exit(1);
}
const tag = args[0];
await $`git tag -d ${tag}`;
await $`git push origin :refs/tags/${tag}`;
const fs = require("fs");
const zipdata = fs.createReadStream("1.zip");
const { zip, tar } = require("compressing");
async function getTarReadStream(download) {
return new Promise((resolve, reject) => {
function onEntry(header, stream, next) {
if (header.type === "file" && header.name.endsWith(".tar")) {
resolve(stream);
return;
}
@bytemain
bytemain / dns-restart.sh
Created June 13, 2021 05:22
MacOS X DNS related
#!/bin/sh
echo "restart dnscrypt-proxy..."
sudo brew services restart dnscrypt-proxy
echo "restart dnsmasq..."
sudo brew services restart dnsmasq
pid story vote_yes vote_no
3 Gauss didn’t discover the normal distribution, nature conformed to his will. 267 49
4 Gauss can trisect an angle with a straightedge and compass. 33 8
5 Gauss can get to the other side of a Möbius strip. 269 39
6 “Uncountably Infinite” was a phrase coined to explain the intelligence of Gauss. 53 14
7 There are no Fermat Primes greater than 65,537 because Gauss saw that Fermat was on to something, and well…he put an end to that. 82 8
8 For Gauss, arithmetic is consistent AND complete. 41 5
9 It only takes Gauss 4 minutes to sing “Aleph-Null Bottles of Beer on the Wall”. 175 36
10 When Gauss tells you that he’s lying, he’s telling the truth. 347 25
11 Gauss once played himself in a zero-sum game and won $50. 440 28
const fs = require('fs');
var readline = require('readline');
var stream = require('stream');
const buf = fs.readFileSync('./1.txt');
var bufferStream = new stream.PassThrough();
bufferStream.end(buf);
var rl = readline.createInterface({
@bytemain
bytemain / bench.js
Created April 19, 2021 11:19
benchmark example
const Benchmark = require('benchmark');
const { md5, blake3 } = require('hash-wasm');
const map = {
'hash-wasm-md5': md5,
'hash-wasm-blake3': blake3,
};
const _1b = '0';
const _10b = '0'.repeat(10);

Keybase proof

I hereby claim:

  • I am lengthmin on github.
  • I am lengthmin (https://keybase.io/lengthmin) on keybase.
  • I have a public key ASA2kMzkIDiKUZUo6YkxplS75GjHVdbHO1a9MFKWTiuT3Ao

To claim this, I am signing this object:

@bytemain
bytemain / awk
Last active January 2, 2021 11:38
cheat
cat /etc/passwd |awk -F ':' '{print $1}'
通过 awk 命令我们可以筛选出符合要求的行或者列数据
以:为分隔符,将 password 分为多列,并且提取出第一列的内容
---
$(awk '/Host github.com/{print NR}' ~/.ssh/config)
查找内容出现在第几行