Skip to content

Instantly share code, notes, and snippets.

Avatar

David Holstius dholstius

  • Bay Area Air Quality Management District
  • San Francisco Bay Area
  • Twitter @dholstius
View GitHub Profile
@dholstius
dholstius / cosm.R
Created Jul 24, 2012
#AirQualityEgg Chicago Meetup
View cosm.R
# 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 Sep 18, 2012
Read from SoftwareSerial
View PollSerial.ino
#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 Sep 20, 2012
Wrapper for fasttime::fast.POSIXct
View fast_POSIXct.R
#' 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 Nov 27, 2012
Quickly convert local timestamps to a POSIXct vector
View fast_POSIXct.r
#' 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 Nov 27, 2012
Helpful scales for use with ggplot2
View scale_x_hours.r
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 Oct 13, 2015
Fast rollup of rows from a data.frame (uses data.table for speed)
View aggregate.data.table.r
#' 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 Nov 27, 2012
Metric and significant-digit formatters for use with ggplot2
View format.r
#' 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 Mar 11, 2019
Reading and writing KML in R
View kml.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 Dec 26, 2015
Hadoop 1.2.1 on OS X Mavericks
View core-site.xml
<?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 Dec 26, 2015
HBase 0.94.11 on OS X Mavericks
View hbase-env.sh
#
#/**
# * 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