Agent is an abstraction over GenServer. It is used when we want to store and retrieve only the data from the process without doing any additional logic.

Check my book for Elixir starters at https://gum.co/XgbKSE


This is the slide walkthrough of the talk I gave at Erlang & Elixir Bangalore meetup.

We use spawn, send, receive concepts from Elixir and a function loop to implement a GenServer.

GenServers expand to Generic Servers. What do we mean by servers here? Let’s consider a web server. We can create new data, change data and get data from the running web server. Similar to web servers these are microservers within elixir which work on top of processes.


https://unsplash.com/photos/atSaEOeE8Nk

Elixir Task provides an abstraction over processes to perform long running jobs in parallel.

Let’s see first iteration.

Here we want to spawn a process and perform task in that process and collect back the result.

eg: [10000, 1000, 100] |> Enum.map(fn duration -> TaskiFirst.Taski.async(fn -> :timer.sleep(duration); duration end) end) |> Enum.map(fn _ -> TaskiFirst.Taski.await() end)

Here in…


https://unsplash.com/photos/RCAhiGJsUUE

How long can we stare at a picture? 1hour? I don’t know.

This pandemic has made us stare pictures of our house and monitor for the longest time.

We miss the commute, office space, lifts, meeting rooms, pantry, food courts, restaurants, weekend trips etc. We miss these ever changing pictures.

Visually we are bored to the extreme. If not aware this boredom might get shifted on to our work, relationships, home etc.

The work we enjoyed, the relationships we longed, home we loved, shows we binged might seem boring suddenly.

So be aware of this shift in boredom. Don’t mix.


https://unsplash.com/photos/OgvqXGL7XO4

Beware of converting any data type to atom dynamically, as atoms once created won’t be garbage collected.

We may not face this scenario often. But in scenarios where atoms are required, we might overlook this and convert dynamic values to atoms.

One such case is registering dynamic GenServer or Agent with a name.

Use {:global, term} or via_tuple to handle such scenarios appropriately.

More info at

https://hexdocs.pm/elixir/String.html#to_atom/1

https://hexdocs.pm/elixir/GenServer.html#module-name-registration


A laptop and a mounted television.
Not related to the article. Just added to make thumbnail look good ;)

tl;dr

'in' is usually used with list or range. But here we

1. Implement Enumerable for another data type to use ‘in’.

2. Define macro with ‘in’ to improve readability.

Don’t try this at home

Just kidding, we can use this, but we might introduce unnecessary bugs in the code and might make the code unreadable as this is not widely practiced. Let’s do this as an experiment to know more about Elixir.

Using ‘in’ with string

Let’s try to find whether a substring is present inside a string.

"lix" in "Elixir"

I want this to give back ‘true’. But it errors as

** (Protocol.UndefinedError) protocol Enumerable not implemented for…

Final output

Project creation

In terminal use mix to create a new live view project without ecto.

mix phx.new chart --live --no-ecto

and press ‘y’ when asked to install dependency.

We are going to work on these following files.

  • lib > chart_web > live > page_live.ex
  • lib > chart_web > live > page_live.html.leex
  • lib > chart_web > templates > layout > root.html.leex
  • assets > js > app.js

Cleanup

In page_live.ex delete all other functions except mount. Modify mount function such that it returns only

{:ok, socket}

In page_live.html.leex delete entire stuff.

In root.html.ex replace the entire <header> block with

<h1>Phoenix LiveView Chart.js</h1>


Eligibility:

Am I eligible to comment? NO. Because it’s a belief system. And many people follow rigorous routine to do Sabarimala pilgrimage. I didn’t have the opportunity to do it. So I won’t have full understanding of the belief system.

And this should not be approached with 'sociological' or 'biological' logics of human equality. It’s a matter of 'psychological' logic of belief system. We have to hear the opinion of women who have deep belief. The decision should be made by the people who follow rigorous routine and belief to do Sabarimala pilgrimage.

A misdirection:

We are living in a time where men…


Our brain always trys to abstract a piece of information. It will save space while storing and energy while retrieval. Because in-depth knowledge of all informations are not needed for survival. Only that those required are stored further, that too on repeated encounter.

Eg. Instead of, lions need us for food and will chase ,kill and eat us and that will be bad for my survival, it will be stored as ‘Avoid lions’.

This is boon.

Here comes the bane part.

Eg. Old diesel engines without catalytic converter releases more NOx and hence bad for environment. But what registered was ‘Diesel is bad’.

Because of development and knowledge, nowadays a word can alter the meaning. So it’s better to analyse(it’s hard to keep up with the information flow) before raising an opinion.


Throughout human history we tend to increase comfort. We started with food, then health and travel and all the physical comforts of life. We did the physical explorations and found ways to keep us comfortable.

In the mean time late in the game we started exploring metal comfortness. Recent technological advances try to keep us happier than ever before, by adjusting the contents we consume online and the medications we take, etc.

Two questions arise

Or the meaning of happiness be redefined in future?

Boobalan AP

Self referencing automaton

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store