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 / 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 ""
@tos-kamiya
tos-kamiya / trans
Last active September 4, 2024 04:21
A simple text translator script
#!/bin/bash
# Function to display help message
function show_help() {
echo "Usage: $0 <language_code> [-p] <text_file_or_text>"
echo
echo "Arguments:"
echo " <language_code> The target language code (e.g., 'en' for English, 'ja' for Japanese)."
echo " <text_file_or_text> The path to the text file to be translated, or the text itself if -p is used. Use '-' to read from stdin."
echo
@tos-kamiya
tos-kamiya / git-status-summary.py
Created June 2, 2024 22:13
VSCode like Git status viewer
#!/usr/bin/env python3
from typing import List, Iterable, Iterator, Tuple
import subprocess
import sys
def colorize(text: str, color: str) -> str:
"""
Colorize the text for terminal output.
@tos-kamiya
tos-kamiya / flexcomm.py
Last active March 25, 2024 19:21
flexcomm: flexible comm utility, handle three or more files with use-specified predicates.
import argparse
import ast
import sys
from typing import List, TextIO, Optional
def get_variables(expr: str) -> List[str]:
"""
Given an expression, return a sorted list of variable names used in the expression.