This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from sklearn.base import BaseEstimator, TransformerMixin | |
# Adapted from https://www.kaggle.com/ogrellier/python-target-encoding-for-categorical-features | |
class TargetEncoder(BaseEstimator, TransformerMixin): | |
def __init__(self, columns, noise_level = 0): | |
self.columns = columns | |
self.maps = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include "math.h" | |
using namespace std; | |
float pmf(int k, double lambda) { | |
// https://en.wikipedia.org/wiki/Poisson_distribution#Definition | |
return pow(M_E, k * log(lambda) - lambda - lgamma(k + 1.0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
rubies = `rvm list`.split(/\s+/).find_all{|s| s.include? "ruby"} | |
def fetch_for(rvm_spec) | |
system "rvm use #{rvm_spec}" | |
system "gem install rcodetools" | |
end | |
def valid_gemset?(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
args <- commandArgs() | |
trailing_args <- commandArgs(trailingOnly = TRUE) | |
print(args) | |
writeLines("\n====Just Trailing====\n\n") | |
print(trailing_args) |
NewerOlder