Thursday, July 11, 2019

Learning something new - Kotlin

Main: https://en.wikipedia.org/wiki/Kotlin_(programming_language)
Ref: https://medium.com/@mayuroks/learn-kotlin-for-android-in-one-day-50aa0bc099b0

Kotlin has been Google’s preferred language for Android app development since 7 May 2019.
I started working with Kotlin on 7 July 2019. That's 2 months of delay/gap.
I was busy traveling - Tokyo - Seattle - San Francisco - Tokyo - Mumbai - Delhi.

Now that i have settled in one place - Gurgaon, it's time to dive in.

History: Kotlin v1.0 was released on 15 February 2016.
It’s influenced by Java, Scala, Groovy, C#, Gosu, JavaScript, and Swift.

val : constant (immutable)
var : variable (mutable)

var username: String = "some user name"
val API_DELAY_CONSTANT: Int = 100

var myString: String? = null

fun getNumber(): Int {
return 1
}
private fun getStringLength(str1: String, str2: String): Int {
return str1.length + str2.length
}

var items: List<String> = ArrayList<String>()
for (item in items) {
// do something with item
}


for (index in items.indices) {
// access items using index
// items.get(index)
}


var i: Int = 0
// Some while loop
do {
    // do something
    i++

} while (i < 5)
// Another while loop
while (i < 10) {
    // do something
    i++


}

// A cool example of when statement
fun describe(obj: Any): String? {
var res: String? = null

when (obj) {
1 -> { res = "One" } // if obj == 1
"Hello" -> res ="Greeting" // if obj == "Hello"
is Long -> "Long" // if obj is of type Long
!is String -> "Not string" // if obj is not of type String
else -> {
// execute this block of code
}
}

return res
}



Kotlin has support for nested functions wow!

All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects need special care from developers: null-check must be performed before using the value. Kotlin provides null-safe operators to help developers:
1. A safe navigation operator "?."
2. A null coalescing operator "?:" named Elvis operator after Elvis Presley


foo()?.bar()?.baz().

Android Studio (based on IntelliJ IDEA) has official support for Kotlin, starting from Android Studio 3.
link: https://developer.android.com/kotlin/index.html
Apps built with Kotlin:
  1. Slack
  2. Lyft
  3. Robinhood
  4. Evernote
  5. Square
  6. Deliveroo
  7. Periscope
  8. Udacity
  9. Instacart
  10. Pinterest
  11. Basecamp
  12. Pocket
  13. Reddit
  14. Camera360
  15. Trello
  16. Foursquare
  17. Stride
  18. Amex
  19. Expedia
  20. Netflix
  21. Kindle
  22. KeepSafe
  23. NYTimes
  24. Wordpress
  25. Simple Bank
  26. Twitter
  27. Airbnb
  28. Flipboard
  29. Foursquare Robin
  30. Tencent WeChat
  31. GoJek
  32. Confluence
  33. June
  34. Adobe Reader
  35. Zomato

30 minutes to Learn Kotlin : https://developer.android.com/kotlin/learn
Developer Story - Zomato : https://www.youtube.com/watch?v=ao9QvtpszOU

Sunday, April 14, 2019

If Money is not a concern

If you aren’t using your money (not only to make/earn more money) to enjoy yourself, to make your life better,
and to give back and to make the lives of others better, then you’re literally wasting your millions.

The more money people have, the more selfish they seem to become.

Money is only good if it’s spent. The trick is to spend it on the right things. Spending money on what matters in life will make you happier.
No one said that you can’t pamper yourself from time to time.

How?

1. Live in a different part of the world every year. Just close your eyes and point to the map. Don't just travel. Live like a local. Stay.

2. Buy an Island. Why would you want an island? Why wouldn’t you want an island?! It’s a friggin’ island.
With palm trees. And coconuts. And tons of women (or men) wearing tiny bikinis and partying late into the tropical night.

3. Figure out a way to feed the hungry. Money can do just about anything these days. With enough of it, you could cure world hunger.
You could simply just buy every starving person some food.
Better yet, figure out how to stop people from wasting so much of it so that we can feed the remainder without further damaging the planet.

4. Eat and Drink the best, healthiest stuff out there. It should have been made with passion and skill.

5. Learn everything you can - languages, street smart skills. Try every sport.

If you aren’t doing what you want, what are you doing now? And what do you want to do?

ref: https://redditblog.com/2015/11/18/what-would-you-spend-your-life-doing-if-money-was-no-concern/

Tuesday, April 2, 2019

popular busy airport codes

EU
Main: CDG, FRA, MUC, VCE, FRO, MAD, BCN, AMS, CPH, HEL, VIE, BRU, ZRH, OSL, ARN
Others in Germany: CGN, DUS besides TXL,SXF for BER

USA
Main: SEA, BOS, NYC, SFO, LAX, SAN, SJC, ORD
Secondary: ATL, PDX, ANC, MSP, DTW, DFW

Canada
Main: YVR, YYZ, YUL, YYC, YOW
Vancouver, Toronto, Montreal, Calgary, Ottawa

Hawaii: KOA, ITO, OGG, HNL, LIH
Kona, Hilo, Kahului, Inouye, Lihue

Australia:SYD,MEL,BNE,CBR,CNS,ADL
Sydney,Melbourne,Brisbane,Canberra,Cairns,Adelaide

Sunday, February 10, 2019

hiring great software engineers that know regex is important

There is an old joke… The manager tells all the developers they need to come in at 9 am, take lunch at noon, and leave by 6 pm. Half the developers quit and productivity drops to almost zero. The manager then says come and go as you like. The developers show up at noon, work until 3 am, productivity skyrockets. The joke is, it is no joke.

I hate PHP. I hate Symfony.
It's a great thing though that you write strings for different languages/locales in yml files similar to the strings.yml used in Android apps.

I came across a bug in my code leading to failure in compilation/rendering.
The cause was unescaped "unquoted" strings inside the yml file.

such as
variable:"message in a "box""

correct way to use is
variable:"message in a \"box\""

I spent time trying to find a regular expression to detect such cases.

Here it is: 
((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)\1

Reference:
https://www.metaltoad.com/blog/regex-quoted-string-escapable-quotes

Going one step further with Kotlin & gRPC

Recently, I tried using Quarkus with Kotlin for grpc. I have worked with grpc for communication between microservices in Java & Golang. ...