Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Lincoln mdlincoln

View GitHub Profile
@wcaleb
wcaleb / waybackup.py
Last active Dec 29, 2020
Quick script to save URL to Wayback Machine
View waybackup.py
#! /usr/bin/env python
import sys, requests
# Usage: Pass URL to script, get back URL to Wayback Machine snapshot
base_url = 'http://web.archive.org'
r = requests.get(base_url + '/save/' + sys.argv[1])
if r.status_code == requests.codes.ok:
@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 na.R
# let x be John's age (but I don't know what it is)
x <- NA
# let y be Mary's age (but I don't know what it is)
y <- NA
# are Mary and John the same age?
x == y
View SPARQL queries to obtain statistics.
# Obtain the label of a given class (:class1).
SELECT DISTINCT ?c (STR(?l) AS ?lb)
WHERE {
?c a :class1 ;
<http://www.w3.org/2000/01/rdf-schema#label> ?l .
}
# Obtain a list of classes.
SELECT DISTINCT ?c
WHERE {
View nice-xml.r
library(httr)
library(XML)
library(selectr)
xpath <- function(x) structure(x, class = "xpath")
sel <- function(x) xpath(css_to_xpath(x, prefix = "//"))
url <- "http://www.boxofficemojo.com/movies/?id=ateam.htm"
html <- content(GET(url), "parsed")
@jgm
jgm / letter.latex
Created Jan 12, 2014
pandoc letter template
View letter.latex
\documentclass[letter,$if(fontsize)$$fontsize$,$else$10pt,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{ucbletter}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{amssymb,amsmath}
\linespread{$if(linespread)$$linespread$$else$1.1$endif$}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
@hrbrmstr
hrbrmstr / notify.R
Last active Nov 28, 2018
Send OS X notifications from R (RStudio, R GUI or R console)
View notify.R
notify <- function(msg="Operation complete") {
in.osx <- (Sys.info()['sysname'] == "Darwin")
in.rstudio <- (Sys.getenv("RSTUDIO") == "1")
in.rgui <- (Sys.getenv("R_GUI_APP_REVISION") != "")
if (in.rstudio) { # hack to see if running in RStudio
title <- "RStudio"
sender <- activate <- "org.rstudio.RStudio"
}
@Thell
Thell / Exmple.Rmd
Created Jun 20, 2013
R markdown to illustrate creation of in-document referencing for chunks, sections, pages, and such.
View Exmple.Rmd
```{r setup, echo=FALSE, results='hide'}
chunkref <- local({
function(chunklabel) {
sprintf('[%s](#%s)', chunklabel, chunklabel )
}
})
secref <- local({
function(seclabel) {
sprintf('[%s](#%s)', seclabel, seclabel )
@jcheng5
jcheng5 / server.R
Last active Jun 17, 2021
Shiny example: Diamonds Explorer
View server.R
library(shiny)
library(ggplot2)
function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({