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 / PPTP_client.sh
Last active August 29, 2015 14:00
[RHEL] Setup PPTP connection
sudo yum -y install ppp pptp pptp-setup
sudo pptpsetup --create "vpn" --server "vpn.example.jp" --username "vpnuser" --password "vpnpass" --encrypt
# configuration
# -> /etc/ppp/peers/vpn
# -> /etc/ppp/chap-secrets
# connection
sudo pppd call vpn updetach
@dceoy
dceoy / cran_pkg_load.R
Last active August 29, 2015 14:02
[R] Load packages
#!/usr/bin/env Rscript
load_pkgs <- function(pkgs, repos = 'http://cran.rstudio.com/') {
update.packages(checkBuilt = TRUE, ask = FALSE, repos = repos)
sapply(pkgs,
function(p) {
if (! p %in% installed.packages()[,1]) install.packages(p, dependencies = TRUE, repos = repos)
require(p, character.only = TRUE)
})
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accordion</title>
<meta name="author" content="d4i"/>
<style>
.accordion {
list-style: none;
}
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D3 Word Clouds</title>
<meta name="author" content="d4i"/>
</head>
<body>
<script src="https://rawgit.com/mbostock/d3/master/d3.min.js"></script>
<script src="https://rawgit.com/jasondavies/d3-cloud/master/d3.layout.cloud.js"></script>
#!/usr/bin/env Rscript
sapply(c('data.table', 'ggplot2'), function(p) require(p, character.only = TRUE))
mtx <- fread('matrix.csv')
heatmap <- ggplot(mtx, aes(x = col, y = row, fill = val)) +
geom_tile() +
scale_fill_gradient(trans = 'log', breaks = c(10, 100, 1000), low = 'grey', high = 'blue') +
labs(x = 'col', y = 'row')
#!/usr/bin/env Rscript
# Diabetes survey on Pima Indians
#
# variables:
# 'glucose' Plasma glucose concentration at 2 hours in an oral glucose tolerance test
# 'diabetes' Diabetes pedigree function
# 'test' test whether the patient shows signs of diabetes (coded 0 if negative, 1 if positive)
data(pima, package = 'faraway')
@dceoy
dceoy / mcmc_logit.R
Created June 4, 2015 00:28
[R] Logistic Regression using MCMCpack
#!/usr/bin/env Rscript
sapply(c('dplyr', 'data.table', 'MASS', 'MCMCpack'), function(p) require(p, character.only = TRUE))
# Biopsy Data on Breast Cancer Patients
#
# variables:
# 'V1' clump thickness.
# 'V4' marginal adhesion.
# 'class' "benign" or "malignant".
@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_vboxadd.sh
Last active August 2, 2016 16:46
[RHEL] Install virtualbox guest additions
#!/usr/bin/env bash
if [[ -f "/etc/lsb-release" ]]; then
apt-get --version
sudo apt-get -y update
sudo apt-get -y install gcc make
elif [[ -f "/etc/redhat-release" ]]; then
if `dnf --version`; then
sudo dnf -y update
sudo dnf -y install gcc make
@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