Skip to content

Instantly share code, notes, and snippets.

View nqbao's full-sized avatar
Make Stuff Works

Bao Nguyen nqbao

Make Stuff Works
View GitHub Profile
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y docker.io
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
@nqbao
nqbao / install_mesos.sh
Last active February 27, 2017 06:09
install_mesos.sh
#!/bin/bash
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
CODENAME=$(lsb_release -cs)
echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \
sudo tee /etc/apt/sources.list.d/mesosphere.list
sudo apt-get update
sudo apt-get install -y mesos
@nqbao
nqbao / gist:15cec9836de80d20c60ef9b737be0dd8
Created August 26, 2016 07:33
remove untagged docker images
sudo docker rmi `sudo docker images --format "{{.ID}},{{.Tag}}" | grep "<none>" | awk -F',' '{print $1}'`
@nqbao
nqbao / latlong2fips.r
Created June 29, 2016 09:43 — forked from ramhiser/latlong2fips.r
Latitude/Longitude to FIPS Codes via the FCC's API
# FCC's Census Block Conversions API
# http://www.fcc.gov/developers/census-block-conversions-api
latlong2fips <- function(latitude, longitude) {
url <- "http://data.fcc.gov/api/block/find?format=json&latitude=%f&longitude=%f"
url <- sprintf(url, latitude, longitude)
json <- RCurl::getURL(url)
json <- RJSONIO::fromJSON(json)
as.character(json$County['FIPS'])
}
library("nnet")
splitdf <- function(dataframe, ratio=0.8, seed=NULL) {
if (!is.null(seed)) set.seed(seed)
index <- 1:nrow(dataframe)
trainindex = sample(1:nrow(dataframe), size=ratio*nrow(dataframe))
trainset <- dataframe[trainindex, ]
testset <- dataframe[-trainindex, ]
list(train=trainset,test=testset)
}
# An example of using decision tree to classify iris data
library("party")
splitdf <- function(dataframe, ratio=0.8, seed=NULL) {
if (!is.null(seed)) set.seed(seed)
index <- 1:nrow(dataframe)
trainindex = sample(1:nrow(dataframe), size=ratio*nrow(dataframe))
trainset <- dataframe[trainindex, ]
testset <- dataframe[-trainindex, ]
# Visualize iris data using T-SNE
library(ggplot2)
library(tsne)
r = tsne(iris[, 2:4])
r2 = as.data.frame(r)
names(r2) = c('x', 'y')
r2 = cbind(r2, class=iris$Species)
ggplot(r2) + geom_point(aes(x, y, color=class))
# pricing prediction with linear regression
# we use linear regressions to predict the price of house
# then use RMSE to evaluate the model
library(arimo)
housing_ddf = arimo.getDDF('housing')
housing = head(ddf, nrow(ddf))
splitdf <- function(dataframe, ratio=0.8, seed=NULL) {
# pricing prediction with kmeans
# hypothesis: lotsize, bedrooms, bathrms, stories affects price
# we use kmeans to cluster into N clusters and use mean price
# of that's cluster as a prediction method
library(ggplot2)
library(plyr)
library(arimo)
ddf = arimo.getDDF('housing')
library(ggplot2)
irisCluster = kmeans(iris[,1:3], nlevels(iris$Species), nstart=20)
iris$cluster = irisCluster$cluster
# build contingency table
t = table(iris$Species, iris$cluster)
ggplot(data=iris) + geom_point(aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(aes(Sepal.Length, Sepal.Width), data=as.data.frame(irisCluster$centers), size=5)