Wednesday, January 18, 2012

Creating Symbolic Links in Linux

This one is a pretty easy one, but I always forgot which one comes first - the symlink name or the target file/folder.

So, here's how you create a symlink in Linux:-

ln -s [target directory or file] [symlink shortcut]

For example:-

ln -s /usr/local/lib/example /example

Thursday, January 5, 2012

Fix the Netbeans Master Password prompt on Ubuntu 64 bit

Refer: http://wiki.netbeans.org/FaqMasterPasswordDialog

I've been having this prompt for quite a while everytime I run Netbeans, and it's REALLY annoying. Googled a bit, and found out about the wiki above. So, here's what I did to solve it.

Note: for Netbeans 7, you can just disable the master password by using the options below in your netbeans.conf (this should be in your <netbeans installation path>/etc/netbeans.conf):-
-J-Dnetbeans.keyring.no.master=true

For Netbeans 6 though, you have to troubleshoot what's causing the problem. First, add this option to netbeans.conf:-
-J-Dorg.netbeans.modules.keyring.level=FINE

Then start Netbeans, and you will STILL get the master password prompt. Check the IDE log (View -> IDE Log). Look for what's causing the error. In my case, I found this in my IDE Log:
java.lang.UnsatisfiedLinkError: Unable to load library 'gnome-keyring': libgnome-keyring.so: cannot open shared object file: No such file or directory
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
        at com.sun.jna.Library$Handler.(Library.java:123)
...

I tried to search fo that libgnome-keyring.so file in my Ubuntu installation:-
khairi@ubuntu:~$ locate libgnome-keyring.so
/usr/lib/libgnome-keyring.so.0
/usr/lib/libgnome-keyring.so.0.1.1
/usr/lib32/libgnome-keyring.so
/usr/lib32/libgnome-keyring.so.0
/usr/lib32/libgnome-keyring.so.0.1.1

Ahah! I'm missing that libgnome-keyring.so file in my 64 bit library. That's why Netbeans is prompting me for the master password, coz it can't find my Gnome Keyring.

This is an easy fix. Just create a soft symlink to the actual file. Here's how:-
khairi@ubuntu:~$ cd /usr/lib
khairi@ubuntu:/usr/lib$ sudo ln -s libgnome-keyring.so.0 libgnome-keyring.so
khairi@ubuntu:/usr/lib$ ls -l libgnome-keyring*
lrwxrwxrwx 1 root root     21 2012-01-05 09:06 libgnome-keyring.so -> libgnome-keyring.so.0
lrwxrwxrwx 1 root root     25 2011-10-19 09:05 libgnome-keyring.so.0 -> libgnome-keyring.so.0.1.1
-rw-r--r-- 1 root root 139144 2011-09-26 21:45 libgnome-keyring.so.0.1.1
khairi@ubuntu:/usr/lib$ ls -l ../lib32/libgnome-keyring*
lrwxrwxrwx 1 root root     21 2011-10-19 09:06 ../lib32/libgnome-keyring.so -> libgnome-keyring.so.0
lrwxrwxrwx 1 root root     25 2011-10-19 09:06 ../lib32/libgnome-keyring.so.0 -> libgnome-keyring.so.0.1.1
-rw-r--r-- 1 root root 133412 2011-09-26 21:44 ../lib32/libgnome-keyring.so.0.1.1

That should fix it.

Cheers!

Wednesday, October 19, 2011

SVN revert all other properties changes after an SVN merge

Usually after doing an SVN merge, there will be a lot of SVN properties changes to our local copy. If we committed these changes to our repo, we will have headache later on to resolve the issues (at least that's what my colleague told me).

Thus, in order to revert all other properties changes (except for the things that we really change) after doing an SVN merge, type the following in shell prompt:-

svn status | grep "^ M" | awk '{print $2}' | xargs svn revert

Sunday, October 9, 2011

PHP Pretty Backtrace

Sometimes during development, you want to look at the execution stack to see what's being passed around, and from where it's being called. That's when PHP's debug_backtrace function becomes useful. At other times, you probably only want a few of those information for debugging. Here's how I filtered those info to get what I really want:-

$log = debug_backtrace();
for ($i=0; $i < sizeof($log); $i++) {
  $dump[$i]['file'] = $log[$i]['file'];
  $dump[$i]['function'] = $log[$i]['function'];
  $dump[$i]['line'] = $log[$i]['line'];
}
error_log(__METHOD__.":".__LINE__.print_r($dump,true));

I've also found this blog post, which does similar, but only takes out the args argument.

$trace = debug_backtrace();
foreach ($trace as &$t) {
  unset($t['args']);
}
echo "<pre>".print_r ($trace,true)."</pre>";
exit();

Happy debugging!

Friday, September 9, 2011

How to change workspace in Netbeans

By default, Netbeans' workspace is located at

/home/<username>/.netbeans/<version>

or (for Windows users):-

C:\Users\<username>\.netbeans\<version>

If you want to work with different workspace, then you'll need to use the --userdir switch when executing Netbeans' shortcut.

In Linux, right click on your Netbeans' shortcut, and edit the command to be something like this:-

/bin/sh "/path/to/NetBeans x.x/bin/netbeans" --userdir /path/to/your/new/workspace

For Windows users, right click on your Netbeans' shortcut, and select Properties.
In the Target textbox, add the --userdir parameter to the very end. It should look something like this:-

"C:\Program Files\NetBeans x.x\bin\netbeans.exe" --userdir C:\path\to\new_workspace

Tips: You can create multiple shortcuts for different workspaces ;-)

References:-
http://stackoverflow.com/questions/973557/is-there-a-netbeans-equivalent-to-eclipses-workspace
http://mangstacular.blogspot.com/2009/03/netbeans-and-workspaces.html
.