Tuesday, January 25, 2011

Pragmatic Diary with LaTeX

A while ago, I decided to write something like a personal diary, and wanted to do it with LaTeX. I wanted to have a pragmatic environment, which is established when typing a simple command.

Before I describe the implementation, I would like to describe this environment:
  • When I run the command diary, an instance of kate opens a file named with the current date (e.g. 2010-12-09.tex, located in a directory, let's say $DIARY)
    • If this file exists, then a warning appears, and it is opened
    • Otherwise, this file is created
  • This file contains a skeleton for a LaTeX document, where I immediately can start writing down my thoughts
  • In the terminal-area of kate, I simply have to type pdflatex 2010-12-09.tex to compile the tex-file into a PDF.

And here is how I implemented it.
The template for the LaTeX-skeleton looks as follows (file named $DIARY/template.tex):


Here goes the text

The file $DIARY/macros.tex contains document and package definitions, that define the common properties for all tex-files, and hence a unique look for all resulting pdf-files.


The script, that launches when typing diary is the following ($DIARY/diary.sh):

TODAY=$(date +"%Y-%m-%d")
if [ -f $TEXFILE ] 
  zenity --error --text "Tex-File $TEXFILE already exists!!!"
  cp $BASE/template.tex $TEXFILE

kate $TEXFILE &
cd $BASE
pdflatex $TEXFILE
okular $PDFFILE &

Some notes:
  • zenity simply pops up a dialog box with the given warning
  • okular is my favorite PDF viewer - in fact it could be any other viewer
Finally, I made a softlink to $DIARY/diary.sh in /usr/bin.

By the end of each year I might create a document named diary-201x.pdf, which includes all entries and is a nice compilation of my diary entries. For instance, this could be done with the pdftk. (pdftk *.pdf cat output diary-201x.pdf)

P.S.: You may wonder, why I'm mixing Gnome and KDE software. I'm working with Ubuntu and have some KDE-packages installed. Well, that's my environment, and I'm very fine with that. If you are Ubuntu-User, too, you will find all of the necessary software in the Ubuntu repositories (sudo apt-get install XXX, whereas XXX stands for kate, okular, zenity, pdftkm, etc.)

Monday, January 24, 2011

CropPDF integrated in Nautilus

During my master thesis I had to perform the following task several times: crop a PDF, i.e. remove the outer white borders of the PDF.

A software called pdfcrop (I think it is in the Ubuntu repositories) can do this. From a console the syntax is the following:

pdfcrop input.pdf output.pdf

I wanted to use this feature from my file browser (Nautilus), by right-clicking the file-to-be-cropped and choosing "Scripts -> Crop PDF". Here is how to do this:
  • Create a file called CropPDF located at ~/.gnome2/nautilus-scripts with the following content
  • #!/bin/bash
  • Make it executable (chmod +x CropPDF)
That's it.
Caution: this modifies the file, on which you execute the operation!

Portable Apps - PortableApps.com

Today I found a very useful web page: http://portableapps.com/
It provides (freeware, free and open source) software, that can be carried on a portable device and can be used on any Windows computer.

This seems to be optimal for my journey, because Internet caf├ęs will mostly operate on Windows machines, and I won't have the rights to install software.

Saturday, January 22, 2011

E-Mail Obfuscation

This blog shows nine ways to obfuscate e-mails
See the HTML source of this page to see the internals.

One of the easiest "rock-solid" methods, that do not earn spam is the following:

<style type="text/css">
span.codedirection { 
  direction: rtl; 

<span class="codedirection">

This produces daniel@foo.com.

This is the other "easy" way:

<style type="text/css">
span.displaynone { display:none; }

daniel@<span class=”displaynone”>null</span>foo.com

Tuesday, January 11, 2011

Scala == Effective Java ?

Well, this is an interesting article.

The author states, that most of the items in the first chapter of Josh Bloch's famous Effective Java present recommendations that are "either unnecessary, because Scala doesn't permit the corollary bad practice, or built into the language of Scala, or made easier to implement than they are in Java".

The article closes with the following words:
"If 'Effective Java' is considered essential reading, and the best practices in it are the de facto standard for writing good programs, shouldn't we all be giving serious consideration to switching to a language that is so very close to Java, but makes good programming even easier?"
That motivates to get deeper into Scala. Thank you, Graham!

Saturday, January 8, 2011

Time from GeoNames' RESTful Web Service via JSON/AJAX

I needed a small gadget for my travel blog (which is not published yet) to display the current time where I am currently at. As I did not find a useful one, I decided to write my own, and soon found that GeoNames.org offers a RESTful Web Service for this purpose.

GeoNames publishes its work under a Creative Commons Attribution 3.0 License.

Here's the code:
<script language="JavaScript">

var url = "http://ws.geonames.org/timezoneJSON"+
var jo = {}; // JSON Object
var req = new XMLHttpRequest();
req.open( "GET", url, true );
req.onreadystatechange = function () {
 if (req.readyState == 4 && req.status == 200) {
  jo = JSON.parse( req.responseText );
  document.getElementById("tt").innerHTML = jo.time;

<div id="tt">...wait</div> 

Short Explanation:
The URL of the GeoNames Service contains the latitude and longitude of the place where I will stay. That's implies the only drawback: I have to change this code, but I'm sure I won't change timezones every week.
The request is sent via HTTP, and the server asynchronously (i.e. AJAX) sends back the result, which is handled in the shown function. The response is a JSON object, that has an attribute time, which is finally written to a reserved region (the div at the bottom of the code).

Well, to demonstrate that it works -- that is the current time of Buenos Aires:

Note, that this method is not reliable, as it does not always work! Sometimes, the JSON-response contains a message like "Sorry, we cannot serve your request as our servers are busy". That's why I searched for another alternative, and found it here.