Ubuntu insights, Programming in groovy, java, et als!

Tuesday, September 15, 2015

Basic Authentication using Groovy

Here is a very minimal groovy based Basic Authentication Client which can come handy whilst talking to APIs.

def jsonBody = '{"day" : "11", "month" : "03", "year" : "2010", "hour" : "09", "min" : "08", "lat" : "18.9750", "lon" : "72.8258", "tzone" : "5.5", "gender" : "male"}'

new BasicAuthClient(

class BasicAuthClient{

    def userName, password, address, conn
    def getAuthHeader(){
        def authHeader = "$userName:$password".getBytes().encodeBase64().toString()
        return authHeader
    def getConnection(){
        this.conn = address.toURL().openConnection()
        conn.setRequestProperty("Authorization", "Basic ${getAuthHeader()}")
        return conn
    def doPost(body){
        def out = getConnection().getOutputStream(); 
        return getResponse()
    def getResponse(){
        def responseCode = conn.getResponseCode();
        def instream = responseCode < 207 ? conn.getInputStream() : conn.getErrorStream()        
        int i = instream.read()
        while (i != -1) {
            i = instream.read()


Tuesday, June 16, 2015

ConEmu for developer productivity

For the last one and half years, I have been a loyal user of Console 2, an alternative to command prompt on windows. Now, I have moved on to ConEmu for better productivity at workplace. It comes with many settings for customization. What I really love in ConEmu is its split screen support. At times when one is even lazy to shift between tabs/windows. In conjunction with vim, it is a breeze.

Say, you have an executable jar that also produces a log file. To hell with notepad and other UI editors - You could simply split your ConEmu screen to open up two or more console windows and spare one to skim through the output log file (using vim) simultaneously as and when you run the executable through an other.

The only caveat that I see with conEmu is that it eats up a tad bit more of memory than Console2 does (around 40 MB). But I guess I can live with that considering the fact that my laptop is powered with 16 GB of RAM. :)

Wednesday, June 03, 2015

VIM - first things first

Install theme :


Append the following lines in ../.vimrc (Startup Settings)

set guifont=Consolas:h11:cDEFAULT
color wombat
set guioptions-=T
set nu
let g:netrw_liststyle=3