Skip to content

Instantly share code, notes, and snippets.

View thoolihan's full-sized avatar

Tim Hoolihan thoolihan

View GitHub Profile
@thoolihan
thoolihan / path_check.bash
Created February 12, 2024 14:57
Check for duplicates in your $PATH variable
#!/usr/bin/env bash
RAW_PATH_TMP=`mktemp`
CLEAN_PATH_TMP=`mktemp`
echo $PATH | sed 's/:/\n/g' | sort > $RAW_PATH_TMP
cat $RAW_PATH_TMP | uniq > $CLEAN_PATH_TMP
declare -i LINES=$(( `diff $RAW_PATH_TMP $CLEAN_PATH_TMP | wc -l` / 2 ))
WITH cteRevenueDays(Orders, StoreDate, Revenue) AS (
SELECT COUNT(SalesOrderID) AS Orders
,CAST(OrderDate AS DATE) as [StoreDate]
,SUM(SubTotal) AS Revenue
FROM [AdventureWorks2019].[Sales].[SalesOrderHeader]
WHERE DATEPART(YEAR, CAST(OrderDate as DATE)) = 2011
AND DATEPART(MONTH, CAST(OrderDate as DATE)) = 7
GROUP BY CAST(OrderDate as DATE)
) SELECT
StoreDate
@thoolihan
thoolihan / clip.R
Last active October 10, 2020 14:33
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 October 22, 2019 16:12
creating ordinal numbers
# 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 October 22, 2019 15:28
Probability of getting exactly 2 6's out of 4 dice rolls
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 September 30, 2019 14:31
A simple example using mcstatus to query a minecraft server
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 July 19, 2019 13:57
Run `Rscript args.R` to see how R command line arguments work
args <- commandArgs()
trailing_args <- commandArgs(trailingOnly = TRUE)
print(args)
writeLines("\n====Just Trailing====\n\n")
print(trailing_args)
@thoolihan
thoolihan / main.tf
Created June 27, 2019 17:08
Terraform ML machine
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 July 13, 2018 15:42
Run tensorboard
tensorboard --logdir /tmp/myproject --host 0.0.0.0
@thoolihan
thoolihan / tensorboard_callback_example.py
Created July 13, 2018 15:34
Example of tensorboard callback
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,