## Thursday, August 18, 2011

### How-to make LaTeX footnotes stick to the bottom of the page

Disclaimer. The credit goes all to Nikos Skalkotos, on whose blog I found this. I couldn't help but repost it here.

Sometimes, when you write something in LaTeX which has a number of figures, some pages have a lot of whitespace. If you also have a footnote on this page, the footnote won't be typeset at the bottom of the page, but directly below the text .

I find this utterly annoying. So, after a little Googling, I found the package footmisc. It can be used to typeset the footnotes at the bottom of the page, even if there's a boatload of whitespace before. Just use the following command in the preamble:
\usepackage[bottom]{footmisc}

Happy TeXing!

### Return user-defined sets in PostgreSQL

Returning sets of data with PL/pgSQL functions can be somewhat tricky. The documentation has a line saying how to do it somewhere, but the beginner SQL user (like the author of this post) might be confused at the impressive amount of information given by this document.

This post is thus intended as an example that firsts creates a small database and a function that manipulates data. Let's do this!

First, let's create two tables with some data in them.
CREATE TABLE foo (
"IndexFoo" integer DEFAULT nextval('"sq_IndexFoo"'::regclass) NOT NULL,
"FOO_IndexCol1" integer NOT NULL,
"FOO_Timestamp" timestamp without time zone DEFAULT now()
);

And a table that is pointed to by foo:
CREATE TABLE foo_info (
"IndexInfoFoo" integer DEFAULT nextval('"sq_IndexFooInfo"'::regclass) NOT NULL,
);
Now say we want to return rows from both tables. Say we want the answer, given in foo_info and the timestamp, given in foo. We just have to create a function that does just
CREATE OR REPLACE FUNCTION "f_whatIsTheAnswer"(OUT answer integer, OUT "time" timestamp without time zone)

RETURNS SETOF record AS $$BEGIN RETURN QUERY SELECT fi."INF_Answer", f."FOO_Timestamp" FROM foo f JOIN "foo_info" fi ON f."FOO_IndexCol1" = fi."IndexInfoFoo"; END;$$ LANGUAGE plpgsql;
Notice how the returned columns are defined in the function's arguments. This defines the column set returned by the function. If left out, PostgreSQL will complain that the record type has not been assigned any return type.

Because we use PL/pgSQL, the RETURN QUERY statement is used. Since this is a simple query with no complex data manipulation, it could have been a simple SQL request. The RETURN QUERY would have been unnecessary.

Try it yourself! Here's the database dump.

## Wednesday, August 10, 2011

### Removing files from working directory not under version control

I've been using SVN since the beginning of summer and I'm liking it so far. However, I stumbled across a little problem this week.

I use SVN to write a LaTeX document which spans multiple files. Being textual, the contents of the .tex files are diff-able and all the features of SVN can be used. However, when I compile the document to have a nice PDF file, a plethora of files are simultaneously created. I don't want to put these files under version control. I hear you say: "Well, do not add them to your repository, then!". Fair enough, here's the result of a svn st:
 Cluttered up svn st. I hate cluttered
I hate cluttered things! Now, the easy solution is to remove all files you do want to put under version control, marked by a '?'. You always the manual way, i.e. rm file1 file2 file3 ... fileX but that's cumbersome. Let's use some of our bash knowledge to solve this problem.

WARNING. The following command will remove all files marked with a '?'. Be careful with it!

rm svn st | grep ?

Simple enough, huh?