<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mark's Blog &#187; Software</title>
	<atom:link href="http://longair.net/blog/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://longair.net/blog</link>
	<description>(occasional miscellanea)</description>
	<lastBuildDate>Tue, 08 May 2012 15:59:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Making an encrypted partition on a USB drive</title>
		<link>http://longair.net/blog/2011/04/11/making-an-encrypted-partition-on-a-usb-drive/</link>
		<comments>http://longair.net/blog/2011/04/11/making-an-encrypted-partition-on-a-usb-drive/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 05:37:59 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Linux Notes]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=634</guid>
		<description><![CDATA[<p>On Ubuntu or Debian, it&#8217;s really simple to create an encrypted partition on a newly-purchased USB mass storage device.  In my case, I had bought a 1TB hard drive which had very mixed reviews, some people saying their drives had failed very early.  I wanted to be able to return the drive under warranty if [...]]]></description>
			<content:encoded><![CDATA[<p>On Ubuntu or Debian, it&#8217;s really simple to create an encrypted partition on a newly-purchased USB mass storage device.  In my case, I had bought a 1TB hard drive which had very mixed reviews, some people saying their drives had failed very early.  I wanted to be able to return the drive under warranty if it broke without worrying about personal data.</p>
<p>It turns out that if you want to reformat a partition on an external USB drive so that it&#8217;s encrypted, this is just a matter of doing the following:</p>
<pre>sudo luksformat -t ext4 /dev/partitiondevice
</pre>
<p>&#8230;. where <tt>/dev/partitiondevice</tt> is the device for the drive partition you want to overwrite.  Obviously, this will <em>destroy everything that was previously on that partition</em>.</p>
<p>I like to use a proper filesystem for USB mass storage devices, but if you leave out the <tt>-t ext4</tt> then the default is to use VFAT.</p>
<p>When you next plug in that drive, you&#8217;ll be prompted to enter the password that you picked when creating the partition &#8211; if you type that correctly, the drive will be mounted and usable.  (If you mistype it, you&#8217;re not given another chance to enter the password, so you&#8217;ll need to go to the command line and do: <tt>gvfs-mount -d /dev/partitiondevice</tt> to try again.)</p>
<p>One small thing is that the mount point in <tt>/media</tt> will be based on a UUID by default, but if you set the ext4 partition label, it&#8217;ll be mounted under that name in <tt>/media/</tt> instead.  To do this, starting from when your disk is mounted, you can run <tt>mount</tt> without parameters to find the unencrypted device name and then unmount it and change the label:</p>
<pre>$ umount /dev/mapper/udisks-luks-uuid-b7bbb2c8-etc
$ e2label /dev/mapper/udisks-luks-uuid-b7bbb2c8-etc topsekrit
</pre>
<p>If you unplug and plug in the disk again, it should be mounted on <tt>/media/topsekrit</tt></p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2011/04/11/making-an-encrypted-partition-on-a-usb-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Guardian on your Kindle</title>
		<link>http://longair.net/blog/2010/10/04/the-guardian-on-your-kindle/</link>
		<comments>http://longair.net/blog/2010/10/04/the-guardian-on-your-kindle/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 18:26:08 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=523</guid>
		<description><![CDATA[<p>Update: It is now possible to buy an official subscription to The Guardian and The Observer. The rest of this post is now largely of historical interest if you just want The Guardian on your Kindle, but I&#8217;ve left the rest of the content unchanged for people who are interested in how I generated my [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> It is now possible to buy an <a href="http://longair.net/blog/2011/07/11/official-kindle-subscription-to-the-guardian/">official subscription to The Guardian and The Observer</a>.  The rest of this post is now largely of historical interest if you just want The Guardian on your Kindle, but I&#8217;ve left the rest of the content unchanged for people who are interested in how I generated my unofficial version.</p>
<hr />
<p><em>If you just want a copy of today&#8217;s copy of The Guardian or The Observer for you Kindle, you can download one from <a href="http://mythic-beasts.com/~mark/random/guardian-for-kindle/">this automatically generated page</a>.  This post describes the script that generates that generates the file and the motivation for it.</em></p>
<p>Since moving to Switzerland, I&#8217;ve found that I really miss being able to get <a href="http://www.guardian.co.uk/">The Guardian</a> in the morning on my way into work.  Unfortunately, reading the website on a phone (or any other device) is no substitute if you&#8217;re relying on data over the mobile phone networks &#8211; one really wants all the articles cached for fast navigation through the paper.  The solution for this should be my shiny new Kindle, but sadly subscriptions to The Guardian aren&#8217;t available in the Kindle store.  (There are <a href="http://www.amazon.co.uk/Newspapers-Kindle/b/ref=sa_menu_knews2/279-2950573-6970532?ie=UTF8&amp;node=341691031">many other papers</a> available.)  Fortunately, The Guardian has <a href="http://www.guardian.co.uk/open-platform">an excellent API</a> for accessing its content, and the lovely interface produced by <a href="http://guardian.gyford.com/">Phil Gyford</a> for reading the paper in a cleaner interface suggested that I could similarly generate a bare bones version of the paper for my Kindle.  I believe that this is permitted under the terms and conditions of the <a href="http://www.guardian.co.uk/open-platform">Guardian Open Platform</a>, since I&#8217;m (a) including the advertisement linked to from each article, (b) linking back to the original article and (c) acknowledging that the data is supplied by that service.  If I&#8217;ve misunderstood, and in fact this is not allowed, please let me know.</p>
<p>To generate a book in the Kindle&#8217;s preferred format, you have to generate a <a href="http://en.wikipedia.org/wiki/EPUB#Open_Packaging_Format_2.0">.opf</a> file describing the contents of the book, which refers to other files describing its text, images, structure, etc.  Then you can run a binary called <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&amp;docId=1000234621">&#8220;kindlegen&#8221;</a> to generate a .mobi archive from those files that will work on your Kindle.  (The samples in the kindlegen archive and the <a href="http://s3.amazonaws.com/kindlegen/AmazonKindlePublishingGuidelines.pdf">Amazon Kindle Publishing Guidelines</a> are quite sufficient to figure out how to do this.)  My <a href="http://github.com/mhl/guardian-for-kindle/">script</a> to generate the .opf and supporting files is far from elegant, but I&#8217;m very happy with the results that it produces &#8211; it&#8217;s a really lovely reading experience.  You can use the normal page forward / back buttons to go from page to page, while the left and right buttons on the five-way skip to the next article&#8217;s headline.  This means you can skip quickly through the articles that you aren&#8217;t interested in, but each article you do want to read is presented very clearly on the amazing eInk display:</p>
<p><a href="http://www.flickr.com/photos/mhl20/5051259913/sizes/l/"><img class="alignnone" src="http://farm5.static.flickr.com/4112/5051259913_23aa8a2924_m.jpg" alt="" width="157" height="240" /></a><a href="http://www.flickr.com/photos/mhl20/5051237635/sizes/l/"><img class=" alignnone" src="http://farm5.static.flickr.com/4144/5051237635_0fd27b4834_m.jpg" alt="" width="158" height="240" /></a><a href="http://www.flickr.com/photos/mhl20/5051859946/sizes/l/"><img class="alignnone" src="http://farm5.static.flickr.com/4084/5051859946_2be6d21162_m.jpg" alt="" width="158" height="240" /></a></p>
<p>There are a few articles for which the API won&#8217;t return the text, saying that rights for redistribution are not available &#8211; I&#8217;m still including the other metadata for these article and the link to the original article, so that you know what&#8217;s missing:</p>
<p><a href="http://www.flickr.com/photos/mhl20/5051864202/sizes/l/"><img src="http://farm5.static.flickr.com/4145/5051864202_2509e44e34_m.jpg" alt="" width="159" height="240" /></a></p>
<p>At the end of each article is the advertisement image that&#8217;s included &#8211; this is to comply with the requirements of the Guardian Open Platform:<br />
<img src="http://farm5.static.flickr.com/4086/5051862326_1b5372e589_m.jpg" alt="" width="158" height="240" /></p>
<p>You can download the generated .mobi file for today&#8217;s Guardian (or The Observer on Sunday) from this page:</p>
<p style="padding-left: 30px;"><a href="http://mythic-beasts.com/~mark/random/guardian-for-kindle/">A Kindle version of today&#8217;s Guardian or Observer</a></p>
<p>You can bookmark that page in your Kindle&#8217;s web browser.  Then, whenever you select the bookmark and then &#8220;Reload&#8221;, then it&#8217;ll be refreshed with a link to that day&#8217;s generated edition of the newspaper for your Kindle, which you can download straight from that page.</p>
<p>If you&#8217;re interested in this project, or have any comments or suggestions, you can contact me by email at:</p>
<p><img class="alignnone" src="http://mythic-beasts.com/~mark/random/email-kindle.png" alt="&quot;mark&quot; followed by a dash, then &quot;guardian&quot; then &quot;kindle&quot; then an &quot;at&quot; sign then longair dot net" width="262" height="19" /></p>
<p>&#8230; or leave a comment below.  The script for generating this version of The Guardian is available at <a href="http://github.com/mhl/guardian-for-kindle">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2010/10/04/the-guardian-on-your-kindle/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Hashing Flickr Photos</title>
		<link>http://longair.net/blog/2009/12/19/hashing-flickr-photos/</link>
		<comments>http://longair.net/blog/2009/12/19/hashing-flickr-photos/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:30:27 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[flickr scripting]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=405</guid>
		<description><![CDATA[<p>I used to host my photos with a simple set of CGI scripts that basically worked well enough for my simple requirements.  Such web applications are easy and fun to write, but in the end I decided that it wasn&#8217;t worth it because:</p> Hosting large amounts of data on a generic shell account is typically [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/mhl20/4197661773/"><img class="alignright" src="http://farm3.static.flickr.com/2756/4197661773_d671c5feea_m.jpg" alt="" width="240" height="124" /></a>I used to host my photos with a simple set of CGI scripts that basically worked well enough for my simple requirements.  Such web applications are easy and fun to write, but in the end I decided that it wasn&#8217;t worth it because:</p>
<ul>
<li>Hosting large amounts of data on a generic shell account is typically quite expensive.  <a href="http://www.flickr.com">Flickr</a>&#8216;s <a href="http://www.flickr.com/upgrade/">&#8220;pro&#8221; account subscription</a> is a very good deal in comparison: as long as each photo is beneath 20 megabytes in size, you can upload as many as you like for $24.95 a year.</li>
<li>The community aspect of sites like Flickr is very encouraging &#8211; it&#8217;s lovely to have random people say nice things about your photographs, and occasionally have people use them in articles, etc.</li>
</ul>
<p>(Some people are put off from using Flickr by the appearance of the site, but its API means that there are plenty of alternative front-ends for viewing or presenting your photos, such as <a href="http://www.flickriver.com/photos/mhl20/">flickriver</a>.)</p>
<p>The slight problem with switching to hosting on Flickr was that previously I&#8217;d indexed all my photos by the MD5sum of the original image, so several of my pages had links or inline images that pointed to an MD5sum-based URL on the old site.  It occurred to me that it might be useful in general to have <a href="http://www.flickr.com/groups/api/discuss/72157594497877875/">&#8220;machine tags&#8221;</a> on each photo with a hash or checksum of the image, so that, for example:</p>
<ul>
<li>You can simply check which photos have already been uploaded.</li>
<li>You can find URLs for all the different image sizes, etc. based on the content of the file.</li>
</ul>
<p>Unfortunately, I hadn&#8217;t done this when uploading the files in the first place, so had to write a script (<a href="http://github.com/mhl/flickr-checksums/blob/master/flickr-checksum-tags.py">flickr-checksum-tags.py</a>) which takes the slightly extraordinary step of downloading the original version of every photo that doesn&#8217;t have the checksum tags to a temporary file, hashing each file, adding the tags and deleting the temporary file.  This add tags for the MD5sum and the SHA1sum, using a namespace and keys <a href="http://www.flickr.com/groups/api/discuss/72157594497877875/#comment72157594506503786">suggested in this discussion</a>, where someone suggests taking the same approach. These tags are of the form:</p>
<pre>
  checksum:md5=c629c63f8508cfd1a5e6ba6b4b3253a8
  checksum:sha1=df44fc771660fbe7a2d6b2e284ae61e9ed3e377c
</pre>
<p>The same script can return URLs for a given checksum:</p>
<pre>
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 --short
  > http://flic.kr/p/7oQxqK
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 -p
  > [... the Flickr photo page URL, which WordPress insists on turning into an image ...]
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 --size=b
  > http://farm3.static.flickr.com/2552/4196574615_491c6387f8_b.jpg
</pre>
<p>The <a href="http://github.com/mhl/flickr-checksums">repository</a> also has a <a href="http://github.com/mhl/flickr-checksums/blob/master/find-not-uploaded.py">script to pick out files that haven&#8217;t been uploaded</a>, and a <a href="http://github.com/mhl/flickr-checksums/blob/master/flickr-upload.py">simple uploader script</a> which will upload an image and add the checksum tags.  The scripts are based on the very useful Python <a href="http://stuvel.eu/projects/flickrapi">flickrapi module</a> and you&#8217;ll need to put your Flickr API key and secret in <tt>~/.flickr-api</tt></p>
<p>Anyway, these have been useful for me so maybe of some interest to someone out there&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2009/12/19/hashing-flickr-photos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LyX Tips for Thesis Writing</title>
		<link>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/</link>
		<comments>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 15:22:42 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[PhD Work]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=304</guid>
		<description><![CDATA[<p>LyX is a lovely bit of software for preparing beautiful documents &#8211; you get the high quality output of LaTeX and the advantages of logical document description in a usable interface and without having to remember TeX syntax.  There are a few aspects of using LyX that puzzled me while writing a certain large document, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lyx.org">LyX</a> is a lovely bit of software for preparing beautiful documents &#8211; you get the high quality output of LaTeX and the advantages of logical document description in a usable interface and without having to remember TeX syntax.  There are a few aspects of using LyX that puzzled me while writing <a href="http://longair.net/blog/2009/10/21/thesis-visualization/">a certain large document</a>, however &#8211; many of these are dealt with in the <a href="http://wiki.lyx.org/FAQ/">LyX FAQ</a>, but I thought it would be worth collecting those that were most useful to me here.</p>
<h3>Use pdflatex for Output</h3>
<p>There are various different options for generating output PDF output in LyX, but it will save you trouble if you do everything using <strong>pdflatex</strong> in the first place. (I think this is the upshot of the <a href="http://wiki.lyx.org/FAQ/PDF#toc14">slightly unclear advice in the FAQ</a> on the subject.) This turned out to be particularly important because when your document is 50000 words long and has over 100 figures, the other methods take over 10 minutes to generate a PDF; pdflatex would finish in a couple of seconds. If you take this advice then you have to change the <em>Document -&gt; Settings -&gt; Document Class</em> option to pdfTeX, or you get some surprising errors. Also, I would strongly recommend that you only use PNG files for bitmap images and PDF for vector graphics. (PNG is obviously sensible, but in the case of vector graphics I found PS and EPS files unexpectedly awkward in terms of getting the orientation and clipping right.)</p>
<h3>Incorrect Colours in Bitmap Graphics</h3>
<p>I came across a bizarre problem where the colours would be slightly wrong for certain PNG files that I include in the document. (I suppose I should say &#8220;colors&#8221; too, just for the sake of searchers using American English.) This turned out to be a problem with full-colour PNG images with transparency (i.e. RGBA images), which my notes say is discussed further <a href="http://forums.adobe.com/thread/395348">in</a> <a href="http://forum.planetpdf.com/wb/default.asp?action=9&amp;fid=106&amp;read=62468">these</a> <a href="http://sarovar.org/tracker/?func=detail&amp;atid=493&amp;aid=896&amp;group_id=106">posts</a>. Setting the PDF version as suggested in the first of those posts didn&#8217;t help me at all, so I had to convert all my RGBA PNG files to RGB. If you want to check for these files you can use file(1), something like:</p>
<pre>find . -type f -iname '*.png' -print0 | xargs -n 1 -0 file | egrep RGBA</pre>
<p>&#8230; and I fixed them by feeding the filenames (one per line) to a script like:</p>
<pre>#!/bin/sh

set -e

while [ $# -ne 0 ]
do
 t=`mktemp`
 convert "$1" png24:"$t" &amp;&amp; mv "$t" "$1"
 shift
done</pre>
<p>Obviously you need imagemagick installed for the &#8220;convert&#8221; command.</p>
<h3>Footnotes</h3>
<p>By default there is no extra vertical space to separate footnotes, but I much prefer there to be a small gap. To do that, add to the following line to the document preamble:</p>
<pre>\setlength{\footnotesep}{12pt}</pre>
<h3>Captions</h3>
<p>By default, the formatting of caption text in floated figures looks very similar to the main body text. Somewhere on the web I found the recommendation to use the &#8220;caption&#8221; package to change this, e.g. by adding the following to the preamble:</p>
<pre>\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption}</pre>
<h3>Fitting Tables Onto Pages</h3>
<p>Making tables fit on the page is annoying &#8211; just changing the text size often doesn&#8217;t reduce the overall size or causes a horrible font to be used. Resizing the whole table is the best way I found. Before the table (either in a float or in the normal flow of the document) I added the following in ERT:</p>
<pre> \resizebox{\textwidth}{!}{%</pre>
<p>and then immediately after the table added, again in ERT:</p>
<pre> }</pre>
<p>This scales the table such that the width of the table fits the page width.</p>
<h3>Suppressing Pages Numbers For Full Page Figures</h3>
<p>If you want to use a whole page for a floated figure, the page number can overlap with the figure or just look odd.  However, second tip here: <a title="http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage" href="http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage" rel="nofollow">http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage</a> works well to remove page numbers from all-page figures. To summarize, add the following to the preamble:</p>
<pre>\usepackage{floatpag}
\floatpagestyle{plain} % Default page style for pages with only floats</pre>
<p>Then, in ERT before the figure (but still in the float) add:</p>
<pre>\thisfloatpagestyle{empty}
\vspace{-\headsep}</pre>
<p>&#8230; and similarly, after the figure but above the caption add:</p>
<pre>\vspace{0.3cm}</pre>
<p>&#8230; or you may find the caption too close to the graphics.</p>
<h3>Better On-Screen Fonts in PDFs</h3>
<p>As explained in the second question in this <a href="http://www.mail-archive.com/lyx-docs@lists.lyx.org/msg00209.html">mini-FAQ on generating PDFs from LyX</a> you should use the outline font version of Computer Modern instead of the bitmapped versions. For me, this boiled down to going to Document -&gt; Settings -&gt; Fonts and setting the Roman font option to &#8220;AE (Almost European)&#8221;.</p>
<p>You can further improve the rendering of text in your output by using <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/microtype/">microtype</a>. Just add</p>
<pre>\usepackage{microtype}</pre>
<p>&#8230; to the preamble. (These suggestions only apply if you&#8217;re using the pdflatex workflow as suggested above.)</p>
<h3>Adding Footnotes in Tables</h3>
<p>You might notice that adding footnotes in table cells doesn&#8217;t work. One <a href="http://wiki.lyx.org/LyX/Tables#toc12">answer to this</a> is manually add them in ERT with <tt>\footnotemark</tt> and <tt>\footnotetext</tt>, possibly adjusting the counter as described in that FAQ entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

