Run JUnit test from the command line

December 23rd, 2012 No comments

JUnit tests can be run easily from within your IDE. Every remotely up to date IDE has some built-in view that gives nice visual feedback, usually red or green indicators.

But of course it is also possible to invoke your tests from the command line. A simple example:

import org.junit.runner.JUnitCore;

public class MyClass {
    public static void main(String[] args) {
        JUnitCore.main(MyJUnitTest.class.getName());
    }
}

A very nice article on JUnit testing by Lars Vogel can be found at http://www.vogella.com/articles/JUnit/article.html. He suggests iterating through the failures of a Result class to run the tests via code, which works fine, too:

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class MyClass {
    public static void main(String[] args) {
        Result result = JUnitCore.runClasses(MyJUnitTest.class);
        for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
        }
    }
}
Categories: Uncategorized Tags: ,

Set file’s time stamp to exif header date

December 10th, 2012 No comments

Jhead is a great tool for manipulating jpeg exif headers. To change a file’s time stamp to what’s stored in the header, invoke:

$ jhead -ft filename.jpg

To change the time stamp of all files that were changed within the last day:

find . -mtime -1 -exec -type f jhead -ft {} \;

See also http://www.sentex.net/~mwandel/jhead/usage.html

Categories: Uncategorized Tags:

KDE multi-monitor display settings are lost on logout

November 29th, 2012 No comments

There are quite a few bug reports on the kde bug tracking system about kde losing display settings on logout (e.g. Bug 183143). But since this problem has been present for a couple of years and is still existing in the latest version of KDE (i.e. 4.8.5 at this writing), here’s a workaround:

Add a parameter called StartupCommands to the krandr configuration file (usually located at ~/.kde/share/config/krandrrc that adjusts your display layout using xrandr on login:

[Display]
ApplyOnStartup=true
StartupCommands=xrandr --output "HDMI-0" --primary --output "VGA-0" --right-of "HDMI-0"

You also need to make sure that the command is invoked on login by setting the ApplyOnStartup parameter to true.

The actual xrandr command may of course look different, depending on the actual number and layout of screens. So YMMV!

Categories: Uncategorized Tags: , ,

Expendable Fedora 17 default services

November 16th, 2012 No comments

Based on Harald Hoyer’s great tutorial on boot time optimization for Fedora 17, here’s a list of services I usually disable on my Fedora 17 boxes:

cd /lib/systemd/system
for i in abrt* auditd* sendmail* sm-client* firstboot* ip6tables* fedora*storage* plymouth-*.* lvm2-monitor.* mdmonitor*.*;
do
  systemctl mask $i
done
for i in livesys livesys-late spice-vdagentd ; do sudo chkconfig $i off;done

This is just a memory hook for myself. YMMV and of course what’s expendable depends on the configuration you use on your box.

For an explanation of the systemctl mask command have a look at Lennart Poettering’s systemd tutorial or the systemctl manpage.

Categories: Uncategorized Tags:

rsync over ssh on non-default port

November 1st, 2012 No comments

There are basically two ways of archiving this

Changing rsync’s rsh parameter

You can simply feed ssh with a different port parameter as remote shell to ssh:

$ rsync -a --inplace --rsh='ssh -p12345' file user@remotehost:dir/

Create a per host config for ssh

Add a Host entry to ~/.ssh/config

[...]
Host foobar
    Port 12345
    User user
    Hostname host.example

and invoke rsync with that alias

$ rsync -a --inplace file foobar:dir/
Categories: Uncategorized Tags:

Bootstrapping a Fedora 17 rootserver

October 20th, 2012 No comments

Quite a few things have changed since I made the Bootstrapping a Fedora 15 rootserver post, e.g. download urls, anaconda options and the way you add boot targets to grub2 (in contrast to legacy grub). So here’s an updated version…

Get initial ramdisk and kernel

This is basically still the same as with Fedora 15. The download links have changed a bit since download.fedora.redhat.com doesn’t exist any longer (but I’ve updated the old post anyway)

cd /boot/
wget http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/x86_64/os/isolinux/initrd.img
wget http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/x86_64/os/isolinux/vmlinuz

Add a boot target to grub

Edit /etc/grub.d/40_custom and add the following menu entry

[...]
menuentry 'Fedora 17 Install' {
  set root='hd0,2'
  echo    'Loading Linux'
  linux   /vmlinuz vnc vncpassword=SECRET ksdevice=link ks=http://server/ks.cfg
  echo    'Loading initial ramdisk ...'
  initrd  /initrd.img
}

Adjust the root parameter depending on the partition that contains the vmlinuz and initrd.img files (/dev/sda2 in this example, see also Adding custom boot target to GRUB2).

Also note, that I changed the ksdevice parameter from eth0 (which sets a specific interface) to link (which uses the first interface with link up) since NIC interface names are no longer predictable in recent kernel versions (p10p1, em1, eth0, etc.). For a list of all possible value of ksdevice hava a look at the corresponding Fedora wiki page.

After editing /etc/grub.d/40_custom, don’t forget to recreate grub.cfg by invoking

grub2-mkconfig -o /boot/grub2/grub.cfg

After rebooting, connect to the vnc server using the password you specified as usual.

F17vncInstall

click for full size image

Categories: Uncategorized Tags: ,

Adding custom boot target to GRUB2

October 1st, 2012 No comments

In GRUB2 one doesn’t alter the main configuration file /boot/grub2/grub.cfg manually any more. Boot menu entries are automatically determined by the grub2-mkconfig script.

To add a custom menu entry, edit /etc/grub.d/40_custom

[...]
menuentry 'Custom Entry' {
  set root='hd0,msdos2'
  echo    'Loading Linux'  
  linux   /vmlinuz
  echo    'Loading initial ramdisk ...'
  initrd  /initramfs.img
}

Note that GRUB2 partition numbering starts with 1 (not 0 like GRUB) but disk numbering starts with 0, e.g. if your kernel and inital ramdisk are located on /dev/sda2, this translates to hd0,2.

On MS-DOS type partitions (which currently is the majority of partitions out there) hd0,2 and hd0,msdos2 are interchangeable.

To recreated grub.cfg with the added boot menu entry, invoke

grub2-mkconfig -o /boot/grub2/grub.cfg

Resources:
http://home.roadrunner.com/~computertaijutsu/grub2.html

Categories: Uncategorized Tags:

Change GRUB2 default boot target

September 19th, 2012 No comments

In GRUB, the default boot menu entry was determined by the order of entries in /boot/grub/menu.lst, the default one being the n-th specified by the default=n parameter.

In GRUB2 the main configuration file /boot/grub2/grub.cfg isn’t usually altered manually any more but automatically generated by invoking grub2-mkconfig. You can change the default boot target by changing the GRUB_DEFAULT paramater in /etc/default/grub. It takes three different values:

GRUB_DEFAULT=n specifies the n-th entry in /boot/grub2/grub.cfg. The first entry is selected with GRUB_DEFAULT=0, just like in GRUB.

GRUB_DEFAULT="String" chooses an entry by name (e.g. “Fedora (3.5.3-1.fc17.x86_64)”)

GRUB_DEFAULT=saved chooses the boot target specified in /boot/grub/grubenv regardless whether the order of entries has changed (e.g. due to a kernel update).

To manipulate /boot/grub/grubenv, you can list all possible entries

grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2

and specify the desired one with

grub2-set-default <menu entry title>

To verify the default menu entry, use

grub2-editenv list

Note that you have to run

grub2-mkconfig -o /boot/grub2/grub.cfg

if you make any changes to /etc/default/grub (e.g. change the GRUB_DEFAULT parameter). You don’t have to invoke it, if you just change the default target with grub2-set-default since this just alters grubenv but doesn’t make any changes to grub.cfg.

Resources:
http://fedoraproject.org/wiki/GRUB_2
http://www.linuxreaders.com/2011/11/fedora-16-how-to-change-boot-sequence-grub2.html

Categories: Uncategorized Tags: ,

Simulating a lowpass filter with gEDA and ngspice

September 4th, 2012 No comments

Getting started with ngspice can be quite tricky. It’s a very powerful piece of software and although the user manual is quite comprehensive, its complexity can easily scare off beginners.
Here’s a simple step-by-step tutorial on how to simulate a very simple electronic circuit. It should enable you to run your own simulations of circuits you designed.

Read more…

Categories: Uncategorized Tags:

Minimal privoxy tor configuration

August 1st, 2012 No comments

Privoxy is an extremely versatile and powerful non-caching web proxy. It’s often used in combination with Tor to anonymously surf the web.

The downside to privoxy’s versatility is that it can be very difficult and complex to configure. The Tor wiki however has a nice minimal privoxy configuration example. Assumed Tor listens as SOCKS-proxy on your local host at port 9050 (could be any other host or port, as well), a minimal privoxy configuration file (/etc/privoxy/config) could look like this:

# Generally, this file goes in /etc/privoxy/config
#
# Tor listens as a SOCKS4a proxy here:
forward-socks4a / 127.0.0.1:9050 .
confdir /etc/privoxy
logdir /var/log/privoxy
# actionsfile standard  # Internal purpose, recommended
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations
filterfile default.filter

# Don't log interesting things, only startup messages, warnings and errors
logfile logfile
#jarfile jarfile
#debug   0    # show each GET/POST/CONNECT request
debug   4096 # Startup banner and warnings
debug   8192 # Errors - *we highly recommended enabling this*

user-manual /usr/share/doc/privoxy/user-manual
listen-address  127.0.0.1:8118
toggle  1
enable-remote-toggle 0
enable-edit-actions 0
enable-remote-http-toggle 0
buffer-limit 4096

To check if Tor is up and running correctly, the Tor project offers a nice little GUI, called Vidalia.

Categories: Uncategorized Tags: ,
This website uses a Hackadelic PlugIn, Hackadelic SEO Table Of Contents 1.7.3.