Skip to content

Instantly share code, notes, and snippets.

View bytemain's full-sized avatar

Jiacheng bytemain

View GitHub Profile
@bytemain
bytemain / check-encoding.mjs
Created November 22, 2025 03:21
Find out invalid encoding for Chinese
import fs from "node:fs/promises";
import path from "node:path";
import process from "node:process";
import { TextDecoder } from "node:util";
const docsDir = path.join(process.cwd(), "site", "content", "zh", "docs");
async function listFiles(dir) {
const out = [];
const entries = await fs.readdir(dir, { withFileTypes: true });
@bytemain
bytemain / format-chinese.mjs
Created November 22, 2025 03:20
A tiny script that can improve copywriting, correct spaces, words, and punctuations between CJK. Powered by https://github.com/huacnlee/autocorrect
import autocorrect from "autocorrect-node";
import fs from "node:fs/promises";
import path from "node:path";
import process from "node:process";
const docsDir = path.join(process.cwd(), "site", "content", "zh", "docs");
async function run() {
const entries = await fs.readdir(docsDir, { withFileTypes: true });
for (const entry of entries) {
@bytemain
bytemain / format-chinese.mjs
Created November 22, 2025 03:20
A script that can improve copywriting, correct spaces, words, and punctuations between CJK
import autocorrect from "autocorrect-node";
import fs from "node:fs/promises";
import path from "node:path";
import process from "node:process";
const docsDir = path.join(process.cwd(), "site", "content", "zh", "docs");
async function run() {
const entries = await fs.readdir(docsDir, { withFileTypes: true });
for (const entry of entries) {
@bytemain
bytemain / index.ts
Created May 7, 2024 03:03
Buffer to JSON playground
import filesize from 'filesize'
import crypto from 'crypto'
function testIt(buffer: Buffer) {
console.log("========")
console.log(`原始 buffer 长度`, filesize.filesize(buffer.byteLength));
const stringified = JSON.stringify(buffer)
if (stringified.length < 200) {
console.log(`原始数据`, buffer);
console.log(`序列化结果:`, stringified);
@bytemain
bytemain / replace.js
Last active January 26, 2024 08:53
use ast grep to replace import default statement and replace all usage
const { js } = require('@ast-grep/napi');
const MagicString = require('magic-string').default;
/**
* Replace the local variable name of the import statement
*/
exports.replaceImportDefault = (source, pkgName, expectLocalName) => {
const magic = new MagicString(source);
const ast = js.parse(source); // 1. parse the source
@bytemain
bytemain / .gitconfig
Created April 19, 2023 02:57 — forked from Kovrinic/.gitconfig
git global url insteadOf setup
# one or the other, NOT both
[url "https://github"]
insteadOf = git://github
# or
[url "[email protected]:"]
insteadOf = git://github
@bytemain
bytemain / conf.lua
Last active February 21, 2023 09:27
love2d official nogame script
function love.conf(t)
t.title = "L\195\150VE " .. love._version .. " (" .. love._version_codename .. ")"
-- t.gammacorrect = true
-- t.modules.audio = false
-- t.modules.sound = false
-- t.modules.joystick = false
-- t.window.resizable = true
-- t.window.highdpi = true
t.window.width, t.window.height = 1280, 720
t.window.fullscreen = true
@bytemain
bytemain / main.sh
Created February 19, 2023 09:05
linux 生成不同大小的文件
# 1g.txt zero
dd if=/dev/zero of=1g.txt bs=1M count=1000
# 10m.txt random
dd if=/dev/random of=10m.txt bs=1M count=10
@bytemain
bytemain / HttpProxy.go
Created February 17, 2023 11:46 — forked from yowu/HttpProxy.go
A simple HTTP proxy by Golang
package main
import (
"flag"
"io"
"log"
"net"
"net/http"
"strings"
)
@bytemain
bytemain / esbi.ts
Created February 14, 2023 11:28
Build your Typescript Node.js projects using blazing fast esbuild
#!/usr/bin/env tsx
import { config } from 'dotenv';
config();
import { context as createContext, Plugin } from 'esbuild';
import ts from 'typescript';
import { build } from 'esbuild';
import mri from 'mri';