Skip to content

Instantly share code, notes, and snippets.

@dominiccooney
Last active September 4, 2015 00:14
Show Gist options
  • Save dominiccooney/233296 to your computer and use it in GitHub Desktop.
Save dominiccooney/233296 to your computer and use it in GitHub Desktop.
Tool Tips

diff

To diff directories recursively: diff -rupN -x .svn old-dir new-dir > my.patch
To patch: patch -p1 < my.patch

Emacs

To type a linefeed in emacs (for example, in replace-string): C-q C-j

R

To convert CSV data with values in columns (say, labeled T1, T2, … Tn) to values in rows:

data <- read.csv('page-load-times.csv')
library('reshape')
data.m <- melt(data, id=c('Site', 'Browser'), measure=paste('T', 1:10, sep=''))

This assumes there are columns 'Site' and 'Browser' which label the data. Then to select subsets of the data:

subset(data.m, subset=(Site=='www.bbc.co.uk' & Browser=='lynx'))

To compute a statistic for all sites, and then plot a bar chart with percentage difference:

library(plyr)
meds <- ddply(data.m, c('Site', 'Browser'), summarize, Time = median(value))
meds_wide <- reshape(meds, idvar='Site', timevar='When', direction='wide')
meds_wide$Delta <- (meds_wide$Time.After / meds_wide$Time.Before) - 1
meds_wide$Id = 1:dims(meds_wide)[1]
library(ggplot2)
ggplot(meds_wide, aes(x=factor(Id), y=Delta)) + geom_bar()

And to draw a boxplot to facilitate comparison between two specific values:

boxplot(subset(data.m, Site=='www.bbc.co.uk'&Browser=='lynx')$value,
        subset(data.m, Site=='www.bbc.co.uk'&Browser=='wget')$value)

Or alternatively:

library(ggplot2)
qplot(data.m$Browser[data.m$Site=='www.bbc.co.uk'], data.m$value[data.m$Site=='www.bbc.co.uk'], geom='boxplot')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment