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 / 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 \
@dceoy
dceoy / HotelligT2.py
Last active October 12, 2018 06:54
[Python] Hotelling's T-squared anomaly detection
#!/usr/bin/env python
import numpy as np
from scipy import stats
class HotellingsT2(object):
def __init__(self, alpha):
self.anomaly_score_threshold = stats.chi2.ppf(q=(1 - alpha), df=1)
@dceoy
dceoy / install_packages.R
Last active June 17, 2018 18:04
[R] Install R packages
#!/usr/bin/env Rscript
if(length(argv <- commandArgs(trailingOnly = TRUE)) > 0) {
install.packages(pkgs = argv,
repos = c(CRAN = 'https://cran.rstudio.com/'),
dependencies = TRUE)
} else {
message('Nothig to do.')
}
@dceoy
dceoy / disable_DS_Store.sh
Created May 9, 2018 13:01
[Shell] Disable .DS_Store in macOS
defaults write com.apple.desktopservices DSDontWriteNetworkStores True
@dceoy
dceoy / docker-compose.yml
Last active August 30, 2018 09:09
[Docker Compose] Run a Hugo server
---
version: '3'
services:
hugo:
container_name: hugo
image: dceoy/hugo:latest
user: ${UID}:${GID}
ports:
- 1313:1313
@dceoy
dceoy / download_pkg.sh
Created February 15, 2018 20:23
[Shell] Download Python and R packages
#!/usr/bin/env bash
#
# Usage:
# ./download_pkg.sh \
# --py-pkg ./py_requirements.txt \
# --r-pkg ./r_requirements.txt \
# --py-dir ./src/py \
# --r-dir ./src/r
#
# Options:
@dceoy
dceoy / read_vcf.py
Last active February 17, 2025 16:19
[Python] Read VCF (variant call format) as pandas.DataFrame
#!/usr/bin/env python
import io
import os
import pandas as pd
def read_vcf(path):
with open(path, 'r') as f:
lines = [l for l in f if not l.startswith('##')]
@dceoy
dceoy / pypi_upload.sh
Created May 15, 2017 15:55
[Linux] Upload a Python package to PyPI
python setup.py bdist_wheel
twine upload dist/*.whl
@dceoy
dceoy / install_vbox_guest_additions.sh
Last active June 3, 2018 17:48
[Linux] Install the latest version of VirtualBox Guest Additions
#!/usr/bin/env bash
#
# # Mount vboxsf
# $ sudo mount -t vboxsf vbox ~/synced
set -uex
v=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
curl http://download.virtualbox.org/virtualbox/${v}/VBoxGuestAdditions_${v}.iso -o /tmp/vbga.iso
sudo mount -t iso9660 /tmp/vbga.iso /mnt/