<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[⚡️ Mohammad Maqbool Alam Khan]]></title><description><![CDATA[spawn(fn -&gt; @elixirlang/@elmlang developer end)]]></description><link>https://www.maqbool.net</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 20:18:24 GMT</lastBuildDate><atom:link href="https://www.maqbool.net/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Create a sorted Index in Ecto]]></title><description><![CDATA[defmodule MyApp.Repo.Migrations.AddMessagesInsertedAtIndex do
  use Ecto.Migration

  @disable_ddl_transaction true
  @disable_migration_lock true

  def change do
    create index("messages", ["inserted_at DESC"], concurrently: true)
  end
end

if y...]]></description><link>https://www.maqbool.net/create-a-sorted-index-in-ecto</link><guid isPermaLink="true">https://www.maqbool.net/create-a-sorted-index-in-ecto</guid><category><![CDATA[ecto]]></category><category><![CDATA[Elixir]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Sat, 09 Sep 2023 11:45:03 GMT</pubDate><content:encoded><![CDATA[<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">MyApp.Repo.Migrations.AddMessagesInsertedAtIndex</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> Ecto.Migration

  <span class="hljs-variable">@disable_ddl_transaction</span> <span class="hljs-keyword">true</span>
  <span class="hljs-variable">@disable_migration_lock</span> <span class="hljs-keyword">true</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">change</span></span> <span class="hljs-keyword">do</span>
    create index(<span class="hljs-string">"messages"</span>, [<span class="hljs-string">"inserted_at DESC"</span>], <span class="hljs-symbol">concurrently:</span> <span class="hljs-keyword">true</span>)
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>if you have multiple Elixir application nodes don't forget set the advisory lock</p>
<pre><code class="lang-elixir">config <span class="hljs-symbol">:wave</span>, Wave.Repo, <span class="hljs-symbol">migration_lock:</span> <span class="hljs-symbol">:pg_advisory_locke</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Start async task under our application Supervision tree]]></title><description><![CDATA[Inside your application.ex file we will add our task supervisor with the name MyApp.TaskSupervisor
MyApp.Application is the module where we essentially describe in what order BEAM should start our elixir application and it's the place where you descr...]]></description><link>https://www.maqbool.net/start-async-task-under-our-application-supervision-tree</link><guid isPermaLink="true">https://www.maqbool.net/start-async-task-under-our-application-supervision-tree</guid><category><![CDATA[Elixir]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Sat, 09 Sep 2023 11:31:04 GMT</pubDate><content:encoded><![CDATA[<p>Inside your <code>application.ex</code> file we will add our task supervisor with the name <code>MyApp.TaskSupervisor</code></p>
<p><code>MyApp.Application</code> is the module where we essentially describe in what order BEAM should start our elixir application and it's the place where you describe your worker or supervisor process et.al.</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">MyApp.Application</span></span>
 <span class="hljs-keyword">use</span> Application
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">start</span></span>(_type, _args) <span class="hljs-keyword">do</span>
    childern = [
    ...
    {Task.Supervisor, <span class="hljs-symbol">name:</span> MyApp.TaskSupervisor},
    ...
   ]
 opts = [<span class="hljs-symbol">strategy:</span> <span class="hljs-symbol">:one_for_one</span>, <span class="hljs-symbol">name:</span> MyApp.TaskSupervisor]
 Supervisor.start_link(children, opts)
<span class="hljs-keyword">end</span>
</code></pre>
<p>Now we have added our MyApp.TaskSupervisor to our supervision tree and let us spawn new task processes to process our async tasks of sending an email to a list of users concurrently.</p>
<p>In this post, we will be using the function <code>Task.Supervisor.async_stream/4</code> to process a list of data that could be any enumerable in our case it would be a list of users.</p>
<pre><code class="lang-elixir">users_list = [<span class="hljs-number">1</span>..<span class="hljs-number">100</span>]
</code></pre>
<p>To process our list of users the <code>MyApp.Supervisor</code> will spawn the task processes by default to the number of schedular available on your VM that's equal to the number of cores you have on your machine in my case with M1 pro that's 10 cores so my VM will have created 10 schedular (you could check with <code>System.schedulers_online/0</code> function to find the number scheduler you have online).</p>
<p>You can change the number of processes created by <code>Task.Supervisor.async_stream/4</code> by passing the option of <code>max_concurrency: n</code> where n could be an arbitrary number of processes to be created for processing the list.</p>
<pre><code class="lang-elixir">Task.Supervisor.async_stream(MyApp.TaskSupervsior, data, work)
</code></pre>
<p>Now for each user in our <code>users_list</code> our <code>Task.Supervisor.async_stream/4</code> will invoke the <code>work/1</code> anonymous function and start processing that could be sending an email or some other expensive task or batch inserting data into our database or making a network call.</p>
<pre><code class="lang-elixir">work = <span class="hljs-keyword">fn</span> user_id -&gt; 
  IO.puts <span class="hljs-string">"sending email to <span class="hljs-subst">#{user_id}</span>"</span>  
  Process.sleep(<span class="hljs-number">1000</span>)  
  IO.puts <span class="hljs-string">"email sent to <span class="hljs-subst">#{user_id}</span>"</span>
<span class="hljs-keyword">end</span> 

user_list = <span class="hljs-number">1</span>..<span class="hljs-number">100</span> 

Task.Supervisor.async_stream(MyApp.TaskSupervsior, data, work) |&gt; Enum.count()
</code></pre>
<p>Since <code>async_stream/4</code> produces a stream which are lazy so kick start processing our user_list I'm passing it to <code>Enum.count/1</code> which returns the total number of users.</p>
<p>References:</p>
<p><a target="_blank" href="https://hexdocs.pm/elixir/1.12/Task.Supervisor.html#async_stream/6">https://hexdocs.pm/elixir/1.12/Task.Supervisor.html#async_stream/6</a></p>
<p><a target="_blank" href="https://elixir-lang.org/getting-started/enumerables-and-streams.html">https://elixir-lang.org/getting-started/enumerables-and-streams.html</a></p>
<p><a target="_blank" href="https://hexdocs.pm/elixir/1.13/Application.html">https://hexdocs.pm/elixir/1.13/Application.html</a></p>
]]></content:encoded></item><item><title><![CDATA[The Big Elixir 2022 - Building a Note taking App using LiveView, OTP, and friends - Mohammad Maqbool Alam]]></title><description><![CDATA[In this talk, we will start by building the Backend while taking advantage of OTP primitives such as GenServer and friends to build a simple cron to fetch messages from Telegram API and then we build using Phoenix LiveView and Alpine.js to build the ...]]></description><link>https://www.maqbool.net/the-big-elixir-2022-building-a-note-taking-app-with-telegram-liveview-maqbool-alam</link><guid isPermaLink="true">https://www.maqbool.net/the-big-elixir-2022-building-a-note-taking-app-with-telegram-liveview-maqbool-alam</guid><category><![CDATA[Elixir]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Sat, 30 Apr 2022 05:44:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1651296750450/6k3Y1zCWR.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this talk, we will start by building the Backend while taking advantage of OTP primitives such as GenServer and friends to build a simple cron to fetch messages from Telegram API and then we build using Phoenix LiveView and Alpine.js to build the frontend for the app.</p>
<iframe src="https://docs.google.com/presentation/d/e/2PACX-1vTvUGTZbG8UKp17R1j9nbGr5nO017P68g-hKg_TSmsXg-fAhf64eiQRa3liks4L-yDrRne_s-IKW8cA/embed?start=false&amp;loop=false&amp;delayms=3000" width="785" height="569"></iframe>

<iframe width="785" height="315" src="https://www.youtube-nocookie.com/embed/kev-XCVsvG4?start=105"></iframe>]]></content:encoded></item><item><title><![CDATA[GenServer from first principles: Mohammad Maqbool Alam // Elixir Wizards Conference 2021]]></title><description><![CDATA[In this talk, I'll try to convey the intuition of how GenServers are created from isolated actors and gain some deep and intuitive understanding of GenServer.
https://youtu.be/zK5GnJwfrak]]></description><link>https://www.maqbool.net/genserver-from-first-principles-maqbool-alam-elixir-wizards-conference-2021</link><guid isPermaLink="true">https://www.maqbool.net/genserver-from-first-principles-maqbool-alam-elixir-wizards-conference-2021</guid><category><![CDATA[Elixir]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Tue, 20 Jul 2021 03:42:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1626752367688/bLiG7x4oL.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this talk, I'll try to convey the intuition of how GenServers are created from isolated actors and gain some deep and intuitive understanding of GenServer.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/zK5GnJwfrak">https://youtu.be/zK5GnJwfrak</a></div>
]]></content:encoded></item><item><title><![CDATA[Maqbool on System and Application Architecture @ Elixir Wizards Podcast]]></title><link>https://www.maqbool.net/maqbool-on-system-and-application-architecture-elixir-wizards-podcast-8ed80cbc37e7</link><guid isPermaLink="true">https://www.maqbool.net/maqbool-on-system-and-application-architecture-elixir-wizards-podcast-8ed80cbc37e7</guid><category><![CDATA[Elixir]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Fri, 22 May 2020 05:02:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1612424302866/LpsWHirds.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<iframe src="https://open.spotify.com/embed-podcast/episode/0RF9SAwu8ljyFfTqdvYltk" width="100%" height="232"></iframe>

]]></content:encoded></item><item><title><![CDATA[Building a MySQL Database Driver in Elixir @ Code BEAM Lite]]></title><description><![CDATA[Have you ever wondered what happens beneath the covers when you talk to your Database? Well, you are in for a treat! In this talk, we are going to uncover the dark magic behind Database Drivers. We will look at everything that is needed to talk to a ...]]></description><link>https://www.maqbool.net/building-a-mysql-database-driver-in-elixir-422710302b72</link><guid isPermaLink="true">https://www.maqbool.net/building-a-mysql-database-driver-in-elixir-422710302b72</guid><category><![CDATA[Elixir]]></category><category><![CDATA[MySQL]]></category><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Wed, 25 Dec 2019 05:28:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1622654055688/teGy9qLFl.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever wondered what happens beneath the covers when you talk to your Database? Well, you are in for a treat! In this talk, we are going to uncover the dark magic behind Database Drivers. We will look at everything that is needed to talk to a database, query its data, and transform it into the native data types in Elixir.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://speakerdeck.com/maqbool/building-a-mysql-database-driver-in-elixir">https://speakerdeck.com/maqbool/building-a-mysql-database-driver-in-elixir</a></div>
<iframe width="750" height="315" src="https://www.youtube-nocookie.com/embed/UoxzAPBVuQs?start=169"></iframe>]]></content:encoded></item><item><title><![CDATA[How to install Pharo on Gnu/Linux]]></title><description><![CDATA[Pharo the Modern Smalltalk
Download the Pharo and decompress the file
$ unzip Pharo.zip 
$ sudo mv Pharo /opt/
Create the pharo.desktop file and paste the following contents
[Desktop Entry]
Encoding=UTF-8
Name=Pharo
GenericName=Pharo
Exec=pharo
Icon=...]]></description><link>https://www.maqbool.net/how-to-install-pharo-on-linux-a053de254bfa</link><guid isPermaLink="true">https://www.maqbool.net/how-to-install-pharo-on-linux-a053de254bfa</guid><dc:creator><![CDATA[Maqbool]]></dc:creator><pubDate>Fri, 24 Nov 2017 00:14:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1612424284314/xfod0lljy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Pharo the Modern Smalltalk</p>
<p>Download the <a target="_blank" href="https://pharo.org">Pharo</a> and decompress the file</p>
<pre><code>$ unzip Pharo.zip 
$ sudo mv Pharo /opt/
</code></pre><p>Create the pharo.desktop file and paste the following contents</p>
<pre><code class="lang-desktop">[Desktop Entry]
Encoding=UTF-8
Name=Pharo
GenericName=Pharo
Exec=pharo
Icon=/opt/pharo6.1–64/icons/Pharo.png
Terminal=false
Type=Application
StartupNotify=false
Categories=Development;
Exec=/opt/pharo6.1–64/pharo
</code></pre>
<p>Move .desktop file to .local/share/applications/</p>
<pre><code>$ mv pharo.desktop .<span class="hljs-keyword">local</span>/<span class="hljs-keyword">share</span>/applications/
</code></pre><p>Create ~/.icons directory</p>
<pre><code>$ <span class="hljs-keyword">mkdir</span> ~<span class="hljs-regexp">/.icons
$ sudo cp /opt</span><span class="hljs-regexp">/pharo6.1–64/icons</span><span class="hljs-regexp">/Pharo.png ~/</span>.icons
</code></pre><p>Happy Coding!</p>
]]></content:encoded></item></channel></rss>