Skip to content

Instantly share code, notes, and snippets.

View mdlincoln's full-sized avatar

Matthew Lincoln mdlincoln

View GitHub Profile
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")
@hadley
hadley / na.R
Last active August 29, 2015 14:26
# 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
@Thell
Thell / Exmple.Rmd
Created June 20, 2013 23:59
R markdown to illustrate creation of in-document referencing for chunks, sections, pages, and such.
```{r setup, echo=FALSE, results='hide'}
chunkref <- local({
function(chunklabel) {
sprintf('[%s](#%s)', chunklabel, chunklabel )
}
})
secref <- local({
function(seclabel) {
sprintf('[%s](#%s)', seclabel, seclabel )
@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
@jgm
jgm / letter.latex
Created January 12, 2014 18:06
pandoc letter template
\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
@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
@wcaleb
wcaleb / waybackup.py
Last active December 29, 2020 06:55
Quick script to save URL to Wayback Machine
#! /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:
@jcheng5
jcheng5 / server.R
Last active June 17, 2021 18:37
Shiny example: Diamonds Explorer
library(shiny)
library(ggplot2)
function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
@hrbrmstr
hrbrmstr / notify.R
Last active May 27, 2022 15:27
Send OS X notifications from R (RStudio, R GUI or R console)
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"
}
@olivierlacan
olivierlacan / launch_sublime_from_terminal.markdown
Created September 5, 2011 15:50
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation