DaniloP Blog

Grails: How-to access the default H2 in-memory database

Posted in Grails by Dennis on 18/11/2014
Tags: , ,

When you use Grails for a new project, the default DBMS (DataBase Management System) is H2. A cool characteristic of this DBMS is its capability to handle in-memory tables: it is possible to create a database living in the RAM memory.

This is usually not the desired behavior, since Databases are by nature persistent entities. However, when developing a new application, having the possibility to use an in-memory database may speed up the development process, given that the table structure may vary quite frequently.

Grails makes use of H2 in-memory tables by default. If you create a new application and define a new domain class, Grails will take care of creating a suitable table for your class.
Sometimes it is useful to actually see the tables that Grails generated for us. Assuming you are running your web server (e.g.: Apache) on localhost port 80 and that your app name is myApp, while running the application you can access the in-memory database browsing to: http://localhost/myApp/dbconsole/. It should be possible to login immediately by clicking on “Connect”. From there you will be able to see and manipulate your in-memory database.

If you wish your Grails application to use a different database, you can start here.

Ubuntu: gedit creates files with tilde (~)

Posted in Ubuntu by Dennis on 04/07/2009
Tags: , , ,

gedit is a very simple but great text editor for Linux. It comes already preinstalled in Ubuntu and most of users use this program almost daily.

There is an issue with gedit which may disturb some of us: it creates some strange files. If you are for example editing “text.txt”, gedit will create “text.txt~” . This file is hidden, so in most of the cases is not showed directly. To show it browse to the directory where the file is and use CTRL+H to see hidden files, or, if you are using terminal, go to the directory where the file is and use the ls command to list all the files.

This file is a backup file created by gedit. If we want the program not to create that file anymore:

  1. Open gedit
  2. Edit -> Preferences
  3. Select the “Editor” tab
  4. Uncheck “Create a security copy of the file before saving it” (I am not totally sure this is exactly the right sentence they use, but it should be quite near)

This will make gedit stop to produce those files.

Enjoy gedit! :)

Digital Transmission: Hard and Soft decoding

Hi everybody,

I am sitting here in front of this PC studying Digital Transmission. This basically means that I am studying how information can be sent over a channel (ex: a cable) in a discrete way (basically using bits). Now I want to write a very short example about what hard and soft decoding is.

Before sending bits to the channel, they are usually somehow coded. By coding the bits we want to make it easier for the receiver to localize errors which are likely to occur during our transmission (the most easy case to understand is the additive noise added by the channel). It is actually also possible to correct some of these errors. But this is not the topic now.

If we code, we of course have also to decode in order to get the original information back. When you read about decoding techniques you will find Hard Decoding and Soft Decoding. The idea behind these two was not clear for me until I read a nice explanation. I will try to report this explanation with my own words here on the blog.

Useful concepts: metrics
It is important to understand what Hamming Distance and Euclidean Distance mean, especially  applied to vectors. You can have a look at the following links:

The example

Imagine we want to send 1 bit of information, either 0 or 1, over a channel. To make our system more robust, we decide to use coding. We use a very simple and straight-forward coding technique: we just repeat the bit 4 times. So if the bit we have to send is 0, we will actually send 0000, and if it is 1 we will send 1111. We decide that on our cable we will have +1 V (volt) if the bit to send is 1, and -1 V if the bit to send is zero.

Ok, let’s assume we like the number one and we want therefore to send a bit with value 1.

What we will actually send on the cable (=channel) is [+1V, +1V, +1V, +1V], four impulses of +1 V (the duration of these impulses is not really crucial for this discussion).

Our channel will introduce distortions, additive noise (AWGN) and all possibile mess. At the end, what we receive is [+1.1, -0.2, -0.1, -0.1]. Now, based on this, in the receiving phase we have to decide weather we sent a 1 or a 0. here is how the two decoders will act:

  • Hard decoder: it treats all bits separately. basically the received sequence is though to [+1, -1, -1, -1] and based on this we use Hamming metric to find out which sent sequence is nearer. As we basically have more negative values than positive ones, we conclude that the sent bit was a zero;
  • Soft decoder: it does not make a decision on each bit. First it sums up all the single bit values, obtaining +0.7. After this, the decoder looks which bit is, in an Euclidean way, nearer to this value. In this case of course +1 V is nearer to 0.7 V than -1 V. We therefore conclude that the sent bit was a one.

Both decoders use a Maximum Likelihood principle. They just use different metrics.

As we can see in this small example the soft decoder is able to decode the sent bit correctlym, while the hard decoder fails. It is usually true that soft decoders have better performance than hard decoders, but they are also usually more difficult to implement in practice.

Hope this helps somebody to understand better these concepts. I think I got it right now! :)

How-to: Start using LaTeX

Posted in Uncategorized by Dennis on 18/03/2009

I am right now starting to write my bachelor thesis in Telecommunication Engineering. The main topic of the thesis will be Reversible Data Hiding. But this is not the intresting news nor is the main topic of this post.

When I went to see my relator teacher he said to me “ok, you now have an argument for your thesis. How are you going to write it? For me it does not really matter, choose the system which suits more to you”. After this I started to think about which possibilities I had and after a quick research I found three ways:

- Using OpenOffice: writing as everybody probably does, through a normal WYSIWYG (what you see is what you get) editor;
– Using Lyx (http://www.lyx.org): something in between a normal text editor and pure LaTeX;
– Latex.

After carefully thinking, after looking for useful info online for several days, after some trials I decided to write it in pure Latex.

What is LaTeX
To be short, LaTeX is a markup language widely used in the scientific community. It can be regarded as something similar to HTML, where the elements of the webpage are described through tags.  For a more formal definition, have a look at Wikipedia: http://en.wikipedia.org/wiki/LaTeX

Why LaTeX
The best thing that LaTeX offers for writing a complex document like a thesis is the fact that it lets you focus on the content rather than on the visual aspect of your work. Something like HTML and CSS, if you are familiar to that. 100% distachment. This is maybe the main reason because I decided to use it for the thesis work. I have some previous experience with common Word Processors (MS Word and OpenOffice) and complex documents… I got quite pissed off when the images were floating around all the time like a fish in an aquarium.

At the beginning Lyx looked to me like a very nice alternative. It is probably a good alternative for someone who wants to start approaching the LaTeX way of writing without modifying too much his/her habits. The problem I encountered with Lyx is that I did not feel really “free” to control the document. Maybe I did not like the user interface… I do not know. But do not discard Lyx directly if you have to chose. Give it a try, it may me something for you.

How LaTeX
You need basically to understand just a concept: the document you write in LaTeX is commonly stored with the extension *.tex and needs to be compiled by a compiler in order to give you a nice PDF, DVI or PS output file. Assuming this, what you need to work with LaTeX are two things:
An Editor: you can take whichever text-editor, like for example gedit. What I suggest you to do is to use an editor which is though for writing in LaTeX as it will give you some facilities (some functions, or some code-highlight) which can help you a lot in writing your document. On Linux I personally use Kile (http://kile.sourceforge.net/) which has a nice interface and lets me compile my .tex file with an easy keyboard shortcut. I have no experience in writing in LaTeX under Windows. What I can suggest you to do is just try to search “Latex editor windows” or something like that. Try some programs, have a look into some forums, and you will quickly find a nice editor.

- The LaTeX binaries: here you have the compiler, the style sheets and so on which tell the compiler how your document should look like. For example tex-live (http://www.tug.org/texlive/, but mostly likely you can get it from a repository) for Linux and MiKTeX (http://www.miktex.org)  for Windows.

Wanna try?
LaTeX can be used to prepare slides, too! There are so many guides to LaTeX on the internet that is totally unuseful for me to write some basics about it. What I can do is to suggest you Wikibooks, which has a great guide to LaTeX which can lead you through your very first document to quite tricky issues. Start from here: http://en.wikibooks.org/wiki/LaTeX/ . You can also download the guide in PDF, very nice!

Enjoy and write a comment here about how it was to try out LaTeX!

Multidimensional arrays in MATLAB

Posted in Uncategorized by Dennis on 12/03/2009
Tags: , ,

Today I feel like writing something about MATLAB. I am using it for some projects in the Univerisity. Among all other projects, one very important to me is related to Digital Image Processing, as it is the topic of my Bachelor Degree Thesis, which should be ready in a couple of months. Anyway, dealing with images and MATLAB means dealing with arrays. If you have an image you can import it in MATLAB using the command

imread(‘filename.tiff’); %or whatever extension your image has (jpg, bmp, gif,…)

MATLAB will create of course an array out of this but which kind of array? In case of grayscale images it is clear: the resul will just be a matrix with pixel intensities. What about if the input is an RGB image (color image)=? As each pixel is characterized by three components, RGB (Red, Green, Blue), you will get a 3D array of size height x width x 3. You can think about this array like three matrices one behind another. Maybe this image can make it clearer:

Think about this cube, but change the size to height x width x 3.

Setting / Reading the elements of multidimensional arrays

Now we will see briefly how MATLAB implements 3D (and in general, multidimensional) arrays. Let’s call our test variable a. In our pratical case with color images, the way you have to think the matrix is the following:

a = (rows, cols, channel)

where channel=1 means RED, channel=2 means GREEN and channel = 3 means BLUE.

Setting / Reading a single value in a single channel

Let’s image you want to set a single element of this 3D array. For example, in the RGB contest, you want to set the Green component of the pixel which has coordinates (3,2) to 231 (image it is a 8-bit per channel image: all the values of the matrix will be in the range 0-255):


This approach works of course for all the elements of the multidimensional matrix.

Note: If you for example take an empty variable and set: a(100,100,3)=1; , this will create a 100x100x3 matrix, full of zeros and the last element, (100,100,3), equal to one.

Setting / Reading the RGB value of a pixel

Imagine now you want to set/read not only one value of the 3D matrix, but, let’s say, the RGB value for a specific pixel. Imagine you are interested in the pixel which has coordintes (2,2). Then you have to do following:

a(2,2,:)=[100, 200, 255];

here the “:” sign means “use the vector the user is giving me in the direction “channels””. 100 is the RED, 200 is the GREEN and 255 is the BLUE component.

Setting / Reading a whole channel (color)

Another think you maybe need to do is to set a whole plane, let’s say to set the R component for the whole image. This means that you want to set the whole first plane to some values you have in a matrix, which of course has the same size as the image:

a(:,:,1)=[100 120; 200 250]; %In case of a 2×2 image

Very basic stuff, as you can see. Hope this helps somebody.

Remove old Kernels from Ubuntu

Posted in Tutorials,Ubuntu,Uncategorized by Dennis on 20/01/2009
Tags: , , , ,

If you are reading this you have probably been using Ubuntu for a while, updating it quite regularly. You mostly likely use GRUB (www.gnu.org/software/grub/) to handle a dual boot, because on your computer you have a Dual Boot or simply you use GRUB to handle your start-up, because Ubuntu keeps old kernels and you never know if the newest one will crash your machine or work perfectly. That’s a nice feature because it brings you stability and choice, but after a while it may get useless and totally superfluous.

After a while, you can end up with many entries in your GRUB menu and you maybe dislike this situation. The solution is very simple. Here are the steps you have to follow in order to clean up you GRUB menu and remove your old kernels for your computer:

  1. Open a terminal and type uname -r. This will show you which kernel you are actually using. If you boot your system normally, like 99,9% of the users do, you will be using the newest kernel, let’s say  2.6.24-23-generic.
  2. OK, now you know that you need to keep 2.6.24-23-generic. As I mentioned above, is a good thing not to remove the last two kernels, expecially if the one you are using is very new (ex: you downloaded it today).
  3. Open Synaptic (System->Administrator-> Package Manager Synaptic). Use the search button and search for linux-image-2. This will show you all the package named linux-image-2* where * means “something”. Some of these packages will have a GREEN box at the beginning of the corresponding row, some will have a WHITE box. The green box tells you that the package on that row is installed in your system. I think you can guess alone what the white box means…
  4. Among all the installed packages, locate your current kernel, ex: 2.6.24-23-generic. This is the package you do not want to remove. As we said above, we want to keep another version. So, starting from the row of your actual kernel, go upwards and find the newest version which was installed before the actual one you are using. For example: 2.6.24-22-generic.
  5. Now you want to uninstall everything which is not 2.6.24-23-generic or 2.6.24-22-generic. So, locate all the other GREEN boxes, representing older kernels, click with the right button of your mouse on the corresponding line an select Mark for removal. The line will get very RED, telling you that it will be removed. Repeat this option for all the other old kernels you do not want to keep;
  6. Once you are done, simply click on the apply button. Synaptic will remove all the old kernels you do not need anymore, giving you some more free space on your disk and cleaning the GRUB menu. Yes, the GRUB menu should update automatically.

In case for some reason, after rebooting your system, the GRUB menu did not change, you can manually edit the configuration file. Open a terminal and type:

sudo gedit /boot/grub/menu.lst

scrolling down this file will show you your menu. It is quite intuitive so I do not explain how it looks like. Simply remove the rows referring to the OLD kernels, remembering not to remove the new ones. Once you are done, click on save and reboot your system.

This should clean up both your hard disk and your GRUB menu from old kernels you do not need anymore. Hope this helps.

Rainlendar on Ubuntu: everything fine except…

Posted in Ubuntu by Dennis on 14/07/2008
Tags: , , , , , , ,

I’ve been using rainlendar for quite a while now. I really love it, I can easily manage all my schedule and remember staff that I would forget..

There is just a little problem in using Rainlendar with Ubuntu. Probably you would like your Rainlendar calender to start at the startup. In order to do this you probably did the following:

System->Options->Sessions->Add (Name: rainlendar, Command:rainlendar2, Comment: whatever you want)

this action is supposed to make Rainlendar start at the startup. It’s actually the right way, and it actually starts in the majority of cases. But in a non-trascurable number of cases, it doesn’t start properly. This mean that Rainlendar could not start at all or that it maybe starts but it’s interface is splitted over the whole desktop (there is typically a small number in the upper left corner of your Desktop).

This happens if Rainlendar starts before some important elements of the GNOME toolbar has been initialized.

An easy and powerful way to resolv this issue is quite obvious: delay the startup of Rainlendar.

Creating the script
As you maybe already know the Terminal is really, really powerful. For an advanced user it’s basilar to have a terminal to use, because it gives you the full (well, almost :D) control on your machine. As this tool is really useful, it also provides a nice function which can be used in our case: sleep. As the name states, this function make the script sleep (wait) for X seconds before going on executing the script content). So these are the steps to take:

  1. Open a terminal
  2. Move to the directory where you want to create the script (maybe you home directory it you just want to modify the behavior for your user, otherwise you can put it in /home). To move between your directories, the command to use is cd. For example: cd ~/Desktop will lead you to your user’s desktop as the tilde (~) stays for home directory;
  3. If you are in your home directory you don’t need any particular permission to move. If you on the other hand are in the /home directory you need to get the rights of administrator. In order to do this you can try sudo su. After this command you will be asked for your password. If you are among the sudoers (administrators) you should immediatly gain the administrator rights. If you are not among them, well… you can only act in your home directory;
  4. Create the script. Now type nano startRainlendar.sh. Nano is a small but very powerful command-line writing tool. This command will open the newly created startRainlendar.sh file;
  5. Now fill in this file! As we discovered before we need to use the sleep command. So these are the rows you have to insert:#!/bin/sh
    sleep 10
  6. Now save the file. To do this type CTRL+O and then ENTER;
  7. We now have the file we need. Making this file start at the startup should solve our problem. But there is just another issue: we must make our file executable! To do this the command to use is chmod. I’ll probably tell you what I know about this command in another post some day. So far you just need to execute this command chmod 700
  8. The last thing to do is to make this script start at the startup. You should already have a rainlender2 entry in your startup list. To modify this (or to add a new one) go on System->Preferences->Session. Find the rainlendar2 entry and change the “Command” to /home/startRainlendar.sh or /home/USER/YOURDIR/startRainlendar.sh depending on where you decided to create your startup script. If you don’t have a rainlendar2 entry, click on the “Add” button and simply create a new entry (the important field is “Command”, the other two fields are just your your usage.

This should solve the issue. Hope this helps.

Now let’s go on with studies.

Ubuntu: Top programs for normal users

Posted in Ubuntu by Dennis on 10/07/2008
Tags: , , , , , , , , ,

I am sitting here in the library studying and I just took a pause. Today I want to describe some programs which I use everyday and which are really good.This programs are about browsing, calendar, music listening, istant messanging, calls, office and dictionary. So, let’s start.

  • Firefox 3: Well, I think many of you use Firefox, as it comes pre installed on Ubuntu. This new Firefox 3 has really improved from the former version. I expecially like the new address bar which seems to be kind of “intelligent”, trying to recognize where you want to go while you type the address; Together with Firefox I use GMAIL notifier, a small add-on which keeps constantly controlled my e-mail address. You can find it here: https://addons.mozilla.org/en-US/firefox/addon/173;
  • Rainlendar2: This program is a really nice desktop calendar. As I tend to forget a lot of stuff it’s really useful for me to have this small application on the right side of my desktop. I use it really much: exams, things to do, birthdays, everything. Rainlendar2 comes with 2 skins. I don’t like the default one, but the second one is… really nice! Rainlander2 has plenty of useful feauters. There are two version avaiable: the free one and the pro one, which costs some dollars. You can read more about this program on it’s official website: http://www.rainlendar.net. I suggest you to have a loot to the FAQ section, really useful expecially for Linux users. The installation for Ubuntu users is really simple: you only have to download the *.DEB package, click on it, insert your admin password (sudo password) and install it. There is a version for Windows;
  • BMPX: I love it’s simply, light and complete interface. This player lets you play your own music from your hard disk (library), listen to internat radios (shouthcast, icecast), listen to lastfm (if you don’t know what it is I suggest you do discover it: http://www.last.fm), Podcasts, CDs and finally Jamendo, a really intresting music database on internet (http://www.jamendo.com). It is still in a quite early stage of the developement and it sometimes crashes (it happens to me when I listen for hours to lastfm) but I’m sure that if a lot of people will download and use this software the community will fix the bugs and provide new intresting and useful features. To get this software: http://bmpx.backtrace.info/site/BMPx_Homepage;
  • Pidgin: this IM (Istant Messaging) comes preinstalled (If I’m not wrong) with Ubuntu. If it doesn’t you can install it via terminal typing sudo apt-get install pidgin. I love it because it easily lets me to use different accounts (Messenger, GMAIL, ICQ) at the same time. It’s interface is really simple, so that this software is nothing for you if you love spectacular effects and complex interfaces. It still doesn’t support audio/video call and this is really a pity. But for the rest is really nice. It functions without problems even behind proxy: it can use the system’s (GNOME’s) settings (System->Settings->Proxy). Website: http://www.pidgin.im;
  • Skype: not much to say about this software. I use it quite a lot, both for calling other computer and normal phones to good rates (expecially cheap if you have to call fix mobile numbers around the globe). As for Rainlenard2, you can install Skype downloading the *.DEB package from the official website. With this newer versions, Skype starts a good support of webcams. http://www.skype.com;
  • OpenOffice: it’s simply a wonderfull application, containing a really powerful set of tools to handle many kind of documents (databases, written documents, excel files, presentation and much more). You simply have to try it out, as it comes preinstalled with Ubuntu. If you were used to Microsoft Office it will take you a while to understand how OpenOffice really works (there are some differences, of course) but after that you will love it. On the net there is a lot of material and tutorials teaching you everything you need. If you want, try to go on Youtube and type “OpenOffice” to get some tutorials! Website: http://www.openoffice.org;
  • Stardict: a really powerful dictionary on your desktop. It can both function with local and remote databases. I make it start automatically when the computer stars and if I don’t know a word I just have to select it and click the WIN button (you can set this behavior in the options window). Stardict opens a small window telling me what the word means (of course, I installed some dictionaries on my computer). To check out more about this software visit: http://stardict.sourceforge.net/. There is even a version for Windows.

That’s it, if you liked my description the best thing to do is to go and get the software and to try it out yourself!These are just opinions and you maybe like other software better than these ones! :)

Now, back to my studies.

Ubuntu: How to create a link to a directory on your Desktop

Posted in Ubuntu by Dennis on 09/07/2008
Tags: , , , , ,

I remember it took me some time to understand how this worked… so I want to let you know how you can add a link to a generic directory on your Desktop. It’s really easy to do that, but it can be quite of tricky because it’s a different way from Window’s one.

In Ubuntu (assuming that you are using GNOME), there are many different ways to create your link:

  1. Nautilus. Simply navigate to the containter of the directory you want to link, right click on that directory and “Create Link”. This will place a link to your dir exactly where you are. Now take the link (cut: CTRL+X) and paste (CTRL+V) it on the desktop;
  2. Mouse. Drag the folder to the Desktop using the middle mouse button. A small window will open: select “Link here”;
  3. Terminal. ln -s /path/directory ~/Desktop/Name
  4. Right click on the Desktop and choose “create launcher”. In the “command” field write “nautilus /path/directory” without the quotes.

A short (and hope useful for somebody) post today! :)

OpenOffice: Working with formulas

Posted in Tutorials,Ubuntu by Dennis on 07/07/2008
Tags: , , , , ,

As I am studying telecommunication engineering and I like to work with my computer, I use quite a lot OpenOffice to write pages of formulas for my projects, essays and so on. Working with formulas in OpenOffice is not difficult at all. What I want to do today is to give you some basic advice on how to work with formulas in an easy and quick way.

Supporting Formulas

First of all you have to make sure that your OpenOffice has the support for formulas. It can happen that you didn’t install it when you installed OpenOffice… some years ago maybe. It’s simply to understand if your OpenOffice can work with formulas or not. Simply go on Insert -> Objects -> Formula. If you are able to do this then everything is fine. Otherwise, if you are not able to select the “Formula” option then you have to install something.

If you are under Linux then you have to install the package “openoffice.org-math”. If you use Ubuntu you can do this in two ways:

  • By using Synaptic package manager (System->Administration->Package Manager Synaptic;
  • By using a simple terminal (Programs->Accessories->Terminal)

I’ll explain you how to do this in the second way. Open a terminal and write

sudo apt-get install openoffice.org-math

and click ENTER. You should see something like this:

now insert your password. Sudo is the command you have to use in order to (try..) to gain administrator rights on your machine. If your account (username) is among the sudoers (administrators), you will be able to install whatever you want, otherwise you will be blocked and you have to ask an administrator to install things for you.

You have of course to be connected to Internet in order to permit Ubuntu to go on a repository and pick up your package. After that the package should be installed. Close and open OpenOffice again and try to go on Insert->Object->Formula. Wow, it functions!

The formula syntax

Of course there is a syntax you have to use in order to correctly insert your formulas. The best way of quickly understand how this syntax works is try, try and try. OpenOffice will show some ? when you write something it doesn’t really like. I suggest you to have a look on this PDF File:


This is the official Formula Reference by OpenOffice. It contains all the symbols and stuff you can insert in your formulas.

Quick tips

Here are some quick trick you may need to know:

  • If you need invisible parenthesis use this ones: {};
  • To create a division bar write over. For example {3+x} over {e^x};
  • To insert a letter of the Greek alphabet write %nameofletter. For example %alpha, %omega, %BETA. Case matters here!;
  • For writing something just over or under something (apex position: powers and so on) try a^2, or a_2, or a^1_2;
  • If you use lots of formulas it’s boring to always go on Insert->Object->Formula. Select one formula and copy it (select the object formula, not its text). Then paste it and modify it whenever you need a new formula.

That’s it. You can have a look on this file, which is a ODT doc (OpenOffice written document) which contains some basic test I did with OpenOffice Formula: formulatest.odt

Next Page »


Get every new post delivered to your Inbox.