Skip to content

Instantly share code, notes, and snippets.

View ianmcook's full-sized avatar

Ian Cook ianmcook

View GitHub Profile
@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 / 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 / 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 / hive-jdbc-example.R
Last active April 26, 2021 05:51
Query Apache Hive from R using JDBC
# 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 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 / hello_world.js
Created August 30, 2017 17:58
Hello World JavaScript
alert('Hello world!');
@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 / 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