<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rafi on Medium]]></title>
        <description><![CDATA[Stories by Rafi on Medium]]></description>
        <link>https://medium.com/@notsohuman?source=rss-ef117c13708f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*W1t0Nhg5x53MglCeTRsvoQ.jpeg</url>
            <title>Stories by Rafi on Medium</title>
            <link>https://medium.com/@notsohuman?source=rss-ef117c13708f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 09:55:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@notsohuman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building git part-1]]></title>
            <link>https://medium.com/@notsohuman/building-git-part-1-5a7882d7bc5e?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a7882d7bc5e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[git-internals]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 10:50:44 GMT</pubDate>
            <atom:updated>2021-12-10T05:34:53.137Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpdCB8ssHVk6dpHL31rKbA.jpeg" /><figcaption>Thanks to <a href="https://unsplash.com/@yancymin">Yancy Min</a> for sharing their work on Unsplash</figcaption></figure><h3>Building git</h3><p>We developers use git all the time. Git internals might feel like magic but what git actually does is really simple. Let first see how git works and then build a simple clone to really understand it.</p><p>Lets create a empty folder and then run initialize the git repo by running</p><pre>$ git init</pre><p>This creates .git folder inside your empty folder. The structure of this .git folder is as follows</p><pre>.git/<br>├── branches<br>├── config<br>├── description<br>├── HEAD<br>├── hooks<br>├── info<br>│   └── exclude<br>├── objects<br>│   ├── info<br>│   └── pack<br>└── refs<br>    ├── heads<br>    └── tags</pre><p>If you open up the HEAD file in your text editor you will see<br>the following text in it</p><pre>ref: refs/heads/master</pre><p>which means that your current branch is master.</p><p>Now add a file and make a first commit by doing</p><pre> $ echo &quot;Hello&quot; &gt;&gt; README.md<br> $ git add .<br> $ git commit -m &quot;Initial commit&quot;</pre><p>now run $ git log and you will get</p><pre>commit acde617e8ab39bb157821d3bf84d04e157bff52c (HEAD -&gt; master)<br>Author: username &lt;test@email.com&gt;<br>Date:   Wed Aug 05 18:43:48 2020 +0330</pre><pre>    Initial commit</pre><h4>Note:</h4><ul><li>The exact commit hash that you get will differ from what you see here depending on your username, email and time that you make the commit</li></ul><p>And if you open up <strong>refs/head/master</strong> it will have text acde617e8ab39bb157821d3bf84d04e157bff52c inside it.</p><p>In git each commit is associated with a hash. The content of the file <strong>refs/head/master</strong> means master is pointing to the commit<br>acde617e8ab39bb157821d3bf84d04e157bff52c</p><pre> // TODO:</pre><pre> 1. Now make a second commit<br> 2. check `$ git log` and content of **refs/head/master**</pre><p>After you have made your first commit if you inspect the contents of the .git folder again you will see something new</p><pre>.git/<br>├── branches<br>├── COMMIT_EDITMSG<br>├── config<br>├── description<br>├── HEAD<br>├── hooks<br>├── index<br>├── info<br>│   └── exclude<br>├── logs<br>│   ├── HEAD<br>│   └── refs<br>│       └── heads<br>│           └── master<br>├── objects<br>│   ├── ac<br>│   │   └── de617e8ab39bb157821d3bf84d04e157bff52c<br>│   ├── dc<br>│   │   └── 0a29da1d9b3f68dcd56af0e34f8df4fbf8b24f<br>│   ├── e9<br>│   │   └── 65047ad7c57865823c7d992b1d046ea66edf78<br>│   ├── info<br>│   └── pack<br>└── refs<br>    ├── heads<br>    │   └── master<br>    └── tags</pre><p>There is a new file called index and there some weird things inside object folders (we will ignore all other new things for now).<br>When you run $ git add . git takes the changes that you have made and creates objects for it. The names of the objects are determined by running your file content into SHA1 algorithm. SHA1 algorithm basically takes some input and outputs 40 character string.</p><p>Lets try to generate SHA1 of the file README.md. You can do that by running</p><pre>$ git hash-object README.md</pre><p>which will give you output</p><pre>e965047ad7c57865823c7d992b1d046ea66edf78</pre><p>So that is where the content of the file README.md is stored. The first two characters of the hash are used for folder name. The file 65047ad7c57865823c7d992b1d046ea66edf78 is binary file to see its<br>content we can run</p><pre>$ git cat-file -p e965047ad7c57865823c7d992b1d046ea66edf78</pre><p>which outputs</p><pre>Hello</pre><p>Which is the content of your README.md !!!</p><h3>But what are other two objects?</h3><p>There two other objects that are present in the objects directory. What are those?<br>Git has four types of objects blob, tree, commit and tag. Blob is used to store the content of the file the one we just saw is a blob.<br>You can see the type of the object by running</p><pre>$ git cat-file -t e965047ad7c57865823c7d992b1d046ea66edf78</pre><p>which will print</p><pre>blob</pre><p>When you run</p><pre>$ git cat-file -p acde617e8ab39bb157821d3bf84d04e157bff52c</pre><p>and you will get</p><pre>tree dc0a29da1d9b3f68dcd56af0e34f8df4fbf8b24f<br>author username &lt;test@email.com&gt; 1597845162 +0530<br>committer username &lt;test@email.com&gt; 1597845162 +0530</pre><pre>Initial commit</pre><p>That is our actual commit and it has author, committer and something called tree which is another git object</p><p>Lets see what that tree object has by running</p><pre>$ git cat-file -p dc0a29da1d9b3f68dcd56af0e34f8df4fbf8b24f</pre><p>It outputs</p><pre>100644 blob e965047ad7c57865823c7d992b1d046ea66edf78    README.md</pre><p>It has the name of the file and name of the blob that has the file content. It is essentially how your working directory looked like at that commit.</p><p>Lets sum up our understanding till now. When you make a commit in git. The content of the file are passed through an SHA1 hash to get a 40 character length string which is used to store the content of the file. Then it creates a tree object which is essentially how your working directory looked at that point in time. The tree says which blobs are associated with which file names. Then there is a commit object which points to this tree object and also has the commit message, author, committer, and email.</p><pre> // TODO</pre><pre> 1. Now make another commit<br> 2. inspect the contents of the .git folder<br> 3. See what are the objects that are there in .git folder<br> 4. Look at content of objects</pre><h3>Branching</h3><p>Now lets create a branch by running</p><pre>$ git branch feature-1</pre><p>Now lets take a look at content of .git folder</p><pre>.git/<br>├── branches<br>├── COMMIT_EDITMSG<br>├── config<br>├── description<br>├── HEAD<br>├── hooks<br>├── index<br>├── info<br>│   └── exclude<br>├── logs<br>│   ├── HEAD<br>│   └── refs<br>│       └── heads<br>│           ├── feature-1<br>│           └── master<br>├── objects<br>│   ├── ac<br>│   │   └── de617e8ab39bb157821d3bf84d04e157bff52c<br>│   ├── dc<br>│   │   └── 0a29da1d9b3f68dcd56af0e34f8df4fbf8b24f<br>│   ├── e9<br>│   │   └── 65047ad7c57865823c7d992b1d046ea66edf78<br>│   ├── info<br>│   └── pack<br>└── refs<br>    ├── heads<br>    │   ├── feature-1<br>    │   └── master<br>    └── tags</pre><p>Now there is a new file called <strong>refs/heads/feature-1</strong> and if we take a peak at its content it will be the commit hash from which you created the branch.</p><p>Now if we checkout <strong>feature-1</strong> branch by running</p><pre>$ git checkout feature-1</pre><p>The content of our HEAD file changes to</p><pre>ref: refs/heads/feature-1</pre><pre> // TODO</pre><pre> 1. Try creating a file refs/heads/feature-2<br> 2. Run git log<br> 3. Put the hash inside that file<br> 4. Try running git branch</pre><h3>Staging area</h3><p>When you create a file you are creating the file in your local file system and after you are done you add the file to git by running $ git add . this adds the file to the staging area. Then when you make commit the files the commit object is created for files in the staging area.</p><p>So the question now is where is this staging area? The answer is it is in the index file</p><p>We can see the contents of the staging area by running</p><pre>$ git ls-files --stage</pre><p>which gives us</p><pre>100644 e965047ad7c57865823c7d992b1d046ea66edf78 0 README.md</pre><pre> // TODO</pre><pre> 1. Create a README2.md file<br> 2. Run git ls-files --stage and look at its content<br> 3. Run git add .<br> 4. Now run git ls-files --stage again</pre><h4>Note:</h4><ol><li>We have skipped some details like tags, packing… which is not necessary for building simple git</li><li>The number 100644 is essentially permissions of the file</li></ol><p>This post is cross published from <a href="https://skeletonsinsoftwarecloset.com/">https://skeletonsinsoftwarecloset.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a7882d7bc5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Atomic Habits]]></title>
            <link>https://medium.com/@notsohuman/atomic-habits-7d6597d39d94?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d6597d39d94</guid>
            <category><![CDATA[habit-building]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Sat, 12 Jan 2019 09:53:50 GMT</pubDate>
            <atom:updated>2019-01-12T09:54:45.854Z</atom:updated>
            <content:encoded><![CDATA[<p>When we do set out things to do we generally make ambitious plans and we are pumped up to do it but then after the few days the motivation we had initially disappeared and boredom replaces it we give up. There is a good reason for this. Our Reptilian brain is wired to seek immediate rewards for actions that happen now. Since it was designed to thrive in what is called “<strong>Immediate return Environment”</strong>. But our modern society offers what is called as “<strong>Delayed return Environment”</strong> where our actions may take days, weeks or even years for us to reap its benefits. The cost of our bad habits is in the future while the cost of our good habits is in the present.</p><p>If we were able to provide simple markers for us to achieve rather than our grand plan. And if we could see our markers accumulate as time passes by. we would simply show up even when we are down just so that we don’t miss the streak. And simply showing up when we hit our lowest point is more important than doing it when you are motivated. If you do it repeatedly enough it will become a habit and as we do it more often our brain will automate it and it will become a part of your identity.</p><p>Imagine things you do as a scientific experiment you start the experiment with given assumptions and you conduct the experiment and you measure the outcome in a definite means at each possible step If your data suggest that you are doing it wrong you start tweaking your habit till you get the expected result. This is called the “<strong>Growth mindset”</strong> People with a growth mindset generally focus on the process rather than on the end goal. Focusing on the process helps you to persist longer since measuring your progress through the process is its own reward. It is not the people who are smart, intelligent or really motivated who make it to their end goal but it is people who can persist through their boredom.</p><p><strong>Recommended Reading</strong></p><ul><li><a href="https://www.amazon.in/Atomic-Habits-James-Clear/dp/1847941834"><strong>Atomic habit </strong>by “James Clear”</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d6597d39d94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rubber duck debugging]]></title>
            <link>https://medium.com/computer-stuff/rubber-duck-debugging-e85b2e0cbb9f?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e85b2e0cbb9f</guid>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 09:07:22 GMT</pubDate>
            <atom:updated>2018-08-22T09:09:19.882Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently was struggling with a problem and I couldn’t come up with a simple solution without constructing complex hoops through jump through. But then I had a little chit chat without a friend of mine. All I did was just explain him the solution I came up with and it didn’t take much time for me to realize my mistakes and I felt dumb after coming up with a really simple solution. this method is called <strong>Rubber duck debugging</strong>.</p><p>In rubber duck debugging you need to explain the flow of your code in line by line to another person who has no knowledge of the subject or to a rubber duck. In doing so you are forced to retrace the path you took while writing the code and to rethink your logic thus to find a flaw in it.</p><p>There is another similar technique called <strong>Feymen’s technique</strong>. Awesome physicist Richard Feyman whenever he learnt something new or thought of something he would explain it to his students or colleagues in really simple words. That will force him to see the gap in his understanding. There is a reason why he is called “The Great explainer”. People often tend to use lots of jargon in their words just to make themselves feel smart. While jargons may sound cool and smart they are often dumb and will help you get away with half-baked knowledge of the subject. Using simple words to explain complex subject is very hard and to do that you will need a good grasp of the subject at hand.</p><p>There has been tons of research done to explain Feymen’s technique (ironically most these papers use complex jargons). I guess we don’t need to be just programmers but rather we need great explainers.</p><p><strong>Further Reading</strong></p><ul><li><a href="https://blog.codinghorror.com/rubber-duck-problem-solving/">https://blog.codinghorror.com/rubber-duck-problem-solving/</a></li><li><a href="https://en.wikipedia.org/wiki/The_Pragmatic_Programmer">https://en.wikipedia.org/wiki/The_Pragmatic_Programmer</a> ( the book where the word <strong>**rubber duck**</strong> was used first)</li><li><a href="https://www.youtube.com/watch?v=MlJdMr3O5J4">https://www.youtube.com/watch?v=MlJdMr3O5J4</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e85b2e0cbb9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-stuff/rubber-duck-debugging-e85b2e0cbb9f">Rubber duck debugging</a> was originally published in <a href="https://medium.com/computer-stuff">computer Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coconut : Making python functional]]></title>
            <link>https://medium.com/computer-stuff/coconut-making-python-functional-4280d57685b0?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4280d57685b0</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Sun, 18 Feb 2018 22:36:51 GMT</pubDate>
            <atom:updated>2018-02-18T22:36:51.293Z</atom:updated>
            <content:encoded><![CDATA[<p>These days there is talk of functional programming everywhere from JavaScript to c++ (yeah c++ now has lamda functions, higher order functions). But if you were someone who is writing python writing functional code (meaning without classes and using other functional concepts casually) every where is not a comfort you have without compromising the efficiency. So python has been lagging in this area.</p><p>But as always people with their awesomeness will figure out ways around it. One such effort is Coconut (yeah it is named after Monty python holy grail for those who remember it). Coconut is a language that compiles to python (don’t run away now). It is a super set of python. Meaning every python code is a valid Coconut code. More over it runs both python 2 and 3.</p><pre>pip install coconut</pre><p>Just to give you a taste of what it provides lets say you have a problem of finding largest element from the list and calculating its divisors.</p><p>in regular python you may do</p><pre>def problem1(vals):<br>   # calculate largest element of array<br>   # find the divisor of the number<br>   pass</pre><p>Now that functions does more than one thing and may be hard to test if those things were complicated. In coconut you may write it as</p><pre>(largest_elem...find_divisors)(vals)</pre><p>that&#39;s more neat and it is more easily testable since each function does one simple thing (and if you were using lamdas to do this it might not look good as above and you have to worry about performance).</p><p>Coconut provides tail call optimization. Meaning you can go recursive as much as your heart content without worrying about performance reduction (someday python should have inbuilt tail call optimization ). and it also makes writing parallel programming more easy than you can think.</p><p>Here is the short list of features provided by Coconut</p><ul><li>pipeline-style programming</li><li>prettier lamdas</li><li>partial application</li><li>pattern matching</li><li>function composition</li><li>destructing assignment</li><li>infix function</li><li>operator functions</li><li>lazy list</li><li>parallel programming</li><li>tail call optimization</li><li>algebraic data types</li></ul><p>whats more you can start using coconut straight of the bat on your existing python code base. May be some day python may decide to include these features natively hope that day comes soon but till then lets use coconut like Monty python used coconut as a horse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*O_Ae2XTBsCElcaYmVh0_JQ.jpeg" /><figcaption>Someday coconut may turn into a real horse</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4280d57685b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-stuff/coconut-making-python-functional-4280d57685b0">Coconut : Making python functional</a> was originally published in <a href="https://medium.com/computer-stuff">computer Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type check JavaScript with sanctuary-def]]></title>
            <link>https://medium.com/computer-stuff/type-check-javascript-with-sanctuary-def-744515a3a05c?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/744515a3a05c</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Mon, 13 Mar 2017 12:18:01 GMT</pubDate>
            <atom:updated>2017-03-13T12:18:58.118Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is awesome and flexible but sometime this dynamic typing comes<br>at cost. It can sometime result in awful errors that will be hard to detect.<br>while we don’t want to loose these advantages of dynamic typing it would be awesome if we could leverage some of the advantages of static typing without loosing another language that compiles to JavaScript.</p><p><a href="https://github.com/sanctuary-js/sanctuary-def">sanctuary-def</a> provides enables us to create optional type system that we can use as tool during development to aid us and can disable it in production. So it’s not some new language that compiles to Js but just plain Js and the type system will not stand in our way.</p><p>to enable this type checking you do</p><pre>const $ = require(&#39;sanctuary-def&#39;);<br>const def = $.create({<br>  checkTypes: process.env.NODE_ENV === &#39;development&#39;,<br>  env: $.env,<br>});</pre><p>why the $ you may ask it is just a convention that is followed by sanctuary-def nothing special if you want you could name it whatever you want.</p><p>The create method of $ allows you to setup the environment. The <strong>checkTypes</strong> if set true enables type checking. We have used</p><pre>process.env.NODE_ENV === &#39;development&#39;,</pre><p>to enable type checking during development and disable it in production to improve performance. Here we have used the default environment ($.env) that comes with sanctuary-def. It comes by default some types like</p><p><strong>Function, Arguments, Array, Boolean, Date, Error, Null, Number, Object, RegExp, sanctuary-def/StrMap, String, Undefined …etc</strong></p><p>so if I were to create a function called add that would take two <strong>Numbers</strong> and<br>return a result which is a <strong>Number</strong> we could do</p><pre>const add = def(&#39;add&#39;, {}, [$.Number, $.Number, $.Number],<br>  (x, y) =&gt; x + y);</pre><p>the first two argument in the array [$.Number, $.Number, $.Number] indicate the input to the function and the last argument indicates the output.</p><p>The function <strong>add</strong> is now curried by default meaning that <strong>add</strong> will take<br>an argument and return function that will take argument and return sum. Here is awesome <a href="https://www.youtube.com/watch?v=iZLP4qOwY8I">video</a> explaining that.</p><p>But if you want to define custom types which is not provided by sanctuary-def<br>you could do that by just adding new elements to the array $.env and pass<br>the new array instead to the create method.</p><pre>const env = $.env.concat([Integer, NonZeroInteger]);</pre><p>And if you want to remove some existing types you could also do the same by<br>just removing the elements from the $.env and pass the new array to the create method.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=744515a3a05c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-stuff/type-check-javascript-with-sanctuary-def-744515a3a05c">Type check JavaScript with sanctuary-def</a> was originally published in <a href="https://medium.com/computer-stuff">computer Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional programming with SanctuaryJs (with optional types of course..)]]></title>
            <link>https://medium.com/computer-stuff/point-free-programming-with-sanctuaryjs-with-optional-types-of-course-4a1007fc9dcc?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a1007fc9dcc</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Sat, 11 Mar 2017 07:43:19 GMT</pubDate>
            <atom:updated>2017-05-24T09:01:25.836Z</atom:updated>
            <content:encoded><![CDATA[<p>Functional Programming has been on the rise recently in Javascript with the introduction of ES6, ReactJs, CycleJs, ramdaJs etc. in which you use just functions to do every thing without using any loops (recursion and other functions are there for doing that). So is the style of Point free programming where code is written with minimal use of using variable names. There is an awesome article on <a href="http://lucasmreis.github.io/blog/pointfree-javascript/">that</a> In functional programming you make your code into small Lego pieces(functions) that fit together to make a Lego set. making it easier to debug and reason about code.</p><p>In spite of all this Javascript seems to be lacking something. Types No I’m not talking about the horrible one that <strong>C, C++ or Java</strong> has that require you to write verbose code making your code into a abomination. I’m talking about type inference and optional typing like the one Haskell has. Type inference means you don’t need to specify the type and the compiler decides it for itself. Languages like typescript tried to do that but most of us don’t want to write in a language that compiles to Javascript. So how do you do that? SanctuaryJs provides a simple solution. So what advantage does it offer you may ask as they say it in their website</p><p><em>Sanctuary makes it possible to write safe code without null checks</em></p><h3>Getting Started With SanctuaryJs</h3><p>SanctuaryJs performs run-time type checking meaning that it will check using a module called sanctuary-def but this comes with performance cost so you are given an option to disable it during run-time. This type checking is done during development and the code is optimized without type checking during production.</p><p>And functions in sanctuaryJs are curried by default. <a href="https://www.youtube.com/watch?v=iZLP4qOwY8I">This</a> video explains currying.</p><p>SanctuaryJs create() function is used to enable and disable type checking by default. So you can do</p><pre><strong>const</strong> {create, env} <strong>=</strong> require(&#39;sanctuary&#39;);<br><strong>const</strong> S <strong>=</strong> create({<br>  checkTypes<strong>:</strong> process.env.NODE_ENV <strong>!==</strong> &#39;production&#39;,<br>  env<strong>:</strong> env,<br>});</pre><p>the code segment <strong>process.env.NODE_ENV !== ‘production’</strong> enables type checking in developement and disables it in production. The env defines types you can extend env if you want to create your own type most of the time you don’t need to mess with it.</p><h3>Handling missing Values</h3><p>Pure functions should always return something so how will you deal with missing values in pure function?. The solution is <strong>Maybe</strong></p><p>consider you have an array and a function head that returns the first element of the array</p><pre><strong>var</strong> arr <strong>=</strong> [1,2,3];<br><strong>function</strong> head(array) {<br>  <strong>return</strong> array[0]<br>}<br>head(arr)</pre><p>so how do you deal with it when array of zero length is passed to it. trivial approach might be</p><pre><strong>var</strong> arr <strong>=</strong> [1,2,3];<br><strong>function</strong> head(array) {<br>  <strong>if</strong>(array.length <strong>!=</strong> 0)<br>    <strong>return</strong> array[0];<br>}<br>head(arr)</pre><p>but pure function should always return something. You might instead try returning an object that has value and key indicating if it has value or not. so you can do</p><pre><strong>var</strong> arr <strong>=</strong> [1,2,3];<br><strong>function</strong> head(array) {<br>  <strong>if</strong>(array.length <strong>!=</strong> 0)<br>    <strong>return</strong> {<br>      &quot;isNothing&quot;<strong>:</strong> <strong>false</strong>,<br>      &quot;isJust&quot;<strong>:</strong> <strong>true</strong>,<br>      &quot;value&quot;<strong>:</strong> array[0]<br>    }<br>  <strong>else</strong><br>   <strong>return</strong> {<br>     &quot;isNothing&quot;<strong>:</strong> <strong>true</strong>,<br>     &quot;isJust&quot;<strong>:</strong> <strong>false</strong><br>   }<br>}<br>head(arr)</pre><p>here <strong>isJust</strong> is true if value is there else it is false. <strong>isNothing</strong> is the reverse of it. The value key is added to the object only if value is present.</p><p>sanctuaryJs excatly does this.and it has a head function that does this</p><pre><strong>var</strong> arr <strong>=</strong> [1,2,3]<br>S.head(arr)</pre><p>produces</p><pre>{<br>  &quot;isNothing&quot;: false,<br>  &quot;isJust&quot;: true,<br>  &quot;value&quot;: 1<br>}</pre><p>this object is said to be of type <strong>Maybe</strong> since it can maybe have value or not. The function that returns object of type maybe is said to be of type <strong>Maybe</strong></p><h3>Either</h3><p>Either is similar like Maybe but unlike missing values it can have values either of type a or value of type b. so for example we say the function can return value either of type ‘a’ or of type ‘b’. The value on the left (here it is ‘a’) is called left and the value on the right (here it is ‘b’) is called right. similar to may be a function that is said to be of type either will return either value of type ‘a’ or of type ‘b’ inside a JSON and will have keys isRight or isLeft set to true or false accordingly.</p><p>and also the functions are curried by default the docs in santuaryJs says. Here is an awesome <a href="https://www.youtube.com/watch?v=iZLP4qOwY8I">video </a>that explains what is currying is. If you look into the docs you will find some weird symbols like this</p><pre><em>// add :: FiniteNumber -⁠&gt; FiniteNumber -⁠&gt; FiniteNumber</em><br>S.add(1,1)</pre><p>for S.add meaning it takes a number and returns a function which can take a number and then return a FiniteNumber (meaning some countable number). also note that type is shown as after double colon :: (it is inspired from haskell).</p><p>And you can compose multiple functions into one using S.compose. Meaning it will take many functions and return a function that does what all those functions will do. This <a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-function-composition-20dfb109a1a0#.evmc9tzcz">article</a> goes into in depth.</p><pre>S.compose(Math.sqrt, S.inc)(99)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a1007fc9dcc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-stuff/point-free-programming-with-sanctuaryjs-with-optional-types-of-course-4a1007fc9dcc">Functional programming with SanctuaryJs (with optional types of course..)</a> was originally published in <a href="https://medium.com/computer-stuff">computer Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Internet Explorer Tax]]></title>
            <link>https://medium.com/@notsohuman/internet-explorer-tax-a704536b55ab?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a704536b55ab</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Sat, 11 Mar 2017 05:32:10 GMT</pubDate>
            <atom:updated>2017-03-11T05:32:10.835Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently found an old <a href="https://www.kogan.com/au/blog/new-internet-explorer-7-tax/">blog</a> on kogan.com an online retailer about tax on users who use IE7 to purchase stuff from the site. Internet Explorer for years has been the dread of the web developers. You could divide the world of web development into two the world of Internet explorer and other browsers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*n06OzlnRk9YB0G26Rg1UzA.png" /></figure><p>Yes Internet Explorer 11 has done more than its predecessor but it is still lagging lot behind. If you are developing for electron or mobile apps using the web technology you are free to use flex box, most of ES6 <a href="https://kangax.github.io/compat-table/es6/">without transpilation</a> etc.. ( most of desktop browsers support that except IE 11 which has buggy support) While even today when most of the web API has stabilized across browsers you still have to do some extra hacks just to support Internet explorer. In large code base huge chunk of code will be devoted just make the software run in a new environment rather adding new feature. Just to extend it to new environment rather than adding features.</p><p>Web technologies have evolved into the stage where you don’t need to add huge <strong>“meta code” </strong>just for your code to run in new environment that’s what makes attractive compared to traditional platforms. These meta code will cost the company huge chunk of the profit and time. But users don’t want to upgrade their browsers. But if more people are made aware of this economic incentive most of us will stop supporting ancient browsers and users will be forced to upgrade to new ones.The internet explorer tax is a sarcastic way to do this (may be we should have something like zombie browser tax or even more creative ways to do this). As they say money always wins the argument but in this case it means it should make you not support old browsers ( except in the case where your client irrationally wants you to support IE1 and is willing to pay you few million dollars).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3FPAvSOMqs-obTBdx0oolA.jpeg" /><figcaption>if money always wins then you should save it by not supporting ancient browsers ( <em>Image: </em><a href="http://www.flickr.com/photos/hikingartist/5727283114/sizes/m/in/photostream/"><em>HikingArtist</em></a><em>)</em></figcaption></figure><p>This will make development faster and the developers can add more value rather than just writing some new meta code.</p><p>Web development has come a long way from static web pages to full blown applications in the webpage but it still has lots to go but as always sometimes you need to trash some old code to move forward. And If you are reading this article in old browser please upgrade it now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a704536b55ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Un-tooling your way out]]></title>
            <link>https://medium.com/@notsohuman/un-tooling-your-way-out-c5b1bb188b00?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5b1bb188b00</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Fri, 10 Mar 2017 03:13:33 GMT</pubDate>
            <atom:updated>2017-03-10T03:14:22.241Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started with programming like many I thought having the best tool and frameworks will make you more productive and awesome. I first started using vim and spent considerable time exploring just to build the right vimrc file, then I was amazed by sublime and atom. and when I entered JavaScript world I thought Jquery was the thing then backbone, angular, react …∞. After some time I was overwhelmed by all this tooling and switching frameworks. And I entered the <strong>spiral of despair.</strong></p><p>Then I came across this awesome <a href="https://www.joelonsoftware.com/2001/10/14/in-defense-of-not-invented-here-syndrome/">article</a>. This article explains much of the situation of what is happening in JavaScript world. Where many developers are trying to<strong> npm install</strong> their way out of everything. That’s where the problem comes from. When you depend on other packages out there to do the work “<a href="https://www.youtube.com/watch?v=rI8tNMsozo0">easily</a>” then you are bringing a load of problems when that functionality is core to your software. That’s why JavaScript is exploding with packages , frameworks and libraries. I don’t meant to say you should not use them. You should use them not because you don’t know how to do it without them. But because you don’t want to re-invent the wheel and it is not the core functionality of your software.</p><p>The same story could be said for build systems ( gulp, grunt, webpack … ∞) each one of them comes with a promise of some new world changing thing but it fails horribly in some new creative way and so comes the next. None of these tools are better or worse than others. In the end it is all just JavaScript.</p><p>Editors and plugins for editors is something different. Even from the day vim and Emacs were out there people looking for the best text editor. There would be raging discussions about how Emacs has plugins to watch videos inside it while vim does not (why would anyone want that). and same goes for sublime, atom , vscode. People have built these massive Eco-system of plugins for everything in these editors. But in the end you might not use most of them after installing it once and even if you do the boost in productivity it provides you might be infinitesimally small.We humans have limited brain power and switching between these tools and plugins just drains your brain power without giving you something valuable. This is not actual work but rather <a href="https://xkcd.com/1205/">meta work</a>. It does not mean you should not use any tools but as long as they don’t get in your way there is nothing harm in using them and never switch <a href="https://www.youtube.com/watch?v=hlYiWznhhzw">tools </a>unless it is absolutely necessary. These days I use atom without plugin and keep it simple that way it does not distract me from the actual work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5b1bb188b00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Vanilla Js]]></title>
            <link>https://medium.com/@notsohuman/use-vanilla-js-ab757588dc59?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab757588dc59</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Sat, 04 Feb 2017 16:01:14 GMT</pubDate>
            <atom:updated>2017-02-04T16:27:29.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3rOfG1BAirxIgCQ8Hqkmw.jpeg" /></figure><p><strong>JavaScript</strong> community has had a lot of JavaScript framework leading to JavaScript fatigue. With each framework coming up every week. Saying it performs something better than the previous framework. Most developers tend spend most of their time learning all these frameworks just to make sure they stay “<a href="https://www.youtube.com/watch?v=ZZUY37RQS-k">relevant</a>” in the development community. And the time they spend on developing the actual project tends is very less an in the end it all ends up with dissatisfaction and feeling overwhelmed by all the noise so we have to learn to filter the noise or else it we be a slow descend into the madness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DNlxDsffhgLP4awnVxltqQ.gif" /></figure><p><strong>The Problem</strong></p><p>While all these frameworks are great they all have one inherent defect. They provide an abstraction over existing vanilla JavaScript so that you could certain things easily with minimal code since others some of them is “<strong>taken care for you</strong>”. And these abstraction always tend to be <a href="https://www.youtube.com/watch?v=gRsyY0kzXfw">leaky</a>. Meaning all these frameworks are designed to solve a particular problem in mind and are easy to do certain things easy in them without much code. But you will sometime hit the walls of this fishbowl and you might need to something that the framework was not designed in mind so you deploy certain hacks to overcome this and in the end they make your code more complex than it should be ( some time to do this hacks you need to know internal of the framework to do this which kind of breaks the purpose of this abstraction).</p><p>Thus when a new framework comes around that promises to solve this problem people tend to jump the boat only to later realize that they cant do something else in that and so does the descend into the spiral of madness continues.</p><p><strong>So what to do about It</strong></p><p>The solution to this is pretty simple don’t use frameworks rather pure Vanilla Js with some libraries ( like lodash, ramdajs, axios etc.. ) to solve the problems. Considering most modern browsers have large stable API you might not even need to use Jquery. The advantages of libraries over framework is that they just provide utilities that help you solve the problem rather than trying you to make you follow some steps so that the problem could be solved in a particular way. Thus you are free from the mortal bounds of this frameworks.</p><p><strong>Don’t write frameworks</strong></p><p>Another important thing is that you don’t need to write a complete new framework that is not what i’m talking about. If you have your application build as separate small reusable Lego bricks (modules) written in pure js with each of them designed to solve one particular problem in mind with controlled input and output with minimal <a href="https://egghead.io/lessons/javascript-redux-pure-and-impure-functions">side effects</a>. Then your Application becomes more composable. so that later on you could throw out one of these modules when you don’t need that feature and replace that Lego brick with some new one so that it does something else different now. And each Lego brick ( module) is easy to test for defect and can be fixed with kragle if it is broken.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*ShjNLk2U_hf9V39fZvGC4A.jpeg" /></figure><p><strong>With Great power comes great responsibility</strong></p><p>While using vanilla Js is great since it provides great flexibility it comes with a price you need to know good amount of Js to do useful stuff with it. This is a good thing because if you know good amount of Js and can build useful stuff with it. Then you can solve problems easily and you wont ever have the need to learn another new shiny framework. Thus it will free you and give you a peace of mind and you can spend all your focus in solving the real problem rather than solving the meta problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab757588dc59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving from SailsJs to ExpressJs]]></title>
            <link>https://medium.com/computer-stuff/moving-from-sailsjs-to-expressjs-f4c7af2a1798?source=rss-ef117c13708f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4c7af2a1798</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[sailsjs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[sail]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Mon, 26 Dec 2016 08:25:22 GMT</pubDate>
            <atom:updated>2016-12-26T08:27:55.937Z</atom:updated>
            <content:encoded><![CDATA[<p>SailsJs is great for beginners but like all frameworks it has its <a href="https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/SimpleMadeEasy.md">limitations </a>and defects. Its development activity has slowed down considerably and it is stuck with Express 3.x which is not even supported by Express js itself. So I decided to port my old sailsjs code to pure expressjs.</p><p>First I needed to replicate the folder structure similar to saisjs. So that I could port my code without much of hassle. In my sails app I did not use my views since I kept the UI seperate and used sailsjs more like a rest endpoint. And as for ORM I thought of using waterline for now and later port it to mongoose.</p><p>the folder structure of the app is as follows</p><pre>App <br>-api<br>  -controllers<br>  -models<br>  -policies<br>  -servies<br>-config<br>  -bootstrap.js<br>  -connection.js<br>  -cors.js<br>  -error.js<br>  -globals.js<br>  -middleware.js<br>  -policies.js<br>  -routes.js  <br>-app.js<br>-package.json</pre><p>First I installed the base packages I needed and here is my packages.json</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b132587ec9d0345d47f58afae118ecef/href">https://medium.com/media/b132587ec9d0345d47f58afae118ecef/href</a></iframe><p>To get the app running we need app.js here is my complete app.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f6afc4fc63348b4a3ecbd7b7ae4f420/href">https://medium.com/media/7f6afc4fc63348b4a3ecbd7b7ae4f420/href</a></iframe><p>Here I have required modules <strong>express, connect </strong>and <strong>body-parser</strong> for creating express app. <strong>cors </strong>module to enable cors support and <strong>command-line-args </strong>arguments to get command line parameters although here I have accepted only one argument -p for port. the module <strong>./config/policies </strong>contains list of policies to be executed before the controllers and <strong>./config/connection </strong>is used to setup waterline connection. In my <strong>bootstrap.js </strong>I have searched for file ending with name <strong>controllers.js</strong> in controllers directory and I have set them as global variables in express app so that those controllers will be hit when using appropriate route using map. the <strong>routes.js</strong> is used to configure routes and file name with suffix <strong>controllers.js</strong> will be added to route by default else you need to do it manually.</p><p><a href="https://github.com/Rafi993/sails-to-express">here</a> is the full code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4c7af2a1798" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-stuff/moving-from-sailsjs-to-expressjs-f4c7af2a1798">Moving from SailsJs to ExpressJs</a> was originally published in <a href="https://medium.com/computer-stuff">computer Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>