Pages

Thursday, February 2, 2012

Corrrupted SVN repo and the solution

   I'm currently taking a Numerical Physics course at U. Laval. So far, it has been a really enjoyable experience. However, I would like to share some technical know-how I acquired while working on one of the projects.
   We are mostly using MATLAB (I personally use Octave, which is the open-source counterpart) to do the projects. As of the fourth project, I am working with a partner, which immediately lead to the classic problem: how do we share the code?
    Of course, this problem has been solved in thousands of ways. I chose to create an account on SourceForge (I don't have my own server, so it was the easiest way) and start a project where I could dump the all the code in an SVN repository. (By the way, all the code we write, for what it's worth, is Creative Commons.)
   Everything went well; up till yesterday. For some obscure reason, when I tried to svn up in the morning, svn returned the error 
Reading one svndiff window read beyond the end of the representation.
which I didn't know about. Some Googling informed me that the repository was corrupted.  Some more Googling revealed a SourceForge support page that gave a solution to the problem.
   Okay, so here's the complete solution. You log on to the Shell SourceForge provide and run the following commands:

adminrepo --checkout svn
svnadmin dump -r 0:92 /svnroot/projectName/ > ~/repo.dump
The adminrepo checks out the SVN repo of your project in a folder that you can modify. You then dump the repo (I used -r 0:92 because I knew the repo was sane at rev 92 and because I had manually merged the diffs of -r 93:95 in my working directory).
   Now, if you're sure you have a good backup, you can delete the repo. We will then create a new one and load the dump file into this new repo.

rm -rf /svnroot/projectName/
svnadmin create /svnroot/projectName
adminrepo --save svn
Now half the fun is done. The repo is back in the main folder (which you can't modify directly) and your DB should be un-corrupted (or whatever).
   If you're using the new SourceForge bashboard, you can't stop here. You have to tell the dashboard that you've made some drastic changes to the repo. In the SourceForge web interface, navigate to Admin → Tools. Under the SVN tool, click on Import Repo. Enter the following URL:
https://projectName.svn.sourceforge.net/svnroot/projectName

click Import and you're done! 

Please inform me in the comments is something is unclear or just plain wrong. Thanks!

Thursday, November 17, 2011

Contribution to the Book of Knowledge

The old version of Wikipedia. Yes, this is a joke. 
 
   I just made my first contribution to Wikipedia. Considering that it is the first place when I need to check something quickly, or to get references for specific subjects since it launched (yes, I was 11 years old at the time), it was about time I made a contribution!

   Go ahead, do the same! You'll feel better! 
Support Wikipedia

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}

and tada! 

    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,
"INF_Answer" integer DEFAULT 42
); 
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? 

Saturday, June 25, 2011

Programming is fun!

A look at my coding environment
   I've started programming about a month ago. I pretty much learned by myself by reading a book or two about C++. Oh, and I skimmed some parts of C++ GUI Programming with Qt 4, by Jasmin Blanchette and Mark Summerfield. So far, I'm liking it.

   I use the Qt Creator IDE, which provides graphical tools to edit UI files and pretty much helps at every level of application development.

   In short, I'm doing an interface to a PostgreSQL database. I may post screenshots of it when I'm at a more advanced stage. For now, the interface does not do a lot of things.


Tuesday, June 21, 2011

IBM turns 100!



    IBM has just turned 100. To celebrate this stellar achievement, the company has produced a video that summarizes its century of existence in a rather poignant way. 
Enjoy!

[Video LinkIBM Centennial Film