Skip to content

Instantly share code, notes, and snippets.

View briandk's full-sized avatar

Brian A. Danielak briandk

View GitHub Profile
@briandk
briandk / addingEventListeners.html
Created November 16, 2016 21:02
Event Listeners in Vanilla JS
<span id='foo'>Doctor Strange</span>
<script>
const bar = function () { return('hooray!'); };
// what's the difference between onclick and .addEventListener?
bar.onclick = foo;
bar.addEventListener('click', foo);
</script>
@briandk
briandk / babys-first-functions.py
Created November 2, 2016 21:42 — forked from anonymous/babys-first-functions.py
Maybe we don't need object-oriented programming (OOP) in a first-semester computational modeling course
# Here's a dictionary literal with data and behavior in one line of code
baby1 = {
"first_function": lambda x: x + 1,
"first_words": "Zoiby want to buy on margin"
}
# Here's a much more complicated OOP solution in 5 lines
class Baby:
def __init__(self, first_function, first_words):
"""
@briandk
briandk / pirates.txt
Created October 28, 2016 06:34
Raw text of _Pirates of the Caribbean: Dead Man's Chest_ from the `webtext` corpus of [`nltk`](http://www.nltk.org)
PIRATES OF THE CARRIBEAN: DEAD MAN'S CHEST, by Ted Elliott & Terry Rossio
[view looking straight down at rolling swells, sound of wind and thunder, then a low heartbeat]
Scene: PORT ROYAL
[teacups on a table in the rain]
[sheet music on music stands in the rain]
[bouquet of white orchids, Elizabeth sitting in the rain holding the bouquet]
[men rowing, men on horseback, to the sound of thunder]
[EITC logo on flag blowing in the wind]
[many rowboats are entering the harbor]
[Elizabeth sitting alone, at a distance]
@briandk
briandk / EnsurePackage.R
Last active October 17, 2016 18:07
Defensive Package Loading from _Introduction to Data Science version 3_ by Jeffrey Stanton
EnsurePackage <- function(x) {
x <- as.character(x)
# the code below can probably be vectorized with apply or a for-in
if (!require(x, character.only=TRUE)) {
install.packages(pkgs=x,​

repos="http://cran.r-project.org")
require(x, character.only=TRUE)
}
}
@briandk
briandk / install-my-fork-of-latexer.md
Last active October 11, 2016 21:39
Downloading and installing my fork of the wonderful LaTeXer package for Github Atom; my fork has pandoc autocompletion support!
$ git clone https://github.com/briandk/latexer.git

To install my package in development mode[^1] in Github Atom,

$ cd latexer && \
                                                         \
 # checkout my feature branch \
@briandk
briandk / flint-water-day-1.ipynb
Created September 28, 2016 18:40
Flint Water Quality Data Day 1 Exercise
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@briandk
briandk / flint-water-day-2.ipynb
Created September 28, 2016 18:39
Day 2 of our Flint Water Quality Data Exercise
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@briandk
briandk / MAKEFILE
Created September 26, 2016 18:35
A standard template makefile for writing manuscripts in RMarkdown
current_directory = $(shell pwd)
manuscript_file = "toce-manuscript.Rmd"
manuscript:
docker run \
--rm \
-v $(current_directory):/manuscript \
manuscribble \
-e 'rmarkdown::render($(manuscript_file), output_format="all")'
@briandk
briandk / Disco-tournament-team-name-candidates.md
Last active September 17, 2016 16:12
Possible names for our disco tournament team

Possible Names for our Disco Tournament Team

  • Toland's Heroes;
  • Cayde's Stash;
  • Oops, I 'naded again;
  • Zavala's Heartbreakers;
  • Iron Banana;
  • Cryptarch Rahool for Sanitation Commisioner;
  • The Ikora Haze;
  • Cleveland, the City the Traveler Forgot;
@briandk
briandk / defensively_install_packages.R
Last active September 16, 2016 04:44
Defensive package loading in R, inspired by @WilDoane. Install any packages not currently in the system, then use sapply to load them all. Because `library()` isn't vectorised :-(
# defensive package loading in pure R
# inspired by @wildoane
install_packages_if_necessary <- function (dependencies) {
packages_to_install <- setdiff(dependencies, installed.packages())
for (package in packages_to_install) {
install.packages(package, dependencies = TRUE)
}
}