Skip to content

Instantly share code, notes, and snippets.

View dceoy's full-sized avatar
Lazy

Daichi Narushima dceoy

Lazy
View GitHub Profile
@dceoy
dceoy / aws_sts_assume_role.py
Last active July 19, 2024 15:53
[Python] Assume an AWS IAM role and make a session with the role
#!/usr/bin/env python
import logging
from typing import Optional
import boto3
from pydantic import BaseModel, model_validator
from typing_extensions import Self
@dceoy
dceoy / press_esc_repeatedly.py
Created May 22, 2023 06:49
[Python] Press a key using PyAutoGUI
#!/usr/bin/env python
import signal
import time
import pyautogui
def press_esc_repeatedly(waiting_sec=300, pressed_key='esc'):
signal.signal(signal.SIGINT, signal.SIG_DFL)
@dceoy
dceoy / extract_lowercase_regions_from_fasta.py
Last active May 19, 2020 17:28
[Python] Extract lowercase regions in a FASTA file and write them into a BED file
#!/usr/bin/env python
import argparse
import bz2
import gzip
import logging
import os
from pathlib import Path
from pprint import pformat
@dceoy
dceoy / read_fasta.py
Created July 10, 2019 04:31
[Python] Read a FASTA file using Biopython
#!/usr/bin/env python
import bz2
import gzip
from Bio import SeqIO
def read_fasta(path):
if path.endswith('.gz'):
@dceoy
dceoy / git_rewind_days.sh
Created June 3, 2019 18:32
[Shell] Rewind days at the latest commit of Git logs
#!/usr/bin/env bash
#
# Usage: ./git_rewind_days.sh <int>
set -eux
DAYS_TO_REWIND="${1}"
COMMIT_DATE=$(git log -1 | sed -ne 's/^Date: \+//p')
REWIDED_DATE=$(date -d "${COMMIT_DATE% *} - ${DAYS_TO_REWIND} days" | awk '{print $1" "$2" "$3" "$4" "$6}')" ${COMMIT_DATE##* }"
@dceoy
dceoy / install_rbenv.sh
Last active May 7, 2019 10:11
[Shell] Install the latest version of Ruby with rbenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/ruby/files/install_rbenv.sh
set -uex
RBENV_DIR="${HOME}/.rbenv"
RB_BUILD_DIR="${HOME}/.rbenv/plugins/ruby-build"
RBENV="${RBENV_DIR}/bin/rbenv"
[[ ${#} -ge 1 ]] && RB_MAJOR_VER="${1}" || RB_MAJOR_VER=2
@dceoy
dceoy / install_pyenv.sh
Last active May 7, 2019 10:12
[Shell] Install the latest version of Python with pyenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/python/files/install_pyenv.sh
set -uex
PYENV_DIR="${HOME}/.pyenv"
PYENV="${PYENV_DIR}/bin/pyenv"
[[ ${#} -ge 1 ]] && PY_MAJOR_VER="${1}" || PY_MAJOR_VER=3
@dceoy
dceoy / install_bio_stack.sh
Last active March 13, 2019 22:00
[Shell] Install BWA, Samtools, Bcftools, and Bedtools
#!/usr/bin/env bash
#
# Usage: ./install_bio_stack.sh <dest dir path>
set -uex
PREFIX_DIR=$(realpath "${1}")
BIN_DIR="${PREFIX_DIR}/bin"
SRC_DIR="${PREFIX_DIR}/src"
mkdir -p "${SRC_DIR}" "${BIN_DIR}"
@dceoy
dceoy / subprocess_line_generator.py
Last active December 4, 2018 14:25
[Python] Generate STDOUT lines from subprocess
#!/usr/bin/env python
import subprocess
def run_and_parse_subprocess(**popen_args):
with subprocess.Popen(**popen_args) as p:
for line in p.stdout:
yield line.decode('utf-8')
if p.poll() == 0:
@dceoy
dceoy / install_cudnn.sh
Created October 12, 2018 06:52
[CUDA] Configure CUDA
#!/usr/bin/env bash
#
# Usage: ./install_cudnn.sh <tar file>
set -ex
[[ -n "${1}" ]] \
&& tar -xzvf ${1} -C /tmp \
&& cp /tmp/cuda/include/cudnn.h /usr/local/cuda/include \
&& cp /tmp/cuda/lib64/libcudnn* /usr/local/cuda/lib64 \