Monthly Archives: noiembrie 2007

Pagerename

Posted by on noiembrie 16, 2007
Fără categorie / No Comments

Pagerename.py is a small Python script that integrates in the pywikipedia framework. For those of you who don’t know, it’s the main tool used by robots on Wikipedia. I wrote the script a good while ago, when I needed to quickly rename several hundred pages on the Romanian Wikipedia. The script was designed to make the same modification on all the titles from a series of pages. You can remove parts of the title or add a new text at the beginning and/or and of the title.

In the mean time the guys at pywikipedia wrote movepages.py, a somewhat similar script. Nevertheless, in September I decided to propose my script for inclusion in pywikipedia. Unfortunately, it didn’t make it, however it was included in the project’s encyclopedia, at http://botwiki.sno.cc/wiki/Python:Pagerename.py. I’d love to hear your opinion about the script. Please leave any comments you might have below.

Using Serialization with non-blocking sockets

Posted by on noiembrie 11, 2007
Fără categorie / 2 Comments

The most common way to make a server in Java is to create a thread pool and associate each request with a thread. Java5 offers a special class called Executor that can help you with the task. However, if you ever needed to make a server which can handle thousands of connections, you know this solution doesn’t scale very well. Most processors can’t handle more than a few hundreds of threads.
The solution is to use non-blocking sockets, a feature introduced in java 1.4 (the java.nio package). However, this has an important drawback: you can’t use the getInputStream(), getOutputStream() functions from the Socket class to serialize objects. The reason is simple: with non-blocking sockets, there is no way the system can guarantee that the whole object has been sent/received.
You can however „trick” the virtual machine by using explicit Streams. You have a simple example below. We try to send an object with the Message type.

  • The sending end

    Message outgoingMessage;
    SocketChannel socketChannel;
    //we open the channel and connect
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(outgoingMessage);
    objectOutputStream.flush();
    socketChannel.write(ByteBuffer.wrap(byteArrayOutputStream.toByteArray()));
  • The receiving end

    SocketChannel socketChannel;
    ByteBuffer data;
    //we open the channel and connect
    socketChannel.read(data);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data.array());
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    Message message = (Message)objectInputStream.readObject();

The code works if you receive the whole object or more than one object (the readObject() function reads exactly one object). However, I had some issues with reconstructing the object if it arrived in multiple pieces. Any suggestions on that part would be useful.
Here are some resources that I found useful: a discussion at forum.java.sun.com and another discution about the subject.

Evolved Interfaces

Posted by on noiembrie 07, 2007
Fără categorie / No Comments

That’s the name of one of the courses taught in the fifth year at the my faculty (InterfeÅ£e Evoluate is the Romanian name). If the name doesn’t tell you much, don’t be alarmed. It’s about XML, HTML, CSS and other web technologies. While I haven’t chosen this course, I have to say I find it’s project to be pretty interesting: the students have to create a website and a blog and promote it. They receive points for their trafic.ro ranking and their PR (well, actually that’s dumb, because the last update was just before the start of most websites and the next one will probably be after the exam 🙂 ).

Anyway, let me show you some of the most interesting things I found while looking at their websites (all links are in Romanian, sorry for my foreign readers:():

  • the ZEIT team has some quizzes about XML and CSS; pretty simple, but interesting nevertheless.
  • this anonymous team (greetings Radu 😉 ) has apparently the best site and blog promotion. No wonder, link exchange is still a good way to promote yourself. Keep up the good job guys, and try to write more on your blog.
  • other teams have tried to get their own domain, from the free .tk to the more expensive .com, .net and .com again. 🙂

That’s it for now, when I’ll find more interesting content from my colleagues, I’ll post it.

Automatic MySQL Backups

Posted by on noiembrie 06, 2007
Fără categorie / No Comments

Ever had a database crush before you made any backups? Then you now how important it is to have regular backups. But why bother doing them yourself, when you can have a script to do it for you?

automysqlbackup.sh is a simple script that automates your backups. It keeps daily backups for the last week, weekly backups for the last month and monthly backups for older versions of the database. The files are gzipped text files, so you can easily check them manually.

The script has many options, including the possibility to send emails with the new backup files and to use a single file for multiple databases.