You are hereCoding
Coding
Coding tips and tricks, pitfalls, snippets, tutorials and more.
Linux: Automatically reconnect NetworkManager's VPN Plugin using D-Bus
In a previous post, I talked about how to use D-Bus to get information about network status changes. Now, since I have been using a private VPN with my Ubuntu as a client, I came across another scenario, where a script using D-Bus could help: The VPN works fine, but sometimes just disconnects. It does not happen very often, but when it happens, it is annoying and I'd like to see it reconnecting automatically. Moreover I'd like to stay in the VPN whenever I have a network connection available. Unfortunately, I didn't found any option within the NetworkManager to manage this. I ended up in writing this script which can be invoked like autovpn <VPN_NAME>, where <VPN_NAME> is the name of the VPN which is displayed in the NetworkManager under VPNConnections. You can even run it automatically on system startup by placing it in "Startup Applications". It does two things:
- It tries to connect the VPN whenever it detects an active internet connection.
- It tries to reconnect the VPN, whenever it disconnects unintentionally. The number of attempts is limited to 5 and there is artificial delay of 5 seconds between attempts.
Parser Generator in Python - Quick PLY Introduction
I have been using regular expressions within my Python projects for a while now, but I've never felt the need to use a full-featured parser generator. This changed yesterday and I had a look at PLY, a pythonic implementation for Lex/Yacc. Being used to parser generation in Java using ANTLR or Cup I came across some remarkable differences which I want to point out for you after the stop. You will also see a small calculator code snippet.
Creativity - New LAN Game on Project Page!

In the last couple of days, my brother and me spent some time to code a little game in Python/PyQt. Though the code is quite a hack, you can still use the program to spend some funny nights with your friends. The program runs on all major platforms and is simple to use. The only thing you will need is a game file with questions and answers. Read more about everything on the application project page here. Feel free to leave your comments.