Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Hoolihan thoolihan

View GitHub Profile
View clip.R
data <- -10:10
lims <- range(data)
x <- sample(data, 50, replace = TRUE)
par(mfrow=c(1, 5))
plot(x, ylim=lims, main="initial data")
# only positive
plot(pmax(x, 0), ylim=lims, main="clip bottom")
@thoolihan
thoolihan / ord.R
Created Oct 22, 2019
creating ordinal numbers
View ord.R
# casting as integer
int_cyl <- as.integer(mtcars$cyl)
int_cyl
# creating a factor
factor_cyl <- as.factor(mtcars$cyl)
factor_cyl
# flag columns / dummy variables
library(caret)
@thoolihan
thoolihan / two_sixes.R
Created Oct 22, 2019
Probability of getting exactly 2 6's out of 4 dice rolls
View two_sixes.R
library(tidyverse)
ROLLS <- 4
SIMS <- 10000
#calculate
ncombos <- choose(ROLLS,2)
two_sixes <- 1/6 * 1/6 * 5/6 * 5/6
print(sprintf("choose(4, 2) * 25/(6^4) = %f", ncombos * two_sixes))
@thoolihan
thoolihan / minecraft_server_info.py
Created Sep 30, 2019
A simple example using mcstatus to query a minecraft server
View minecraft_server_info.py
from mcstatus import MinecraftServer
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument("server", help="server name or ip", nargs='?', type=str, default="localhost")
parser.add_argument("port", help="server port", nargs='?', type=int, default=25565)
args = parser.parse_args()
print("Querying server host: {} port: {}".format(args.server, args.port))
@thoolihan
thoolihan / args.R
Last active Jul 19, 2019
Run `Rscript args.R` to see how R command line arguments work
View args.R
args <- commandArgs()
trailing_args <- commandArgs(trailingOnly = TRUE)
print(args)
writeLines("\n====Just Trailing====\n\n")
print(trailing_args)
@thoolihan
thoolihan / main.tf
Created Jun 27, 2019
Terraform ML machine
View main.tf
provider "aws" {
region = "us-east-1"
profile = "${var.aws_profile}"
shared_credentials_file = "~/.aws/credentials"
}
resource "aws_instance" "mlbox" {
ami = "ami-00ffbd996ef2211e3"
instance_type = "p2.xlarge"
key_name = "${var.keyname}"
@thoolihan
thoolihan / run_tb.sh
Created Jul 13, 2018
Run tensorboard
View run_tb.sh
tensorboard --logdir /tmp/myproject --host 0.0.0.0
@thoolihan
thoolihan / tensorboard_callback_example.py
Created Jul 13, 2018
Example of tensorboard callback
View tensorboard_callback_example.py
from shared.get_start_time get_start_time, get_curr_time
# the tensorboard log directory will be a unique subdirectory based on the start time fo the run
TBLOGDIR="/tmp/myproject/{}".format(get_start_time())
# ...your model code here...
history = model.fit(train_images,
train_images,
epochs=EPOCHS,
@thoolihan
thoolihan / get_start_time.py
Created Jul 13, 2018
python consistent start time
View get_start_time.py
from datetime import datetime
def get_curr_time():
return datetime.now().strftime("%Y.%m.%d.%H.%M.%S")
def get_start_time():
return _start_time if _start_time else get_curr_time()
_start_time = get_start_time()
@thoolihan
thoolihan / nba.R
Last active May 23, 2018
Graphing Sports Odds
View nba.R
library(ggplot2)
library(dplyr)
library(R.utils)
teams <- data.frame(team = c('warriors', 'rockets',
'cavaliers', 'celtics'),
odds_nw = c(5,9,8,20),
odds_w = c(9,4,1,1))
# raw probabilities sum to more than 1 because of house take