Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian A. Danielak briandk

View GitHub Profile
@briandk
briandk / usingSelectionAsAFunction.R
Created Jan 15, 2015
Using the bracket notation ("[") as a function in R
View usingSelectionAsAFunction.R
x = list("red",
"green",
"blue")
print(x)
# [[1]]
# [1] "red"
#
# [[2]]
# [1] "green"
#
@briandk
briandk / nodeAndTransdown.js
Created Feb 15, 2015
Use node and handlebars together
View nodeAndTransdown.js
// load modules
var Handlebars = require('handlebars');
var fs = require('fs');
var template = Handlebars.compile(
fs.readFileSync(
'transcriptTemplate.handlebars',
encoding='utf8'
)
)
@briandk
briandk / mutate-each.R
Last active Aug 29, 2015
Using mutate_each with functions that aren't window functions
View mutate-each.R
library(ggplot2)
library(magrittr)
glimpse(mpg) # note that `trans` and `drv`, for example, are factors
coerce_factors_to_characters <- function (x) {
return(
ifelse(
is.factor(x),
as.character(x),
@briandk
briandk / fantastical-2-mst-bug.md
Last active Aug 29, 2015
A possible bug in how fantastical 2 handles Mountain Standard Time
View fantastical-2-mst-bug.md

The Problem

Entering an event and specifying "MST" (Mountain Standard Time) as the time zone results in the event being recorded with "MDT" (Mountain Daylight Time instead. This results in the actual time of the event being one hour earlier than the user specified/intended.

Expected Behavior

Specifying that an event start at, say, noon MST will result in an event that starts at 12pm PDT.

Actual Behavior

@briandk
briandk / translationsExport.md
Last active Aug 29, 2015
JSON export issue with Translations
View translationsExport.md

How I understand the Translation field export

Here's an example of part of a value for Translations, in this case for the FCI:

"Translations": [{ "ar": ["Hisham A. Alhadlaq", 1 ] }

The general structure seems to be that Translations is an array of objects, where the scheme for each object is a key-value pair:

@briandk
briandk / mutate-each.R
Created May 21, 2015
Using dplyr's mutate_each to coerce a dataframe to character values
View mutate-each.R
mtcars %>% tbl_df() %>% mutate_each(funs(as.character))
# Source: local data frame [32 x 11]
#
# mpg cyl disp hp drat wt qsec vs am gear carb
# 1 21 6 160 110 3.9 2.62 16.46 0 1 4 4
# 2 21 6 160 110 3.9 2.875 17.02 0 1 4 4
# 3 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
# 4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
# 5 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
# 6 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
@briandk
briandk / dockerVMlog.log
Created Jun 25, 2015
A log of my docker Virtual machine which caused Kitematic to fail
View dockerVMlog.log
VirtualBox VM 4.3.28 r100309 darwin.amd64 (May 13 2015 17:42:22) release log
00:00:00.022690 Log opened 2015-06-25T00:59:03.746431000Z
00:00:00.022691 Build Type: release
00:00:00.022704 OS Product: Darwin
00:00:00.022709 OS Release: 14.3.0
00:00:00.022714 OS Version: Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64
00:00:00.022819 DMI Product Name: MacBookPro8,1
00:00:00.022875 DMI Product Version: 1.0
00:00:00.022892 Host RAM: 8192MB total, 1964MB available
00:00:00.022895 Executable: /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless
@briandk
briandk / horsepower-vs-displacement.R
Created Aug 24, 2015
An example plot of horsepower vs. displacement
View horsepower-vs-displacement.R
library(dplyr)
library(ggplot2)
car_performance_data <-
mtcars %>% select(hp, disp)
horsepower_vs_displacement <-
ggplot(
aes(
@briandk
briandk / r-squared-intuition.R
Created Sep 3, 2015
When a bunch of data generates a nicely-fit line with a nearly zero slope, R^2 approaches zero. Why? The line clearly fits well. We think the answer is because R^2 assesses the suitability of a slope-dependent term in the linear model. And a nearly-horizontal line doesn't need a slope-dependent term in its model.
View r-squared-intuition.R
library(ggplot2)
library(magrittr)
set.seed(1001)
time_spent_lecturing <- c(
0.09
, 0.14
, 0.21
, 0.76
@briandk
briandk / Vagrantfile
Last active Sep 22, 2015
Three Easy Steps to a Reproducible R Environment
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at