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 / bayes_factor.cpp
Created December 28, 2015 16:44
[R] Bayes Factor from 2 x 2 contingency table
// [[Rcpp::plugins("cpp11")]]
#include <Rcpp.h>
using namespace Rcpp;
double bf(NumericVector v, int n) {
int h = sum(rbeta(n, 1 + v[0], 1 + v[1]) > rbeta(n, 1 + v[2], 1 + v[3]));
if (h == n) {
return R_PosInf;
} else {
@dceoy
dceoy / install_rundeck.sh
Last active February 3, 2017 06:11
[Ubuntu] Install Rundeck
#!/usr/bin/env bash
wget -q -O - https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
echo 'deb http://dl.bintray.com/rundeck/rundeck-deb /' | sudo tee -a /etc/apt/sources.list.d/rundeck.list
echo 'deb-src http://dl.bintray.com/rundeck/rundeck-deb /' | sudo tee -a /etc/apt/sources.list.d/rundeck.list
sudo apt-get -y update
sudo apt-get -y install rundeck
@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/
@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 / 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 / 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 / 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 / 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 / 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 / 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)