Jonathan Keane's Blog

To content | To menu | To search

Sunday 15 December 2013

Instapaper liked -> buffer

I've been struggling with how best to send articles I like to bufferapp so that they can be slowly added to various social media in a more controlled manner. Since Instapaper doesn't natively support buffer (although they are planning to) IFTTT seemed like the only way. But, IFTTT only seems to be able to post to one buffer account at a time. The way around this is to use Buffer's secret email address which will post to all of one's default accounts. I've made the recipe available.

This is a combination of two ifttt recipes.

Tuesday 19 March 2013

Knitting chapters of a larger work. LaTeX+R

Knitr is a great package for integrating R code into LaTeX documents to make reproducible writeups of scientific work. In writing my proposal and dissertation I realized that it would be easier to have each chapter be a separate tex document, so that I could keep R code chunks separate, and not have to run multiple huge model fittings if I changed one of them (knitr is pretty smart with caching, although sometimes this breaks down and I have to clear the whole cache and recompile everything). To do this I have on master tex file that has each section or chapter included with the command \subincludefrom{foo/}{bar} where foo is the subdirectory of the part and bar is the name of the tex file to include.

I then create knitr bar.Rnw files which I knit separately. This produces the bar.tex file which is referenced in the master document. I then use latex to compile only the master document. The following set of bash (with auctex variables) commands is a template that, in aquamacs, will knit the current document, and then compile the master document.

Rscript -e "library(knitr); knit('%s.Rnw')"; cd ~/dissertation/; texi2pdf -c dissertation.tex

the latex command subincludefrom is from the import package which allows for the sub documents to have their own relative includes (necessary for figures) additionally, it acts like the LaTeX include command in that has some speed benefits with large documents.

Sunday 30 December 2012

Intercept keyboard events on linux.

I run an xbmc media server in my living room, and for the longest time I've been frustrated that sometimes the interface becomes non-responsive which then required me to ssh into the system, kill the xbmc user, and then logging in again. I think I found a solution to at least part of this problem using evrouter to intercept keyboard events, and then kill the xbmc user when a specific key combination is pushed.

First I created an evrouter config file (.evrouterrc) in the xbmc user's home directory, which listens for ctrl+alt+del, and then runs the kill script

"Logitech diNovo Mini" "/dev/input/event15" control+alt key/29 "Shell//usr/local/bin/xbmc-kill"



## This kills all process associated with the xbmc user.

pkill -U xbmc

exit 0

Finally, in order to start evrouter when xbmc started I altered xbmc-standalone to include the following line (right before the crash detection loop):

/usr/bin/sudo /usr/bin/evrouter --config=/home/xbmc/.evrouterrc /dev/input/event15 

Friday 21 December 2012

Latex, and creating exam answer keys.

I've been using latex for all of my typesettings needs for a long time. So, when I need to make exams for classes I wanted a way to make the actual test, as well as an answer key from the same tex source. I stumbled on the following, which makes a new command, \answer{}, with an argument being the answer that is not typeset for the test version, and made red for the key version. There are a few drawbacks, mainly that \phantom can't handle content with line breaks.

%\newcommand{\answer}1\phantom{#1} % for the test \newcommand{\answer}1{\color{red}{#1}\color{black}} % for the key

Thursday 20 December 2012

Natbib, bibtex, and citations with non-year year fields.

I've been annoyed by this many times: whenever I have a citation that has something other than a year in the year field (eg, in press, forthcoming) and I used natbib for citations I would always get things like: Keane (ress) rather than Keane (in press) like I wanted. After doing a bunch of searching a few times, I finally broke down and started hacking at the bst. Based on the thread discussing this, I figured out that one can just replace all instances of year field.or.null purify$ #-1 #4 substring$ with year field.or.null purify$.

Wednesday 28 December 2011

Beamer navigation removal

I'm shocked and appalled it's taken me so long to discover how to disable the silly navigation icons in beamer:

\setbeamertemplate{navigation symbols}{}

I'll say it's that I never really looked for it. That's a good excuse, right? Now if I could only find a way to rearrange sections in the header elegantly.

Tuesday 19 July 2011

SqueezeBox Server and playlists with non latin characters

When I first ran into this problem I did find the bug report which included a patch for fixing this problem. I assumed that if it really was as simple as changing two lines of code it would be put into a release shortly enough. After a few releases I got annoyed enough that I decided to see if the patch works. Turns out it does. Why hasn't this been fixed in the release yet?

Sunday 15 May 2011


I just configured my ubuntu based XBMC box to be an airplay recipient using PascalW's Airplayer. Unfortunately, it works with video and picture streaming, but it is easy to setup (just follow the instructions in the package), and just works.

Next step: getting shairport to work. Update: It's simpler than I thought. I now have shairport working, now to daemonize: something like this should work.

Tuesday 8 March 2011

Towards a less thought, robust backup solution

As everyone knows, backups are critical. Unfortunately, robust backup solutions often require ongoing thought to be sustained. Apple's TimeMachine revolutionized no thought backups and it's relatively easy to use an existing ubuntu server/desktop system with free space to act as a timecapsule (see the many tutorials on the web). This allows my macbook (or any other mac for that matter) to backup to my server at home whenever I'm on the local network. Unfortunately it's not very robust, there is a single backup in a single location. It's difficult to take snapshots of this backup and copy them elsewhere because it is saved as a sparse disk image. There is simply no way to get a non-OS X system to manipulate these images (hdiutils which mounts sparse disk images isn't released back to the BSD community). TimeMachine: no thought – check; robust – not really.

CrashPlan is a service similar to services like Carbonite. They charge to store your backups on their server, but they will provide you with the infrastructure to backup to local drives, as well as remote computers. The interface is not quite as nice as TimeMachine, but so far it seems to replace most of the functionality. CrashPlan: no thought – check; robust – for money.

The best way to cover all of my backup bases that I've found is to use a combination of both. TimeMachine backsup to my server at home as a single, large backup, and then CrashPlan backsup to removable hard drives that are stored outside of my house shuffled at regular intervals to avoid total dataloss in the case of a disaster. CrashPlan isn't setup to play well with removable media in linux (cf CrashPlan forum discussion). In order to overcome this limitation and allow for times when the removable media is not connected, I have written a bash script that unlocks the encrypted block device, mounts it, and then starts the CrashPlan service only after the media is available. It also turns CrashPlan off when the media is unmounted. To use this you need to just change the variables $ENCRYPT_VOLUME to the name of the volume, and $VOLUME_PATH to the path for this volume to mount to. Finally configure CrashPlan to backup to this directory. Finally you need to disable the CrashPlan engine from starting on boot, which can be accomplished by running the following as a super user.

$ update-rc.d -f crashplan remove

 Time Machine + CrashPlan on removable media: no thought – mostly; robust – check

#!/bin/bash -e

## Author: Jonathan Keane
## License: Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
## Date: 7March2011
## Description: A script to mount or unmount a removable hard drive
## that has been LUKS encrypted; it also turns the CrashPlan
## backup engine on when the drive is mounted, and off when
## unmounted. In order to disable CrashPlan starting on boot
## as admin run:
## $ update-rc.d -f crashplan remove
## This deletes the link to the /etc/init.d/crashplan from all
## runlevels, while keeping the init.d script.
## Usage: -m /foo/bar to mount the encrypted block device that is located at
## /foo/bar (on many systems: /dev/sdX) to $VOLUME_PATH below
## -u unmounts the volume specified by $ENCRYPT_VOLUME below

## the name for your encrypted drive

## the location you want the drive to be mounted to

while getopts ":m:u" opt; do
case $opt in
echo "Mounting: $OPTARG" >&2
sudo cryptsetup luksOpen $OPTARG $ENCRYPT_VOLUME
sudo mount /dev/mapper/$ENCRYPT_VOLUME $VOLUME_PATH
sudo /etc/init.d/crashplan start
exit 0
sudo /etc/init.d/crashplan stop
echo "Unmounting: $ENCRYPT_VOLUME" >&2
sudo umount /dev/mapper/$ENCRYPT_VOLUME
sleep 5
sudo cryptsetup luksClose $ENCRYPT_VOLUME
echo "Unmounted."
exit 0
echo "Invalid option: -$OPTARG" >&2
exit 1
echo "Option -$OPTARG requires an argument." >&2
exit 1

echo "Need at least one option either -m /foo/bar to mount and start CrashPlan or -u to stop CrashPlan and unmount your encrypted volume."
exit 1

Saturday 11 December 2010

Using ffmpeg to divide a video into many clips.

Although this seems ludicrously obvious now, a few months ago I was completely unable to come up with a good solution for automatically separating one video into many different clips. After a while I finally stumbled on something suggesting ffmpeg as a solution. And come to find out it's actually relatively easy:

ffmpeg -ss -t -i /foo/ -sameq /foo/bar.out.mpg

In order to then automate this I wrote a short python script that also used rpy2 to grab data on what times I needed video from out of my data in R. Then I just used something like the following to extract 1.6 seconds around each point of time in the list times that I had grabbed from R

for time in times:
    filename = '/foo/'
    dur = "00:00:01.600"
    secs = str(datetime.timedelta(milliseconds=(time-800)))
    cmd = ''.join(['ffmpeg -ss ',secs,' -t ',dur,' -i ',filename,' -sameq ','/foo/bar.out.mpg'])

I've seen other places suggest to use the -vcodec copy -acodec copy options, however this made the clip begin not where I had specified after -ss, but rather at the closest key frame. Using -sameq does take longer and is lossy because the clip is reencoded, but it starts the clip exactly where you specify it. 

Although I used python and R, this could have been accomplished entirely within R, or with any other data source and scripting language. Something similar can be done to extract still images. The ffmpeg documentation is a great resource.

Wednesday 8 December 2010

Local type with MacTeX 2010 (TeX Live 2010 as well?)

I just upgraded to MacTeX 2010 and had some trouble with previously installed type files in my private tree. Using MacTeX 2009 everything was installed appropriately in my local tree (~/Library/texmf) as well as the privately generated ~/.texlive2009 (cf the TeX Live 2010 documentation). I thought all I would need to do is rename the second directory to ~/.texlive2010, and keep the texmf in the library the same. This, however didn't work. 

I took the long way and reinstalled Minion Pro (easy with my script) as well as a few other local fonts. (With a detour through subversion hell: move, recursively delete .svn files, revert to old version, move back, commit) This then generated a new folder: ~/Library/texlive/2010 which seems to be the new home for privately generated files (although this doesn't seem to be documented for either the TeX Live or MacTeX). 

On further investigation it seems that the ~/Library/texlive/2010 directory is now where map files as well as local font files go:

kpsewhich returned ~/Library/texlive/2010/texmf-var/fonts/map/pdftex/updmap/

Almost all of this digging was done very cursorily, but since I didn't see any documentation (other than some for MkIV ConTeXt) I wanted to get this out here. What's not clear is if .texlive2010 has any purpose for MacTeX 2010.

Monday 29 May 2006

Portuguese Sweet Bread

I bought all of the ingredients to make this bread when I made cinnamon buns, but just now got around to making it. It's surprisingly tasty.

Saturday 20 May 2006

Hmm I wonder.

I stumbled across this aritcle on the register today (and to think i wanted to delete it from my rss feeds). It makes one start askign what if questions.

Rosemary Pugliese

I think that I've found one of the more perfect breads I've made so far. Last week I had some mashed potatoes leftover from a dinner so I decided to make some tasty potato rosemary bread, having about 10 oz of biga leftover I decided to also make some pugliese. Which gave me the crazy idea: what about rosemary pugliese. I made it for the second time today and I'm just waiting to crack one open and see if it tastes as good as my initial loaf.