Kristian Lunde

Archive for May, 2008

Using GNU screen

without comments

Recently I’ve been the victim of a really unstable internet connection. This lack of stability has made me a great fan of the GNU screen command in unix systems.

GNU Screen is a small piece of software that lets you initiate a number of terminals inside a single terminal window. The great advantage with screen is that if you loose your internet connection, the screen terminals and operations inside these terminals still run on the server, contrary to operations running directly on the terminal window of your external server.

Screen is real simple and in most cases you only need a few important commands:

  • starting a session
  • listing all running sessions
  • attaching to a session
  • de attaching from a session
  • killing a session

Creating a new screen session

Command: screen

kristian@Saturn:~$ screen 


Listing all active screen sessions

Command: screen -ls


kristian@Saturn:~$ screen -ls
  1. There are screens on:
  2.  11179.pts-0.Saturn (Detached)
  3.  11114.pts-0.Saturn (Detached)
  4. 2 Sockets in /var/run/screen/S-kristian.

Attaching to a session

If only one screen session is active the command below will take you directly to the session. If there are several sessions running the command below will display a list of running sessions. To choose one of them the screen -r command has to be followed by the session name.

Command: screen -r

Example of several screen sessions running:

kristian@Saturn:~$ screen -r
  1. There are several suitable screens on:
  2.  11179.pts-0.Saturn (Detached)
  3.  11114.pts-0.Saturn (Detached)
  4. Type "screen [-d] -r [pid.]" to resume one of them.

Example of attaching to a screen session:

kristian@Saturn:~$ screen -r 11179.pts-0.Saturn

De attaching from a session

De attaching from a screen session is real simple just remember the key combinations :P

Hold the CTRL key down, press A, then D. Thats it.

Killing a screen session

Killing a session is as simple as de attaching from one, just use the correct key combinations.

Keep the CTRL button down, press A, then K.

Written by Kristian Lunde

May 27th, 2008 at 10:14 pm

Posted in Linux

Tagged with ,

Writing exceptions in PHP

without comments

Fredrik Johan Holmström has a entry on his blog about writing exceptions in PHP. He points out that several of the large PHP framework assumes that an exception is a fatal error, and that this may be a flaw in the design.

An Exception is not necessarily a fatal error and it should be the responsibility of the code that catches the exception to determine if it is a fatal error or not.

The blog entry got me thinking, and yes I’ve done that mistake a few times myself, I’ll do it right  the next time I write an exception in PHP,


Written by Kristian Lunde

May 24th, 2008 at 11:48 pm


without comments

Mats forwarded the 123-meme to me today, I’m not entirely sure what 123-meming really is but the instructions are:

  1. Pick up the book closest to you
  2. Open page 123
  3. Find the 5th sentence…
  4. …and publish the next three sentences
  5. Link to 5 other bloggers and tell who linked you

The book closest to me is: AGILE PROJECT MANAGEMENT WITH SCRUM, on page 123, sentenc nr 5 is:

During this day, the nonfunctional scaling requirements for this particular project are determined and placed in the Product Backlog. For example, if you are scaling the project to use multiple teams, the following nonfunctional requirements should be added to the Product Backlog:

  • Decompose business architecture to support clean-interface multi-team development.
  • Decompose system architecture to support clean-interface multi-team development.
  • If necessary, define and implement a development environment to support multi-team collocated or distributed environments.

I pass this 123-meme on to Erik.

Written by Kristian Lunde

May 23rd, 2008 at 8:13 am

Posted in Misc

Google doctype

without comments

Yesterday Google released their internal documentation of html, css and javascript. This is a brilliant resource for us web developers.


Written by Kristian Lunde

May 15th, 2008 at 1:07 pm

Cheat sheets

without comments

When talking about cheat sheets, has a list of a few good cheat sheets. I’ve actually printed some of them at work and taped them to the wall next to my computer.

Thanks to Dave Child for doing the work of putting together these sheets.


Written by Kristian Lunde

May 12th, 2008 at 9:19 pm

Posted in Databases,Misc,PHP,web development

Tagged with , , ,

PostgreSQL cheat sheet

without comments

I often have a blank hole or two when it comes to the basic PostgreSQL commands, and have to do a look up in the documentation, Kitt Hodsden has posted a nice little cheat sheet with the most common basic postgreSQL commands.


Written by Kristian Lunde

May 12th, 2008 at 9:11 pm

Posted in Databases,PostgreSQL

Tagged with redesigned

without comments

Tonight I did a quick google search for a new wordpress design for, I came over this page where I downloaded the earthtones design and added it to

Written by Kristian Lunde

May 11th, 2008 at 9:23 pm

Posted in Misc,web design

Tagged with ,

Adobe Kuler

without comments

Are you sick of never finding the correct match of colors when developing a web application. Adobe solves your problem with their kuler system. This site contains a lot of matching color sets, and you can with ease find a suitable color scheme for your next web application.


Written by Kristian Lunde

May 7th, 2008 at 1:32 pm

Posted in web design,web development

Tagged with ,

Micro languages

with one comment

Mats posted an interesting article about micro languages,

Written by Kristian Lunde

May 5th, 2008 at 10:27 pm

My first introduction to java and databases

with 2 comments

The other day I did a complete reconfiguration of java on my system. Tonight I started to play around with java and postgresql. I installed PostgreSQL 8.2 (yes I know 8.3 is out there), and downloaded the jdbc driver for PosgreSQL.


After installing PostgreSQL, you have to add a user to the authorization file pg_hba.conf located in /etc/postgresql/8.x/main on a ubuntu system, remember to restart the postgreSQL server after editing pg_hba.conf. When that is done add the same user to the postgreSQL server either by using postgreSQL’s createuser function or by logging into the postgreSQL server and doing a SQL CREATE USER, I did the latter one.

  1. CREATE USER kristian WITH PASSWORD 'xxxxxxxx' CREATEDB;

This enables me to do a regular access of the database with:

  1. kristian@Saturn:~$ psql -U kristian crawler
  2. Welcome to psql 8.2.7, the PostgreSQL interactive terminal.</code>
  4. Type:  \copyright for distribution terms
  5. \h for help with SQL commands
  6. \? for help with psql commands
  7. \g or terminate with semicolon to execute query
  8. \q to quit
  10. crawler=#

My table:

  1. crawler=# \d document;
  2. TABLE "public.document"
  3. COLUMN     |            Type             |                       Modifiers
  4. —————+—————————–+————————
  5. id            | integer                     | NOT NULL DEFAULT NEXTVAL('document_id_seq'::regclass)
  6. url           | text                        | NOT NULL
  7. document      | text                        | NOT NULL
  8. ts_downloaded | timestamp without time zone | DEFAULT now()

Data in the table:

  1. crawler=# select * from document;
  2. id |          url          | document |       ts_downloaded
  3. —-+———————–+———-+—————————-
  4. 1 | | jalla    | 2008-04-19 21:11:11.805482


First thing to get the postgreSQL jdbc driver to work is to add it to the java classpath, and of course copy the actual jar file to its correct location, for instance /usr/lib/jvm/java-6-sun- is my java library path.
My classpath:

  1. /usr/lib/jvm/java-6-sun-

Now its about time to write some actual code:

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement; </code>
  8. public class DatabaseTest
  9. {
  10. private Connection connection = null;
  12. private static final String USERNAME = "XXXXX";
  13. private static final String PASSWORD = "XXXXX";
  14. private static final String URL = "jdbc:postgresql:";
  15. private static final String DATABASE = "crawler";
  17. public DatabaseTest()
  18. {
  19. try
  20. {
  21. connection = DriverManager.getConnection(URL + DATABASE, USERNAME, PASSWORD);
  22. ResultSet rs = doQuery("SELECT * FROM document");
  25. System.out.println(rs.getString(2));
  26. }
  27. catch (SQLException e)
  28. {
  29. System.out.println("Database Exception!");
  30. System.out.println(e.toString());
  31. e.printStackTrace();
  32. }
  34. }
  36. public ResultSet doQuery(String sql)
  37. {
  38. ResultSet rs;
  39. try
  40. {
  41. Statement stmt = connection.createStatement();
  42. rs = stmt.executeQuery(sql);
  43. return rs;
  44. }
  45. catch (SQLException e) {
  46. e.printStackTrace();
  47. return null;
  48. }
  49. }
  50. }

Trying to execute my script:

  1. kristian@Saturn:~/workspace/crawler$  javac
  2. kristian@Saturn:~/workspace/crawler$  java -Djdbc.drivers=org.postgresql.Driver DatabaseTest

It works :D The installation and initial setup went pretty much by the book, but as a PHP developer I must say that I’m a little bit disappointed, JDBC cannot compare itself to the PHP PDO extension yet. But then again, maybe I just need to get to know the JDBC library better. Anyhow it was fun writing this little java app and refreshing some of my java skills.

Written by Kristian Lunde

May 5th, 2008 at 10:14 pm

Get Adobe Flash player