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 / 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.
@tos-kamiya
tos-kamiya / csv_to_latex.py
Created December 24, 2023 06:59
Convert CSV file to LaTeX table
#!/usr/bin/env python3
import argparse
import sys
import os
import pandas as pd
def csv_to_latex(input_file, output_file = None):
# Read csv file
@tos-kamiya
tos-kamiya / ai-howdoi
Last active September 2, 2024 15:22
howdoi command with leverage of Phind-CodeLlama
#!/usr/bin/env python3
# ref: https://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line#2813530
import io
import os
import subprocess
import sys
from pygments import highlight
@tos-kamiya
tos-kamiya / lang_ext_counter.py
Created November 19, 2023 16:14
A tool for aggregating file extensions and languages in a directory, compatible with the tokei project (https://github.com/XAMPPRocky/tokei).
# The languages.json is obtained from the tokei project
# Source: https://github.com/XAMPPRocky/tokei/blob/c8e4d0703252c87b1df45382b365c6bb00769dbe/languages.json
from typing import Dict, Counter as CounterType
from collections import Counter
import json
import os
import sys
@tos-kamiya
tos-kamiya / ipynb_to_md
Last active November 15, 2023 18:37
A tool to convert Jupyter Notebook (.ipynb) to Markdown (.md)
#!/usr/bin/env python3
# https://chat.openai.com/share/448d1592-749e-49f4-8e44-948b0207d075
def to_markdown(jypyter_notebook_json):
cells = jypyter_notebook_json["cells"]
for cell in cells:
ct = cell["cell_type"]
if ct == "markdown":
@tos-kamiya
tos-kamiya / trans_nllb.py
Created September 27, 2023 19:59
A command-line translator using Facebook's NLLB LLM (proof of concept)
# ref https://zenn.dev/syoyo/articles/9a159ee747835a
import sys
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
max_length = 512
# ref https://huggingface.co/facebook/nllb-200-distilled-1.3B
# The model was trained with input lengths not exceeding 512 tokens, therefore translating longer sequences might result in quality degradation.