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 / 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 November 22, 2023 06:29
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.
@tos-kamiya
tos-kamiya / prog3.c
Created September 21, 2023 10:42
A Fizz Buzz program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char num_fig_buf[4096]; // the size must be > 3 * 1000
unsigned int keta(unsigned int i)
{
unsigned int k = 0;
while (1) {
@tos-kamiya
tos-kamiya / ChatGPT_20230918T123449936Z_Pythonnkf.md
Last active September 18, 2023 15:46
ChatGPTさんとやり取りしながら日常使いのスクリプトを制作する例

Python nkf ドロップインツール

You

Pyhtonでファイルの文字コードを変換するユーティリティであるnkfのドロップインリプレースメントとなるツールを作りたいと思います。

  • システムのデフォルトの文字コードを取得する
  • システムのデフォルトの改行文字を取得する
  • chardetにより文字コードを判定する
  • python-iconvにより文字コードを変換する
  • このとき、改行文字の変換も行う
@tos-kamiya
tos-kamiya / hyfi.py
Last active May 29, 2023 12:13
HyFi: A Hyphen Fixer for English text (CLI tool)
#!/usr/bin/env python3
import argparse
import re
import sys
from typing import Dict, Iterator, List, Optional, Set, Tuple
def load_words(file_path: str) -> Set[str]:
with open(file_path, 'r') as f:
@tos-kamiya
tos-kamiya / arxiv-papers.py
Last active March 15, 2023 13:56
クエリと本数を指定するとarXivから論文をとってきて要約を日本語で表示します
# 2023.03.15 fix: change spec of command-line arguments
# ref: https://github.com/zushi0516/arxiv_paper2slack/blob/main/paper_arxiv.py
# python3 -m pip install arxiv
import argparse
import re
import arxiv