Skip to content

Instantly share code, notes, and snippets.

@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';
// Released under MIT license
// Copyright (c) 2009-2010 Dominic Baggott
// Copyright (c) 2009-2010 Ash Berlin
// Copyright (c) 2011 Christoph Dorn <[email protected]> (http://www.christophdorn.com)
/*jshint browser:true, devel:true */
(function( expose ) {
/**
@bytemain
bytemain / wsl-hosts.ps1
Created August 10, 2022 02:50 — forked from kakkun61/wsl-hosts.ps1
WSL v2 windows hosts sync (powershell - updates domains to wsl2 ip)
If (!(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host 'Run this as administrator.'
$choice = Read-Host 'Do you want to re-run this as administrator? [y/N]'
if ($choice -ne 'y') {
exit 1
}
$actualScriptRoot = $PSScriptRoot
if ((Get-Item $PSCommandPath).Target) {
$actualScriptRoot = Split-Path -Parent ((Get-Item $PSCommandPath).Target)
}
@bytemain
bytemain / bh.user.js
Created July 19, 2022 14:38
Fundebug Userscripts
// ==UserScript==
// @name enableBh
// @namespace xxxxx.enableBh
// @grant none
// @version 1.0
// @match *://www.fundebug.com/*
// @run-at document-start
// @description 2020/2/28 上午12:16:59
// ==/UserScript==