Skip to content

Instantly share code, notes, and snippets.

@lxl66566
lxl66566 / README.md
Last active May 26, 2026 09:22
nix flake auto calculate follows

no more _2 _3 in your flake.lock.

usage:

cat flake.lock | python nixfollows.py
@lxl66566
lxl66566 / .jjconfig.toml
Created March 25, 2026 09:47
lxl66566's jujutsu config (20260325)
# :schema https://docs.jj-vcs.dev/latest/config-schema.json
# some contents are from https://gist.github.com/thoughtpolice/8f2fd36ae17cd11b8e7bd93a70e31ad6
[user]
name = "lxl66566"
email = "lxl66566@gmail.com"
[ui]
# 当只输入 `jj` 时,默认执行的命令设为 `jj log` (查看日志)
default-command = "log"
@lxl66566
lxl66566 / README.md
Last active June 2, 2026 09:55
use idea cli to format java project, only format changed lines. support both git/jujutsu repo, can be executed directly or git commit hook.

If you don't use idea, it's hard to maintain the same code style with your colleagues. This script solves this problem, it uses idea cli and the code style XML of your project to format your code.

@lxl66566
lxl66566 / main.py
Created October 17, 2025 08:35
python upload server
import http.server
import os
import re
import socketserver
PORT = 9000
UPLOAD_DIR = "./"
# 一个简单的辅助函数,用于解析 multipart/form-data 的头部
@lxl66566
lxl66566 / index.js
Last active July 23, 2025 06:54
划词高亮页面内相同文字(效果类似划词自动 ctrl + f 在页面上搜索)
// ==UserScript==
// @name 划词高亮页面内相同文字
// @namespace http://tampermonkey.net/
// @version 2.1
// @description 当在网页上选中一段文字后,自动高亮所有其他相同文字。点击或选择新内容后自动清除旧高亮。当选中的文本是在输入框或可编辑区域内的时候,不会触发高亮。
// @author lxl66566 (Gemini 2.5 pro)
// @match *://*/*
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
@lxl66566
lxl66566 / Cargo.toml
Created June 11, 2025 02:59
Rust version of AES-256-CFB using SIMD (AI translated)
[package]
name = "aes_simd_rust"
version = "0.1.0"
edition = "2021"
[dependencies]
openssl = "*"
rand = "0.9" # For generating test data
[dev-dependencies]
@lxl66566
lxl66566 / build.rs
Created June 1, 2025 16:17
Automatically build sqlite database for compiling sqlx
//! The entire build.rs does one thing: applies schema.sql to
//! target/sqlx_schema.db for sqlx to use during compilation.
use std::process; // For panic
use std::{env, fs, path::PathBuf};
// build.rs runs in a sync context, so we need a runtime to run sqlx async functions
use fuck_backslash::FuckBackslash;
use path_absolutize::Absolutize;
// We need the execute trait from sqlx prelude
@lxl66566
lxl66566 / main.rs
Created December 6, 2024 01:17
Rust counter implemention benchmark
#![feature(test)]
extern crate test;
use std::collections::HashMap;
use counter::Counter;
use dashmap::DashMap;
use rayon::prelude::*;
use test::black_box;
@lxl66566
lxl66566 / README.md
Last active November 23, 2024 17:51
Kth Largest Elementt in an Array, benchmark

我一直不明白,第 k 大的数的正解为什么时间复杂度是 O(n)。看快排代码,二分递归代码一眼就是 O(nlog n),一看题解,全都说证明在算法导论,自己看书。 我看不懂书,因此想尝试做一个 benchmark,通过数据规模增长和 benchmark 用时来判断其时间复杂度。

  1. 生成足够数量的随机数。后续所有测试都在这样同一个相对随机的数据上进行。
  2. find_kth_largest 函数为 leetcode 题解(基于快速排序的选择方法) 改写为 rust 版本的结果。

注:find_kth_largest 函数本身没有 clone;我在 benchmark 之前就进行了数据 clone。

测试结果为(已排序,否则 cargo test 输出的排序为 10 100 1000 10000 50 500 5000):

@lxl66566
lxl66566 / test.ts
Last active October 26, 2024 10:59
TypeScript partition array into two by condition, performance compare
import { Bench } from "tinybench";
const bench = new Bench({
time: 1000,
});
// This will not change the origin array
function partition<T>(
arr: readonly T[],
predicate: (item: T) => boolean,