This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
author: "<a href=\"http://twitter.com/klmr\">@klmr</a>" | |
title: "Gun deaths and gun ownership in the USA" | |
date: 2015-06-19 | |
output: | |
html_document: | |
theme: readable | |
--- | |
```{r echo=FALSE} | |
library(dplyr, warn.conflicts = FALSE, quietly = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' (Re-)source parts of a file | |
#' | |
#' \code{rs} loads, parses and executes parts of a file as if entered into the R | |
#' console directly (but without implicit echoing). | |
#' | |
#' @param filename character string of the filename to read from. If missing, | |
#' use the last-read filename. | |
#' @param from first line to parse. | |
#' @param to last line to parse. | |
#' @return the value of the last evaluated expression in the source file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_password(): | |
import subprocess | |
import re | |
cmd = ['security', 'find-internet-password', '-gs', 'github.com'] | |
pwinfo = subprocess.Popen(cmd, stdout = subprocess.PIPE, | |
stderr = subprocess.PIPE) | |
pwline = pwinfo.stderr.read().strip() | |
return re.sub('password: "(.*)"', '\\1', pwline) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
box::use( | |
dplyr[...], | |
glue[glue], | |
grid, | |
ld = lubridate, | |
ragg[...], | |
rvest, | |
scales[label_date_short, label_percent], | |
tidyr[...], | |
./screen_size[...], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Command line tools don’t want to clutter their output with unnecessary noise. | |
library = function (...) | |
suppressMessages(base::library(...)) | |
#' The command line arguments | |
args = commandArgs(trailingOnly = TRUE) | |
#' The name of the script | |
#' | |
#' @note If the script was invoked interactively, this is the empty string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dummy object, only required for name resolution. | |
set = structure(list(), class = 'set') | |
print.set = function (x, ...) invisible(x) | |
`[.set` = function (set, expr, filter) { | |
expr = substitute(expr) | |
filter = substitute(filter) | |
stopifnot(identical(expr[[1]], quote(`<-`))) | |
stopifnot(identical(expr[[2]][[1]], quote(`|`))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto read_file(std::string_view path) -> std::string { | |
constexpr auto read_size = std::size_t{4096}; | |
auto stream = std::ifstream{path.data()}; | |
stream.exceptions(std::ios_base::badbit); | |
auto out = std::string{}; | |
auto buf = std::string(read_size, '\0'); | |
while (stream.read(& buf[0], read_size)) { | |
out.append(buf, 0, stream.gcount()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright 2008-2009 Konrad Rudolph | |
* All rights reserved. | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_cases_desc = R'( | |
Given the starting numbers 1,3,2, the 2020th number spoken is 1. | |
Given the starting numbers 2,1,3, the 2020th number spoken is 10. | |
Given the starting numbers 1,2,3, the 2020th number spoken is 27. | |
Given the starting numbers 2,3,1, the 2020th number spoken is 78. | |
Given the starting numbers 3,2,1, the 2020th number spoken is 438. | |
Given the starting numbers 3,1,2, the 2020th number spoken is 1836. | |
)' | |
`%>%` = magrittr::`%>%` |