Sunday, September 28, 2008

Build Numbers

Having an automatic versioning for your project is quite useful. Every time you build it, you get a new build number, so you can distinguish between the builds, and make sure your users are always using the latest version (without comparing the exe files).

Today I wanted to make that trick work automatically in C#. That means I have a C# application, which I want to have automatic "Assembly Version". How can this be done in Visual Studio (need to try for mono as well)? Simply. Edit the AssemblyInfo.cs file, and delete the AssemblyFileVersion section. Also, change the AssemblyVersion to something like:

[assembly: AssemblyVersion("1.0.*")]

The * represents the "degree of freedom" for build numbers. That means that the sub-versions after the * (in this case, the third and the fourth numbers) would be automatically incremented by Visual Studio. Actually, it is a number which represents time since January 2000.

Now, all we have to do is to print this value from our code, which usually would be in the "About" dialog. The snippet that gets the version is:

System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

Conversion to string can be done with ToString(). That's it.

And in another (related) topic: I became addicted to stackoverflow. I find myself looking for questions which I can answer. Already earned two bronze medals and 76 reputation points.

Friday, September 19, 2008

Migrating from MySQL to SQLite

Last week I had a meeting with my university project's client (and mentor). During that meeting it was clarified that the resulting product should be easily installable. Since the code is written in Python and our DB of choice was MySQL, this could pose a problem. This means deploying the project would require installing MySQL, Python, the MySQL Python library, configuring the DB (creating users, importing data) and so on. Since such administration is beyond the scope of the project, and I don't expect my users to be DBAs, I started looking for alternatives.

The most obvious solution is to use some embedded DB which doesn't require any server software. This is where most people (I think) would choose MS Access. My intention is to be as portable as possible, and I don't like Access a bit, so I though about migrating to SQLite. I wasn't aware to the fact SQLite is quite a complete DB solution for such cases as my project. So I made the choice.

The next step was to migrate the schemas and data from the already running MySQL DB. My first Google search raised only complicated solutions, or costly solutions. Just before giving up, I started looking for some Windows GUI for SQLite, to allow me to insert the data manually. This is when I came across the freeware (not opensource) SQLite2008 Pro. Without the intention, I found myself with a nice tool which allowed my importing my existing MySQL schema information, and data, into SQLite. Even more surprising, the tool converted more complicated data types, such as auto_increment columns (autoincrement in SQLite).

Finally, some code modification was required. Luckily, I'm quite experienced with designing software that relies on databases, so I had a separate Python module which encapsulates DB specific logic. Importing the pysqlite2 library and adding two lines of code was all that needed to convert the entire application (over 2000 Python lines of code, mostly relying on DB) from MySQL to SQLite. Now the deployment of the project was stripped down to: install Python, install Python sqlite library. Cool.

Monday, September 15, 2008

Having the right tool for the job

As I wrote before, in the past several weeks I've been looking for a job. Since I have quite a lot of experience (at least I'd like to believe so) in several IT fields (SysAdmin, DBA, developer, management and so on), I decided it'll be nice to add something extra to my resume, and find a job which involves stuff which previously were my hobbies (developing was and still a hobby). This lead me to find a job in the security field. In my new job I'm responsible of both research (which is very important for me) and development of complamentry tools.

I guess that the research part would influence my blog in the future, since finding new and exciting stuff is a good reason to blog. This is why now I'll concentrate on the development part.
Developing software in my group is quite a versatile task. This is due to the fact that every tool developed, has to be very oriented to it's purpose, and most tools won't be used outside my group (though some tools does). The meaning of all this is that I get to choose how to develop each solution. If Python's quick modeling ability is required - Python it is. If it's Perl's regular expression power - Perl it is. Heavy lifting? - .NET or Java would do.

Just as the research part of my job involves me using the right security tools (sandboxes, forensic tools, decompilers etc.), so does the development part. This lead me to look for a good place for resources and Q&A, so I could complete my programming tasks faster. As I wrote before about stackoverflow, this is the right tool for the job. It think it'll grow very rapidly, and would be a great place for a great community to develop.

Last, what facinated me most, is the fact I didn't have to register to stackoverflow. I'm already registered via the same account from which I blog right now. That's right - stackoverflow uses OpenID, so I feel safer and there's one password less to remember. Great work.

Saturday, September 6, 2008

DNS query in Perl

As mentioned before, I'm doing a project which involves email spam research. Part of the project requires me to query DNS servers for their TXT and SPF records, since they contain valuable information regarding which servers from a specific domain are allowed to send mail.

When we (my partner and I) started coding the project, we decided Python would be our primary language, since we both know it, and it makes life easy. This was true, even on the difficult parts of using a database (MySQL), connecting to SMTP/IMAP/POP3 server, etc.

Last week I stumbled into a block, when querying a DNS server was required. Usually, I'd use the output of 'dig' or 'host', but I cannot be sure the project would run on a platform that has those tools. My second try was to use Python modules (pydns etc.) which should solve this problem, but they were all buggy/undocumented/not-working/too-complicated-to-use.

The annoying part is that I know how to do what I want in Perl:

use Net::DNS;
my $res = Net::DNS::Resolver->new;
my $answer = $res->search('', 'TXT');
print $answer->string;

And that's it. 4 lines of code. Still I hadn't found a decent Python-way to do this. So now I'm using Pydig to query DNS servers. Over 1200 lines of code. Pretty big hammer to solve a tiny problem.

If any of you know a better way to do this in Python, I'd love to hear about it.

Great music service

The first time I heard of Pandora, was few years ago, when it was still accessible to users outside the US. I used it for some time, and stopped using it when it stopped "choosing" music I like. The concept of listening to music on-line is something I like since it's a very convenient way to discover new music, or have your music wherever you are (assuming you have an internet-connected PC).

About a year ago, a friend told me about deezer. Ever since, I'm using it regularly. It works pretty well, has huge database of songs, sound quality is good and it has nice features. Every once in a while I find myself looking for some old songs that there's no way I'd find in other places, and then I sit back and listen to it... that's fun. You should all try it. Opening an account would allow you to store playlists and enjoy several more features.

A nice feature of deezer allows me to play to the song I was listening to when writing this post, so you could enjoy it as well:

Discover Extreme!

Wednesday, September 3, 2008

Bureaucracy vs. Technology

Sometimes I think I grumble to much in my blog, since there are more posts in which I say bad things about stuff that annoys me, that there are about pure technology or CS related stuff. Unfortunately, this one would be no different. But I'll try to connect it to technology as much as possible.

Today I went to buy a used (second hand) car. The person from whom I'm buying the car is a real nice person, who wishes to sell the car due to relocation to the US. After going through the standard procedures of checking that the car is alright mechanically and electronically, we agreed to meet this morning at the post office, for conveyance ("ownership transfer"). As this is not my first vehicle, I'm familiar with this procedure, and thought everything would be just fine, and I'll be driving home with my new car. So I thought.

At the post office, they check whether there are any limitations regarding selling the property, such as whether it is confiscated or stolen. Since I already checked it beforehand, I knew there shouldn't be any problem. After they ran the check in their computer, they told us "sorry, you cannot convey this vehicle, we don't know why". We asked what the problem is, but they kept repeating that sentence, without supplying any reason. We both thought it was weird, so we headed to the closest ministry of transport office.

At the ministry of transport office there were HUGE lines, unlike any other office in Israel, including banks, post offices, etc. Since we had no choice, we stood there. That took about an hour. As our turn finally arrived, we thought we're gonna find out what is this all about, and close the deal. Unfortunately, we got a new answer "The police have ordered to remove the car from the road, we don't know why". Again, they looped that answer several times, without further explanations. 

At this point, I returned back home, with my old car (luckily it's still going), while the selling person had to drive to the traffic-police station (somewhere not very close to the rest of the offices), in order to check what is wrong with the car, and why the hell did the police ordered to remove his car from the road, without him ever getting any ticket or ever being arrested even for a regular check. After two hours he called me and said that it all was a big mistake. The police wrote the ticket with the wrong number and ordered to stop the wrong car (they actually arrested a truck!). So now he has a letter to the MOT that says they we can complete the transaction in their office (and not the post office, which means HUGE lines again).

I've been dealing with technology for quite a while, and I was responsible for research and modeling of SOA (service oriented architecture) and connectivity between different systems. This made me think about several problems that arose from bureaucracy and could be easily solved with technology:
  • If there's already a network between the police to the MOT, and between the MOT to the post office, why can't they pass a simple string saying what's the problem with the car? That would have saved us at least an hour.
  • Why can't the lines in the MOT be better organized, like in modern banks, medical centers and post offices?
  • If there is connectivity as described above, why can't the police update the record about the car, so we could go back to the post office? Why would we need a letter if we have
  • Why do they still trust the hand writing of police officers and volunteers, instead of equipping them with cameras, and using OCR software (the same which is being used for toll roads, such as road 6)? That could have saved us the entire day, and the day after.
If I owned a company, at which SOA and such other products were the line of business, I'd volunteer to implement these products at the MOT/police/post-office, so that every citizen could see it in action (everyone visits these places). I think it'll bring me a lot of customers, perhaps world-wide. As for the typo in the car number, this is plain stupidity: A tiny little check would have shown this number doesn't belong to a truck. Simple input validation that every programmer could've implemented.

Edit: Since everyone is talking about Google's chrome (the new browser), and since this is a technology blog, I can't stop myself from writing something about it. This post was written using chrome, and I must say it was quite fluent, although not that much of a difference from Firefox. I'll be using it for some more time, and try to stress it out.
Tip: If you close a tab by accident, simply click the (+) sign at the tab bar (is this how it is called?), and the newly opened page (assuming it's the home page built into the browser) would suggest you to open the recently closed tab.