Home
Søren's Blog
Random Ramblings

Søren Lund
Date: 2009-04-28 12:24
Subject: Considering to enter the Iron Man Blogging Challenge
Security: Public
Tags:perl

My blogging activity is kinda irregular. I would like to change that.

Maybe the Iron Man Blogging Challenge could be an incitement. One blot post about perl every week should be possible.

Oh, and I much enjoyed the original rant from Matt Trout about this competition.

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2009-03-23 07:12
Subject: M-x DONUTS
Security: Public


M-x DONUTS
Originally uploaded by silent11
It's monday morning and I'm in a Emacs-mode (you know, haven't really been hacking anything the whole weekend). Naturally this made my morning...

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2009-03-22 09:41
Subject: How I got my wlan back after a Ubuntu upgrade from 8.04 to 8.10
Security: Public

Yesterday I upgraded the Ubuntu on my Thinkpad t41p. It was a "simple" upgrade from 8.04 to 8.10, which was fully automated. But when the upgrade was done, and I rebooted the machine, the wireless network was gone.

Did some google'ing, but didn't find a solution - although other people reported the problem as well. Today, after sleeping and clearing my head, I figured out how to solve this.

The wireless card is an Atheros AR5212, this can be verified by issuing:

lshw -class Network

Atheros is supported in Ubuntu (I guess Linux in general) by the ath_pci module, which is part of Madwifi. The module is restricted, as it is not completely free software.

For some reason the restricted modules wasn't updated by the upgrade. The kernel was updated. Kernel and module versions must match, which they now didn't, and thus the ath_pci module didn't work.

The solution is simple, as root issue:

apt-install linux-restricted-modules-`uname -r`

then

modprobe ath_pci

After that the Network Manager automatically took over and connected me to the network.

Just to be safe I did a reboot, and everything still worked.

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2009-03-22 08:39
Subject: Getting Things Done with org-mode
Security: Public

I've been using GNU Emacs for many years. The first version I remember using was 18.52, which was released in 1988 - that's more than twenty years ago!

A couple of years ago I began using org-mode. Mainly for taking notes. But org-mode is capable of so much more, so I'm thinking that it's about time I looked into what and (especially) how to use org-mode more efficiently.

I will start by reading two tutorials:

GTD is short for "Getting Things Done", which is a book/concept by David Allen. Haven't read it, but the principles seems easy to grasp.

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2009-02-10 10:30
Subject: Stop Software Patents
Security: Public
Mood:busy

If you live in an EU country, go sign the petition:

stopsoftwarepatents.eu petition banner

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2008-08-14 13:40
Subject: Getting the kernel source code for ASUS Eee PC 900
Security: Public
Location:YAPC::Europe::2008
Mood:geeky
Tags:eee, linux, ye2008

After some googling, I'v found the linux-source tar-ball here:

http://update.eeepc.asus.com/p900/misc/

Now I can (hopefully) get my Cisco VPN Client up an running (an maybe VMWare Player as well)

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2008-07-19 22:07
Subject: Installing Unreal Tournament on a new Ubuntu
Security: Public
Tags:game, linux

I tried Counter Strike Source in my summer vacation, and that inspired me to begin playing games again...

Obviously, I wanted to play my old favourite: Unreal Tournament. I have the Game of the Year edition (also known as GOTY). To install on linux you need to download the installer - It's called ut-install-436-goty.run. I got mine from BeyondUnreal.

Open a terminal and change directory to where you downloaded the installer to. Issue the following command:

$ sudo _POSIX2_VERSION=199209 ./ut-install-436-goty.run 
Verifying archive integrity...OK
Uncompressing Unreal Tournament version 436-GOTY Linux install......
...................................................................

Notice the "_POSIX2_VERSION=199209" part? It's needed on modern versions of linux, e.g the Ubuntu I'm running. The installer for UT calls the head command in a way that is not supported anymore. Setting the _POSIX2_VERSION variable makes the head command backwards compatible.

Without setting the variable you would get this error:
Verifying archive integrity...tail: cannot open `+6' for reading: 
No such file or directory

Next you need to edit the to scripts: ucc and ut. You'll find them in the /usr/local/games/ut directory (if you installed in the default location).

In both files change the contents of the following if-statement:
    if [ -L "$fullpath" ]; then
        fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    fi

to:
 
    if [ -L "$fullpath" ]; then
        fullpath=`ls -l "$fullpath" |sed -e 's/.* -> //' |sed -e 's/\*//'`
    fi

Finally create a script called convert.sh (you can store in /usr/local/games/ut) and copy the following to the script:
#!/bin/sh
# FILENAME: convert.sh
#
# Change this to YOUR install-dir of UT
#
INSTALLDIR=/usr/local/games/ut

cd $INSTALLDIR/System

for i in ../Maps/*.unr.uz
do
ucc decompress $i -nohomedir
done

mv *.unr ../Maps

cd ../Maps
for f in *.unr
do
rm $f.uz
done

echo "..:: Done! ::.."

Now run the script:
$ sudo ./convert.sh 

This will unpack the map files.

Now you should be ready for a killing spree ;-)

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2008-03-11 23:02
Subject: Fixing the case of all files and directories
Security: Public
Location:home
Mood:tired tired
Tags:shell upper lower case

When moving files around between Linux/UNIX and Windows, you sometimes end up with files and directories with the wrong case. For example UPPERCASE names a suddenly lowercase or CamelCase becomes all UPPERCASE.

If you're (only) a Windows user, then you might think "the case of a filename isn't important - it's case insensitive." True, on Windows, but not true on Linux/UNIX. On a Linux system you can have three files called README, ReadMe and readme placed in the same directory, and they will coexists fine.

Most of the time such changes in case doesn't really break anything (they are just annoying). You might end up with the same file twice (remember "FILE.TXT" and "file.txt" can coexists).

But occasionally the case does matter. For example the name of Java source file should match the class name, including the case.

I just had a directory full of files and directories, that I'd moved from a Windows machine to a Linux machine. The original (and correct) case were all UPPERCASE, but that was lost, and all files and directories were now all lowercase.

To fix it I did the following from my bash-prompt:

$ for n in $(find directory| tac); do mv $n $(dirname $n)/$(tr [:lower:] [:upper:] <<< $(basename $n)); done

Let's see that again, as a "script":


for n in $(find directory | tac); do
  mv $n $(dirname $n)/$(tr [:lower:] [:upper:] <<< $(basename $n));
done


First line is a simple for-loop, but what is it looping over? The $(...) construct is called a command substitution. The commands inside the parenthesis are called and the output is fed back into the line. It's a bit line having a shell within a shell, you can even have command substitution within a command substitution, which I'm using on the next line. But back to the first line: the "find directory | tac" simply finds all files and directories withing the directory called "directory" (replace with you own directory name). The tac filter in the end reverses the list (note that tac is cat in reverse, funny eh?)

The inner part of the loop (the second line) renames (moves = mv) the file or directory we just found (and stored in $n) to a new name. The new name is constructed as "$(dirname $n)/$(tr [:lower:] [:upper:] <<< $(basename $n))". The dirname and basename command simple cuts off the directory and the filename parts of the complete path returned by find. But I want to make all name UPPERCASE, a simple call to tr does the magic (using the output from basename as input.

That wasn't so hard, was it?

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2008-03-05 15:29
Subject: Updating softlinks after moving the files they were pointing at
Security: Public
Location:Home
Mood:accomplished
Tags:shell softlinks

I'm currently doing some cleanup work on my main desktop computer. Not only is this "a good thing" in general, I'm also planning on replacing my Fedora Core Linux with a Ubuntu Linux. Although the latter does not require it, I'm planning on re-formatting the disk when installing Ubuntu.

Well, during my cleanup, I've shuffled my photos around a bit. The result is better, but today I stumbled across a directory that contains softlinks to a directory containing photos. I'd moved the (target) directory, thus none of the softlinked image files were readable.

How could I update the softlinks to point the the new location?

I ended up with this solution:

$ for f in *.JPG; do test -L $f && test -f /new/path/$f && rm $f && ln -s /new/path/$f .; done

obviously you should replaces /new/path with the new path to the files.

Here's a "script" version of the above one-liner:

for f in *.JPG; do 
test -L $f && \
test -f /new/path/$f && \
rm $f && \
ln -s /new/path/$f .
done


I'm looping over all files with the extension .JPG in the current directory. For each file i check if it's a softlink (test -L $f) and a file with the same name exists in the new location (test -f /new/path/$f). If both checks are true the softlink is removed (rm $f) and a new softlink is created (ln -s /new/path/$f .)

Pretty simple, eh?

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2008-02-21 16:12
Subject: Just installed ljupdate
Security: Public
Mood:happy
Tags:emacs livejournal

It's been a long time (once again) since I've blogged anything. And this post isn't much more than a test of ljupdate - a livejournal client for Emacs. If you can read this it worked ;-) Se more at http://edward.oconnor.cx/ljupdate/

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2007-10-18 16:46
Subject: Don't try this at home
Security: Public
Mood:embarrassed embarrassed
Tags:cooking microwave accident

Be careful what you wish, it might come through!

Yesterday i was thinking about my blog, and how it's been a long time since I've written anything to it. What do you put in a blog anyway? I know this is my Random Ramblings, but I usually need some kind of trigger - an event of some kind - to get me writing...

Well, that event occurring when cooking dinner.

I was roasting a leg of lamb. The lamb had been dry roasting in the oven for about 15 minutes. Next step was to smear a mix of sour cream and feta on top of it, and add some broth to the roasting pan. I had already mixed the sour cream and feta. As I didn't have any broth, I found a bouillon cube, and now I just needed some boiling water (actually I didn't need boiling water, but I thought I did).

How do you boil water quickly? Using the microwave oven of course! (Please queue the dramatic music now.)

I had mixed the sour cream and feta in the measuring cup that I would normally use to boil water in. But I had another measuring cup, which is actually a shaker. I poured the water into the shaker, it was too tall to stand up in the microwave oven, so I screwed the lid on before placing it in the oven and starting the timer.

Ping! Said the timer four minutes later.

POP! Said the lid when I touched the shaker, and (almost) boiling water shot out in my face!

Luckily the lamb needed an hour in the oven, meanwhile i took a cold shower.

I got burns on my face, lower arm and chest. But the 45 minutes cooling in the shower helped a lot.

t doesn't really hurt today, but the skin is still a little red.

2 Comments | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2007-09-04 23:21
Subject: Be fair - drink beer
Security: Public
Location:home
Mood:tired tired
Tags:beer

Went to the FAIR FÆLLED festival the previous weekend. It was arranged by the Danish Association for International Co-operation.
When we (Rune and I) stumbled upon the Mongozo beers we simply had to try them.

I kinda liked these extreme beers - but I'm a beer-lovin' guy - your milage may vary!

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2007-08-02 14:54
Subject: The New Simpson - Linda
Security: Public
Mood:amused amused
Tags:simpsons

Did you know, they added an extra character in the new Simpson's Movie? Apparently there was room for one more on the couch...

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2007-02-05 11:21
Subject: Precision of Java integer types
Security: Public
Location:Work
Mood:accomplished
Tags:java

I was having some problems with a numerical overflow, so I needed to know the precision of Java integer types. Could't find a simple overview, so I made one myself:

Precision of Java integer types
TypeBitsMin ... max values
Byte8-128 ... 127
Short16-32.768 ... 32.767
Integer322.147.483.648 ... 2.147.483.647
Long649.223.372.036.854.775.808 ... 9.223.372.036.854.775.807

The min/max values can be calculated like this: If n is the number of bits, then the min ... max interval is

-2^(n-1) ... 2^(n-1)-1

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2006-02-09 17:10
Subject: Just installed LogJam
Security: Public

I just installed the LogJam client for updating my LiveJournal.

The client can automatically detect the music your're listening to. However this only works out-of-the-box if your're using XMMS or RhythmBox.

I'm using Music Playing Deamon, and created the following little script (called it songname) which will do as the second comment line says:

#!/bin/bash 
# Prints out currently playing artist/songname or [none]

mpc | ( 
    read s; read t; # read first two lines: song info and status
    if [[ "${t:0:9}" == "[playing]" ]]; then 
        echo $s; 
    else 
        echo "[none]"
    fi
)

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2006-01-05 19:30
Subject: This is really funny
Security: Public
Mood:amused amused

Wow! I just stumbled across the
best blonde joke ever.

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2005-01-18 06:53
Subject: HSQLDB - we're almost there
Security: Public
Mood:sick sick

Well, I haven't finished my notes on using HSQLDB. So far I've written five notes:

  1. HSQLDB - how to install and create a database
  2. A very simple example - a simple console application for testing the database
  3. Java Server Pages - old school JSP, i.e. ugly and not the way to do it
  4. JSTL - using a tablib cleans up the JSP
  5. Using a Bean - splitting the code into a Bean
The examples so far, have all been queries. I need to write an example that puts data into the database (an update). This means expanding the last example to include a form that submits to a Servlet.

This is all very simple stuff, for a large (enterprise) project you should use some kind of framework (e.g. Webwork or Struts) and the database calls shold use pools and some abstraction (I like iBATIS)... hmmm I kinda need to write a conclusion.

3 Comments | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2005-01-05 17:36
Subject: HSQLDB Part 5 - Using a Bean
Security: Public
Mood:tired tired

I my previous entry I created a JSP Document, which is the way I prefer to write JSP's. However there were still a little too much coding going on in the JSP, so I've take the main part of the code and put it in a class. The class is then used from the JSP Document with a jsp:useBean-tag. I'm still using the core tags of JSTL to render the page, but have moved all database-related code to the Bean.

Here's first the new and improved JSP Document:

<?xml version="1.0" encoding="iso-8859-1"?>

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
          xmlns:c="http://java.sun.com/jstl/core">

  <jsp:directive.page contentType="text/html; charset=iso-8859-1" />

  <c:set var="title" value="Database Test" />

  <jsp:useBean id="bookmarks" scope="session" class="soren.Bookmarks" />

  <c:set target="${bookmarks}" property="database">
    <jsp:scriptlet>
      out.print(application.getRealPath("/database/demobase"));
    </jsp:scriptlet>
  </c:set>
	  
  <html>
    <head>
      <title><c:out value="${title}" /></title>
    </head>

    <body>

      <h1><c:out value="${title}" /></h1>
  
      <h2>Bookmarks</h2>
    
      <ul>
        <c:forEach var="row" items="${bookmarks.links}">
          <li>
            <c:out value="&lt;a href='${row.value}'&gt;${row.key}&lt;/a&gt;" 
               escapeXml="false" />
          </li>
        </c:forEach>
      </ul>

    </body> 
  </html>

</jsp:root>


This is actually what I would consider production quality code, except for the scriptlet code that sets the database property in the bookmarks Bean. This should be placed in a properties file or defined with JNDI in the servlet container.

Next create the Bookmarks.java file and compile it. Place the resulting Bookmarks.class file in a directory called soren in your WEB-INF/classes directory. This is still not production quality code, but it's getting closer.
package soren;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class Bookmarks {    
    String sql = "SELECT title, url FROM Bookmarks ORDER BY title";
    String database = "";
    HashMap links = null;

    public Bookmarks() {
	links = new HashMap();
    }
    
    public String getDatabase() {
	return database;
    }

    public void setDatabase(String database) {
	this.database = database;
    }       
    
    public synchronized Map getLinks() {
	Connection connection = null;
	Statement statement = null;
	ResultSet resultSet = null;
	    
	try {
	    Class.forName("org.hsqldb.jdbcDriver");
	    connection = DriverManager.getConnection("jdbc:hsqldb:" + 
						     database, "sa", "");
	    
	    statement = connection.createStatement();
	    resultSet = statement.executeQuery(sql);
	    
	    while (resultSet.next()) {
		links.put(resultSet.getString("title"), 
			  resultSet.getString("url"));
	    }       	    
	}
	catch (Exception e) {
	    e.printStackTrace();
	}
	finally {
	    try {
		resultSet.close();
		statement.close();
		connection.close();
	    }
	    catch (Exception e) {
		e.printStackTrace();
	    }
	}
	
	return links;
    }    
}

1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2005-01-05 17:11
Subject: HSQLDB Part 4 - JSTL
Security: Public
Mood:calm calm

I'm getting closer and closer to some code, that I would actually recomend using.

I the previous entry I created a crude JSP Page (old fashion style). The page works, but it is ugly and alternates between code and view contexts several times (code is the scriptlets in <% ... %> and view is the HTML). These are well known problems related to all Server Pages technologies. The remidy (when using JSP) is use tag libraries instead of scriptlets (this makes it more pretty to look at), and separate the code into classes (which makes it even more pretty).

Below is a better version of the previous JSP Page. Now as a JSP Document (i.e. it's an XML document). It uses JSTL (JavaServer Pages Standard Tag Library), which means that (almost) all embedded scriptlet code is gone.

<?xml version="1.0" encoding="iso-8859-1"?>

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
          xmlns:c="http://java.sun.com/jstl/core"
          xmlns:sql="http://java.sun.com/jstl/sql">

  <jsp:directive.page contentType="text/html; charset=iso-8859-1" />

  <c:set var="title" value="Database Test" />
  <c:set var="database">
    <jsp:scriptlet>
      out.print(application.getRealPath("/database/demobase"));
    </jsp:scriptlet>
  </c:set>

  <sql:setDataSource var="connection"
    url="jdbc:hsqldb:file:${database}" driver="org.hsqldb.jdbcDriver"
    user="sa" password="" />

  <sql:query var="resultSet" dataSource="${connection}">
    SELECT title, url FROM Bookmarks ORDER BY title
  </sql:query>
	  
  <html>
    <head>
      <title><c:out value="${title}" /></title>
    </head>

    <body>

      <h1><c:out value="${title}" /></h1>
  
      <h2>Bookmarks</h2>
    
      <ul>
        <c:forEach var="row" items="${resultSet.rows}">
          <li>
            <c:out value="&lt;a href='${row.url}'&gt;${row.title}&lt;/a&gt;" 
               escapeXml="false" />
          </li>
        </c:forEach>
      </ul>

    </body> 
  </html>

</jsp:root>

Post A Comment | Add to Memories | Tell a Friend | Link



Søren Lund
Date: 2005-01-03 23:58
Subject: HSQLDB Part 3 - Java Server Pages
Security: Public

Now in the previous installment of my notes regarding HSQLDB, I presented a very simple console program. It would connect to the database and lists the contents of the Bookmarks-table to the console.

Below is a webified version of the program. It's implemented as a single JSP file, TestDemobase.jsp. Store it in your webapps directory ($CATALINA_HOME/webapps/app/).

Note: this is absolutely not the way to do it. The code below is ugly and difficult to maintain. It is meant as a very simple example of connecting to a database from JSP.

<%@ page language="java" 
           import="java.sql.Connection,
                   java.sql.DriverManager,
                   java.sql.ResultSet,
                   java.sql.Statement" %>

<%!
  String title = "Database Test";
  String database = ""; 
  String sql = "SELECT title, url FROM Bookmarks ORDER BY title";
  Connection connection = null;
  Statement statement = null;
  ResultSet resultSet = null;
%>

<%
  try {
    database = application.getRealPath("/database/demobase");
  
    Class.forName("org.hsqldb.jdbcDriver");
    connection = DriverManager.getConnection("jdbc:hsqldb:file:" +
                                             database, "sa", "");
  
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);
  }
  catch (Exception e) {
    out.print("Unable do make connection database<br>");
    out.print(e);
  }
%>

<html>
  <head>
    <title><%=title%></title>
  </head>

  <body>

  <h1><%=title%></h1>

  <h2>Bookmarks</h2>

  <ul>

    <% while (resultSet.next()) { %>
      <li><a href="<%=resultSet.getObject("url")%>"><%=
          resultSet.getObject("title")%></a></li>
    <% } %>
  </ul>

  </body> 
</html>

<%
  resultSet.close();
  statement.close();
  connection.close();
%>

3 Comments | Post A Comment | Add to Memories | Tell a Friend | Link



browse
my journal
links
April 2009