Skip to content

Instantly share code, notes, and snippets.

@hashibit
hashibit / move_targets_to_external_disk.py
Created May 15, 2026 22:33
Move Rust target/ directories to an external disk and symlink back. Zero-dep Python; idempotent.
#!/usr/bin/env python3
"""
Recursively scan SRC for directories that contain both Cargo.toml and a real
`target/` subdirectory. Move that target/ to DST mirroring the relative path,
then leave a symlink in place. Idempotent: already-symlinked targets are
skipped. If DST already has a stale `target/` for that crate, it's removed
before the move.
Usage:
move_targets_to_external_disk.py DST [--src SRC]
@hashibit
hashibit / shrink_foreign_repos.py
Created May 15, 2026 22:33
Shallow-truncate foreign git repos to last N commits. Zero-dep Python; preserves HEAD commit SHA via .git/shallow + gc.
#!/usr/bin/env python3
"""
Recursively scan the current directory for git repos. For each repo that:
- is not ours (no remote URL contains one of OUR_NAMES)
- has a remote configured
- has at least KEEP_COMMITS commits
- is not already shallow
truncate history to the last KEEP_COMMITS commits using the .git/shallow
mechanism (preserves the HEAD commit SHA), then expire reflog and gc.
[
// 基础编辑
{ "keys": ["super+c"], "command": "copy" },
{ "keys": ["super+v"], "command": "paste" },
{ "keys": ["super+x"], "command": "cut" },
{ "keys": ["super+z"], "command": "undo" },
{ "keys": ["super+shift+z"], "command": "redo" },
{ "keys": ["super+a"], "command": "select_all" },
// 标签页导航(Vim 风格:h=左,l=右)
@hashibit
hashibit / box-drawing.md
Created December 3, 2025 12:14 — forked from flaviut/box-drawing.md
Box Drawing characters with examples

Box drawing fun

A few boxes drawn with Unicode box drawing characters:

╔═╦═╗
╠═╬═╣
║ ║ ║
╚═╩═╝
// engine/utils/json_ptr.h
#pragma once
#include <json/value.h>
#include <memory>
#include <optional>
#include <string>
class JsonPtr {
public:
explicit JsonPtr(const std::shared_ptr<Json::Value>& json) : json_(json) {}
# Git aliases compatible with both bash and zsh
## Functions
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return 0
@hashibit
hashibit / Emacs.kms
Created September 28, 2023 04:04 — forked from machinekoder/Emacs.kms
Emacs keys for Qt Creator
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE KeyboardMappingScheme>
<!-- Written by Qt Creator 4.2.1, 2017-03-27T21:24:06. -->
<mapping>
<shortcut id="CppTools.OpenHeaderSourceInNextSplit">
<key value="Ctrl+E, F4"/>
</shortcut>
<shortcut id="CppTools.SwitchHeaderSource">
<key value="F4"/>
</shortcut>
@hashibit
hashibit / left_ctrl & left_shift => spacebar
Last active December 31, 2021 06:45
cat ~/.config/karabiner/assets/complex_modifications/My.json
{
"title": "Change left ctrl/ left shift to spacebar",
"rules": [
{
"description": "Change left_ctrl to spacebar if pressed alone, to left_ctrl if pressed with other keys",
"manipulators": [
{
"from": {
"key_code": "left_control",
"modifiers": {
@hashibit
hashibit / .xvimrc
Created December 13, 2021 06:06
xvimrc
""""""""""""""""""""""""""""""
" XVim config
""""""""""""""""""""""""""""""
set blinkcursor
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
@hashibit
hashibit / spacebar => right_control
Created July 30, 2021 12:04
~/.config/karabiner/assets/complex_modifications/My.json
{
"title": "My e changes",
"rules":
[
{
"description": "spacebar -> right_control (spacebar if pressed alone)",
"manipulators":
[
{
"from":