Skip to content

Instantly share code, notes, and snippets.

View CerebralMastication's full-sized avatar
☠️
brilliantly executing terrible plans

JD Long CerebralMastication

☠️
brilliantly executing terrible plans
View GitHub Profile
#! /usr/bin/env Rscript
#start an instance
startup <- system("ec2-run-instances ami-b232d0db -k ec2ApiTools", intern=T)
Sys.sleep(45) #rather random but 45 seconds is typically long enough to boot
#query running instances
instances <- system("ec2-describe-instances", intern=T)
instancesParsed <- sapply(instances, strsplit, "\t")
set.seed(2)
x <- 1:100
y <- 20 + 3 * x
e <- rnorm(100, 0, 60)
y <- 20 + 3 * x + e
plot(x,y)
yx.lm <- lm(y ~ x)
lines(x, predict(yx.lm), col="red")
<?xml version="1.0" encoding="UTF-8"?>
<medals xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.sportradar.com/sportsapi/v1/winterolympics" generated_at="2017-12-03T12:23:38+01:00" xsi:schemaLocation="http://schemas.sportradar.com/sportsapi/v1/winterolympics http://schemas.sportradar.com/bsa/winterolympics/v1/xml/endpoints/winterolympics/medals.xsd">
<medals_by_country>
<medal_info country="Slovenia" country_code="SLO" ioc_code="SLO" total_ranking="1" gold_ranking="1" total="24" gold="14" silver="3" bronze="7"/>
<medal_info country="Canada" country_code="CAN" ioc_code="CAN" total_ranking="2" gold_ranking="1" total="17" gold="9" silver="5" bronze="3"/>
<medal_info country="Germany" country_code="GER" ioc_code="GER" total_ranking="3" gold_ranking="1" total="19" gold="8" silver="6" bronze="5"/>
<medal_info country="USA" country_code="USA" ioc_code="USA" total_ranking="4" gold_ranking="1" total="17" gold="5" silver="8" bronze="4"/>
<medal_info country="Russia" coun
# multivariate normal example using Cholesky decomposition
require(Matrix)
#make this reproducible
set.seed(2)
#how many draws in our starting data set?
n <- 1e4
@CerebralMastication
CerebralMastication / pivot.R
Created April 1, 2011 14:24
Joshua Ulrich's pivot() function for R
## Joshua Ulrich's pivot function
## This code is alpha and is in development.
## please test all results to ensure accuracy
pivot <- function(x, rows, cols, FUN=NULL) {
clean <- function(xx, dd) {
cd <- merge(dd,xx,by=0,all=TRUE)
rownames(cd) <- cd$Row.names
cd$Row.names <- NULL
return(cd)
@CerebralMastication
CerebralMastication / convert to normal.R
Created January 25, 2011 13:09
example of converting a non-normal dist to normal
## make some non norm data
d1 <- rnorm(20, 5, 1)
d2 <- rnorm(5, 10, 2)
d <- c(d1,d2)
hist(d)
## no mean adjustment
myUniform <- ecdf( d )( d )
mean( myUniform )
## hey that mean's not .5!
@CerebralMastication
CerebralMastication / Python_R_together.Rmd
Created March 28, 2018 09:12
RMarkdown Example using Python and R together
---
title: "Markdown Y'All"
author: "James Long"
date: "March 27, 2018"
output:
html_document: default
pdf_document: default
word_document: default
---
#draw.circle is from the plotrix library
require(plyr)
draw.circle <- function (x, y, radius, nv = 100, border = NULL, col = NA, lty = 1,
lwd = 1)
{
xylim <- par("usr")
plotdim <- par("pin")
ymult <- (xylim[4] - xylim[3])/(xylim[2] - xylim[1]) * plotdim[1]/plotdim[2]
angle.inc <- 2 * pi/nv
query <- "SELECT uid,
timestamp,
sensor_1
FROM database_name.long_table_name_here
WHERE ( ( uid = 'abxyz1230'
AND filter_id = '1'
AND timestamp >= '2018-07-23'
AND timestamp <= '2018-08-02' )
OR ( uid = 'abxyz1236'
AND filter_id = '1'
@CerebralMastication
CerebralMastication / cluster_multi_future.R
Created August 16, 2018 13:15
cluster and multiprocess with future and analogsea
library(analogsea)
library(tidyverse)
library(furrr)
cluster_tag <- 'r_cluster'
cluster_prefix <- 'node-'
number_of_nodes <- 2
# Path to private SSH key that matches key uploaded to DigitalOcean
# it looks like ~ does not work here... not sure why
ssh_private_key_file <- "/Users/jal/.ssh/id_rsa"