Author : beriba | 03/27/2018
#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/opt/project/project.jar
PID_PATH_NAME=/tmp/${SERVICE_NAME}-pid
LOG_FILE=/var/log/${SERVICE_NAME}.log
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup java -jar $PATH_TO_JAR >> $LOG_FILE 2>&1&
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup java -jar $PATH_TO_JAR >> $LOG_FILE 2>&1&
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac
Author : beriba | 03/25/2018
tr ' ' "\n" < FILE | grep "string_you_want_to_count" | wc -l
Author : beriba | 09/16/2016

Installing agilo error:

protagonist@1.5.0 install: `node-gyp rebuild`

Installing protagonist error:

gyp: Call to 'node -e "require('nan')"' returned exit status 127 while in binding.gyp. while trying to load binding.gyp

Solution:

sudo apt-get install nodejs-legacy

Do it even if you have nodejs installed!

Just install:

sudo apt-get install kio-extras

It works on Kubuntu 16.04 so it’ll probably also work on Ubuntu 16.04. I also found out that it may work on Ubuntu 15.04.

Author : beriba | 08/08/2016
sudo apt-get install exfat-fuse exfat-utils

Then just mount exFAT device.

There is a simple trick to specify a tab as a separator. You simply have to write it as:

$'\t'

For example:

cat in.txt | sort -t $'\t' -k 2

It should work in all commands where you can specify separator.

Author : beriba | 06/08/2015

This is plain and simple. Just go to the line you want to select and hit

Shift+V
Author : beriba | 02/09/2014

Have you ever wondered is there any way to get private or protected properties from other object? Of course you have. If you’re developing something from scratch this is totally unneeded. You can just made a property either public or make get/set methods. Of course the second option is way much better.
But sometimes you are using a third-party module, you just can’t edit it and you need a private/protected property. In PHP it’s not the end of the world. Below you can find two methods, which sets and gets (respectively) non-public values.

/**
 * Sets value of protected or private property in given object
 *
 * @param mixed  $object   Object in which we want to change property value
 * @param string $property Property name
 * @param mixed  $value    New property value
 */
protected function setNonPublicValue($object, $property, $value)
{
    $reflectionObject = new ReflectionObject($object);
    $reflectionProperty = $reflectionObject->getProperty($property);
    $reflectionProperty->setAccessible(true);
    $reflectionProperty->setValue($object, $value);
}

/**
 * Gets value of protected or private property from given object
 *
 * @param mixed  $object   Object in which we want to change property value
 * @param string $property Property name
 *
 * @return mixed
 */
protected function getNonPublicValue($object, $property)
{
    $reflectionObject = new ReflectionObject($object);
    $reflectionProperty = $reflectionObject->getProperty($property);
    $reflectionProperty->setAccessible(true);

    return $reflectionProperty->getValue($object);
}

This is very dirty solution and should be used only when you’re aware what you’re doing and only when no other ways are possible.

Author : beriba | 02/01/2014

Using virtual machines is a very common practice. I’ll not tell you here the pros and cons of using them because it’s not the point of this post. One of the most popular VM tools is VirtualBox. While using linux VM you sometimes need to share some data between host and VM. Of course VirtualBox has a functionality to do that. From host (assuming that it is Windows) this folder is instantly accessible. But from VM this folder is only accessible by root. Adding sudo to every cp or any other command using shared folder isn’t what we really want. There is a solution. You just need to add your user to vboxsf group. You can do that by executing

sudo usermod -a -G vboxsf myusername

But that’s not everything. Now you just have to re-login (or reboot). But sometimes there are reasons to not reboot the VM. There’s also solution for that. You just have to do an explicit login.

su - myusername

There’s only one thing you have to remember. Until doing a re-login, you have to do an explicit login in every terminal session you open.

In the previous post I wrote about Windows Azure Queue. But back then, when I was playing with it I had a significant problem with creating it. The main difficulty was connecting to real Azure Queue (not emulated one). I couldn’t find anywhere how connection string should look like. After some ‚shotgun debugging’ I came up with something that works.

$queueRestProxy = ServicesBuilder::getInstance()->createQueueService('DefaultEndpointsProtocol=https;AccountName={your_account_name};AccountKey=4Gu6Jvm9c5zlaaGEmuA9GZqYr3RzqRfC0W20Yrjnu0sayRnhXeHMCQYWy0IfXnlwTWwPHW2fU+bJ8bqlJRBPgg==');

My AccountName in this string was lower case and you may want to write it that way if something doesn’t work with upper case letters.

I don’t know if it is still valid because it was 6 months ago or more but maybe it will be useful for someone.