<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sushant Bajracharya</title>
    <description>The latest articles on DEV Community by Sushant Bajracharya (@sushant12).</description>
    <link>https://dev.to/sushant12</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F169832%2F8e07a785-b132-47b6-bb02-ebdfcd3b3b52.jpeg</url>
      <title>DEV Community: Sushant Bajracharya</title>
      <link>https://dev.to/sushant12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sushant12"/>
    <language>en</language>
    <item>
      <title>Mix task to search for alias name</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sun, 08 May 2022 11:09:53 +0000</pubDate>
      <link>https://dev.to/sushant12/mix-task-to-search-for-alias-name-4o6b</link>
      <guid>https://dev.to/sushant12/mix-task-to-search-for-alias-name-4o6b</guid>
      <description>&lt;p&gt;I recently had to work on a project which used multi alias&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias ModA.{ModB, ModC}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Searcing is difficult on project like this so I wrote a mix task that would look for the alias name and then print the file and line number on the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sushant12/find_alias"&gt;https://github.com/sushant12/find_alias&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
    </item>
    <item>
      <title>Building a game server in elixir</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Wed, 05 May 2021 08:18:31 +0000</pubDate>
      <link>https://dev.to/sushant12/building-a-game-server-in-elixir-27of</link>
      <guid>https://dev.to/sushant12/building-a-game-server-in-elixir-27of</guid>
      <description>&lt;p&gt;I am not an expert so take this post with a grain of salt like every other posts of mine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sushant12/snake_ladder/tree/v0.2.0"&gt;https://github.com/sushant12/snake_ladder/tree/v0.2.0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, now that it is out of the way let me tell u what I think a game server is first. I think that a game server is a process that keeps the state of the game and their implementation depends on the type game itself.&lt;/p&gt;

&lt;p&gt;As a kid, I used to play snake and ladders a lot. So, I built one but with minimal rules and two players only.I am not going to go through the code one by one , what I would like to tell you is what approach I took to build it.&lt;/p&gt;

&lt;p&gt;Since I am building a 2P game, I have to keep track of who is what. So, whoever visits the root url is "Player 1" because a random token and a &lt;code&gt;foreman=true&lt;/code&gt; is appended to the url. Player 2 will have just the random token in their url.&lt;/p&gt;

&lt;p&gt;When someone visits the root url, I am treating it as start of a new tournament which will start a new "GameServer" which is a GenServer process. The "GameServer" is a child of DynamicSupervisor which was started with "mix phx.server". The state is kept in sync between the connected players via phoenix pubsub.&lt;/p&gt;

&lt;p&gt;I know that the game will need to have structures so that's why the "game" and "player" struct. The "game" struct would store the list of players, dice state, game token and current players turn. The "player" struct stores the player name and their position. The "game" struct has functions to help manipulate/update itself. For eg: updating the dice state when user rolls a dice.&lt;/p&gt;

&lt;p&gt;I have used liveview to dynamically show the changes in the UI. I do need to show some animations like rolling a dice when clicked on "roll", moving the piece, etc for which I will use js hooks.&lt;/p&gt;

&lt;p&gt;So, that's about it for now. I have couple more things that I want to implement like cleaning off zombie game servers, notifying user when a player leaves the game, etc. I guess when I finish implementing it, it will be a time for new blog.&lt;/p&gt;

&lt;p&gt;:)&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
    </item>
    <item>
      <title>live_render from phoenix controller</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Wed, 21 Apr 2021 13:54:44 +0000</pubDate>
      <link>https://dev.to/sushant12/liverender-from-phoenix-controller-2183</link>
      <guid>https://dev.to/sushant12/liverender-from-phoenix-controller-2183</guid>
      <description>&lt;p&gt;Recently, I rendered a liveview from one of my controller and I had to pass some params to that liveview. You can pass the params if you put it in the &lt;code&gt;session&lt;/code&gt; option but that didnt felt right to me.&lt;/p&gt;

&lt;p&gt;So, I figured I ask the community and I got to know when not to use &lt;code&gt;live_render&lt;/code&gt; in the controller instead and got a reply from the creator himself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;when you have an existing controller and dead views already in place and you want to add in a bit of live stuff&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
    </item>
    <item>
      <title>assign in redirect</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sat, 17 Apr 2021 07:28:07 +0000</pubDate>
      <link>https://dev.to/sushant12/assign-in-redirect-3hpf</link>
      <guid>https://dev.to/sushant12/assign-in-redirect-3hpf</guid>
      <description>&lt;p&gt;So, I just found out that if you are redirecting to other routes, the &lt;code&gt;assign&lt;/code&gt; that you did in your &lt;code&gt;conn&lt;/code&gt; wont be available to the next template.&lt;/p&gt;

&lt;p&gt;That's because &lt;code&gt;assign&lt;/code&gt; stores value in current request's connection struct and if we use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conn
|&amp;gt; assign(:something, "sdf")
|&amp;gt; redirect(to: route)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it will never make it to another template.&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
    </item>
    <item>
      <title>alias in elixir</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Thu, 08 Apr 2021 09:19:07 +0000</pubDate>
      <link>https://dev.to/sushant12/alias-in-elixir-3a19</link>
      <guid>https://dev.to/sushant12/alias-in-elixir-3a19</guid>
      <description>&lt;p&gt;This post will not explain about &lt;code&gt;alias&lt;/code&gt; , rather I would like to share a piece of code that caught me off guard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="no"&gt;Rumbl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Accounts&lt;/span&gt; &lt;span class="c1"&gt;# context&lt;/span&gt;
&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="no"&gt;Accounts&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;User&lt;/span&gt; &lt;span class="c1"&gt;# schema&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;(%&lt;/span&gt;&lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;name:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I compile it, it would give me compilation error &lt;code&gt;Rumbl.Accounts.User__struct__/0 is undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It's pretty obvious why, looking at the code now. Since the &lt;code&gt;Rumbl.Accounts&lt;/code&gt; is already aliased, the &lt;code&gt;Accounts.User&lt;/code&gt; assumed &lt;code&gt;Accounts&lt;/code&gt; to be &lt;code&gt;Rumbl.Accounts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Just updating their position would fix it&lt;/p&gt;

</description>
      <category>elixir</category>
    </item>
    <item>
      <title>Understanding "warning: redefining module x" in elixir</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sun, 21 Mar 2021 05:49:38 +0000</pubDate>
      <link>https://dev.to/sushant12/redefining-module-warning-in-elixir-4oij</link>
      <guid>https://dev.to/sushant12/redefining-module-warning-in-elixir-4oij</guid>
      <description>&lt;p&gt;Take this article with a grain of salt.&lt;/p&gt;

&lt;p&gt;This particular warning is telling you that even after loading the module, elixir is trying to recompile it.&lt;/p&gt;

&lt;p&gt;There are different ways to clear such warning in the internet like removing the &lt;code&gt;_build&lt;/code&gt; directory. It did not work for me initially.&lt;/p&gt;

&lt;p&gt;In my case, I had an unused variable in my eex file. Since my project was configured to treat warnings as error in my credo setting, it failed to compile leaving me with a lot of "redifing module" warnings. And in that noise, another warning was hidden which pointed out on prefixing the unused variable.&lt;/p&gt;

&lt;p&gt;After prefixing the unused variable and &lt;code&gt;mix do clean, phx.server&lt;/code&gt;, those warnings went away&lt;/p&gt;

</description>
      <category>elixir</category>
    </item>
    <item>
      <title>A free pomodoro app</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sun, 23 Aug 2020 07:02:35 +0000</pubDate>
      <link>https://dev.to/sushant12/a-free-pomodoro-app-1m02</link>
      <guid>https://dev.to/sushant12/a-free-pomodoro-app-1m02</guid>
      <description>&lt;p&gt;Visit &lt;a href="https://pomo-do.netlify.app/"&gt;https://pomo-do.netlify.app/&lt;/a&gt; for a demo&lt;/p&gt;

&lt;p&gt;I have to learn alpinejs for work and I was looking for a pomodoro app where I can check my history for &lt;strong&gt;FREE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, I wrote a pomodoro app with alpinejs. It's like killing two bird with one stone.&lt;/p&gt;

&lt;p&gt;TBH the pomodoro app could have been written on vanilla js but like I said I just wanted to learn it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make it work, make it right, make it fast&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code is filled with a lot of conditions which I MIGHT improve later on.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>alpinejs</category>
    </item>
    <item>
      <title>Emulate bash "history" but for iex</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sun, 16 Aug 2020 07:06:24 +0000</pubDate>
      <link>https://dev.to/sushant12/list-all-history-in-iex-408b</link>
      <guid>https://dev.to/sushant12/list-all-history-in-iex-408b</guid>
      <description>&lt;p&gt;Personally, I think the bash command, &lt;code&gt;history&lt;/code&gt;, is a neat productivity tool. I use it all the time &lt;code&gt;history | grep&lt;/code&gt; and I wanted the same thing in IEx as well.&lt;/p&gt;

&lt;p&gt;To search through the history in IEx, you need to first enable it. Then either use &lt;strong&gt;up&lt;/strong&gt; arrow keys or &lt;strong&gt;ctrl + r&lt;/strong&gt; to search. That's cool but still not exactly what I need.&lt;/p&gt;

&lt;p&gt;So, the first thing I had to do was to find the place where the history is stored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# run it in your IEx&lt;/span&gt;
&lt;span class="ss"&gt;:filename&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;basedir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:user_cache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"erlang-history"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The history files are written by erlang's &lt;code&gt;disk_log&lt;/code&gt;, so there will be weird characters when you open it in your editor. My initial thought was, if the history is written by &lt;code&gt;disk_log:log/2&lt;/code&gt; which uses &lt;code&gt;erlang:term_to_binary/1&lt;/code&gt;, then I can read those history files with &lt;code&gt;erlang:binary_to_term/1&lt;/code&gt;. But it turns out when writing history, &lt;code&gt;disk_log&lt;/code&gt; appends some kind of weird binaries which you can find in &lt;code&gt;disk_log.hrl&lt;/code&gt; eg &lt;code&gt;&amp;lt;&amp;lt;12,33,44,55&amp;gt;&amp;gt;&lt;/code&gt;. So, I tried &lt;code&gt;disk_log:chunk/2&lt;/code&gt; to parse it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# this will print the content of the history file with header&lt;/span&gt;
&lt;span class="c1"&gt;# in IEx, it will print charlists&lt;/span&gt;
&lt;span class="c1"&gt;# in erl, it will print strings&lt;/span&gt;

&lt;span class="ss"&gt;:disk_log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="s1"&gt;'$#group_history'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It did parse the history but it had weird headers and also didn't give me the whole content of all the history files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{:continuation, #PID&amp;lt;0.81.0&amp;gt;, {1, 52393}, []},
 [
   {:vsn, {0, 1, 0}},
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I found a file called &lt;code&gt;group_history.erl&lt;/code&gt;. It has two public api &lt;code&gt;load/0&lt;/code&gt; and 'add/2'. The &lt;code&gt;load/0&lt;/code&gt; api parsed and returned the whole history just as I wished.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="ss"&gt;:group_history&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And then I finally wrote the rest of the code to emulate bash &lt;code&gt;history&lt;/code&gt; command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;History&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;load_history&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;match?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;&amp;amp;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sr"&gt;~r/#{term}/&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;with_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
      &lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;  "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ANSI&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}#{&lt;/span&gt;&lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="si"&gt;}#{&lt;/span&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ANSI&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;default_color&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;load_history&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;with_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
      &lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;  &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;defp&lt;/span&gt; &lt;span class="n"&gt;load_history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;:group_history&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="no"&gt;List&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_string&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I have put this code in my &lt;code&gt;.iex.exs&lt;/code&gt; file so that I can call it whenever I am in my IEx.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;History&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"map"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;History&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Hi there!!
&lt;/h2&gt;

&lt;p&gt;Hi, I am looking for awesome opportunities to work with Elixir. If you are hiring or need a hand to finish your pet/side project then let's get connected. Here is my email sussyoung9[at]gmail[dot]com&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>erlang</category>
    </item>
    <item>
      <title>Generate n digit random number in elixir</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Fri, 24 Jul 2020 06:11:42 +0000</pubDate>
      <link>https://dev.to/sushant12/generate-n-digit-random-number-in-elixir-469l</link>
      <guid>https://dev.to/sushant12/generate-n-digit-random-number-in-elixir-469l</guid>
      <description>&lt;p&gt;To generate n digit of random number you can do&lt;/p&gt;

&lt;p&gt;Enum.random(10,20)&lt;/p&gt;

&lt;p&gt;It will generate 2 digit number between 10 and 20&lt;/p&gt;

</description>
      <category>elixir</category>
    </item>
    <item>
      <title>postgres timestamp and timestamp(0)</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Fri, 24 Jul 2020 05:19:49 +0000</pubDate>
      <link>https://dev.to/sushant12/postgres-timestamp-and-timestamp-0-1eo6</link>
      <guid>https://dev.to/sushant12/postgres-timestamp-and-timestamp-0-1eo6</guid>
      <description>&lt;p&gt;timestamp(p) where p can be a value from 0 - 6.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;p&lt;/code&gt; stands for precision which retains the number of fractional digits in the seconds field.&lt;/p&gt;

</description>
      <category>postgres</category>
    </item>
    <item>
      <title>Ecto's Repo.insert</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Wed, 22 Jul 2020 05:23:43 +0000</pubDate>
      <link>https://dev.to/sushant12/ecto-s-repo-insert-i32</link>
      <guid>https://dev.to/sushant12/ecto-s-repo-insert-i32</guid>
      <description>&lt;p&gt;If you have default values set in your database, then &lt;code&gt;Repo.insert&lt;/code&gt; will not return its value. &lt;/p&gt;

&lt;p&gt;To return the value, you have to pass &lt;code&gt;Repo.insert(returning: true)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you dont want to do &lt;code&gt;returning: true&lt;/code&gt; you can set default return value in your schema.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schema "rooms" do
  field :enable_chat, :boolean, default: false
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then when you do insert, it will return the default &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>ecto</category>
      <category>phoenix</category>
    </item>
    <item>
      <title>TIL: Import app.css in app.js</title>
      <dc:creator>Sushant Bajracharya</dc:creator>
      <pubDate>Sat, 30 May 2020 11:05:51 +0000</pubDate>
      <link>https://dev.to/sushant12/til-import-app-css-in-app-js-3cj2</link>
      <guid>https://dev.to/sushant12/til-import-app-css-in-app-js-3cj2</guid>
      <description>&lt;p&gt;impoet app.css in app.js for webpack to compile it&lt;/p&gt;

</description>
      <category>phoenix</category>
      <category>webpack</category>
    </item>
  </channel>
</rss>
