Skip to content

Instantly share code, notes, and snippets.

Avatar

Shawn Graham shawngraham

View GitHub Profile
View excel macro save row as text
' this script was posted at http://stackoverflow.com/questions/15554099/write-each-excel-row-to-new-txt-file-with-columna-as-file-name/15665756#15665756
'and is presented here for readers of the Historian's Macroscope
Sub SaveRowsAsTXT()
Dim wb As Excel.Workbook, wbNew As Excel.Workbook
Dim wsSource As Excel.Worksheet, wsTemp As Excel.Worksheet
Dim r As Long, c As Long
Dim filePath As String
Dim fileName As String
View R2MALLET.r
# Set working directory
dir <- "C:\\" # adjust to suit
setwd(dir)
# configure variables and filenames for MALLET
## here using MALLET's built-in example data and
## variables from http://programminghistorian.org/lessons/topic-modeling-and-mallet
# folder containing txt files for MALLET to work on
importdir <- "C:\\mallet-2.0.7\\sample-data\\web\\en"
View xls2txts.R
#' Making many text files from a single Excel file
#'
#' Convert a single Excel file (one text per row) into
#' separate text files. A function in R. Requires Java Runtime
#' Environment (JRE), version 6.0 or higher
#'
#' To use this function for the first time run:
#' install.packages("devtools")
#' then thereafter you just need to load the function
#' fom github like so:
View Readme.md

D3 Streamgraph Example

Series Hover

The series hover interactivity uses the technique from lgrammel seen here: http://bl.ocks.org/1963983

Data Tooltip

It isn't necessarily a tooltip, but data is displayed by inverting the x-axis value into a date, and mapping the date to the corresponding data value for the series.

@shawngraham
shawngraham / mimnowrapperexample
Last active Aug 29, 2015
Mimno's Mallet Wrapper- example
View mimnowrapperexample
#this is adapted from Ben Marwick's Day of Archaeology 2013 analysis
#this is for an example of using Mimno's wrapper for Mallet
#we're using the sample data that comes bundeled when you download MALLET from
#http://mallet.cs.umass.edu/download.php
#we've assumed that, on Mac, you've put MALLET that you unzipped from Umass into a folder
#under [user], ie "shawngraham/mallet-2.0.7"
#on windows, use the full path "C:>\\mallet-2.0.7\\"
#insert the path to your documents between the quotation marks
#and windows users be sure to use \\ instead of a single \
View xls2txts.R
#' Making many text files from a single Excel file
#'
#' Convert a single Excel file (one text per row) into
#' separate text files. A function in R. Requires Java Runtime
#' Environment (JRE), version 6.0 or higher
#'
#' To use this function for the first time run:
#' install.packages("devtools")
#' then thereafter you just need to load the function
#' fom github like so:
View grab-identifiers-dpla.R
install.packages("devtools")
devtools::install_github("ropensci/rdpla")
library('rdpla')
mykey = "PUT YOUR KEY FROM DP.LA HERE"
# do a query; here we want ids which we can feed to wget
itemlist = items(key=mykey, q="science", date_before=1900, page_size=100, fields=c("id"))
# this will write the ids to a list; you'll need to open it in a spreadsheet, remove the first row if it's not an id
write.csv(itemlist $data, "itemlist.csv", row.names=FALSE)
# save the csv to txt (utf 8), then you can pass to wget as in Exercise 4 at
# https://github.com/hist3907b-winter2015/module2-findingdata/blob/master/m2-exercises.md
@shawngraham
shawngraham / getting a History Machine
Last active Aug 29, 2015
setting up a history research machine. Follow the instructions.
View getting a History Machine
# By Ben Marwick, from: https://gist.github.com/benmarwick/11204658 with modifications by S. Graham
Short instructions to setup a Lubuntu Virtual Machine with
R & RStudio:
1. Download these:
http://lubuntu.net/ (Intel x86 desktop cd)
https://www.virtualbox.org/wiki/Downloads (Oracle VM VirtualBox)
2. Install Oracle VM VirtualBox, open it (if using windows,
View CND-topic-model.r
setwd("desktop/beals-new")
# give yourself as much memory as you've got
options(java.parameters = "-Xmx5120m")
library(rJava)
## from http://cran.r-project.org/web/packages/mallet/mallet.pdf
library(mallet)
#CND xml file transformed in browser into csv table. copy & paste into excel, saved as csv. Cut the column headers and paste them in the line below:
library(RCurl)
@shawngraham
shawngraham / archaeology-geolocatedtweets.geojson
Created Feb 17, 2015
twarc scrape of "archaeology", geolocated tweets
View archaeology-geolocatedtweets.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.