Skip to content

Instantly share code, notes, and snippets.

---
title: "Nobel genre tallies"
output:
html_document:
self_contained: false
...
```{r setup, include=F}
library(tidyverse)
library(rvest)
@agoldst
agoldst / contacts_query.sh
Last active November 28, 2023 01:15
Query macOS contacts for mutt
#!/bin/bash
#
# contacts_query.sh
# Andrew Goldstone, July 2017. All yours to use or modify, but no promises.
#
# The mutt e-mail client has an option to query an external address book for
# e-mail addresses. On a Mac it is nice to be able to query the Address Book
# (now known as Contacts). For a while I used a utility called contacts
# (http://gnufoo.org/contacts) but this stopped working under Sierra. There is
# an official API for querying Contacts as a unified datastore, but it is only
@agoldst
agoldst / enex.R
Last active August 6, 2017 10:09
Quick and dirty conversion of exported evernote notes to tagspaces-type files
# Please see the accompanying enex.md file for usage notes.
library(xml2)
library(stringr)
enex_tagspace <- function (enex, d, dry=T) {
node_title <- . %>% xml_find_all(".//title") %>% xml_text()
# Tagspaces delimits tags by spaces, so we have to eliminate spaces from
# tag names.
@agoldst
agoldst / mallet-inference.R
Last active November 12, 2023 07:23
Functions for using MALLET's topic-inference capability from R: given an existing topic model, estimate topic proportions for new documents
# mallet-inference.R
#
# functions for using MALLET's topic-inference functionality: given an
# existing topic model, estimate topic proportions for new documents
#
# source() this file
#
# Workflow
# --------
#
@agoldst
agoldst / dh2014-slides.R
Created July 11, 2014 12:24
R code used to produce the slides for this DH 2014 presentation: http://andrewgoldstone.com/blog/2014/07/02/dh2014/ . Generated by knitr::purl()
opts_chunk$set(echo=F,warning=F,prompt=F,comment="",
autodep=T,cache=T,dev="tikz",
fig.width=4.5,fig.height=3,size ='footnotesize',
dev.args=list(pointsize=12))
options(width=70)
options(tikzDefaultEngine="xetex")
options(tikzXelatexPackages=c(
"\\usepackage{tikz}\n",
@agoldst
agoldst / jekyll-pandoc.rb
Last active August 29, 2015 14:03
Jekyll 2 plugin for pandoc-ruby
require 'jekyll'
require 'pandoc-ruby' # add pandoc-ruby to your Gemfile
# Plugin for using pandoc as Jekyll markdown processor
# http://jekyllrb.com/docs/extras/ q.v.
# install in jekyll _plugins/ folder
# or Octopress plugins/
# In _config.yml, specify
# markdown: Pandoc # capital P
@agoldst
agoldst / laureates.R
Created May 19, 2014 16:02
Query the Nobelprize.org API to create a CSV table of all the literature laureates.
library("httr")
r_lits <- GET("http://api.nobelprize.org/v1/prize.json",query=list(category="literature"))
laureates <- content(r_lits,"parsed")$prizes # JSON
ids <- sapply(laureates,function (psn) {
psn$laureates[[1]]$id
})
@agoldst
agoldst / emp2-handout.md
Created November 24, 2013 00:20
Markdown source for a handout on markdown, HTML, and LaTeX, typesettable with pandoc + xelatex.

% DH@RU Workshop: Empowerment Part II % Andrew Goldstone ([email protected]) % November 20, 2013

Markdown

Text conventions

*emphasis* or _emphasis_; **strong emphasis**
@agoldst
agoldst / emp2.md
Last active October 26, 2024 07:37
Markdown etc. demo: source for a blogpost on…markdown.

Empowerment Part II

The actual "empowerment" (modest but real) comes in getting a more detailed understanding of the way the systems we already use handle text, and in learning more ways to manipulate that text, beyond the confines of any single program. The business of plain-text-slinging, a minor craft on its own, nonetheless forms a natural starting point for thinking more deeply about analyzing digitized texts, expressing yourself in "code" of various kinds, and composing in the digital medium.

Downloads

In order to do the workshop on your own, first install Pandoc and LaTeX (links above). Komodo Edit is optional; any text editor will do, though I'll occasionally refer to details in Komodo (menu items, etc.) that may be slightly different in other editors. See below for text editor suggestions.

The handout from the workshop (PDF)

# for this file, clone http://github.com/agoldst/dfr-analysis
source("~/Developer/dfr-analysis/metadata.R")
library(plyr)
library(stringr)
wordcounts_v <- function (f) {
frm <- scan(f,what=list(word=character(),weight=integer()),sep=",",skip=1,quiet=T)
result <- frm$weight
names(result) <- frm$word
result