Skip to content

Instantly share code, notes, and snippets.

Avatar
☠️
In a world of hurt

JD Long CerebralMastication

☠️
In a world of hurt
View GitHub Profile
View example_query.R
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 Aug 16, 2018
cluster and multiprocess with future and analogsea
View cluster_multi_future.R
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"
@CerebralMastication
CerebralMastication / do_furr.R
Last active Aug 11, 2018
Digital Ocean and furrr
View do_furr.R
# 1. set up digital ocean account
# 2. configure ssh keys, upload public key to DO
# 3. get API key
# 4. set Sys.setenv(DO_PAT = "API_KEY_GOES_HERE") in ~/.Rprofile
#devtools::install_github("sckott/analogsea")
library(analogsea)
library(tidyverse)
View web_example.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 1 column, instead of 3. in line 2.
# 2018 Barkley Marathons lap 1 finish time
# source: http://www.mattmahoney.net/barkley/
Name,Location,Time
Gary Robbins,CAN,8:38:08
Allie Beaven,SCO,8:38:09
Guillaume Calmettes,CA,8:38:10
Jamil Coury,AZ,8:58:55
Benoit Laval,FRA,9:07:15
Valery Caussarieu,FRA,9:07:20
Jodi Isenor,CAN,9:23:31
@CerebralMastication
CerebralMastication / Python_R_together.Rmd
Created Mar 28, 2018
RMarkdown Example using Python and R together
View Python_R_together.Rmd
---
title: "Markdown Y'All"
author: "James Long"
date: "March 27, 2018"
output:
html_document: default
pdf_document: default
word_document: default
---
@CerebralMastication
CerebralMastication / r_commented_example.r
Created Feb 14, 2018
r example using random numbers
View r_commented_example.r
require(tictoc)
tic()
# create a 250 col x 80000 row matrix of random uniform (0,1) numbers
random_numbers <- matrix( runif(250 * 80000), ncol=250)
#square root of the random numbers
sqrt_random_numbers <- sqrt(random_numbers)
View no_ns.json
<?xml version="1.0" encoding="UTF-8"?>
<medals>
<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" country_code="RUS" ioc_code="RUS" total_ranking="5" gold_ranking="1" total="19" gold="5" silver="7" bronze="7"/>
<medal_info country="Ireland" country_code="IRL" ioc_code="IRL" total_ranking="6" gold_ranking="1" total="20" gold="5" silver="6" bronze="9"/>
<medal_info country="Japan" country_code="JPN" ioc_code="JPN" total_rank
View example.json
<?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
View example.csv
header1 header2
1 2
3 4
5 6
View r tag stackoverflow.r
# query run here: https://data.stackexchange.com/stackoverflow/query/edit/543286
#
# select
# TagName,
# str(DATEPART(yyyy, p.CreationDate )) + '-' + str(DATEPART(mm, p.CreationDate )) as postmonth,
# count(pt.PostId) as Num
# from