## Run JUnit test from the command line

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;

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

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 {} \;  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


#### 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

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

[...]
set root='hd0,2'
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.

click for full size image

Categories: Uncategorized Tags:

## Adding custom boot target to GRUB2

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.

[...]
set root='hd0,msdos2'
linux   /vmlinuz
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.

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

Categories: Uncategorized Tags:

## Change GRUB2 default boot target

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.

Categories: Uncategorized Tags:

## Simulating a lowpass filter with gEDA and ngspice

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.

Categories: Uncategorized Tags:

## Minimal privoxy tor configuration

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

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
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: