Wednesday, December 10, 2008

Exchange plans

I haven't written for a long time, among the reasons I can say is that blogspot is unreachable from Turkey and whenever it is reachable, it has a long response time. That's not the only reason of course. I've been very busy. I've completed my Pardus Internship and received my TOEFL scores. I've scored 105 (R:27, L:27, S:22, W:29) in iBt. That's a great score for me, I needed 92 to apply for exchange to Carleton University in Ottawa,ON,Canada. Then I applied and I was the only student nominated for this exchange agreement. I sent a course list that I'd like to take and after some iterations, they registered me to Computer Vision and Applied Cryptography with 3 additional social courses. But I will consider dropping some of them when I arrive there, figuring out their course loads and the study time requirements. I need 2 courses to take and I'll graduate when I return back to Turkey if I don't face any problems.

After the registration, they sent me the letter of acceptance and I applied for Canadian Visa with Student Permit. I've sent the application documents wednesday afternoon and my visa had come back the next tuesday! It is wonderful that they are that fast! The next step was to look for a plane ticket. I've spent my 2 days in searching for the cheapest and the best alternative and finally I've found one on http://www.ekobilet.com. The plane will take off on 1st of January and fly to Frankfurt and then Ottowa waiting me 6 hours in Frankfurt airport. My return flight is on 28th of April.

Meanwhile, I had made some research on the accomodation and decided to stay in the residences with the suggestion of some friends there. Hasan, Serhat and other people I've found through facebook has helped me a lot in deciding what to do in the preparation process. I want to thank all of them, especially Hasan. I've applied for the residences on the Carleton Central web site and specified my preferences (quiet, wake up and sleep early etc.) and they offered me a single suite Leeds residence room. Rooms are great as far I see on the net. There are 4 single rooms around a common kitchen and there are 2 bathrooms which are shared by 2 people each. The residences get open on 3rd of January and I'm flying there 2 days before so I will need to stay somewhere. We'll look at it when the time comes. But the only thing I know for now is that Ottawa is freezing cold around -19*C.

Nowadays I'm looking for the payment options for the residence fees and the health insurance. And I have started to pack up slowly. I won't bring my laptop there as I need a new one so I have to organize my files and take the important ones with me. I also started to-know, to-bring, to-do lists to avoid any surprizes on the way. Hope I haven't forgotten much to tell :)

We're now on holiday and we have already passed half of it :( Now I have to do the master application organization and study the courses I'm currently taking: Bioinformatics, Software Engineering, Computer Networks, Cultural Anthropology and the Final Thesis. I and my friend Remzi are working on the Driver Recognition project of Assist. Prof. M. Taner Eskil. I'm planning to focus on that issue in another post but as far as I can sum, the project aims to recognize the car driver by analyzing the driving features (acceleration, velocity, engine RPM, brake, steering). We're trying to do PCA on the features to find the most dominant features to reduce the processing time.

Hope to write soon! :)

Monday, September 1, 2008

Internship @ Pardus

I've entered my TOEFL exam and it was pretty good, except for the listening part in which I lost my attention and thought about the examination software (it was written in Java but the Cambridge, Longman etc. preparation CDs are prepared in Shockwave as I saw). I asked myself: "Why don't they write them in Java too so that I can use them on Linux? And guess what, at that moment, a lecture was being given on the computer and I lost lots of details :D

Nevermind, I started my third internship last week, in TÜBİTAK (National Scientific Research Center) on Pardus Linux Distribution Project. It's been very beneficial for me so far. I've learned lots of things about software, python, GUI design and opensource. I want to share what I've learned in this blog as much as I can do. You can see examples here. I've written a program called Sahip, which is an XML generator. It produces the installation settings for Yali (installation software of Pardus) to perform silent installs.

PyQt4 GUI Building
Let's start with PyQt4 GUI building. I used to think that we could not import GUI files from python modules and this caused us to refactor our python code whenever we wanted to change the gui, unlike GTK with Glade (you can import XML from python). But I was wrong. There was some options I could follow. One of them is the kdedesigner module for python. But I used the other one, inheriting the compiled GUI.

After you design a GUI on Qt Designer 4, you can compile it to Python code with:

pyuc4 gui.ui -o mygui.py -x


and after that we can import and inherit it as written below:

from PyQt4 import QtCore, QtGui
from sahip.usergui import Ui_UserDialog

class UserDialog(QtGui.QDialog):
def __init__(self, caller=None, user=None):
QtGui.QDialog.__init__(self, None)
self.ui = Ui_UserDialog()
self.ui.setupUi(self)

self.ui.lineEdit.setText('test')
# All the other stuff here or in other methods.

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
UserDia = UserDialog(None)
UserDia.show()
sys.exit(app.exec_())


That's all!

Opening up a new dialog
I imported UserDialog class above and used it as a dialog.

def slotUserNew(self):
self.userDialog = QtGui.QDialog(self)
self.userDialog.ui = UserDialog(self) # caller=self
self.userDialog.ui.show()


Lists items with checkboxes

You can set all the items of a list have a checkbox near it with the following code:

for i in range(count):
item = self.ui.groupList.item(i)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
item.setCheckState(QtCore.Qt.Checked)


Handlers
In lists, I could only store the username of a user but the rest of the information should be stored somewhere else. That could be a dictionary, list etc. Dictionary was the most convenient for me but I had to define a dictionary for each list/combobox. That was a replication of code! So I wrote WidgetHandler, and specialized ListHandler, ComboBoxHandler to store them and defined addItem/removeItem, etc. methods to update both the dictionary and the widget. It was much more clear.


i18n

I have always wondered about internationalization and I saw that it was pretty easy. What you should do is to add the following code to the beginning of each of your files you want to be translated.

import gettext
__trans = gettext.translation('sahip', fallback=True)
_ = __trans.ugettext

and you will use _('string') instead of 'string' if you want that string to be translated. And here comes the pot file generation part. As you can see the example project on the link above, I have a tools, po and sahip directory. So I recommend you to create such directories. I put pot generator sh file into tools dir and po/pot files into po dir. After creating an empty po dir, you can execute the following script (above po dir)

#!/bin/bash
LANGUAGES=`ls po/*.po`
set -x

xgettext -L "python" -k__tr -k_ sahip/sahip sahip/*.py -o po/sahip.pot
for lang in $LANGUAGES
do
msgmerge -U $lang po/sahip.pot
done

As you might understand, this script crawls through the given paths (sahip/sahip and sahip/*.py) and generates pot file by reading the py files and main (non-extensioned) sahip file. You will then find the pot file in your po directory. You can translate and rename it to lang.po format (tr.po, de.po, es.po). Then the python setup script will probably compile po file into mo file and copy it into proper place.


Setting Icon
  1. Create a directory called images in the same directory of your codes.
  2. Put an image file in it, such as icon.png
  3. Create a qrc file such as resources.qrc and fill it with the content

    images/icon.png


  4. Open your GUI with Qt4 Designer and click on ... button of windowIcon on the Property Editor when main form is selected.
  5. A dialog will be shown, click on pen and then the open button (middle). Select the qrc file you created.
  6. Select the icon appeared on the right side of the dialog and click OK.
  7. Save the GUI.
  8. On the console, apply the following command:

    pyrcc4 resources.qrc -o resources_rc.py

  9. Generate your gui py file with pyuic4 and that's all!
Publishing the Code
I needed to copy YALI setup.py file and modify it for sahip. This file compiles po and qrc files, and then copy required files to the system for installation. Then I wrote a digestrelease.py script which copies the program directory to desktop and removes the unnecessary ones. Then the packager.py file compresses the directory and sha1sums it, updates a sample pisi pspec.xml file with the sha1sum, uploads the compressed targz file to ftp server and then build the pisi package, and install it.

It was a good way of automation for me. I could make modifications and try the result in seconds. I might have written this entry too confusing, sorry but I don't have much time. My next project is to develop a web site where files can be searched within the pisi packages so that for instance you can find which package the 'ls' file comes from. I'm currently writing the database generator and after I'll pass to the Django side.

Friday, August 8, 2008

Les Miserables

I've just finished the book Les Miserables from Victor Hugo. Yeah, it's pretty late for me, for a 21-old boy(or should I say man)! In my childhood, this novel was tought to be tough for children, so hard to read. I even remember my mother saying "Look at her! She even read the Les Miserables" for somebody whom I don't remember. Maybe I was really too young and told my subconscious even not to attempt to read that book or forgot about it later.

By the way, it was pretty easy to read it now. Because it was the Penguin simplified edition(3000-words Advanced) which I had bought in High School by mistake. I just had misunderstood which reading books we had to buy and bought the ones for the English Language class, who study English in detail. So I did not attempt to read them, until now. Getting prerpared for the TOEFL exam, I see that I have weakness of speaking and vocabulary. So I tought this book could help some. Yes, I learned more than 20 words.

The book is very beautiful, indeed I think the writer has some sadistic side because I felt really bad in the first 4 chapters(how can people be so cruel!). But afterwards, it tended to make me so curious abot what would be the next pages that I read it too fast. As a result, I probably missed a lot of words to learn. I recommend this book to be read!

New electrolyzers open up the way to Solar Century

In the earlier days of this week, while watching CNN International, I run into a wonderful news. The visitor was a professor from MIT and they were going to talk about a recent invention on storing solar energy.

As you may know, solar energy is known to be unlimited as long as the sun lives but limited as it can't be used efficiently because not only the solar panels can't absorb all the energy but also the energy can be obtained only during the daytime. It seems that the absorption is still a problem but the recent news promise in storing the excess energy.

The scientists at MIT, have found a new method to store the excess energy by dividing the water into its ingredients, Hydrogene and Oxygene. Heey, this is already being done worldwide, you might say. But this operation needed high maintenance costs and abnormal operation conditions(temperature, pressure, etc.). This new method, inspired by the photosynthesis, uses a new catalyst consisting of cobalt metal, phosphate and an electrode to produce Oxygen and another catalyst like platinum to produce Hydrogen and does not require any special conditions for the reaction to start.

As this is an easy-implementing method of storing energy, it is tought to change the world, contributing to the works on solutions for the global warming problem. But as the proffessor says, it will take 8 years for us to have these sets on our roofs. I wish it was closer if it was that easy to implement but maybe the other (efficient absorption) problem needs to be solved in order these products to be more efficient.

By the way, I have finished my internship. Nowadays I'm preparing for my TOEFL exam and working on Python as usual. My Python presentation went very well and I saw that most of the aspects of Python could be introduced in 2 hours! Such a beautiful language...

Friday, July 25, 2008

BOLO and Python

We worked on BOLO for some time but we found it very complex. The code is unnecessarily too much (less code could achieve the same functionality). One manager for each POJO is defined although those manager methods could be defined in POJOs. So, crawling in the code is a funny(!) way of spending time for us (me and Melih). We tried to implement the search by status functionality but got stuck at the enumarator types for the Status class properties. Showing them on JSF and selecting them is a problem. Then we tried to add a timestamp on the CVs uploaded. But finding the code where the file is uploaded, where the filepath is inserted into the database were the problem in that case. Moreover, the service had been giving "Out of memory" errors after 10 minutes of run.

Getting bored from all these stuff, I tried to write the model in Python/Django. It was a good try. I found a model to UML Diagram script and generated a database model diagram. Showing the diagram, Melih was impressed by the easiness and practicality. Then he wanted me to show my work to the team leader and I showed what I did:
But he did not welcome my work as much as I expected: "Good, but when your internship ends, there's nobody to maintain it here. I don't want my staff to learn Python for such a thing. Because nobody uses Python". I didn't know what to fell sorry for. For my effort, or the misknowledge for Python. Nevermind, I'm spending my time with some trying on that BOLO stuff, and some with fixing some errors in my Python projects.

By the way, some colleagues wanted me to give a talk about Python and how it is used. I'm going to get prepared for it and give a brief presentation called "Python for Java Geeks". So, first of all, I have to find some resources on the differences between Java and Python so that making it easier to understand, I can go faster. Maybe in 3 hours, instead of 8 hours that I had given at school for programming newbies.

Tuesday, July 22, 2008

BOLO

After the crazy boring minutes of trying to develop a new project with appfuse, my guide told me that he has found a project of his colleagues: BOLO. This is an interview manager, developed using appfuse (JSF+Hibernate) as a final thesis in Ege University. We are going to improve it by fixing some lackness and adding new features on it. We are going to work on it this evening (overtime) to understand its structure. Now, I'm preparing my internship report, filling the part for SOA. This is at the same time a preparation for my SOA presentation which will be at the end of my internship.

Sunday, July 20, 2008

Google Code Jam

Last Thursday, I saw a blogpost on a Python related RSS, mentioning about the Google Code Jam. I saw that it was a programming contest and took a look at it. Reading the rules, I saw that there was a 4 - 8 minute limit. At first I thought that it was the time to solve a problem that is given to you. I thought it was a crazy idea to solve a problem in 4 minutes and code it. As I was at the company, I put it off to the evening for details. When I came home, I did some stuff I needed to do and when I realized that the limit is not for solving but submitting the output after downloading the input, I was angry with myself. Why didn't you read it! There had been 4 hours left. It was 10 pm and the contest was going to end by 2 am. So I started to look at the questions. There were 3 questions of which I had to solve 1 of them correctly to qualificate to the first round. I needed to code to solve the problem and then download two (small and big) inputs and submit them.

I started with the first question, here you are a summary: "In a planet, there are some search engines. When you search the name of a search engine on itself, the planet explodes. So you shouldn't search for Gogool on the Gogool engine. Scientists developed a central system to prevent this. This system forwards the search requests to the engines other than the engine with the name in the request. The question is that with the least switch between the engines, how many switches are required to serve all the search requests."

I developed a greedy algorithm. First, I was going to determine the indexes of the engines where they were first seen. Then I was going to find the furthest one and serve the request before that with this engine. For example below, the furthest first seen engine is NSM. So I should handle the first 4 requests with NSM:

Yehhaw
Yehhaw
Gogool
Dont Ask
NSM
Gogool
DontAsk
DontAsk
Gogool
Yehhaw

Then I had to remove the indices below 5 which belongs to NSM. Then I looked ahead like having a new beginning from NSM:
Gogool
DontAsk
DontAsk
Gogool
Yehhaw

So, it is now obvious that the index 11, (i.e. Yehhaw) is the engine to be used for serving 5-10 (NSM-Gogool). And then the previous indices would be removed after that and so on. The input files were large with the 20 different cases in the number of various engines and the number of searches.

I coded this algorithm on Python and when I ran the sample input, it was successful. Then I downloaded the input file but it told me that my output was incorrect. After the contest, I learned that there were only 3 digits wrong, possibly caused by boundary checking or exceptional conditions.

After the wrong answers, I decided to look for the other questions and started the second question, the train question. There were two towns, A and B between which there were train routes. Input file consisted of the turnaround time for the trains, the timetable from A and timetable from B. The question is that with how many trains at minimum you can handle these timetables such a way that a train coming from A, after completing the turnaround can handle the closest train route on the timetable B to go back to A.

A: 9.00 - 12.30
Turns around in 5 minutes
B: 13.00 - 15.00
The turned around train undertakes the 13.00 route and goes to A. So there's no need to have an additional train to go from B to A at that time.

At first I did not have a clear algorithm but I thought it would be great if I could match the trains as complement and show the complement pairs on the screen so that I could draw inferences on it. Maybe I could develop a matching algorithm after marking them as complements. But the things were not the same as they seemed to be. When marking as complement, I fell into a infinite loop, the train from A matched B and the train from B matched A and A did the same, etc ... They matched each other again and again. Then I realized the time was nearly up. I could not do anything but to post my code and the small output. They were incorrect, of course. But at least a hope that they would look at the codes.

So, I could not qualificate to the first round. I wish I could know it before. For months, they had been practicing for the contest and I hadn't ever heard about it. It was the contest day (last day) when I saw it. So all I can do is this in four hours. Maybe I can do better next year, using all the 24 hours. :)

Friday, July 18, 2008

appfuse

I have never seen such an un-documented framework, tool or whatever it is! You just can’t know what it is and what you have to do. There are lots of directories with the same name and nobody describes you which directory is for what. It always errors... I don’t want to use it, I want my Python baaaaaaaaaack!

Wednesday, July 16, 2008

First days in the Alcatel-Lucent Internship

Hello everybody, now I decided to write here about my internship journeys. I won’t be able to write all the details of my previous days but I’ll give you some summary. First of all, I normally write on my personal web site http://www.emrealadag.com in Turkish and I had my first internship as a Network intern in Tellcom, a telecommunication company and now I’m in Alcatel-Lucent, as a Software intern.

The first day, I was taking a look at the Eclipse and the J2EE plugins when they saw me that I’m using Linux and asked me to install one on their server which needed to be re-installed. Then I installed Fedora 9, but with a wrong preference: KDE4. It was a terrible experience. I could not do any kind of basic desktop operations. We could not install gnome on it either just because we didn’t know the package names required for it. Then I installed RHEL5 and installed/configured Oracle 10g Enterprise server, for a test purpose. After that, I installed and configured the VNC server. Both were to launch at startup. Then I wrote some documentation about it. You can reach them here: Oracle 10g on RHEL5 , VNC Server on RHEL5.

I worked on the pre and post configurations a lot. So I wanted to automatize this process. So I worked on a Python Script, pyorainstaller for two days. This script does all the pre-configruation like configuring kernel parameters, security levels, some prerequisite checking, etc. and post-configuration like hostname and launching at startup. You can download this program from its site.

I worked a lot on testing this site, as I did not have any testing machine at work so I had to test it on my desktop PC at home which meant I had to spent my nights with it. Then I was faced with JSF. They told me that I was going to develop two projects with JSF and gave me a book called Core JavaServer Faces 2nd edition. There were examples on glassfish but the examples did not work :) So they told me ’Nevermind, just use Tomcat.’ But there was nothing about Tomcat in the book. So I got crazy; because there was no short and smart tutorials for the first learners. Then I finished the day, looking over the web sites. Some collegues told some stuff about the JSF architecture but there were too many things to keep up in mind. I cought the general idea up.

Then at the weekend, I upgraded to Pardus 2008 on a clean system and on Tuesday, I worked on Tomcat+JSF to build a login form. I wanted to get the session information and used the core jsf libraries but they conflicted with the Tomcat’s catalina. I just was going to fix that but they told me to move on appfuse. As I was told, I am going to develop an HR system for the employment, managing the reviews about recent employee candidates.

Appfuse is an project-automator which gathers the tools required for you depending on your project-type. I now just created a new JSF Modular project and run the mvn command but it gave a strange error:

Embedded error: The following error occurred while executing this line:
/home/emre/dev/hr/web/src/test/resources/web-tests.xml:52: Wrong document title found!. Expected value ".*Login.*" but got "Error - Error calling action method of component with id passwordForm:execute | AppFuse"

I’m now trying to figure out what it is. I can’t do anything just because of these silly errors.