Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Cook ianmcook

View GitHub Profile
@ianmcook
ianmcook / tx_la_weather_alerts.R
Created Aug 26, 2020
Map of active weather alerts for Texas and Louisiana
View tx_la_weather_alerts.R
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",
@ianmcook
ianmcook / nc_tornado_warnings_map.R
Created Feb 6, 2020
Create map of North Carolina tornado alert polygons and home location
View nc_tornado_warnings_map.R
install.packages(c("ggmap", "leaflet", "sp"))
devtools::install_github("ianmcook/weatherAlerts")
devtools::install_github("ianmcook/weatherAlertAreas")
# geocode home address
library(ggmap)
register_google("ENTER_GCP_GEOCODING_API_KEY_HERE")
home <- geocode("University of North Carolina at Chapel Hill")
# or specify coordinates of home
@ianmcook
ianmcook / nc_tornado_warnings.R
Last active Oct 31, 2019
Map of active tornado warnings for North Carolina
View nc_tornado_warnings.R
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 / one_chess_set.csv
Last active Oct 4, 2019
Scatterplot of chess piece dimensions with ggplot2
View one_chess_set.csv
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 / vented_box_equations.R
Created Feb 12, 2019
Vented box loudspeaker equations
View vented_box_equations.R
# 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 / closed_box_equations.R
Created Feb 12, 2019
Closed box loudspeaker equations
View closed_box_equations.R
# 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 / column_references_in_spark_dataframe_methods.py
Created Sep 14, 2018
Column references in Spark DataFrame methods
View column_references_in_spark_dataframe_methods.py
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 / hive-jdbc-example.R
Last active Sep 3, 2019
Query Apache Hive from R using JDBC
View hive-jdbc-example.R
# Copyright 2018 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@ianmcook
ianmcook / fl_weather_alerts.R
Last active Sep 10, 2017
Map of active weather alerts for Florida
View fl_weather_alerts.R
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 / hello_world.js
Created Aug 30, 2017
Hello World JavaScript
View hello_world.js
alert('Hello world!');
You can’t perform that action at this time.