Programming and Exciting Things

Routing specific IP blocks over VPN on MAC OS

Published on 26.07.2016
I have one NAS device at home and I want to access it from office unfortunately default VPN client in MAC OSX doesn't have built in option to specify which traffic to go over current connection, it has only one checkbox which says "Send all traffic over VPN connection" but I don't want to send all traffic over my home router, it's slow and etc.
Probably good option is to use some other VPN clients like "Shimo" but there is other quick and simple solution.
Solution is pretty simple, because I'm using PPTP for VPN which is basically "pppd" program, I can create a script in "/etc/ppp/ip-up" with execution permissions, for example:
And file content can be:

IP address 192.168.89.255 is given by VPN server to me and it's same every time.
When the VPN link drops, those routes are automatically removed.
More examples for ip-up script can be found at
http://www.tldp.org/HOWTO/PPP-HOWTO/x1455.html and https://ppp.samba.org/pppd.html

Implement Android Notification Listener using NotificationListenerService

Published on 01.05.2016
NotificationListenerService was introduced from Android team as part of API 18 (Android 4.3), this class allows an application to receive information from notifications when it's created and removed.
To use it we need to implement 2 callback methods. Both of them have paramether named sbn which is object of StatusBarNotification class.
In this example I will show quickly how to listen notification events with just print them to console.logs
Let's start with creating new Java Class named NotificationService.java with following content:
Also we need to update our Manifest file to include this newly created service.
So basically that is :) Run and enjoy :) Note: User require to enable notification permission from "Settings > Security > Notification access".

MySQL usage of new JSON field

Published on 25.12.2015
As a part from my new project, I'm using MySQL JSON field which was introduced in version 5.7, functions are described in https://dev.mysql.com/doc/refman/5.7/en/json-functions.html Creating JSON data is pretty simple like:
As you can see Create Table syntax is same, difference is in `custom_data` JSON . So let's insert some data to it.

And lets assume that we want to filter data in JSON field. Result is:
Or if we want to check existence of sub element:
Result is:
And one more example for extracting value from JSON:

It's look pretty easy, right ? :)

Go lang create map from database results without using predefined struct

Published on 07.12.2015
I created some function which get "random" data from MySQL database and return it as JSON. Here is some example code for achieve this, I skipped boring part with imports and creating net/http server and error handling is skipped.

Fake rsyslog server with Go Lang

Published on 18.11.2015
Few months ago I created script which act as fake rsyslog server with python, so because I fall in love with Go Lang, here is updated version of this script with added logging into MongoDB