defmodule Alisinabh.Blog do

def Jalaali_calendar_for_elixir do # 2017-9-21T23:37:57Z

Hi everyone.

Today i released jalaali package version 0.2 for elixir.

It offers a new module Jalaali.Calendar which is an implementation of elixir’s Calendar module.

With help of this it is possible now to convert DateTimes to each other easily by using DateTime.convert or Date.convert functions.

Long story short

The previous version of jalaali was a mess! really.

It just provided functions to users for converting from/to ISO calendar.

The most annoying thing was it actually did not change the calendar property in a Date/DateTime struct.

Even if it did it wouldn’t be a useful feature cause conversion was not possible throw Elixir < 1.5

So after a very long talk in community about this which you can read here use of day number + day fraction was chosen to implement. This decision has made elixir one of rare languages with a very very very strong native calendar system.

It’s been a while since elixir 1.5.x was released and i’ve been really excited about adapting my jalaali library with the new Calendar system in elixir.

At first i thought it may take me several days to make that happen, BUT surprisingly it was so easy that it only took me less than 5 hours (including tests and documentations) and jalaali 0.2 is now published.

I really liked it and i may try adapting other calendar systems for elixir as well just for fun of it.

btw, i will be happy if you take a look at jalaali and maybe star it?

Thank you

{:ok, :happy_coding}



def Old_code_backfire! do # 2017-6-24T4:8:21Z

As a daily programmer who lives by programming as a profession, Sometimes projects are not cool and they don’t cheer you up.

Specially if they are you OLD CODES -__-

Your old projects can kill you when they are still in use. Every day you learn more and they that code makes less sense. But sometimes things go wrong when you realize that the code is bad an unreliable AT THE SAME TIME!

For instance let me tell you my story about one.

I’ve developed an Asterisk AGI server with .net and AsterNET. AsterNET does’t use the async feature of .net and uses a Thread Pool.

So if you need 500 calls, you’ll need 500 threads!

We’ve been migrated our new projects to a new server in last two years but our old projects are still running on AsterNET server. The problem with that server is it will crash from time to time. Because of StackOverflow exceptions. The old projects are not valuable enough to fix and not so useless to just go on.

So, I came up with a fairly good solution. Using a process supervisor (AKA Safe process runner).

It will simply run the process and wait for it to exit. If so, SafeProcess will re-run the process.

It’s not the perfect solution but it will buy me time and because this exception happens rarely (once or twice a month on average traffic) we can ignore it.

SafePorcess is available to use for everyone under no license:

{:ok, :be_safe}



def X_window_multi_monitor_brightness_control do # 2017-4-24T6:35:46Z

Not so long ago, I’ve decided to move from Windows to Arch for both my office and home PCs.


Because i loved Elixir so much and it works much better and easier on linux.

Why arch?

Two reasons:

  1. It’s a rolling release, means i always can use latest version of software unlike Debian.
  2. AUR man. B) AUR ROCKS!!!

You mean Debian is bad?

Absolutely not, Debian is perfect choice for servers. Indeed debian is super robust!

It just limits you as a home user.

Tell me more

I’ve finally managed to get arch up and running after three failures thanks to Nvidia’s lack of support for linux. It was my mistake to install proprietary drivers. Everything was OK with open sourced drivers provided by community.

My station setup for both home and work has two 21.6 monitors. When i first learnt about Night-shift i was using Windows. Back in windows everything was nicely handled with f.lux. But flux lack good user interface in linux. after searching just a bit i found Redshift it is really nice. it lacks users interface but seriously a linux user wont need that, will they?

Everything was fine with Redshift even it does fake brightness adjustment BUT my problem was when i wanted to turn Redshift off at nights, it would also turn off brightness settings. So I’ve made a script to have two presets and even adjust brightness by fractions like f.lux.

The script is available here:

Just remember to change DVI-I- 1 or 2 with your display port names.

You can find them by running xrandr -q command.

Thank you for reading

{:ok, :controll_is_illusion}



def Daylight_saving_headache do # 2017-4-9T21:5:23Z

Daylight saving headache!

Not so long ago, I’ve ported jalaali calendar for Elixir. In that process i’ve figured out Elixir’s standard Date structure is missing something to accomplish calendar conversions. So i’ve started a conversation in Elixir forum which you can read here

My idea was to force every calendar to provide callbacks to convert specific Date to ISO date or Unix Epoch (Which i liked more at that time!)

Then… I was intruduced to Date and DateTime complexities!

Calendars were not as easy as i thought it was. I even didn’t know that we have Leap seconds in some years!!!

A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC) in order to keep its time of day close to the mean solar time, or UT1. Without such a correction, time reckoned by Earth’s rotation drifts away from atomic time because of irregularities in the Earth’s rate of rotation.

The brilliant people in elixir community, @josevalim, @kip, @Qqwy came up with a nice solution using Ratta die. It is awesome an i think Elixir has one of the best native calendar implementation.

Anyways, I didn’t learn my lesson yet at that time. :(

So i begun to use epoch millisecond as time in one of enterprise projects. We needed an offline TimeTable to handle timings of events in our application. So we designed ZigorTimeTable

Each time table entry uses a startDate::DateTime as beginning of time, A duration::Long in milliseconds as time of availability and a cycle::Long in millisecond as how often is this entry repeated.

Everything was awesome and fine. It worked like a charm! You understand? Worked!

And suddenly, Daylight saving time occurred! :(( Every time table was messed up. they were all behind by one hour.


because of DST+1 (Day light saving) there was one hour missing from DateTime but it wasn’t missing in milliseconds!

We had to change real times from server to wrong ones so the app would work correctly.


Please do not mess with calendar and calendar systems in your enterprise level projects. these methods should be tested and verified precisely over long periods of time and not by normal tests. Instead, try to use a known implementation like JodaTime via updated TZDB data.

{:error, :sick_of_this_shit!}



def DIY_3D_printer_with_CD_Roms_build do # 2017-4-2T10:52:6Z

Today is last day of Nowruz holidays in Iran.

Having Fun?

I didn’t write much code in holidays. I’ve decided to spend more family time in holidays and have some fun. But as you can guess, i could’t resist the Cheap 3D printer Project. It was so damn fun :D

What did you do?

I’ve successfully competed the build. (Yayyyyy!) The X, Y and Z axis are good. the platform is fair. Extruder is a bit weak! and the Hotend Rocks! Im Using an Arduino UNO as controller with grbl 1.1f (Which is a CNC controller software for atmega32)

What can it do?

grbl supports G-Code but grbl doesn’t know about Extruder and Hotend temperatures. It only knows spindle and its direction.

Sure you can use spindle enable as extruder controller BUT the tricky part is slicers does not know spindle G-Code. So i had to design a script that translate Reprap flavor G-Code into grbl G-Code. It still needs some work.

But Currently i can do fallow paths on my printer with help of I have done stars, hand, rocket, and eiffel tower.

3D printed objects

Build size?

It is roughly 35x35x35mm

Extruder and hot end?

I have used a 3D printing pen as hotend and extruder. I have completely removed pen’s circuit, connected the hotend to the power supply and the extruder to arduino PWM pin of grbl (D11)


The pen came with it’s own 1.75mm ABS filament.

What about the housing?

Uh… Due to small build size i cannot print NanoPi housing with it. NanoPi NEO has dimensions of 40x40x40mm.

But i’m planning on building a bigger Reprap printer without the kit. If i can finish my works i may be able to do that.

Wasn’t it a waste of your time?

Absolutely not! I’ve learned so many things with this project and this is really the important part. learning everyday and having fun. it was a lot of fun finishing this project as i didn’t think i could do that at the very begining.

If you are interested in building this you can click HERE for instructions

Thank you for reading this

{:ok, :lets_3d_print!}



def NanoPi_NEO_Housing do # 2017-3-20T12:50:10Z

So in the last post Nanopi Neo as Webserver i came up to idea of serving on a NanoPi Neo small arm based computer.

The latest things that i struggled with was:

  • Housing
  • Heatsync
  • Static IP

About the heatsync, I found an old asus mainboard which had a tiny heatsync near it’s south bridge. It fit perfectly. Even i used some thermal paste on back of board for better heat flow.

But about the housing… Things got out of hand. Seriously out of hand!

First i wanted to outsource printing of the normal NanoPi Neo housing (Since i cannot buy it from my location) But…

I really wanted a 3D printer for long time! Maybe buy one?

No shit! They’re really expensive and out of my budget.

So after some researching around 3D printers i ended up reading “Super Cheap 3D Printer From CD-Rom Drives”. Of course it is not going to be in any good shape or quality bit it can bdo the job i think.

So this is the reason for the delay of serving my blog on a NanoPi NEO board.

Thank you for reading this.

{:ok, :cheers!}



def NanoPi_Neo_as_Webserver do # 2017-3-11T15:9:37Z

This weekend i was really bored. I just thought maybe its a good idea to play with the nerves-project a bit, So i went to find my raspberry pi from the closet and oh boy, It was a giant mess :| Throw the process of finding the rpi_2 something caught my eye. A NanoPi NEO I bought it around a year ago to make an automatic garden keeper. but things went wrong after i sank it in mineral oil for cooling. the board went crazy and froze 10 seconds after bootup. I’ve wrapped it inside some paper towels and left it inside closet.

“Let’s try and see if it’s still broken.” I downloaded UbuntuCore with Qt-Embedded Image File for NanoPi NEO, flashed image into sd card and pluged it in. It worked!! Best said: “It’s better give time for some problems”

Anyways, it was stable. I liked the performance of Allwinner H3 SOC and it is absolutely a charming feeling watching such a tiny computer working with fair performance. Wait a minute… Can i host this blog on it?

This single seed of idea has taken my entire weekend. I first tried to install Erlang on it. but binaries for arm71 was old. I’ve downloaded otp source code from github and build it on NanoPi NEO. It took about 40 minutes to build. I was not disappointed. In fact, i was surprised because i thought it may take a couple hours.

Then i tried building Elixir from source code. It was all good until it became to compiling unicode. As @josevalim said in issue #5856 to me, compiling unicode module requires loading large amount of unicode tables and optimizing it and because i only have 512mb of RAM and no swap, OS killed the build process. He suggested using precompiled Elixir. (Why i didn’t thought of that?). And Oh boy. It worked.

Elixir 1.4.2 and OTP 19.2 were installed and working on NanoPi NEO.

Now i just needed to run my blog on it. After cloning mix phoenix.server didn’t let me down. has successfully built and run on NanoPi NEO (since i use flat files as database, i don’t need anything else.)

So after all, i decided to host on my NanoPi NEO. there is only a couple things i need to worry about for doing so:

  • Get a housing and a heatsync for it.
  • Get an static IP address for my home internet connection or use DDNS (i don’t like this!)

{:ok, :unbelievable!}



def AWS_Outage! do # 2017-3-6T10:30:10Z

TL;DR: If you use an online service as storage or API it is always better to do Load balancing and failover within the Client side.

About a couple weeks ago we decided to use AWS S3 for storage of a mobile application which needed about 3gb of data dynamically.

We’ve created an AWS account and uploaded all files in a new S3 bucket. Everything was good, until… {:err, :aws_outage}

AWS outage happened. The service was down but fortunately the app was not released at that time.

Our CEO said: Ok, this can happen. What have we thought to prevent this? We did’t! We have not even thought about S3 getting unavailable for a second.

These things can happen. And whatever can happen will happen (Morphies law)

We are responsible for outages. Not Amazon. We could prevent this easily with having another backup bucket on a different IaaS or even on a cheap VPS just to prevent a complete outage.

After this occasion i realized how important is client level redundancy. It’s what we’ve been doing for API services to do the load balancing and failover on client side. It does not require any API gateways and in fact, It’s free of charge and works better if implemented correctly.



def knine_project do # 2017-3-3T17:14:8Z

Knine (pronounced K-9) is a tool for helping maintain of mid size services.

My very first motivation for Knine was about our chat service in one of our projects. unlike most of IM services our service didn’t use XMPP protocol. We have created a light-weight protocol over TCP called Zigor inspired by Telegram’s MTProto. In this structure we cared about every bit of waste and designed communication mechanism in a bitwise level. So one big advantage and of course, a lot of disadvantages and scary things!

One of those scary things was watching the cluster nodes health on a service that is not watchable easily. We could not just check for an open port, Instead we wanted running full diagnosys on protocol to see if it is not working the way it should.

On the other hand there were many other things that needed to be maintained like the charge we got left in our SMS service provider panel. we needed something to watch on that. For example wee needed it to tell us when the balance of the service is below a configured amount.

So Knine was the idea. A daemon that watches other services and can predict and help you prevent service outages.

{:still_working, :release_soon}



def Hello_world do # 2017-3-3T12:56:6Z

Hello and welcome!

This is the first post of this blog after developing is almost finished :D

Yes i know i could build a blog with no misery and of course for free! But i love elixir :) I built this blog with phoenix just to learn it and make something that really works on a daily basis for me with elixir.

Theme of this site is inspired from atom (my first favorite text editor) dark theme with elixir code.

This blog uses markdown text for posts and stores them in flat text files. (seriously?!) It is running on a vps with 512mb of ram and a weak shared cpu. I just want to see how BEAM reacts with this kind of hardware for myself.

This blog is Open Sourced and available at

Thank you for visiting

{:ok, :feels_awesome!}




defmodule Alisinabh.Contact do