Posts from 2013-11

Using yum's shell

posted on 2013-11-30 17:00:39

When using yum and having to search or change a lot of installed packages, it makes sense to use yum's shell.

Invoke it via

yum shell

Do not forget to sudo, when running it as non-root.

Once you are at the yum prompt, you can directly use the following:

search <package-name>
remove <package-name>
install <package-name>

This will lead to a list of changes that are to be applied. If you escape the shell then via exit or quit, nothing will be changed.

Prior do


to apply the transactions you prepared.

Change gradle project layout

posted on 2013-11-26 21:34:39

For java projects, gradle uses by default (or call it 'by convention') the following structure:


src/main/java is was usually is where usually the javacode is located in an eclipse project, src/test/java is where the JUnit tests live.

If you need to change this to look it like this,


this can be easily done.

Add the following lines into your build.gradle:

// fix project structure from src/main/java to 'src' and src/main/test to 'tests'
sourceSets {
    main {
        java {
            srcDir 'src'
    test {
        java {
            srcDir 'tests'

If you have problems with a resources folder, you may have to fix this also in a similar manner.

Remapping Keys in Windows 7 through registry

posted on 2013-11-24 19:18:44

For easier keyboard handling (and to save my fingers) I tend to switch Capslock and right CTRL, as well as left CTRL and left ALT/ALT Gr. For Windows there exist external programs like AutoHotkey and others, but I prefer doing it more low-level through the Windows Registry.

To do this, a key has to be set at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout. To check if it exists (or look up its current setting), WIN+R regedit, and navigate there. (This is just regedit in Windows Run Dialogue.) Note that the key is named Keyboard Layout, not Keyboard Layouts, do not change the latter.

If there is nothing present, do not worry. First a look on the theory and how the key is structured. Easiest to use are .reg files, a working example may look like this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,1d,00,3a,00,3a,00,1d,00,38,e0,1d,e0,1d,e0,38,e0,00,00,00,00 

This switches right CTRL with right ALT and left CTRL with CapsLock.

Looks complicated? This text here can actually be pasted into an empty .txt file. Rename it then to my_keymap.reg (Change the extension so Windows realizes to process this as a registry file.) and double click. Approve the changes, reboot, and you have a sticking change of your keymap. (To undo, delete the registry key and reboot.)

For easier explaining, the same code again, but with some formatting applied, and line numbers added:

 1      Windows Registry Editor Version 5.00
 3      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
 4      "Scancode Map"=hex:
 6      00,00,00,00,
 7      00,00,00,00,
 9      05,00,00,00,
11      1d,00,3a,00,
12      3a,00,1d,00,
13      38,e0,1d,e0,
14      1d,e0,38,e0,
16      00,00,00,00 

This looks a bit better. But what do these hex-combos mean?

DWORDS (Windows data type representing a 32bit unsigned int) in lines 6, 7 and 16 are ALWAYS zeroes. The last one is a null terminator, the first ones are version information and flags as a header. Header information is always zeroes in the current version of the Scan Code Mapper.

Line 9 is a counter of all the DWORDs representing remappings that follow (Lines 11 to 14 are four mappings) plus the terminator in line 16. That is why there is a 5. This depends on how many mappings you create and has to be set accordingly. For comparison in an example without a single remapping, it should be set to 1 and will then look like this:

 1      Windows Registry Editor Version 5.00
 3      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
 4      "Scancode Map"=hex:
 6      00,00,00,00,
 7      00,00,00,00,
 9      01,00,00,00,
11      00,00,00,00 

But no need to create a reg-key like this if you want to have the changes removed again, just delete the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout key and reboot.

These lines from the former example:

11      1d,00,3a,00,
12      3a,00,1d,00,
13      38,e0,1d,e0,
14      1d,e0,38,e0,

are where actually keys are remapped. The first two bytes represent the key's keycode that will be used, the last two bytes represent the key that is changed.


11      1d,00,3a,00,

just means map L-Ctrl (1d) onto Caps-Lock (3a). Line 12 is the same keys, but in reverse, 13 and 14 switches R-Alt and R-Ctrl. (Comes in handy for emacs usage.)

Keycodes were taken from this document here, which I stumbled upon somewhere in the msdn pages. See column 'scan 1 make', the first one of each eight entries, page 16 onwards. Note that i.e. Right Alt is noted as e0_38, but when used as the first half of the DWORD in line 13 or the second half in line 14, it's bytes are actually switched.

A last example, this one just replaces Capslock with R-Ctrl:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:





Last three DWORDS are 02,00,00,00,, since two more lines are following, the actual rebind and finally the null terminator.

If you copy paste this, it will not work. You have to reformat, so that there are no newlines in there:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,01,00,00,00,1d,00,3a,00,00,00,00,00 

This code can be pasted to a file named choose-a-name.reg. Save, double-click, reboot, and your CapsLock key will be gone. If you are interested in the original Microsoft article have based this on, which is from 2001, go here. Also this link helped.

Why to bother with emacs and how to use its help

posted on 2013-11-19 16:33:44

Lately emacs has popped up on my radar. I have been using vim with heavy customization for years, and the benefits are out of question for me. Shell usage, file-related encoding awareness (and understanding), build automatization skills all stem mostly from this editor. That is just because these things are possible. Eclipse and friends will not let you get low-level enough, where you have to understand what you are doing.

Still vim is 'just' an editor, emacs can the environment YOU want, it just lacks a proper editor anecdotically they say. If everything is customizable, why not get vim's editing capabilities into emacs?

Emacs keybinds mostly are strange or are outright crap.

c-n c-p c-f c-b for moving around is nowhere comparable with hjkl in vim. They exist because they could be memoized easily; Next line, Previous line, Forward a char, back a char. But this will fry your hands and pinky finger over time... Also on the keyboards in the time of lisp machines, CTRL and ALT were switched. Once the era of commercial lisp ended, the new keyboards just started to look like what they are now. Compare this to this. Having rebound CTRL to CAPS will lessen this problem, but it will be not as good as it could be.

Emacs is on my task list for its R integration and as it provides an excuse to familiarize myself with elisp (After being forced to learn scheme back in the first semester I was hooked on lisp and programming languages.) ... and down the rabbit hole I go. Emacs' evil-mode helps with the transition a lot, and after one and a half days some comprehension for all the emacs evangelists enthusiasm already shows. If in doubt, watch this.

Only problem is, evil will not work in all the modes (which is good as well as bad). Also most of the time you do not even know what you want to know from the editor, or how to tell him what you want.

For getting help, keep these in mind:

C-h C-h 'open meta-help
and then to scroll:
space 'forward
backspace 'backward
q 'quit

Short for CTRL-h twice, is some kind of 'meta' help.

Also especially helpful are:

C-h f <function> 'describe function
C-h c <key> 'lookup function bound to key
C-h w <function> 'lookup keybind for function

C-h b 'show all key bindings

C-h m 'help on currently active modes
C-h l 'show last several hundred keypresses
C-h C-f 'emacs faq

Especially the first three key sequences are great. To be proficient in emacs, you (more or less) have to rebind keys to work properly. (Claiming otherwise is uneducated guessing. :o))

scp properly explained

posted on 2013-11-16 17:05:03

scp is handy when transferring files from one host to another while being in a shell. How else to transfer stuff without using FTP or a kind of version control? Of course there are other alternatives, but scp's advantage is that it is widely available, does not need any kind of setup on the other host (As long as you have access to your other box, that is.) and has encrypted traffic. Also no GUI, mounting of USB sticks etc. pp. is needed. Sounds great.

The syntax looks like this, higlevel:


Or lower level and a little more concrete:

scp <src-user>@<src-host>:/dir/file <dst-user>@<dst-host>:/dir/file

src is shorthand for 'source', dst for 'destination', in case you wondered. Of course there are flags and parameter settings that can be used. But using man scp yourself is not rocket science. :o)

To specify working scp calls it is helpful to properly understand the user@host:file syntax. If your current use case is to copy a file from the host you are currently on, user@src-host can be omitted. Just the filename (and its path if you are not in the same directory on the shell) is needed. user is the username of the system user on the machine in question. This is the user with which you'd log into the remote machine. If passwords are needed, the system will promt you to enter them.

If you have setup SSH keys properly, and are in the same folder as the file you want to transfer, a call could look like this:

scp example.txt <dst-host>:

<dst-host> is either a valid IP or a domain name pointing to the IP.

Here are several things omitted:

  1. The <src-user>, the user on the machine you are currently logged on, and <src-host>, the address of the current host you are on.
  2. The file path and file name at the destination.

So the file will be put in the homefolder of the user that is used on the remote machine. (This is the folder entry of the user entry, to look it up use grep <username> /etc/passwd on the remote machine, in case it is not /home/<username>.)

The colon in the example above MUST NOT be omitted.

Else nothing will be copied to the remote address. You will not an error message, since linux thinks the destination address you specified is a file name, and the file is copied locally.

If you want to specify a certain folder on the remote host, either use the full path, or specify it in relation to the users home directory.


## file on server will be '/home/sjas/.ssh/asdf.txt'
scp file.txt 123.123.123:.ssh/asdf.txt

## file on server will be '/tmp/file.txt'
scp file.txt

So long. Maybe as a last note that there is the -r flag, so you can copy whole directories and not just files.

Obtain your external ip while being on the shell

posted on 2013-11-16 00:42:42

Before you use google and a web browser, just use:


Easy. For more options go to



is way faster.

Run `git pull` on all folders in current folder

posted on 2013-11-12 04:07:16

To pull newest changes into each of the repositories in your current folder, try this: (All folders lie directly one level below. No recursive check.)

for i in *; do cd $PWD/"${i}" && git pull | cat && cd ..; done

This was kind of tricky to figure out. Important was $PWD else the cd will not work properly, and the cat instead of echo so the console output gets shown.

Run bash from Java

posted on 2013-11-11 08:12:38

Snippet from stackoverflow:

process p = Runtime.getRuntime().exec("");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;

while ((line = in.readLine()) != null) {
   // use bash script line output

I hope I do never have to resort this... but I have doubts. Since this works not only for shellscripts, but basically any executable producing console output. Will have to test this on different platforms i bet, though. Just to make it sure it runs where it has to.

Javascript under pressure

posted on 2013-11-10 00:34:10

Somewhere on twitter I stumbled across this link. Since I know almost no javascript, this was a welcome excuse to fuddle around. It took me quite long, like 1,5 hours. I installed a javascript interpreter during that for fun, too. Which is harder than you would imagine, every browser has js built into, but noone seems to need a single executable to use... but Mozilla helped me in the end.

Anyway, my solutions:

First task: Return double value of i.

function doubleInteger(i) {
    return i*2;


Second task: Return true for even i, else false.

function isNumberEven(i) {
    return !(i % 2);

Still easy, though I was not as concise as this at first.

Third task: Return the file extension of a string i, else false.

function getFileExtension(i) {
    return (new RegExp("(\\w*\\.)*\\w*\\.\\w\\w\\w").test(i)) ? i.match("\\w+$") : false;

No stranger to regexp's, but never done them in js... Also was not as concise as this at first.

Fourth task: Get the longest string from an array.

function longestString(i) {
    var longString = "";

    for (var x in i)
        var stringToCheck = i[x]; 

        if( i[x] ) === '[object Array]' )
            stringToCheck = longestString( i[x] );

        if (stringToCheck.length > longString.length)
            longString = stringToCheck;
    return longString;

Ok, i know i got to use recursion. But what types do I have to check for???

Fifth task: i will be an array, containing integers, strings and/or arrays like itself. Sum all the integers you find, anywhere in the nest of arrays.

function arraySum(i) {

    return i.reduce(
        function(total, i)
            if (typeof i == 'number') 
                return total + i;
            else if (i.reduce) 
                return total + arraySum(i);
            return total;
        }, 0);

So, when this calls itself recursively, and return is found, this is the final return. Counting is stopped, as soon as the first recursive call is finished. Hmmmm. What is this reduce?

Number five I was not able to solve on my own (I blame not knowing any js.). I knew the error cause, but I did not even know what to google beside a complete solution.

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apache2.4, apachebench, apple, applet, arcconf, arch, architecture, areca, arping, asa, asdm, autoconf, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blockdev, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, coleslaw, colorscheme, common lisp, configuration management, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fbsd, fdisk, fedora, file, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, github, gitolite, global, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, innodb, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pct, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plasma, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pveam, pvecm, pvesm, pvresize, python, qemu, qemu-img, qm, qmrestore, quicklisp, quickshare, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x11vnc, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

Unless otherwise credited all material Creative Commons License by sjas