Debug a Junit Ant Task from Eclipse

Posted: April 10th, 2012 | Author: | Filed under: ant, Debugging, Java | Tags: , , , | No Comments »

Sometimes you run into a test that works when run from within Eclipse but not from the command line. To debug the failing test from Eclipse, you can configure the Junit ant task to accept remote debugging sessions.

This can be done by adding the following lines to the junit task:

<junit fork="true">

		<!-- For remote debugging from Eclipse -->
		<jvmarg value="-Xdebug" />
		<jvmarg value="-Xnoagent" />
		<jvmarg value="-Djava.compiler=NONE" />
		<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y" />

This will make the task wait for an incoming debug connection on port 8787. It is necessary to have the fork attribute on the junit task set to true, because the jvmarg values can only be given to a starting Java virtual machine.


Get XML String from JQuery XML Object

Posted: January 9th, 2012 | Author: | Filed under: Uncategorized | Tags: , , | No Comments »

Problem: You have an XML structure in a JQuery object and now you want to extract a string with the raw xml.
Solution: Use the XMLSerializer class. This class provides methods for serializing DOMs and nodes into text or byte streams. In our case, we will call the serializeToString(data) method:

new XMLSerializer().serializeToString(xmlDoc);

Linux Commands

Posted: December 30th, 2011 | Author: | Filed under: Linux | Tags: , , , | No Comments »

find

Find all files from current directory and subdirectories

find . -name ‘*.doc’ -print

Result

report.doc
somedoc.doc

Finding files by date: http://www.cyberciti.biz/faq/howto-finding-files-by-date/

du

Show total disk usage of a directory:

du -sh /tmp/somedir

Computer Forensics

Posted: December 30th, 2011 | Author: | Filed under: Linux, Uncategorized, Windows | Tags: | No Comments »

The tools I use for computer forensics.

Windows

  • Recuva – Excellent at recovering data from Windows partitions and free to boot.
  • UFS Explorer – Not free, but is able to recover from linux partitions (Recuva is better for FAT/NTFS)
  • explore2fs – Access linux partitions from Windows. Free.
  • HFSExplorer – Access Mac partitions from Windows

Linux

  • Hiren’s Boot CD – Contains an impressive lineup of programs for computer forensics, but its legal status is often debated.
  • Trinity Rescue Kit – A live distro with backup programs, Midnight Commander, testdisk, shell and other good stuff. Legal!

Java Array Cast

Posted: December 30th, 2011 | Author: | Filed under: Java | Tags: | No Comments »

Casting the array obtained by invoking the toArray() method on a collection yields a ClassCastException.
For example:

String[] strings = listOfStrings.toArray();

will throw the ClassCastException.
The trick is to use the overloaded version of toArray(), which takes an array as parameter. This the javadoc description of the method

toArray(T[] a)
“Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.”

The solution is therefore to do this:

String[] sv = (String[])v.toArray(new String[0]);

Lightroom Image Archive on QNap TS-239 Pro II

Posted: May 9th, 2011 | Author: | Filed under: Lightroom, network, QNap | Tags: | No Comments »

Moving your Lightroom image library to a NAS

Lightrooms data files can roughly be put into two categories: The catalog file(s), which contain meta data about your images such as their location and the actual image files.

Lightroom does not permit having the catalog files on network attached storage, so you will have to keep those on your workstation. However, you can choose to have Lightroom backup your catalog files to the NAS so they are stored together with your images. This can be configured by going into Edit > Catalog Settings in Lightroom.

The following steps explain how to move your images from your workstation to a location on the NAS.

  • Locate your catalog file (you can find it in Edit > Catalog Settings) and make a backup of it. Just as a safety precaution.
  • Locate the folder containing your images and copy it to the NAS
  • Rename the local image folder to something like ‘images_OLD’
  • Open Lightroom
  • In Library mode, there should now be question marks on the folders, since we renamed the image folder to images_OLD
  • Right click on each folder and select its new location on the NAS
  • Once all folders have been resolved, do a quick check, that all images are there

If something goes wrong you can always replace the catalog file with the backup from step 1 and rename the images_OLD back to using your local image folder.

Performance

As to be expected, there is a slight performance drop, by having the images on a network share instead of a local harddisk. In order to quantify the difference I picked 10 test photos (RAW) and measured the the time it took to zoom in on the image in Library mode. Zooming in on an image forces the actual image to be loaded into memory instead of just showing a preview.

  • Avg. zoom time Local: 6 seconds
  • Avg. zoom time NAS: 6.9 seconds

Not much of a difference and hardly noticable. I have not timed any other operations, but it appears, that the main loading happens only once. I.e., there is no lag when cropping or fixing white balance, since the image has already been loaded into memory.


Harddisk Spindown on TS-239 Pro II

Posted: March 27th, 2011 | Author: | Filed under: Linux, QNap | Tags: | No Comments »

It is possible to configure the harddisks to spin down after a period of inactivity, but if one or more processes keep reading and writing from the disks, that will prevent them from entering standby mode.
To find out which processes are causing disk activity, the following script is very useful:
blkdevMonitor.sh
The script works like this:

  • A standby signal is sent to the disk.
  • Wait until a process wakes up the disk and then prints out name of that process.
  • Repeat.

The following link contains a list of daemons and configurations known to cause random disk activity: Standby Mode FAQ
Older versions of Squeezebox Server caused lots of disk activity, but fortunately that has been resolved in version 7.5.1.
What is jdb2 and flush?
Sometimes the processes “jbd2″ and “flush” are waking up the harddisk. As I understand, these processes are responsible for doing delayed writes to the disk in order to optimize performance. In other words, they are writing to the disk on behalf of other processes which makes it difficult to find the culprit(s). In my case, it was the samba daemon accessing the disk. As long as a PC or media streamer on your network has an open view on any of your samba shares, it will cause the disks to wake up.


Formatting a USB drive from a TS-239 Pro II

Posted: January 31st, 2011 | Author: | Filed under: Linux, QNap | Tags: | No Comments »

Plug the USB stick into the Qnap. Then in a terminal, as root, do an lsusb to confirm that the USB drive has been recognised.

To find out what device name it has been assigned, do a dmesg | tail. This will print the latest lines from the kernel log, which should contain information about the inserted USB drive:

fdisk -l, which shows all connected drives, can also be used to find the right device name. The USB drive can be recognised by its size. In this case, it is a 2 GB one:
output from fdisk -l
If the USB drive is already formatted with e.g. NTFS, it has probably been mounted automatically, in which case it should be unmounted. You can check this with the df command:
df
Once we know the name of the drive and it is unmounted, we can create a new linux partition using fdisk:

  • If for example the device is sdv1, do an fdisk /dev/sdv1
  • type d to delete any existing partitions.
  • Type n to create a new partition.
  • Make it primary and first
  • Go with the defaults when prompted for start and end cylinder
  • Press t to change the filesystem to linux (number 83)
  • Type w to write the changes to the disk and exit

Finally, format the partition with the ext3 filesystem:

mke2fs -j /dev/sdv1


Now the partion is formatted and it can be mounted again:

mount /dev/sdv1

The USB drive is now ready for use :)


Starting, restarting and stopping daemons in Linux

Posted: January 16th, 2011 | Author: | Filed under: Linux, QNap | Tags: , , , , | No Comments »

Daemon services, or just daemons, are started at boot time. They are roughly equivalent to services in the Windows world.
To see which daemons are available on a system, do an

ls -l /etc/init.d/

Every script in that directory represents a daemon, which can be started, restarted and stopped manually using the following syntax:

/etc/init.d/<daemon name> start | restart | stop

If, for example, I wanted to restart an nzb-get daemon due to changes in its configuration files, I would type

/etc/init.d/nzb-get.sh restart

After issuing the command, the daemon will usually print some lines to the terminal indicating what it is doing, e.g.: ”Starting NZB-Get Daemon” or “Shutting Down“.

If you want to make sure whether a daemon is running or not, you can grep for its name in the list of running processes. If I wanted to see if the nzb-get daemon was really started, I could do the following grep:

ps -aux | grep nzb

If the daemon is running, this will produce a result like:

8148 admin 2456 S /opt/bin/nzbget –daemon
8355 admin 564 S grep nzb

The first line is the daemon. Notice the “–daemon” at the end of the line. The second line is the grep process we just ran to find the daemon.


Subversion on QNAP TS-239 Pro II

Posted: December 6th, 2010 | Author: | Filed under: QNap | Tags: | No Comments »

Based on the guide on the QNap wiki. This guide specifically shows how to install a subversion server on port 4000 for multiple repositories on the QNAP TS-239 Pro II.

  • Install svnserve:
    # ipkg update
    # ipkg install svn
  • Create a directory for the repositories:
    # mkdir /share/HDA_DATA/subversion
  • To create a new repository for a project, do the following:
    # svnadmin create /share/HDA_DATA/subversion/repos1

    NB: To delete a repository, just delete the directory itself.

  • Access to the repositories is set up in the repos1/conf/svnserve.conf, repos1/conf/passwd and repos1/conf/authz files. The following is a basic configuration.

svnserve.conf:

[general]
anon-access = read
auth-access = write
password-db = passwd

passwd:

[users]
svnuser= svnusersecret

authz:

[repository:/share/HDA_DATA/subversion/repos1]
svnuser = rw
  • To start the svnserve daemon on startup, we must add a command to autorun.sh.
    This file is located on the configuration ram block, sdx6, which must first be mounted. This is done in the following way on the TS-239 Pro II (for other models, see Running Your Own Application at Startup)

    # mount -t ext2 /dev/sdx6 /tmp/config

    Open autorun.sh in an editor:

    # nano /tmp/config/autorun.sh

    Add the following line, which will make sure svnserve is executed only when opt/bin has been loaded:

    (while test ! -x “/opt/bin/svnserve”; do sleep 5; done; /opt/bin/svnserve -d –listen-port=4000)&

    Finally, make sure autorun.sh is executable and unmount sdx6:

    # chmod +x /tmp/config/autorun.sh
    # umount /tmp/config
  • You can test the subversion server by doing a checkout using your favourite subversion client (e.g. TortoiseSVN). The url to check out will be something like this:
    svn://nas:4000/share/HDA_DATA/subversion/repos1