<?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[computer Stuff - Medium]]></title>
        <description><![CDATA[Blog about computers, math and things in between - Medium]]></description>
        <link>https://medium.com/computer-stuff?source=rss----995e6e7a347f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>computer Stuff - Medium</title>
            <link>https://medium.com/computer-stuff?source=rss----995e6e7a347f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:26:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/computer-stuff" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rubber duck debugging]]></title>
            <link>https://medium.com/computer-stuff/rubber-duck-debugging-e85b2e0cbb9f?source=rss----995e6e7a347f---4</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:08:18 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----995e6e7a347f---4</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----995e6e7a347f---4</link>
            <guid isPermaLink="false">https://medium.com/p/744515a3a05c</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rafi]]></dc:creator>
            <pubDate>Thu, 08 Feb 2018 05:07:19 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[Moving from SailsJs to ExpressJs]]></title>
            <link>https://medium.com/computer-stuff/moving-from-sailsjs-to-expressjs-f4c7af2a1798?source=rss----995e6e7a347f---4</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>Thu, 08 Feb 2018 05:06:45 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>
        <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----995e6e7a347f---4</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>Thu, 08 Feb 2018 05:06:36 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>
    </channel>
</rss>