Friday, March 20, 2020

Changes happens every day, very few sense and rest don't care

Last year was worst with respect to my health but was good at my carrier growth. I have delivered concurrently 3 features on the cisco webex calling product. Last year learn nodejs, reactjs, ML, Some revision of python. Now focus is going towards C++, Rust, Competitive programming, Puzzle, Own product building Keep watching this space to get more posts.

Wednesday, December 5, 2018

Expectation from Software engineering

Quality Bug-free Performance Satisfy customer expectation User-friendly application stability scalability clean code

Thursday, December 21, 2017

What I am doing? I am learning :)

Its been so long that, I met you all though blog post. I have joined in a telecommunication company on this month last year. Since there I have been learning new thing. Its new place with different approach to solve problems. Quite legacy but it is giving nice learning.

Agile:
 Searching for new architecture , algorithm , pattern , language, solution are all keep you motivated and passionate about programming. But what I am learning here is quite simple. Its MVB - minimum viable product. This mantra is where they shine, make something useful for customer. Do research , but don't wait until you complete it. Give a MVB.

You don't have time to do 100 days for a single painting. Give us segment of it. And Go and do agile.

Interview:
 Taking interview for java opening in the current organization. What managers are expecting from the candidate is quite interesting. If you are under 3 years then know well what you worked on. Move your thinking from what and how? to why when you are in 3 - 5 years experience and You must be strong in basics too. 5 -7 years candidate must be strong in, how your current projects architectures works and crack some on the spot technical problems. Design and explain your solution in a such a way that how you normally do it in front of your desk.

Be confident and ready to learn from the interview questions. Don't over argue unless you are super confident. It may eat your interviewe timing and you may lose some other nice question what you could easily crack.

Interview is where candidate do the self judgement and interview do the discussion.

Cloud:
ML, Big data is cool. But moving to cloud is foundation. I had my first cloud training 5 years back. It was costly and cool to think about it on those days. But now cloud is every where. If you are not in cloud then you are not in this era.

Rust : (Every year new language;and new Style)
2015 - Scala
2016 - ELM
My language of 2017 is RUST.

Why I learn new language? for Interest. I am multilingual guy.
What you do with it? I use when I need it. It gives me broad vision to understand and sail in programming ocean.

Why Rust:
Rust influenced Elm - lang.
Low level language; No GC; No Interpret language;
Strong and Strick type and Safe.

Firefox quantum running much faster than the older version. Servo engine supports firefox to run faster which is written on Rust.


Tuesday, March 21, 2017

Found Monads in scala library

Scala library - A view in the Functional programming perspective
Here is the Monad from scala library
implicit class MonadOps[+A](trav: TraversableOnce[A]) {
    def map[B](f: A => B): TraversableOnce[B] = trav.toIterator map f
    def flatMap[B](f: A => GenTraversableOnce[B]): TraversableOnce[B] = trav.toIterator flatMap f
    def withFilter(p: A => Boolean) = trav.toIterator filter p
    def filter(p: A => Boolean): TraversableOnce[A] = withFilter(p)
  }
Lets look some important transfermations and actions available in scala

Transformation

map,flatMap, filter

map

maping to another type in collection
Scala doc says
Creates a new iterator that maps all produced values of this iterator to new values using a transformation function.
def map[B](f: A => B): Iterator[B] = new AbstractIterator[B]

flatMap

mapping to another type and flatterning it
Scala doc says
Creates a new iterator by applying a function to all values produced by this iterator and concatenating the results.
def flatMap[B](f: A => GenTraversableOnce[B]): Iterator[B]

filter

filtering to same type with applied function
Scala doc says
Returns an iterator over all the elements of this iterator that satisfy the predicate p. The order of the elements is preserved.
def filter(p: A => Boolean): Iterator[A]

Reduction

fold,reduce and aggregate

fold

Returns to single unit It takes the default parameter to accumulate the resulting value
Scala doc says
folds the elements of this traversable or iterator using the specified associative binary operator.
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 
Usage
list.map(_.budget).fold(0)((a,b)=> a+b)

reduce

It do the same like fold but does not accept the default value The accumulater is the first value of the traversable
Scala doc says
Reduces the elements of this traversable or iterator using the specified associative binary operator.
def reduce[A1 >: A](op: (A1, A1)  A1): A1

aggregate

It works as like reduce and fold, but in parallel
Scala doc says
Aggregates the results of applying an operator to subsequent elements.
def aggregate[B](z:  B)(seqop: (B, A)  B, combop: (B, B)  B): B

Tuesday, May 24, 2016

Dict - Elm Datastructure

Elm Dict Package /elm-lang/core/1.0.0/Dict

The Dict api is useful when situation comes to store key , pair value.It is Similar to Map / Dictionary in some other language.
Here you can find some basic function to play with Dict Api.
Use elm rector to execute this samples.

Dict.insert

Kind of put operation to store key , value pair in Dict
import Html exposing (Html,text)
import Dict exposing (Dict)

main = text (toString (insertIntoDict "Apple" 1 Dict.empty))

insertIntoDict: String -> Int -> Dict String Int -> Dict String Int
insertIntoDict key input myMap = 
  let      
    newMap =  Dict.insert key input myMap      
  in  
    newMap
Repl
> import Dict
> Dict.insert "A" 1 Dict.empty
Dict.fromList [("A",1)] : Dict.Dict String number
Dict.insert function expection three parameter
  1. Key
  2. Value
  3. Dict (This dict can be empty dict for the first time)

Dict.update

Update need a handler to check before performing the update action, That check function is Higher order function that too accpet Maybe type parameter.
import Html exposing (Html,text)
import Dict exposing (Dict)

main = text (toString  view)

view = 
  let
    appleDict = insertIntoDict "Apple" 1 Dict.empty
  in
    insertIntoDict "Apple" 2 appleDict

process : Int -> Maybe Int -> Maybe Int
process x y = case y of 
    Just val -> Just x
    Nothing -> Just 1

insertIntoDict: String -> Int -> Dict String Int ->  Dict String Int
insertIntoDict key input myMap= 
  let      
    newMap = case (Dict.get key myMap) of
      Nothing -> Dict.insert key input myMap
      Just val -> Dict.update key (process input) myMap
  in  
    newMap
Dict.update key (process input) myMap
Dict Update function expect second parameter to be a higer order function and That should have signature of
Maybe a -> Maybe a
Int this process function we are updating the newValue = 2 to the "Apple" key which already exist in Dict with oldValue = 1.
This process function acctualy expecting first paramter as Int which is new value that to be updated on Dict. This Int value curried out and applied as new value (clousure) to the higher order function. Find the process Signature
  process : Int -> Maybe Int -> Maybe Int

Dict.get

Get function to read the value based on the key from Dict
 import Html exposing (Html,text)
import Dict exposing (Dict)

main = text (toString view)

view = 
  let
    appleDict = insertIntoDict "Apple" 1 Dict.empty
    appleDict2 = insertIntoDict "Apple" 2 appleDict
  in    
    readFromDict "Apple" appleDict2

process : Int -> Maybe Int -> Maybe Int
process x y = case y of 
    Just val -> Just x
    Nothing -> Just 0

insertIntoDict: String -> Int -> Dict String Int ->  Dict String Int
insertIntoDict key input myMap= 
  let      
    newMap = case (Dict.get key myMap) of
      Nothing -> Dict.insert key input myMap
      Just val -> Dict.update key (process input) myMap
  in  
    newMap

readFromDict : String -> Dict String Int -> Int
readFromDict key map =   
  case (Dict.get key map) of
    Nothing -> 0
    Just v -> v
Dict.get function return the Maybe. Which need to be further processed to extract the value. This sample use the pattern matching (case) to process the Int value.
case (Dict.get key map) of
    Nothing -> 0
    Just v -> v

Saturday, May 14, 2016

Elm math formula using functions , pipe and currrying

Simple math formula in elm using pipe and currying
import Html exposing (..)

main = view

view = div [][
  div[] [text "(a + b)2 = a2 + 2ab + b2"] 
  ,div[][text "LHS = RHS"]
  ,div[][text (calcuate 2 2)]
  ]    

-- (a + b)2 = a2 + 2ab + b2

calcuate x y = (left x y) ++ "=" ++ (right x y)

left x y = x |> add y |> sqrt |> toString 

right x y = (sqrt x |> add (2 |> multiply  (x |> multiply y))) |> add (sqrt y) |> toString 
--right x y =  toString (add (add (sqrt x) (multiply 2 (multiply x y))) (sqrt y))

multiply : Int -> Int -> Int 
multiply x y = x * y

add : Int -> Int -> Int
add x y = x + y

sqrt : Int -> Int 
sqrt x = x ^ 2

Pipe

Pipe is helpfull to reduce parentheses usage. They are aliases for function application
x |> multiplyWith10 |> divideBy10 
It is usefull when performing sequance of function call, first function result will be passed to second function and it continues to the until last function call reaches. (a + b)2 = a2 + 2ab + b2 This simple formula can be represented using functions in elm with the same way we do in other language ,but the only difference is the formula representation will not be as the same order as in mathamatical world.
           +  ( +  ( a2)   ( *       2 ( *       a b))) (b2)     
toString (add (add (sqrt x) (multiply 2 (multiply x y))) (sqrt y))
If we read this call, then toString of add of add of sqrt x and multiply with 2 of .....
If you are using pipe , it will be like
-- a2       +   2       *        a      *       b       +    b2
(sqrt x |> add (2 |> multiply  (x |> multiply y))) |> add (sqrt y) |> toString 

Currried out

x |> add y 
add function expect two parameter, that x and y
Using pipe we are currying add with y and passing x as the another parameter.

Friday, May 13, 2016

Elm basic snippet

Elm

If

If and else are something different here without curly brackets {}
if "10" == "10" then "Its ten" else "Not ten"
If Not equal has different symbol here,
if "10" /= "11" then "Its ten" else "Not ten"

String Util

 - toInt
If you want to parse String to Int , this is the right util. The below method will return True if the String is parsable to Int or else otherwise Generaly String.toInt will return Result String Int , Which holds the Value / Error. The below method (validateStringToInt) would be the sample to extract the result value
String.toInt "10"`
Ok 10 : Result.Result String Int
validateStringToInt x =   
  case (String.toInt x) of
    Ok value -> True
    Err msg -> False

String Contact

Use ++ instead of regular + operator to concat. Every thing value here (Immutable) when doing contact it will give your new value
a = "one " ++ "two"
"one two" : String
a ++ "end"
"one twoend" : String

Tuple

- Tuple
Tuples are simple structure which hold the data in a order to server.
(10,11)
Access Tuple
fist element of the typle
fst (10,11)
second element of the tuple
snd (10,11)

Lambda expression

Forward slash for the parameter and -> function body
(\x -> x * 2)
Below code is for maping list to double list
double list = List.map (\x -> x * 2) list
<function> : List number -> List number
double [2,3,4]
[4,6,8] : List number
In Short lambda can be written like for single element , that automaticaly taken as default parameter
double list = List.map ((*) 2) list

Merging two sorted arrays - Big O (n+m) time complexity

 Problem :  Merge the two sorted arrays. Edge case :  Array can empty Arrays can be in different size let getMaxLength = ( input1 , input...