Mai 10, 2013
I was always very facinated of everything about compilers, interpreters, parsers and lexers. Now I was wondering how I could implement such things using Python. I decided to write a simple lexer for algebraic expressions that converts a sequence of characters into a sequence of tokens. Till now I just implemented such things using C or C++ and so I started the simplest way as I learned by reading the Dragon Book.
First of all I created a simple enum type that allows me to create enums as used to from languages like C++ and Java. Then I implemented a Token class that holds all information about a token and enables me to easily print a token using the Python’s magic __str__ method. Finally I added a Lexer class that processes character by character and returns the tokens.
Mai 5, 2013
The object of my last post Running Ubuntu 13.04 on the BeagleBone was how to setup the BeagleBone with Ubuntu, so you are able to run small services and connect to the BeagleBone using ssh with the ability to utilize graphical interfaces. However, you have still a problem to connect to your BeagleBone using ssh, since it automatically obtains an dynamic IP address from the DHCP server. This means that you are not able to connect to your BeagleBone from other networks outside your local network.
Fortunately, there are plenty DynDns services. DynDns is a service that allows you to bind a the dynamic IP address of a host to a static domain. Therefore you have to setup your domain to use DynDns (some providers like Strato support this) or you have to register with a DynDns service provider like dyn.com, which will create a subdomain like yourhost.dyn.com for you. Obviously, the provider of this service is not able to find out the IP your BeagleBone is currently using. Thus, the host that obtains the dynamic IP has to tell the DynDns service, which IP it is currently using.
April 30, 2013
The new BeagleBone Black just released and packs a bunch of new great features. The new BeagleBone now uses an AM335x 1GHz ARM© Cortex-A8 instead of the old AM335x 720MHz ARM© processor, the ram of the new board were increased from 256mb to 512mb DDR3 ram and in addition to the SD card slot, the BeagleBone Black now has 2gb on-board eMMC storage. Furthermore a microHDMI slot was added that enables you to connect a monitor or a TV to your Beaglebone. And finally the best news – the price dropped by 44$ from 89$ to 45$.
I have, of course, already ordered one!
But during the time I have to wait for my new BeagleBone Black, I reactivated my old, now somewhat shabby looking, BeagleBone. And as it is a while ago I played with it, I created a new setup.
April 25, 2013
As I mentioned in my last posts “Using the Samson CO3U usb microphone with Ubuntu 12.10” and “Developing Gimp plugins using Python“, I was trying to create a typed text animation using Gimp, which should be integrated into a screencast intro I am currently working on. One problem I had to face was the renaming of the image layers, that allows me to control the frame rate and overlay behavior.
April 22, 2013
Today a friend asked me how he could execute a script on his server in regular time intervals. And as this is a common task for most Ubuntu users and Linux administrators, I decided to share this knowledge with you. So let’s get started!
There are two possibilities to set up a new cronjob on a linux system. The simplest way is to copy your shell script into one of the following folders:
This ensures that the script is executed once a day, hour, month or week. If this does not meet your needs, you can add more specific task to /etc/crontab. Read more
April 21, 2013
One topic of my last post “Converting gif animations to mpq files on Ubuntu” was my decision to create my own text animation using Gimp. My goal was to create a nice looking animation of text typed in a terminal. A very simple task. You just have to create a layer for each new letter that should be displayed. Finally you append the time in milliseconds, the image should be displayed and the replace flag, which forces gimp to replace the previous layer if the new one should be displayed. Finally your layer stack should look like this:
Layer #n (300ms) (replace)
Layer #n-1 (25ms) (replace)
Layer #2 (25ms) (replace)
Layer #1 (25ms) (replace)
However, you might want to change the time a layer is displayed, which is not really a problem as you just have to change the layer name, but in my case I had to rename about 100 layers. That is really time consuming and in most cases I had to change the display time very often until I had the animation speed I was happy with. That sucks! But there are good news: Python rocks and it is very easy to build Gimp plugins using Python!
April 19, 2013
As I mentioned in my last post “Using the CO3U usb microphone with Ubuntu 12.10” I started recording some screencasts about Android programming, video editting and pythion scripting. But as you all know a good screencast does not only consist of a nice recording, but also a nice intro and a nice outtro (also called “extro”). So I created a nice looking wallpaper and a friend of mine composed a really cool song for me. Thanks Fabi! Using the OpenShot video editor it was very easy to combine these two and then I just had to add some animated text.
However, all text animations offered by OpenShot did not meet my needs, so I decided to create my own using the Gimp. After about two hours of work, several coffees and much copy ‘n paste I had a nice animation of typed text. I exported my Gimp project as animated gif file and added it as a new track to my OpenShot project. Nothing happend. The gif was added but when I viewed the preview of my intro I just saw the first image of my gif animation. Just a short lookup and everything was clear – OpenShot is not able to handle animated gif files. Two hours of wasted time.
I am a great fan of screencasts, because you see what the author is actually doing and could follow through step by step with your own PC while listening. So since I gave some courses and talks about programming android devices using the Android SDK and love solving recurring problems using Python, I decided to record some screencasts for you by my self.
However, I really hate it when the author of a screencasts is not understandable because he is not willing to spend some money to buy an accurate microphone and as my own one is very old, I did some research and decided to buy the C03U USB Condenser Microphone manufactured by Samson. So I ordered one on Amazon and just a day later I received it. But since the microphone stand provided with the CO3U is much to small and a microphone for about 100 euros is to expensive to be used without proper equipment, I ordered some more stuff to get a really cool recording studio upon my desk.
April 11, 2013
As I already mentioned in my post “Be exploited for insufficient validation” the handling of user input requires special observation with regard to security and format issues.
A calendar, which is administrated by the members of a forum to coordinate seminars that should be offered as Google Hangouts, could be exploited using SQL queries that could violate the confidentiality, the integrity and the availability of the forum and the underlaying database.
But such attacks on a webservice or a server are not the only thind that benefit of unfiltered data. Such attacks could also scramble the original layout of a webpage. Whitespaces, style changes, hiding of elements or adding of new elements could cause unexpected effects. Appropriate filters or filter mechanisms can prevent that from happening.
April 10, 2013
Today I would like to show you how to implement and use a class that allows you to store session data within an arbitrary database instead of storing the data in files. At the end of this tutorial I will show you how to use this class in practice.
If we are talking about a session, we always talk about an established connection between a client and a host. Because users could not be unequivocally identified within the world wide web, since it is based on stateless protocols such as http, it is necessary to implement such an identification within the application layer (OSI model). PHP uses therfore the so called session id, which is transfered from the client to the server. This id allows the unambiguous allocation of fragmented session data to one user.
Session data are stored at the server side and are deleted automatically after a fixed delay!
Typical examples for sessions are systems, which handle information that have to remain state between otherwise stateless transactions between different web pages. Typical applications which require this behavior are forums or online shops.
Let’s stay with the example of an online shop. Every online shop offers a cart in which the products are placed in, that should be ordered. This articles and the number of products, that the customer will ultimately source, have to remain state between different web page calls and have to be unambiguous allocated to the correct user.
Some of you may have noticed that in many web shops a user does not have to be authenticated to use the cart, which means that a session could also be established without prior authentication. This also allows us to track the user’s movements when he visits our web page.