About

Archive for June, 2007

Lambda Lives!

It seems that Guido Van Rossum has decided to keep lamda for Python 3000 (or as it will be called when release.. Python 3.0.
I can’t say i like all of the proposed changes. It starts to feel more and more like Java, though that may not be necessarily a bad thing.
It’s backwards incompatibly in a significant way, so don’t expect major applications to be ported right away (or at all!)

Validating Greek VAT code (έλεγχος Α.Φ.Μ)

I recently had to validate the VAT code entered in an internetl Django application. Searching around lead me to this site. The implementation there is Visual Basic though, which wouldn’t suit me. So i translated it to Python as best as i could (given i don’t actually know any VB :p )
Here it is:
def isValidAFM(afm):
    if len(afm) != 9:
        return False

    try:
        int(afm)
    except ValueError:
        return False

    AFMpart = afm[:-1]
    afmsum = 0
    multiplier = 2
    for c in AFMpart[::-1]:

        afmsum += ( int(c) * multiplier )
        multiplier *= 2

    if not afmsum:
        return False

    afmmod = afmsum % 11

    lastdigit = int(afm[-1])
    if lastdigit == afmmod:
        return True
    elif (lastdigit == 0) and (afmmod ==10 ):
        return True
    else:
        return False

Caveats:
  • I don’t know if the actual algorithm is valid since my search for official documentation turned up nothing. It seems to be accepted by a large on-line community of accountants though, and that’s good enough for me.
  • I have not tested it much. You at your own risk, as always

Xine pvr:// undocumented feature

I am happy owner of a Hauppage WinTV PVR 150 card. On linux, both mplayer and xine support it but xine has special support for it (in the form a special MRL for it nonetheless) so this is why i prefer it.
The problem i had was that the PVR input for xine by default uses  the root directory to store its temporary vob files. The partition that my root is located however is rather small and i could only have very small files (and therefore very small recordings if a paused or wanted to go back in a video).
I wanted to change this location but there is nothing on the documentation. A quick Google search turned up nothing. So i looked in the source code and , sure enough, the kind folks had it documented in the comments of src/input/input_pvr.c. 

pvr:/<prefix_to_tmp_files>!<prefix_to_saved_files>!<max_page_age>

In other words all you have to do is specify the path in the MRL! Eg:

xine pvr://mnt/xine_pvr_tmp_files/

There are more settings there (like events you can send to tell xine you want teh recording saved instead of being deleted on exit, but i haven’t explored them yet.

Update: I was at #xine on freenode.net and told people about this. 10 minutes later it was fixed in the CVS.  Now that’s responsive.

Defense against ssh brute force attacks

I have ssh daemon open on this server and accessible to the internet. I need it since i need to access my computer when i am away. Recently, however, i became the target of brute force attacks against sshd. I would block the offending IP using iptables but this would only last a few hours until the next attacker (from a different IP obviously).

I thought if snort and rules that exist to update iptables automatically but a) that would be a lot of work to setup and b) snort would brock my old computer to its knees (PentiumII  with 64Mb ram).

Yesterday i came across denyhosts which is a Python program (yay!) that detects intrusion attemplts and adds them to /etc/hosts.deny. It has a lot of nice features, its easy to setup  and quite effective. (well… its Python.. what did you excpect)

Seems quite cool, and it doen’t need snort and plugins and hours and hours of configuration and reading.

Slashdot story accepted

It seems that a story i submited  to slashdot was accepted and became this story  which appeared in the front page.
They did change it than i originally submited it, as i had mostly copy-pasted the story from the blog of Asteris Masouras.
The story is about the arrest of Tsipropoulos of blogme.gr which you should know by now so no link for you (well, i am lying,  asteris blog has all the information you need).

Moving to Patras

I came to Athens in the summer of 1997. The time has come for me now to return to Patras.
I will be taking the server off in a few hours since i am transfering all the equipment to Patras.

I don’t yet know if adsl access is available in the area of my new residence there there is a chance i won’t be able to bring back my server very fast.  If that’s the case i will try to find a hosting provider, but that may be somewhat expensive (since it will have to support python, webware, cusomized python packages, and an array of other things) i am probably looking for virtual server solutions :)

I have been living for almost 10 years in Athens and i have good friends here that i don’t want to loose.
At least i have a hope that i will reuinite with friends i left in Patras when i moved to Athens.

The distance between Athens and Patras is 216Km and about 2:00 -2:30 hours travel. Not that far i guess. Getting to some areas in Athens takes more time than that :)

The benefits of Web 2.0: Server side blink

Long ago, Netscape introduced the world to the wonders of the amazing <blink> tag. Unfortunately, the blink tag never really cought on. This failure should be attributed to the non-standard nature of the tag, which in other words means that it only works on Netscape (and Mozilla/Firefox).

With the introduction of the Web2.0 it has become apparent that we are in need of a portable, enterprise and robust manner in which to implement this feature. Ajax, enables us to achieve this goal.

Ladies, and gentlement …. the server side blink

MgOpen fonts ebuild for Gentoo

The people at Magenta.gr have released some fine Greek fonts for free. They are available at:  http://www.ellak.gr/fonts/mgopen

For Gentoo users i created an ebuild that will do the installation for you.  get it here. This is my first attempt at creating an ebuild but it is the simplest of ebuilds and it should work without problems. It works fine on my computer anyway.

Just put in in your portage overlay, digest it and emerge it. If you don’t know what i am talking about, then google for this (there is plenty of material on using portage overlay out there, i won’t repeat it here. It’s easy though)

A stupid Sudoku solver in Python (and PyGTK)

During the holidays i was bored out of my mind. Holidays in my family means that we gather some close relatives and friends at our house and eat. Not once. Not twice, but every freaking day. So when a sudoku magazine fell in my hands i thought it would be fun to try and write a sudoku solver. So here it is:
PySudoku UPDATE Because of a server move the tarball is unavailable. Get it using Subversion from svn://arcanum.homelinux.org/sudoku

This stupid little program is written in Python and PyGTK so you need both to run it.

There are some bugs:

  • It can be slow in certain puzzles.
  • It is either too slow or in a loop when the puzzle has no solution.
  • It won’t check if you enter an invalid puzzle from the start (which is easy to do. i am lazy)
  • Probably more things i can’t remember now :)

It does not generate puzzles, not because i don’t know how to do it but because my backtracking solver it so slow that it would be painful to try generating a solution with the “try a random number / see if there is a solution/ try another etc etc.” method.
There are far better solver/generators out there if you are looking for one. Mine is just a toy i did for fun.

Asterisk

During the last days i have been spending most of my time reading about asterisk and toying around with it.
I have managed to set up a few IAX2 and SIP extensions in order to play with soft-phones (mostly kiax and kphone).
However, by far the coolest part is the bluetooth channel (chan_bluetooth). Using a bluetooth dongle and a bluetooth phone (my T610 for example) i can make phone calls from my soft-phone to the real world.
Sample extensions.conf follows:

ignorepat => 9
exten => _9.,1,Dial(BLT/Me/${EXTEN:1})
exten => _9.,2,Playback(invalid)
exten => _9.,3,Hangup


You need to put this in the appropriate context (read asterisk manual for this).
Extensions that start with an underscore are pattern matching. so _9. reads: an extension that starts with 9 and has some more digits afterwards (the dot).
BLT/Me means BLT for Bluetooth channel and Me for the device name of my cell phone (configured at /etc/asterisk/bluetooth.conf).
${EXTEN:1} is a variable that will be substituted with the extension number dialed. the :1 part means to strip the first 1 number (so :3 means strip the first 3 numbers). This is because the first 9 is used to specify that we want an external line, not the actuall number to dial.


The second line is used if an invalid extension is dialed and the last one is to hangup afterwards.

Now, going to bluetooth.conf to configure our bluetooth settings. I am assuming that you have already set up bluetooth in general and you can find out information like your phones MAC address
;; Ericsson T610
[00:0E:07:3D:B1:FF]
name = Me
type = AG
channel = 3
autoconnect = yes

In brackets is my phones MAC address.
The name = Me is the name that we use in extensions Dial() command.
The type=AG means that it is a phone (as opposed to a headset ) the channel is the channel to use.

Now with a kiax (or another softphone) we can call as normal and you will see the phone calling the specified number.
I must note here that during my test i was able to call normaly, i could speak to the other party but i could not listen to the other party. I have not investigated into the matter so it may be wrong soft-phone settings , it may be wrong asterisk settings or simply attributable to the testing nature of chan_bluetooth.

At some later point i will go for opposite, which is to answer cell phone calls from my soft-phone. It should be possible.

I have also been having fun with Free World Dialup (FWD) services. Especially their IAX service offering whereby i can connect my asterisk and integrate their services with my network (eg call FWD subscribers using their number on a keypad).

Asterisk most absolutely positively rocks. And to think that i have not even purchased any hardware yet. Not even an X100P clone or an ATA.