Kotlin Basics II – If you could show me some code, that’d be great

Continuing from where we left off, this is the second part covering the basic syntax and constructs in Kotlin. In this article we’ll cover:
. Using control structures and conditional expressions
. Laying out the source code: packages (and directories)
Continue reading Kotlin Basics II – If you could show me some code, that’d be great

Kotlin Basics I – If you could show me some code, that’d be great

In the previous installment of the series we tried to answer what’s Kotlin all about. Now before we start looking under the bonnet, let’s just take it for a spin a bit.

We’ll go through several code snippets to get a taste of Kotlin and ease into its syntax. In fact, syntax is one of the several things where Kotlin excels – it’s lean and compact.

The article is split into two parts the first of which (this one) covers declaring the basic elements:
. functions,
. variables and
. classes and properties
Continue reading Kotlin Basics I – If you could show me some code, that’d be great

Kotlin: JetBrains’ JVM goodness

This is the debut of a new series called Learn me some Kotlin. The series is aimed at beginner to intermediate Java developers like myself (I’m writing these articles as I learn the language) although it will be easily understandable by anyone with a prior exposure to an object-oriented language.

Kotlin is a programming language targeting the Java platform. It hit version 1.0 in February this year (1.0.3 is the latest stable version) but has been in heavy use at JetBrains (the makers of the language) for several years now (long before they open-sourced it in 2011).

Why Kotlin

Why is Kotlin a worthy contender in an already crowded JVM space? Well, Kotlin positions itself as a concise, safe and pragmatic language for the JVM with a focus on interoperability with Java.
Continue reading Kotlin: JetBrains’ JVM goodness

Introduction to Docker

Welcome to the first part of this series. To understand rest of the series it’s essential to know the basics of Docker. So let’s get started.

Docker is an open platform for developing, shipping, and running applications.

Docker provides a way to run almost any application securely isolated in a container. The isolation and security allow you to run many containers simultaneously on your host. The lightweight nature of containers, which run without the extra load of a hypervisor, means you can get more out of your hardware.

These are the reasons it’s preferred platform for micro-services based applications.

Docker is based on the concept of Linux containers let’s have a look at Linux containers.

Linux containers

In a normal virtualized environment, one or more virtual machines run on top of a physical machine using a hypervisor like Xen, Hyper-V etc. Containers, on the other hand, run in user space on top of operating systems kernel.

Continue reading Introduction to Docker

GCD Of Two Numbers

Naive Algorithm

Function NaiveGCD(a, b)

best <- 0
for d from 1 to a+b:
    if d|a and d|b:
        best <- d
return best

  • Runtime approximately a+b
  • Very slow for 20 digit numbers

Python Implementation

def gcd(m, n):
    gc = 0
    for i in range(1, m+n):
        if m % i == 0 and n % i == 0:
            gc = i
    return gc

default_a = 3918848
default_b = 1653264

a = input("Enter a: [%s]" % default_a)
b = input("Enter b: [%s]" % default_b)

a = a or default_a
b = b or default_b

g = gcd(int(a), int(b))

print("GCD is: ", g)

Continue reading GCD Of Two Numbers