Showing posts from August, 2017

Anonymous Functions - Elixir

In Elixir, functions are first class citizens. What does it mean? It means that functions can be Assigned to variables Passed around as arguments to other functions Anonymous functions has no name and no modules. We can create them with syntax fn -> my_function = fn (param) -> "Passed param: #{param}" end In order to invoke this function we must use the .() syntax my_function.( "my_name" ) Named function can take anonymous functions as argument. This helps promote decoupling. A sample example is shown below defmodule Maths do def calculate (first, second, operation) do operation.(first, second) end end multiply = fn (first, second) -> first * second end addition = fn (first, second) -> first + second end sum = Maths .calculate( 2 , 5 , addition) product = Maths .calculate( 2 , 5 , multiply) The expected value for sum and product will be 7 and

Functional Programming - Elixir

I recently came across a Elixir and thought it's a nice time to talk about it. Elixir is a programming language created in 2012 and is designed to build scalable and maintainable applications. It has following features Functional - language is completely based on modules and functions. There are no classes Dynamic - it is dynamic language. There is no need to define type while creating a variable. They are automatically assigned during run time. Compiled - source code of a elixir file (.exs) is compiled to byte code Distributed and Concurrent - can run quickly and independently Runs on Erland Virtual Machine (BEAM) - highly stable and mature What is it used for? Elixir is a general purpose language especially suitable for Data Processing Network applications High Availability System Functions All named functions in Elixir must be a part of an enclosing module . A sample function declaration is shown below defmodule MyModule do def myFunction

Google Chrome Extension - ReactJS

An extension is a zipped bundle of files (HTML, CSS, Javascript, images etc). It allows us to add functionality to chrome without deeply diving into native code. They can interact with servers through XMLHttpRequest (ajax) and if we wish to read (or modify) HTML from existing web page then content script allows us to do so. Google has already done a great job with documentation and you can find a "Getting Started" guide here . Let's Start We are going to develop a simple extension which will show us the weather for selected city. We will be developing a single page application using ReactJS which will target weather API using XMLHttpRequest and then with help of plain old javascript we will process the JSON response to update UI. You can find source code of this application on Github under " app " folder. Packaging From the "app" folder you can extract the code for our single page application. This is the core of application