Skip to content

Instantly share code, notes, and snippets.

View mdlincoln's full-sized avatar

Matthew Lincoln mdlincoln

View GitHub Profile
@mdlincoln
mdlincoln / rdf-json-csv.txt
Last active August 29, 2015 14:22
jq filter to turn RDF JSON into CSV
.head.vars as $fields | ($fields | @csv), (.results.bindings[] | [.[$fields[]].value] | @csv)
@mdlincoln
mdlincoln / rstudio-cc.yml
Last active August 9, 2022 11:46
cloud-config script to setup Rstudio server and Shiny server on Ubuntu 14.04 on Digital Ocean
#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
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 / excel_utf8.sh
Created September 21, 2015 20:22
How to convert text files from OS X excel into UTF-8
iconv -t UTF8 -f MACROMAN < file.csv > file-utf8.csv
@mdlincoln
mdlincoln / downsample_pdf.sh
Created September 25, 2015 19:10
ghostscript command to downsample a pdf
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUT.pdf INPUT.pdf
@mdlincoln
mdlincoln / yday_months.R
Created September 30, 2015 14:21
ggplot2 scale that displays the months of the year for data that has only the day of the year as an integer
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 / replace_each.R
Last active October 2, 2015 19:48
Replace values in a vector based on a named vector dictionary
#' 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) {
msg <- function(..., prob = 0.25) {
if (runif(1) > prob) {
return(invisible())
}
messages <- c(...)
message(sample(messages, 1))
}
encourage <- function() {
@mdlincoln
mdlincoln / rotate_labels.R
Created October 31, 2015 19:15
Add this snippet to rotate x-axis labels by 45º in ggplot2
theme(axis.text.x = element_text(angle = 45, hjust = 1))
@mdlincoln
mdlincoln / mogrify.sh
Last active November 4, 2015 19:48
imageMagick convert any image to 300x300 DPI
convert image -density 300 -units pixelsperinch outimage