Skip to content

Instantly share code, notes, and snippets.

View ianmcook's full-sized avatar

Ian Cook ianmcook

View GitHub Profile
@ianmcook
ianmcook / sunrise-sunset-2017-RDU.R
Last active March 5, 2017 16:19
Ribbon plot of 2017 daily sunrise and sunset at RDU airport
# load packages
library(maptools)
library(lubridate)
library(ggplot2)
# vector of all the days in 2017
days <- seq(from = as.POSIXct("2017-01-01"), to = as.POSIXct("2017-12-31"), by = "days")
# coordinates of RDU airport
lon <- -78.788
@ianmcook
ianmcook / hello_world.js
Created August 30, 2017 17:58
Hello World JavaScript
alert('Hello world!');
@ianmcook
ianmcook / fl_weather_alerts.R
Last active September 10, 2017 17:04
Map of active weather alerts for Florida
devtools::install_github("ianmcook/weatherAlerts")
devtools::install_github("ianmcook/weatherAlertAreas")
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts("FL") # takes about 30 seconds
severity <- alerts@data$severity
colorMap <- c(Minor = "green",
@ianmcook
ianmcook / tx_weather_alerts.R
Last active October 15, 2017 05:32
Map of active weather alerts for Texas
devtools::install_github("ianmcook/weatherAlerts")
devtools::install_github("ianmcook/weatherAlertAreas")
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts("TX") # takes about 20 seconds
severity <- alerts@data$severity
colorMap <- c(Minor = "green",
@ianmcook
ianmcook / column_references_in_spark_dataframe_methods.py
Created September 14, 2018 20:05
Column references in Spark DataFrame methods
from pyspark.sql import SparkSession
from pyspark.sql.types import StructType, StructField, IntegerType, StringType, FloatType
from pyspark.sql.functions import col, round
spark = SparkSession.builder.master('local').getOrCreate()
games = spark.createDataFrame(
[
(1, 'Monopoly', 'Elizabeth Magie', 1903, 8, 2, 6, 19.99),
(2, 'Scrabble', 'Alfred Mosher Butts', 1938, 8, 2, 4, 17.99),
@ianmcook
ianmcook / closed_box_equations.R
Created February 12, 2019 15:35
Closed box loudspeaker equations
# closed box loudspeaker equations
Qtc <- 0.707 # you choose this; see LDC p.24
Qts <- 0.40 # property of driver
fs <- 19 # property of driver
Vas <- 260 # property of driver
alpha <- (Qtc/Qts) ^ 2 - 1
fc <- (Qtc * fs) / Qts
@ianmcook
ianmcook / vented_box_equations.R
Created February 12, 2019 15:36
Vented box loudspeaker equations
# vented box loudspeaker equations
Qts <- 0.40 # property of driver
fs <- 19 # property of driver
Vas <- 260 # property of driver
# you choose an alignment,
# choose a QL (assume 7 for starters),
# then look up the following values
# in the appropriate table on LDC p.58-62:
@ianmcook
ianmcook / one_chess_set.csv
Last active October 4, 2019 21:53
Scatterplot of chess piece dimensions with ggplot2
piece base_diameter height weight
King 37.3086 95.1557 50.2774
King 36.9878 95.3598 51.5528
King 37.6846 94.8507 50.7298
King 37.4201 96.2158 50.9344
King 36.7413 95.5326 51.9347
King 36.8166 96.0273 51.2393
King 37.5822 95.8491 50.8103
King 37.4132 95.2667 52.2267
King 37.7643 94.9941 51.2417
@ianmcook
ianmcook / nc_tornado_warnings.R
Last active October 31, 2019 23:57
Map of active tornado warnings for North Carolina
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts("NC") # takes a few seconds
alerts <- alerts[alerts$event == "Tornado Warning",]
leaflet() %>%
addTiles() %>%
addPolygons(data = alerts, color = "black", fillColor = "magenta", weight = 1)
@ianmcook
ianmcook / tx_la_weather_alerts.R
Created August 26, 2020 15:17
Map of active weather alerts for Texas and Louisiana
remotes::install_github("ianmcook/weatherAlerts")
remotes::install_github("ianmcook/weatherAlertAreas")
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts(c("TX", "LA")) # takes about 45 seconds
severity <- alerts@data$severity
colorMap <- c(Minor = "green",