Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Lincoln mdlincoln

View GitHub Profile
@mdlincoln
mdlincoln / rotate_labels.R
Created Oct 31, 2015
Add this snippet to rotate x-axis labels by 45º in ggplot2
View rotate_labels.R
theme(axis.text.x = element_text(angle = 45, hjust = 1))
View pick-your-poison.R
msg <- function(..., prob = 0.25) {
if (runif(1) > prob) {
return(invisible())
}
messages <- c(...)
message(sample(messages, 1))
}
encourage <- function() {
@mdlincoln
mdlincoln / replace_each.R
Last active Oct 2, 2015
Replace values in a vector based on a named vector dictionary
View replace_each.R
#' Replace all matching values
#'
#' @param v Vector whose values are to be replaced
#' @param pairs A named vector of replacements
#' @export
#' @examples
#' x <- c("a", "a", "b", "c")
#' p <- c("a" = "alpha", "b" = "beta")
#' replace_each(x, p)
replace_each <- function(v, pairs) {
@mdlincoln
mdlincoln / yday_months.R
Created Sep 30, 2015
ggplot2 scale that displays the months of the year for data that has only the day of the year as an integer
View yday_months.R
yday_months_x <- scale_x_discrete(breaks = cumsum(c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)), labels = month.name)
@mdlincoln
mdlincoln / downsample_pdf.sh
Created Sep 25, 2015
ghostscript command to downsample a pdf
View downsample_pdf.sh
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUT.pdf INPUT.pdf
@mdlincoln
mdlincoln / excel_utf8.sh
Created Sep 21, 2015
How to convert text files from OS X excel into UTF-8
View excel_utf8.sh
iconv -t UTF8 -f MACROMAN < file.csv > file-utf8.csv
View counts.csv
year nationality artists_strict
1550 Flemish 67
1550 Dutch 38
1551 Flemish 66
1551 Dutch 38
1552 Flemish 70
1552 Dutch 37
1553 Flemish 72
1553 Dutch 37
1554 Flemish 76
@mdlincoln
mdlincoln / rstudio-cc.yml
Last active Sep 18, 2021
cloud-config script to setup Rstudio server and Shiny server on Ubuntu 14.04 on Digital Ocean
View rstudio-cc.yml
#cloud-config
# In order to access RStudio server via the web interface, you must log on with
# a user account that allows password access. This script does not add that user
# by default. You may either ssh as root into the server and `adduser` as
# normal, or script a user addition here:
# users:
# - name: # username #
# lock-passwd: false # allow login with password
@mdlincoln
mdlincoln / rdf-json-csv.txt
Last active Aug 29, 2015
jq filter to turn RDF JSON into CSV
View rdf-json-csv.txt
.head.vars as $fields | ($fields | @csv), (.results.bindings[] | [.[$fields[]].value] | @csv)
@mdlincoln
mdlincoln / default
Last active Aug 29, 2015
rstudio on DO
View default
# Goes to /etc/nginx/sites-enabled/default
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL's in order to grasp a solid understanding