This page contains a list of useful hacks that I've coded (on the left), and collected from various places around the internet (on the right).

These relate to categories such as Amazon Mechanical Turk, R, LaTeX, Mac OS X.

#pin: Bonus workers on Amazon Mechanical Turk mTurk

I wrote a simple python script to automate awarding bonuses to workers on Mechanical Turk (mTurK). You can find it here.

Programatically downloading .csv data from Qualtrics and reading it into R R

I wrote an R function to do this at The readme on that page also has the plain cURL code and links to the Qualtrics API documentation so you can explore more!


Justine Kao, Greg Scontras, and I coded up a little interactive web text-visualization demo: colorMeText, which basically colors input text according to ratings using some dictionary (e.g. useful for sentiment analysis, or any other dimension of interest). It's still a work in progress! [ git ]

Continuous version of the Inclusion of Other in Self (IOS) scale mTurk

A simple Javascript implementation (using Raphael.js) of a continuous version of the Inclusion of Other in Self scale (Aron, Aron, & Smollan, 1982).

Set Default Zoom in MS Word

Here's a simple Macro that you can use so that everytime (Microsoft) Word opens a new document, it does so at a specific zoom level. (I like 100% on my Retina Pro.).
1) In Word, Go to Tools->Macro->Macros.
2) On the dropbox after "Macros in", click Normal (Global Template)
3) Create a new Macro called AutoOpen [This particular name seems to be required for it to be run upon opening].
4) Paste the following macro in, where 100 is the desired zoom percentage.

Sub AutoOpen()
    ActiveWindow.ActivePane.View.Zoom.Percentage = 100
End Sub

(refs: various places like this and this.)

One-line redaction of identifiable information R

Simple one liner to replace identifiable information (e.g. mTurk workerids):

d0$workerid <- match(d0$workerid, unique(sort(d0$workerid)))

Compressing PDFs Mac

There are probably better ways to do this (I spent maybe only 20 mins researching this problem because there was a journal with a pdf file size limit).
I found that Mac's Preview can compress (Export->Quartz Filter->Reduce File Size), but images become really low quality. The solution I used was, which provided reasonable results (good enough for the journal submission, at least!)

Updating R RMac

How to update R and re-install all your packages. Neat and simple trick here:

Making GIFs Mac

Sometimes you gotta make gifs... maybe just for fun. I use GIFFun, which is pretty alright if you just need the basic essentials.
There's also a neat guide here that I haven't tried, using ImageMagick on the command line:

Data Munging: Concatenate many (e.g. .csv) files. Mac

Sometimes you just want to concatenate all the data files in a directory into one big file. If it's in a format like .csv, and you want to skip the first header, you can use the following command:

awk 'FNR > 1' *.csv > combined_file.csv

Destructively crop pdfs (useful for LaTeX-ing) LaTeX

If you crop a pdf file in Preview, it doesn't destructively crop it. The parts you cropped out are still hidden in the file (i.e. so you can undo cropping). If you need to destructively crop the file (which I always have to do when prepping graphics for LaTeX), one way to do it is using Ghostscript. Let's say you want to crop "in.pdf" to "out.pdf" (and note that you can't use the same filename, because of the way gs works), at the command line, type:

gs -sDEVICE=pdfwrite -dUseCropBox -sOutputFile=out.pdf - < in.pdf

Convert Files to EPS (useful for LaTeX-ing) LaTeX


[Postscript] Level 1 uses only ascii-coded RGB values, and is very wasteful, producing very large files. Level 2 includes support for JPEG encoded images, which produces much smaller files. Level 3 includes support for Zlib compression, making it well suited for making EPS files from png files.

In general, level 3 will produce the smallest files. Level 2 provides the best compatibility, and works well with jpeg images.

If you decide to use level 2 postscript, I recommend converting first to a jpg file. The "convert" program included Imagemagick uses a quality factor in "percent" that ranges from 0 to 100:

convert -quality 80 fig.png fig.jpg

I find a quality factor of 80 on high resolution images gives good compresssion without too much loss in quality. You can then to convert the image to eps using "convert" with the eps2 settings:

convert fig.jpg eps2:fig.eps

If you can use level 3 postscript, you can convert directly from png to eps:

convert fig.png eps3:fig.eps

Using level 3 postscript from a png image file for scientific figures will often produce a very small eps file. Ghostscript is compatible with these level 3 eps files, so this is often a good way to go.

Drawing Bayes Nets with LaTeX LaTeX

A great package that I use to draw Bayes Nets is XY-pic.

Increase Mouse Sensitivity on Mac OS X Mac

I love having really high sensitivity on my mouse/trackpad. Unfortunately, the maximum that you can go in System Preferences isn't high enough for me. There is a way to increase this sensitivity further. In Terminal, typing

defaults read -g

will give you the current value of your mouse scaling. You can modify it by changing read to write, for example, if you want to set your mouse scaling to 3.0 (the maximum in System Preferences), type:

defaults write -g 3.0

In addition, to change the trackpad, use You can also use .scrolling to change scrolling speed.