Skip to content

Instantly share code, notes, and snippets.

View kiyoon's full-sized avatar

Kiyoon Kim kiyoon

View GitHub Profile
@kiyoon
kiyoon / awesome-bash-defaults.md
Last active November 30, 2022 17:38
Awesome bash defaults for modern users. Locally install most of the programs.

Configure most of the things without root permission.

Neovim, tmux, Starship, zoxide, fzf, exa, bash vi mode, ...

Shows git stats, command runtime etc. in a nice way.

You can change directory with partial keyword you remember. It will remember the most frequent cd and find it.

@kiyoon
kiyoon / torchvision_models.py
Last active October 4, 2022 23:03
Since torchvision 0.13, models are a little bit difficult to import. This provides backward-compatible function to load models and choose weights. It is also backward-compatible with torchvision < 0.13.
"""
Author: Kiyoon Kim ([email protected])
Since torchvision 0.13 (PyTorch 1.12), the new `weights` parameter is introduced and the original `pretrained` parameter is now deprecated.
It supports more pretrained weights but it is more difficult to find the right one.
This script provides a backward compatible but supporting new version in ease, using strings.
"""
from __future__ import annotations
from typing import Callable, get_type_hints, get_args
from enum import Enum
from packaging import version
@kiyoon
kiyoon / text_to_excel_clipboard.py
Last active April 4, 2022 15:52
Copy list of numbers to clipboard so you can paste on Excel sheets.
#!/usr/bin/env python3
# Requirements
# pip3 install pandas
# sudo apt install xclip
import pandas as pd
import numpy as np
import argparse
@kiyoon
kiyoon / Python_gui_executable_conda.sh
Last active May 18, 2022 23:06
Create Python executable under conda environment
#!/bin/bash
# Make this script executable by
# chmod +x Python_gui_executable_conda.sh
# On Mac,
# go to properties of the file, choose open with, Terminal.app in Utilities folder.
# On Ubuntu you need to make another file.
# Follow the `ubuntu.desktop` script.
#!/bin/bash
# If you don't have conda installed, run these in advance.
#wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
#bash Miniconda3-latest-Linux-x86_64.sh
# Run the script using `source epic_viewer_setup.sh`.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
@kiyoon
kiyoon / start_ngrok_telegram_bot.sh
Created March 11, 2022 13:38 — forked from obokaman-com/start_ngrok_telegram_bot.sh
A bash script to start Ngrok in background, and send ngrok URL to a Telegram Bot automatically, copying the remote URL to clipboard
#!/usr/bin/env bash
# Start NGROK in background
echo "⚡️ Starting ngrok"
ngrok http 8080 > /dev/null &
# Wait for ngrok to be available
while ! nc -z localhost 4040; do
sleep 1/5 # wait Ngrok to be available
done
#!/bin/bash
# If you don't have conda installed, run these in advance.
#wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
#bash Miniconda3-latest-Linux-x86_64.sh
# Run the script using `source epic_viewer_setup.sh`.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
@kiyoon
kiyoon / camera_webcam.sh
Last active December 2, 2021 10:22
Canon Camera Webcam with Ubuntu
# https://community.usa.canon.com/t5/Camera-Software/When-available-Canon-EOS-Utility-for-Linux-Ubuntu/td-p/314449
# https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/
pkill -9 gvfs-gphoto2-volume-monitor
pkill -9 gvfsd-gphoto2
# CPU
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
# GPU
@kiyoon
kiyoon / save_stdouterr_print_err.sh
Created December 2, 2021 02:38
Bash: save both stdout and stderr separately, whilst printing stderr.
# https://stackoverflow.com/questions/9112979/pipe-stdout-and-stderr-to-two-different-processes-in-shell-script
# Executes the command, prints the errors, and save the stdout and stderr as separate files.
save_stdouterr_print_err () {
commandstr="$1"
stdoutpath="$2"
stderrpath="$3"
if [[ $# -lt 4 ]]
then
SSH_EVAL='eval'
else
@kiyoon
kiyoon / get_slurm_master_node.py
Created July 22, 2021 20:07
Get Slurm master node address from $SLURM_NODELIST
### get the first node name as master address
### e.g. master(aislab-[2-5],gnoded1) == aislab-2
import argparse
def get_parser():
parser = argparse.ArgumentParser(description="Extract master node name from Slurm node list",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("nodelist", help="Slurm nodelist")
return parser