File reading fun with Elixir and Erlang

To read a file using Elixir File module, all you gotta do is this (if you fire up your iex, and run this - assuming you have your file in the proper location)

In Elixir "c:\\tmp\\test2.log"

Using Erlang 
This also gives us a clue to call Erlang's built in libraries.

Elixir case do pattern matching example

case do allow us to quickly specify some condition and then we're good to go. The only catch here is the sequence condition (1st condition) a <=3 and (2nd condition) a > 3 must be in sequence, otherwise elixir will complaint. It is not a bug, just a logic error that you might want to avoid


defmodule Test do  def say(a) do
    cond do
      a <= 3 -> "lesser than3 "
      a > 3  -> "bigger than 3"


Notice how we specify condition for bigger than 2 conditions.

defmodule Test do
  def say(a) do
    case a do
     1 -> "1"
     2 -> "2"
     n when n > 2 -> "Big"

Creating exceptions using defexception. 

Yes it is why it is called defexceptions. Considered it a special keyword to do this specifically.

Example code and usage :-

defmodule AppError do
   defexception message: "app error"

// invoke it  raise defexception 

Raising error and hand…

TSQL Common table expression getting incorrect syntax near )

This message is really not helpful at all.

Say if you create a common table expression that does not immediate follow by a query, you get this nice error, for example :-

WITH MyDataCTE (Id, SecurityID)
 SELECT [Identity] as Id, SecurityID FROM [Ids_staging].dbo.[StageJPMorganValuationReport] WHERE batchId = 38969

SELECT * FROM MyDataCTE  /// Without this line here, you get this error.

Weird moments in Elixir

Calling Erlang external libraries.

Say you have the huge bunch of erlang libaries goodies from here, how do you call it?  Well, fire up your iex and then run the following command :


And you get the output.

Map data stucture : creating a map using %{}

map = %{:a => 1, 2 => :b}
Pipe operator |>

Getting started with elixir package manager can be a bitch

Many stuff are not well documented. And just crappy to read through so much to do a simple package install. Hopefully this helps.

mix (installed together with your elixir) and hex is your package manager. All you need to do is create a new project using the following command (you're trying to do something like npm install)

a) mix new myProject - after that try running mix compile. You can see your project being compiled.

After you have done that, open a file called "mix.exs". This is your package.json file in node. Locate your "defp deps" as shown here and add in a dependencies for cowboy or whatever you like from here :-

This basically saying that you are trying to use external libraries.

Next run "mix deps.get"  - to download your package to a folder called dep. This is done automatically.

Great and you will see dep folder being filled up.

Fire up your iex (using the following command - iex -S mix) and run the following command to see if your depen…

Getting started with AWS CodeCommit

AWS CodeCommit is Github in a nutshell.

To create your repository, goto AWS Console and click on create repository.

Next, you need to go to IAM and generate your CodeCommit credentials as show in the diagram below :-

Go ahead, download credentials and clone your repository as you would normally do with Git.

 I guess the interesting thing to do is the "Trigger". What' happens if you commit some code into this branch. You can create trigger to AWS SNS or AWS Lambda.

AWSSDK supports .Net Core

Just been messing around with AWS SNS using AWS nuget package and surprisingly it works on .Net Core.


Creating a lambda function which runs C# code

Go to your Amazon console and then choose Lambda.

Next, click on Blank Function.

Click next, when you are given the following screen :-

Next, you need to configure the handler. Handler always start off with your assembly (ONLY DLL please, exe is not supported). More detail info, please have a look at diagram below.

Set the runtime to C#.

If you encounter this error,

{ "errorType": "LambdaException", "errorMessage": "Could not find the LambdaSerializerAttribute on the assembly 'TestApp, Culture=neutral, PublicKeyToken=null' or method 'Main' while attempting to deserialize input data of type 'System.String[]'. To use types other than System.IO.Stream as input/output parameters, the assembly or Lambda function should be annotated with Amazon.Lambda.LambdaSerializerAttribute." }

it probably means you are passing a argument in your aws lambda function. It should not take in any arguments unless those type supported by AWS.