Programiści mylą Halloween z Bożym Narodzeniem bo 31OCT == 25DEC


Copying files between linux hosts

There are many ways to copy the file from one linux box to the other one.


First on the target machine (host:, place where the file should be copied to)

netsend -T machine tcp receive > filename.txt

and on the source machine (where the file is located)

netsend -T machine tcp transmit filename.txt


scp remoteUser@remoteHost:/home/remoteUser/file.txt ~/file.txt

How to set git branch in prompt

add this code to ~/.bashrc file

# git branch in prompt

function parse_git_branch {
git branch –no-color 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/\1/’

function parse_git_dirty {
git diff –quiet || echo “⚡”

function parse_git {
local branch=$(parse_git_branch)
if [[ -n “$branch” ]]; then
echo ” <$branch$(parse_git_dirty)>”

function prompt {
local LIGHT_RED=”\[33[1;31m\]”
local NORMAL=”\[33[00m\]”
local BOLD=”\[33[1m\]”
local OFF=”\[33[m\]”

PS1=’${debian_chroot:+($debian_chroot)}\[33[01;32m\]\u@\h\[33[00m\]:\[33[01;34m\]\w\[33[00m\]\[33[1;31m\]$(parse_git)\[33[m\]\$ ‘
PS2=”${BOLD}>>${OFF} ”


get IP address with maven and groovy

<project xmlns=”; xmlns:xsi=”; xsi:schemaLocation=””&gt;

def addr = InetAddress.getLocalHost();[] addresses=InetAddress.getAllByName(addr.getHostName());
for (address in addresses) {
if (!(address.getHostAddress().startsWith(“0”))) {
println “Your IP address is: ”
println address;;

the output should contain something like:

Your IP address is:


Parsing command line arguments in java with Apache Commons CLI

Simple way to parse command line arguments in java using Apache Commons CLI

first define Options for application

final Options options = new Options();
options.addOption(“d”, “database”, true, “jdbc URL to database, REQUIRED”);
options.addOption(“u”, “dbuser”, true, “database user name, REQUIRED”);
options.addOption(“p”, “dbpass”, true, “database password, REQUIRED”);
options.addOption(“v”, “verbose”, false, “Enable verbose output, OPTIONAL, default is disabled”);

next parse arguments and check it with options

final org.apache.commons.cli.CommandLineParser parser = new PosixParser();
cmd = parser.parse(options, args);

use boolean verbose = cmd.hasOption(“v”)  to check if parameter was passed in command line

use String user = cmd.getOptionValue(“u”); to get the parameter value

automatically generate the help statement

final HelpFormatter formatter = new HelpFormatter();
final StringBuilder usageSb = new StringBuilder();
usageSb.append(“java -jar my-application.jar [-v] -d <jdbc url> -u <db user> -p <db password>”);
final StringBuilder header = new StringBuilder();
header.append(“Description of the application:\n”);
header.append(“more info on the webpage;);
formatter.printHelp(usageSb.toString(), header.toString(), options,
“\nFor more information please check webpage;);

Reading bytes from InputStream

final InputStream is = httpResponse.getEntity().getContent();
final Writer writer = new StringWriter();
final char[] buffer = new char[1024];
try {
final Reader reader = new BufferedReader(new InputStreamReader(is, “UTF-8”));
int n;
while ((n = != -1) {
writer.write(buffer, 0, n);
} finally {
System.out.println(“OUTPUT : ” + writer.toString());


StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();