Skip to content

Instantly share code, notes, and snippets.

View tos-kamiya's full-sized avatar
:octocat:
one by one

Toshihiro Kamiya tos-kamiya

:octocat:
one by one
View GitHub Profile
@tos-kamiya
tos-kamiya / highlight256.py
Created June 10, 2025 17:21
256-color Pygments highlighter with automatic light/dark background
#!/usr/bin/env python3
import argparse
import sys
import shutil
from typing import Optional, Tuple, List, Any, Iterable, Type
from pygments import lex
from pygments.lexers import get_lexer_for_filename, TextLexer
from pygments.styles import get_style_by_name, get_all_styles
from pygments.token import Token
@tos-kamiya
tos-kamiya / bb_unar.py
Created May 17, 2025 20:10
A lightweight clone of unar for Windows: utilizes BusyBox to handle various archive formats, with optional support for 7-Zip and WinRAR if installed.
#!/usr/bin/env python3
import sys
import os
import subprocess
import zipfile
import shutil
import argparse
import time
def is_tool_available(tool_name):
@tos-kamiya
tos-kamiya / latest
Created April 24, 2025 18:25
Select files by modification time with slicing semantics.
#!/usr/bin/env python3
"""Select files by modification time with slicing semantics.
Usage:
latest.py [-n SLICE] [-q] <file>...
Examples:
# The single most recent file
latest.py ~/Pictures/*
@tos-kamiya
tos-kamiya / 300-fish-4.html
Created February 26, 2025 08:27
Fish-school simulation inspired by an X post: https://x.com/snakajima/status/1894382189720092770
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Fish School Simulation</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
@tos-kamiya
tos-kamiya / prettty
Last active January 19, 2025 19:08
A bash script to execute commands in a pseudo-TTY environment
#!/bin/bash
# prettty: pretend TTY
# A tool to execute commands in a pseudo-TTY environment
# Help options
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: prettty <command>"
echo "Pretend TTY: Run a command in a pseudo-TTY environment."
echo
@tos-kamiya
tos-kamiya / blockrunner.py
Created January 12, 2025 17:04
Processes a Markdown file to execute Python code blocks and append the execution results
import sys
import io
import traceback
import argparse
from typing import List, TextIO
def python_interpreter(code: str) -> str:
"""
Executes a given Python code string and captures the output, errors, and final state of variables.
@tos-kamiya
tos-kamiya / Ubuntu 24.04, VSCode, フォントをモノクロのアンチエリアスを設定する設定.md
Created September 23, 2024 12:21
Ubuntu 24.04, VSCode, フォントをモノクロのアンチエリアスを設定する設定

VSCodeでアンチエイリアスをRGBではなくモノクロに設定するためには、rgbaの設定をnoneに変更する必要があります。rgbaは通常、サブピクセルレンダリングの設定を制御し、rgbbgrなどで赤・緑・青のサブピクセルを使ったアンチエイリアスを行いますが、モノクロに設定したい場合は、それをnoneにします。

以下がその設定例です:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="font">
 
@tos-kamiya
tos-kamiya / json-rpc-test.py
Created September 22, 2024 06:36
json-rpc with flask backend test
"""
python3 -m venv venv; venv/bin/pip install wheel
venv/bin/pip install json-rpc
venv/bin/pip install flask
"""
from flask import Flask
from jsonrpc.backend.flask import api
@tos-kamiya
tos-kamiya / timeg
Created September 15, 2024 18:26
A script to monitor CPU/GPU RAM usage of a command on NVIDIA systems, with process search by keyword and JSON support.
#!/usr/bin/env python3
import argparse
import json
import os
import subprocess
import sys
import time
from typing import List, Tuple, Dict
@tos-kamiya
tos-kamiya / ollama-unload
Created September 14, 2024 16:04
A script to immediately free up VRAM used by ollama services.
#!/bin/bash
# The default ollama server address
OLLAMA_URL="http://localhost:11434"
# Help function
show_help() {
echo "Usage: $0 [OPTIONS] [URL]"
echo "Unload all loaded models in ollama."
echo ""