Skip to content

Instantly share code, notes, and snippets.

View dholstius's full-sized avatar

David Holstius dholstius

  • Bay Area Air Quality Management District
  • San Francisco Bay Area
  • X @dholstius
View GitHub Profile
@dholstius
dholstius / cosm.R
Created July 24, 2012 17:18
#AirQualityEgg Chicago Meetup
# Uncomment these lines to get started
# install(devtools)
# require(devtools)
# install_github('cosm', 'holstius')
require(cosm)
key <- 'YoQHIdrFCPkYfYHfzEfWKM6RrjKSAKxCOHRRMWNiSmtsRT0g' # read-only, for meetup
feed <- 23706 # Chicago, IL (AirNow)
feed_detail(feed, key)
z <- feed_history(feed, key, duration='12hours')
@dholstius
dholstius / PollSerial.ino
Created September 18, 2012 17:22
Read from SoftwareSerial
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
@dholstius
dholstius / fast_POSIXct.R
Created September 20, 2012 19:43
Wrapper for fasttime::fast.POSIXct
#' fast_POSIXct
#'
#' Quickly converts local timestamps to a POSIXct vector
#'
#' @param x timestamps (YYYY-mm-dd HH:MM:SS)
#' @param tz local timezone
#' @return POSIXct vector
#' @export
fast_POSIXct <- function(x, tz) {
require(fasttime)
@dholstius
dholstius / fast_POSIXct.r
Created November 27, 2012 20:12
Quickly convert local timestamps to a POSIXct vector
#' fast_POSIXct
#'
#' Quickly convert local timestamps to a POSIXct vector
#'
#' @param x timestamps (YYYY-mm-dd HH:MM:SS)
#' @param tz local timezone
#' @return POSIXct vector
#' @export
fast_POSIXct <- function(x, tz) {
stopifnot(is.character(x))
@dholstius
dholstius / scale_x_hours.r
Created November 27, 2012 20:46
Helpful scales for use with ggplot2
require(ggplot2)
require(scales)
seq_range <- function(x, by) seq(min(x), max(x), by=by)
time_breaks <- function(width) {
function(limits) seq_range(limits, by=width)
}
scale_x_hours <- function(
@dholstius
dholstius / aggregate.data.table.r
Last active October 13, 2015 06:57
Fast rollup of rows from a data.frame (uses data.table for speed)
#' aggregate.data.table
#'
#' Use to quickly aggregate rows from a data.frame
#'
#' @param x data.table
#' @param by list of columns to use for grouping
#' @param FUN summary function
#' @param \dots further arguments to summary function
#' @param is.value determines which of the remaining columns should be aggregated (numeric, POSIXct, character, etc.)
#' @author David Holstius \email{david.holstius@berkeley.edu}
@dholstius
dholstius / format.r
Created November 27, 2012 21:12
Metric and significant-digit formatters for use with ggplot2
#' format_signif
#'
#' Format numbers with a given number of significant digits
#'
#' @param x numeric vector
#' @param digits number of significant digits
#' @return character vector
#' @examples
#' x <- c(0.800, 1704.1, 43.5e6, 10, NaN, NA, Inf, 0.00)
#' format_signif(x, digits=3)
@dholstius
dholstius / kml.R
Last active March 11, 2019 18:01
Reading and writing KML in R
read.kml <- function(file, layers) {
require(sp)
require(rgdal)
read.layer <- function (layer_name) {
spobj <- rgdal::readOGR(dsn=file, layer=layer_name)
coords <- coordinates(spobj)
colnames(coords) <- c('x', 'y', 'z')[1:ncol(coords)]
df <- data.frame(coords, spobj@data)
transform(df, layer=layer_name)
}
@dholstius
dholstius / core-site.xml
Last active December 26, 2015 13:59
Hadoop 1.2.1 on OS X Mavericks
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
@dholstius
dholstius / hbase-env.sh
Last active December 26, 2015 13:59
HBase 0.94.11 on OS X Mavericks
#
#/**
# * Copyright 2007 The Apache Software Foundation
# *
# * Licensed to the Apache Software Foundation (ASF) under one
# * or more contributor license agreements. See the NOTICE file
# * distributed with this work for additional information
# * regarding copyright ownership. The ASF licenses this file
# * to you under the Apache License, Version 2.0 (the
# * "License"); you may not use this file except in compliance