Archive for the ‘uncategorized’ Category

VirtualBox: How to change the UUID of Virtual Disk (vdi)

Wednesday, May 6th, 2009
Copying the image of Virtual Disk (.vdi file) is a convenient way to duplicate the disk, in cases you want to avoid re-installing an operating system from scratch.

However, simply copying the .vdi file into another location will make a verbatim copy of the virtual disk, including the UUID of the disk. If you try to add the copy in the Virtual Media Manager, you will get an error like this:

virtualbox-error.png



In this case, you have to do the following:

giannis@giannis-laptop:~$ VBoxManage internalcommands setvdiuuid /path/to/virtualdisk.vdi
VirtualBox Command Line Management Interface Version 2.2.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

UUID changed to: 9e89fe14-d010-469e-a737-cd65218c4acb


Since the old UUID is replaced with a new one, you can now add and use the virtual disk.

Please note, that you wouldn't have to follow this procedure if you had used the clonevdi function to copy the virtual disk image, in the first place. The clonevdi function makes sure that the new disk image will have its own unique UUID.

The syntax of the clonedvi goes like this:

$ VBoxManage clonevdi Master.vdi Clone.vdi

Ubuntu: Firefox opens without window decoration

Tuesday, April 21st, 2009
If your Firefox suddenly starts to open without window decoration, run this command:

gedit `find ~/.mozilla -name localstore.rdf`

Try to locate the part of the file that looks like this:

<RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
width="1280"
height="1024"
screenX="0"
screenY="0"
sizemode="maximized" />


The order and values may vary in your computer but that does not matter.

Now go ahead and completely erase either the width or the height line. Like this:

<RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
width="1280"
screenX="0"
screenY="0"
sizemode="maximized" />


Then save the file. The problem should be fixed now.

How to enable Hibernate in Windows XP

Wednesday, April 8th, 2009
Hibernate option is not available by default in Windows XP. Follow this instructions to make Hibernate option available in your Turn Off Computer dialog.

Please note that in order to use Hibernate,  the S4 System State (Hibernation) must be supported by your computer's ACPI implementation, othewise you cannot do anything about it.

Go to Start → Settings → Control Panel. Make sure to open the Classic View, and open Power Options:

control-panel.jpg



When the Power Options Properties dialog appears, check if there is a tab labeled Hibernate. It should be the last one:

power-options.jpg



If you are not able to see the Hibernate tab, then Hibernation is probably not supported in your computer...

On the other hand, if you have a Hibernate tab, that's good news. Open the Hibernate tab and make sure to check the Enable Hibernation checkbox:

hibernate-tab.jpg



Click the Apply or OK button to make the changes take effect.

Now, the next time you want hibernate, in the Turn Off Computer dialog, press and hold down the Shift Key. The Stand By option will change to Hibernate whilst you hold the Shift Key pressed:

standby-hibernate.gif



With the Shift Key down click on Hibernate.

Ubuntu: pressing PrtScn takes too long to take screenshot.

Friday, March 20th, 2009
If lately you have been experiencing a short delay when trying to take screenshots by pressing the Print Screen button (PrtScn), it's most likely because of a delay setting in the screenshot accessory.

Go to Application → Accessories→ Take Screenshot. You should get this window:

take-screenshot.png



Change the delay setting to 0. You should have to take a dummy screenshot for the change to take effect. After you do that, when you press the PrintScreen button you will be getting screenshots without the delay.

How to "unlock" a secured PDF file

Tuesday, February 24th, 2009
This is article describes how to "unlock" a secured PDF file, and gain full access to print it, modify it, and copy selected portions of text from it, without paying anything to buy any of this (so called) "pdf cracking software".

You are going to need the help of the Evince Document Viewer that comes with Ubuntu Linux. If you are already using Ubuntu Linux, good for you! If you are not using it, you can ask a friend of yours with Ubuntu installed to help you. Otherwise, you can dive in deep water and try the Live CD that will do the job for you (no installation required).

A "secured" PDF file will look like this if you open it in Adobe Reader:

midsun.png



Boot in your Ubuntu Linux (or boot from the Live CD if you don't want Ubuntu Linux installed). Open your locked PDF from Ubuntu using the standard document viewer, Evince. From the menu go to File → Print... From the printers list select Print to File:

midsun-print.png



Enter the output filename and make sure that you have selected PDF as Output Format. Click Print and you will get a verbatim copy of the original file, only this time it will be free of any restrictions. This is one more practical example that demonstrates how Ubuntu Linux can significantly improve your life...

VirtualBox does not send Control key events to guest OS.

Friday, January 23rd, 2009
Now that's a strange one.

This is the case: you run Windows XP as a guest operating system in VirtualBox in your Ubuntu box. However, VirtualBox refuses to send events for the Control key (for example, if you press Ctrl-N Windows XP will just receive 'N').

It is possible that the problem is caused by a feature of Ubuntu rather than a bug in VirtualBox. Specifically you have to make sure that you have unchecked the Show position of pointer when the Control key is pressed.

Go to System → Preferences → Mouse → General. Make it look like this:

locate-pointer.jpg



Showing the position of the pointer is neat feature but it seems that you have to live without it if you want Control key events to be passed in your VirtualBox guests...

Creating Symbolic Links with Java at Runtime

Sunday, January 4th, 2009
For the time being it seems that there is no other way than calling an external program for doing the job:

Process process = Runtime.getRuntime().exec( new String[] { "ln", "-s", oldName, newname } );
process.waitFor();
process.destroy();


The disadvantage of this method is the overhead for creating the new process. This can be a serious downgrade in performance if you have to execute this code frequently.

Here is an alternative solution that can vastly improve speed.

First you write a small program in C, say it symlinkcreator.c. This is the actual worker:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

int main()
{
char st[1024];
char oldpath[1024];
int count = 0;

while (fgets(st,sizeof(st),stdin) != NULL)
{
for (char *cp = st; *cp; cp++)
if (*cp == '\n' || *cp == '\r') *cp = '\0';

if (count++ % 2)
symlink(oldpath,st);
else
strcpy(oldpath,st);
}
}


You can compile the program by running this command:

# gcc symlinkcreator.c -o symlinkcreator -std=c99

This will give you the symlinkcreator executable file.

Then you going to need an elegant wrapper class that will call the C program:

import java.io.IOException;
import java.io.PrintWriter;

public class SymlinkCreator
{
private Process process;
private PrintWriter out;

public SymlinkCreator( String path ) throws IOException
{
process = Runtime.getRuntime().exec(path);
out = new PrintWriter(process.getOutputStream());
}

public void link( String oldpath, String newpath )
{
out.println(oldpath);
out.println(newpath);
out.flush();
}

public void terminate() throws InterruptedException
{
out.close();
process.waitFor();
process.destroy();
}
}


Have done these, you can then easily create symbolic links from you code, like this:

// You only need one single SymlinkCreator object (just a single unix process is created)
SymlinkCreator symlinkCreator = new SymlinkCreator("/path/to/symlinkcreator");
...
// Create as many symbolic links as you want using the same process
symlinkCreator.link(oldName,newName);
...
// Terminate the symbolic creator process and release resources when done.
symlinkCreator.terminate();


Downloads:
symlinkcreator.c

SymlinkCreator.java




Alternatively, you can use native methods to eliminate the hassle of inter-process communication between two separate processes.

First create a Symlink class that defines the signatures of the native mathod. This class will act as an interface to the actual C functions:

public class Symlink
{
public native static void create( String oldpath, String newpath );
}


Then you will need to generate a header file for this class using the javah utility:

# javah -classpath /path/to/your/classes Symlink

This will generate a header file that looks like this:

Symlink.h

#include <jni.h>
/* Header for class Symlink */

#ifndef _Included_Symlink
#define _Included_Symlink
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:     Symlink
* Method:    create
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_Symlink_create
(JNIEnv *, jclass, jstring, jstring);

#ifdef __cplusplus
}
#endif
#endif


Then you will have to write a small C file that will define the implemtation of the  function:

Symlink.c

#include <unistd.h>

#include <jni.h>

#include "Symlink.h"

JNIEXPORT void JNICALL Java_Symlink_create
(JNIEnv *env, jclass obj, jstring oldpath, jstring newpath)
{
const char *nativeOldpath = (*env)→GetStringUTFChars(env, oldpath, 0);
const char *nativeNewpath = (*env)→GetStringUTFChars(env, newpath, 0);

symlink(nativeOldpath,nativeNewpath);

(*env)→ReleaseStringUTFChars(env, oldpath, nativeOldpath);
(*env)→ReleaseStringUTFChars(env, newpath, nativeNewpath);
}


Then you have to compile the C file as a shared library:

# gcc -shared -o Symlink.so Symlink.c -I /path/to/jdk/include -I /path/to/jdk/include/linux

You will have to load this shared library at the runtime of your java program.

Finally you can write a small test program to see that everything works:

public class TestSymlink
{
public static void main( String[] args )
{
System.load("/path/to/Symlink.so");
Symlink.create("/home/giannis/test1", "/home/giannis/test2");
}
}


zenity windows and dialogs "hidden"

Saturday, January 3rd, 2009
I just discovered that zenity dialogs show up underneath all the other open windows. It was a matter of five seconds to google it and find out that this is a bug of zenity that causes this symptom if zenity is used in combination with Compiz or Metacity.

You can easily fix this problem by applying a small patch. Just run these two commands:

# wget http://launchpadlibrarian.net/18653141/zenity-2.24.0-focus.patch
# sudo patch -p0 /usr/share/zenity/zenity.glade < zenity-2.24.0-focus.patch


The original information was found in launchpad.

how to make bash display username, hostname and current working directory

Tuesday, December 23rd, 2008
Just add the following line:

PS1="\u@\h:\w$ "

in your .profile or .bashrc.

UNIX: how to find files that DO NOT match a pattern or other criteria

Saturday, December 20th, 2008
Most people with some basic command line skills can readily issue the unix find command to find files of a specific type or matching a specific pattern.

You can do the exact opposite, that is, find files that do not fulfil a specific criterion. The "secret" is to precede an exclamation mark (!) in the argument list, just before the criterion that you want to negate.

For example:

# find . -type f ! -iname "*.mp3"

The above command will find all files that have not an .mp3 extension.