Saturday, 24 March 2012

Minion Pro font

Here a really good 'how-to' for installing a rather handsome font in LaTeX:
http://carlo-hamalainen.net/blog/2007/12/11/installing-minion-pro-fonts/

Wednesday, 15 December 2010

changing locale

Working with real (decimal) numbers can be problematic when changing between computer with difference language (locale) settings. For example, in the Netherlands a comma is used for the decimal, i.e., sqrt(2) becomes something like 1,4142. In the US a dot is used, as is in most? scientific fields. So, sqrt(2) becomes 1.4142. Input files made up in one locale will be misread in another locale.

Changing to US locale is easily done:
export LANG=en_US.UTF-8
or
setenv LANG en_US.UTF-8

Thursday, 9 December 2010

AWK - get last field

When I generate output from my programs, it is frequently accompanied with some textual information. For example, an output line could read as
Total time: 1234.5
Avoiding tedious copying and pasting, a simple awk command can get the last field from the lines:
awk '{ print $NF }'

Tuesday, 26 October 2010

tar with excluding files

Sometimes you may want to create a tar ball of a software project, but you don't want to include everything to the archive you are creating. On Google anwers I found the answer. With a caveat: there is a difference between tar-version you are using (GNU or not GNU). The example given below is for GNU tar.

As I am using bazaar for version management, the directory to be archived usually contains a sub-directory called .bzr. This is obviously a directory to be excluded.

In my Makefile I first define a variable for my project's directory:
sourcedir=$(PWD)

This is done for portability.

Then the actual rule to make the tar:

tar: veryclean
(cd ../; tar -cvzf $(PROJECT)-`date +'%b-%d-%y' | tr A-Z a-z`.tgz \
--exclude "$(sourcedir)/.bzr" $(sourcedir))

veryclean is a rule to remove files generated during compilation (like log files), and is called first.

Thursday, 21 October 2010

C programming - reading line from file

Suppose you want to 'feed' a program a file with data. In this case it is often convenient when you add some comments to the data, so you will understand it in the future. So, the file may look like

data data
comments comments
data
more comments

In the program reading this data file, you may want to 'skip' the lines containing comments. One way of doing this is reading the entire line, until end-of-line character.

This can easily be done using
fscanf(fs, "\n%[^\n]", dummy);

where fs is file handlers, and dummy a (large enough) string to hold the line.

Idea was found on programmers heaven. As it took me quite some searching for a solution, henceforth this post.

Wednesday, 20 October 2010

creating push branches

To manage our software we use bazaar as version control system, which worked fine. As a certain point, some changes were needed with respect to the location of the software repository. Until know the repository was located under the home directory of several users (i.e., /net/home/johndoe/sw_repos/OurProject). This however is a bit tedious and not very nice. So a fake 'user' was created that would hold all the software projects, and related distributions, repositories, etc.

Next question was how do we transfer all our present versioned code to the new user, without destroying the lineage and links. In the following bazaar specific terminology is used.

Suppose we have a working branch of our project
/net/home/wdrenth/sw_dev/Project
which is bound (i.e., is a checkout of) /net/home/johndoe/sw_repos/Project
Let the new fake 'user' be called 'omnium'.

First create a repository and branch:
bzr init-repos /net/home/omnium/sw_repos/project
and
bzr init /net/home/omnium/sw_repos/project/Project

then, from user wdrenth
cd /net/home/wdrenth/sw_dev/Project
bzr push /net/home/omnium/sw_repos/project/Project
this populates the branch under 'omnium'
then
bzr bind /net/home/omnium/sw_repos/project/Project
which binds the wdrenth checkout to the new branch under omnium.

and ready!

Wednesday, 13 October 2010

Extracting pages from pdf files

Found somewhere on the www while searching for a tool to extract pages from a pdf document using the command-line. Since gs (ghostscript) is installed almost on all unix type system, this routine is portable:


#!/bin/bash
if [ $# -lt 3 -o $# -gt 4 ]; then
echo $usage
else
if [ $# == 3 ]; then
outfile=${3%.pdf}_p${1}-p${2}.pdf
else
outfile=${4}
fi
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=${1} \
-dLastPage=${2} \
-sOutputFile=${outfile} \
${3}
fi


On the command-line simple type:
pdfpextr firstpage lastpage inputfile [ouputfile]