<?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 Arvind Devarajan on Medium]]></title>
        <description><![CDATA[Stories by Arvind Devarajan on Medium]]></description>
        <link>https://medium.com/@arvindd?source=rss-dc5808fb1cbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*m3oU2tWAC35CM9ojkZvxTw.png</url>
            <title>Stories by Arvind Devarajan on Medium</title>
            <link>https://medium.com/@arvindd?source=rss-dc5808fb1cbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:59:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arvindd/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[Emulating Raspberry Pi on with QEMU]]></title>
            <link>https://blog.ramdoot.in/emulating-raspberry-pi-on-with-qemu-951283daf2bd?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/951283daf2bd</guid>
            <category><![CDATA[qemu]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Sat, 25 Jun 2022 17:02:15 GMT</pubDate>
            <atom:updated>2022-07-10T00:56:26.274Z</atom:updated>
            <content:encoded><![CDATA[<h3>Emulating Raspberry Pi with QEMU</h3><h3><strong>Table of contents</strong></h3><p><a href="#83ca">Introduction</a><br><a href="#7ee0">Downloading Raspberry Pi OS</a><br><a href="#b6b7">QEMU</a><br>- <a href="#38ee">Installation</a> <br>- <a href="#bdba">Raspberry Pi OS Image Creation</a><br>- <a href="#e9df">Starting Raspberry Pi OS in QEMU</a> <br><a href="#1152">Increasing SD card size to about 8GB</a><br><a href="#be16">Connecting to Raspberry Pi OS via SSH</a><br>- <a href="#2ce7">Enabling SSH in Raspberry Pi</a><br>- <a href="#5520">Connecting to Rpi via SSH (using password)</a><br>- <a href="#f97c">Connecting to Rpi via SSH (without password)</a> <br><a href="#5d7f">References</a></p><h3>Introduction</h3><p>Well, a simple search on the internet for this throws up so many links — therefore let me put somethings aside.</p><p>As you may have already seen, the steps for such an emulation. None of them really worked directly for me, so here are the steps that worked.</p><h3>Downloading and extracting files from Raspberry OS</h3><p>These instructions can be performed on a native Linux system, or on a <a href="https://docs.microsoft.com/en-us/windows/wsl/install">Windows Subsystem for Linux (WSL)</a>. They cannot be done on Windows.</p><p><strong>Download Raspberry Pi OS and decompress</strong></p><p>Download the Rapberry Pi OS from <a href="https://www.raspberrypi.com/software/operating-systems/">here</a>. I chose the Raspberry Pi OS 32-bit Lite edition as I need to work only on the terminal. Of course, all that I mention below will also work for the desktop edition.</p><pre>curl &lt;link-to-raspios&gt; -o raspios.img.xz<br>xz -dk raspios.img.xz    # Let&#39;s keep the original image even <br>                         # after decompressing</pre><p><strong>Mount the image to a specific mount directory</strong></p><pre>sudo mkdir /mnt/rpi<br>sudo losetup -f --show -P $(pwd)/raspios.img<br>sudo mount /dev/loop&lt;no&gt;p1 /mnt/rpi</pre><p><strong>Extract out the kernel and all the dtb files from the image</strong></p><pre>mkdir dtbs<br>cp /mnt/rpi/kernel* .<br>cp /mnt/rpi/*.dtb dtbs</pre><p><strong>Remove password for the user “pi”</strong></p><p>The latest versions of <a href="https://www.raspberrypi.com/news/raspberry-pi-bullseye-update-april-2022/">Raspberry Pi OS no longer have the default username-password combo as pi:raspberry</a>. According to its documentation, the Raspberry Pi OS also allows for setting up of the default password in the image it writes.</p><p>In our case, since we manually downloaded the built image directly, we have not set any default password.</p><p>We therefore will simply mount the root-fs of the Raspberry Pi like how we mounted the kernel partition above:</p><pre>sudo umount /mnt/rpi<br>sudo mount /dev/loop&lt;no&gt;p2 /mnt/rpi</pre><p>Edit the file /mnt/rpi/etc/passwd to empty the password for the “pi” user:</p><pre>sudo vi /mnt/rpi/etc/passwd</pre><p>Search for this line in the file:</p><pre>pi:x:1000:1000:,,,:/home/pi:/bin/bash</pre><p>and remove the ‘x’ after “pi:”. Now save the file. By doing this, we have simply made it easy for us to log into the Raspberry Pi OS as soon as QEMU boots with it. The line should now look like this:</p><pre>pi::1000:1000:,,,:/home/pi:/bin/bash</pre><p><em>Unmount image — you’ll not need it any more</em></p><pre>sudo umount /mnt/rpi<br>sudo losetup -d /dev/loop&lt;no&gt;</pre><h3><strong>QEMU</strong></h3><p><strong>Installation</strong></p><p>Installation of Qemu normally involves installing multiple packages in a linux distribution. On Windows, a single download install all Qemu.</p><p>Typically, on linux distributions, the following packages are needed (tested in OpenSUSE, but these names are also on Ubuntu):</p><pre>sudo zypper install qemu qemu-arm qemu-tools</pre><p><strong>Creating QEMU-compatible Raspberry Pi OS Image</strong></p><p>The Rpi image we downloaded above is a raw format image. Converting this to qcow2 format makes it very performant while use with QEMU, and also occupies lesser space on host machine.</p><p>Additionally, we also increase the SD card size to 8GB so that we can use all that space for installation of additional software in run-time.</p><pre>### Convert the raw image to QEMU qcow2 format<br>qemu-img convert -f raw -O qcow2 raspios.img raspios.qcow </pre><pre>### Resize the image to 8GB (it should be a power of 2)<br>qemu-img resize raspios.qcow 8G</pre><pre>### Remove existing raspberry pi os raw image so that we<br>### do not get confused and use it.<br>rm -f raspios.img</pre><p><strong>Starting Raspberry Pi OS</strong></p><p>The instructions below work on both Windows and Linux (or WSL) systems. Of course, on Windows, you will not use the sudo before qemu-system-aarch64.</p><p>At the time of writing, I am using QEMU 7.0.0, but also tested this from QEMU version 5.2 — so I can guarantee that this works atleast from this version.</p><pre># Start the QEMU with Rpi emulation<br>sudo qemu-system-aarch64 -M raspi3b -display none -append &quot;rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1&quot; -dtb ./dtbs/bcm2710-rpi-3-b-plus.dtb -sd raspios.qcow -kernel kernel8.img -m 1G -smp 4 -serial mon:stdio -usb -device usb-mouse -device usb-kbd -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22</pre><p>This will start up QEMU with Raspberry Pi on the console. When it prompts you for the login, just type in pi and press &lt;ENTER&gt;. You’ll now blissfully drop into the Raspberry Pi OS’s terminal. You can get the root shell by simply typing sudo bash on the command prompt.</p><p><strong>Brief explanation of the command line</strong></p><p>Ok, let’s just try to understand what really went on above. Here is a quick explanation:</p><pre>### We select the raspberry pi 3b <br>-M raspi3b </pre><pre>### Since we start a lite image, we do not need QEMU graphics<br>-display none </pre><pre>### The path to the SD card image, mounted on the emulated <br>### SD card. This image was what we downloaded from the <br>### Raspbery Pi site, and also resized to 8G (i.e., a power of 2)<br>-sd raspios.qcow</pre><pre>### The device tree for Raspberry Pi and the kernel images. <br>### These were extracted from the first partition of the <br>### image above.<br>-dtb ./dtbs/bcm2710-rpi-3-b-plus.dtb -kernel kernel8.img</pre><pre>### Redirect all IO messages to/from a serial console.<br>### Specially, we also use &quot;mon:&quot; as an argument to -serial <br>### to make sure that ctrl-c, if used to stop a long running <br>### program in the emulated Rpi will not kill QEMU itself. <br>### &quot;mon:&quot; passes the ctrl-c directly to the guest OS (in our <br>### case, the rapberry pi OS). <strong>Note that this works only on</strong> <br>### <strong>Linux (or WSL) systems - on Windows, it still kills QEMU.</strong><br>-serial mon:stdio</pre><pre>### Pass on some kernel command line: importantly, these <br>### parameters redirect the early boot messages to the serial<br>### terminal ttyAMA0 - this is the same terminal from which <br>### you invoked the QEMU. Since we redirect all IO messages to <br>### serial above, we will see all messages (early boot messages <br>### as well as your inputs) directly on the terminal you invoked <br>### the QEMU. Also, we mention that rootfs is on the <br>### second partition on the image (remember we modified the <br>### passwd file from this partition above?)<br>-append &quot;rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1&quot;</pre><pre>### Memory and number of rocessors that we want QEMU to use. <br>### For -smp, we could use $(nproc) on Linux / WSL systems, <br>### or the number returned by &quot;gci $env:NUMBER_OF_PROCESSORS&quot; <br>### on windows machines.<br>-m 1G -smp 4 </pre><pre>### Finally, we emulate all input devices as well as network <br>### devices as USB devices. Additionally, we also forward the <br>### port 22 in the guest (the port in which sshd listens) to <br>### port 5555 on the host. This will allow us to ssh into this <br>### Rapberry Pi OS from anywhere (including the localhost). <br>-usb -device usb-mouse -device usb-kbd -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22</pre><h3>Resizing the SD card size</h3><p>With all this done to successfully start QEMU, we’ll hit the next problem: the size of the SD card (which hosts the OS and the files in the home-directory of the pi user) would be ridiculously small — about 1.6GB, and most of this is already used up by the base system!</p><p>So, we will have to now increase the size of the card so that any useful work can be done with this emulated Rpi.</p><p>Now. create a file /etc/udev/rules.d/90-qemu.rules in the guest Raspberry Pi OS:</p><pre>sudo vi /etc/udev/rules.d/90-qemu.rules</pre><p>Add these contents in the file:</p><pre>KERNEL==&quot;sda&quot;, SYMLINK+=&quot;mmcblk0&quot;<br>KERNEL==&quot;sda?&quot;, SYMLINK+=&quot;mmcblk0p%n&quot;<br>KERNEL==&quot;sda2&quot;, SYMLINK+=&quot;root&quot;</pre><p>Now, shutdown QEMU — sudo shutdown -h now — and restart it again with the command-line as above.</p><p>After QEMU has gotten back, log into it as pi again, and start raspi-config as root:</p><pre>sudo raspi-config</pre><p>In the curses-window that shows up, select “Advanced Options”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBTPIE04kctpnH3uYMoASg.png" /></figure><p>In the advanced options, select “Expand Filesystem”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4k5fsCmjGUg2t9uUuHRkQ.png" /></figure><p>This will expand the filesystem to fill up the original image size of about 8GB. After resizing, you will have to reboot QEMU to use all the expanded space.</p><h3>Accessing the raspberry Pi from host</h3><p><strong>Enabling SSH on Raspberry Pi</strong></p><p>The stock raspberry pi os does not enable ssh connections. The first thing we need to do is to enable that using the raspi-config tool:</p><pre>sudo raspi-config</pre><p>You will now see a curses tool. Use your arrow to select the “Interface Options”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLHryheTas4sX1XN1Pqqeg.png" /><figcaption>raspi-config tool</figcaption></figure><p>Press &lt;ENTER&gt; and select the SSH:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmcVsdEG_0SrT5zip6lU9w.png" /></figure><p>In the dialog that is shown, select “Yes”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HsnHXsvfqrjmb7NZRpb-tg.png" /></figure><p>Press &lt;OK&gt; and then &lt;Finish&gt;. This enables SSH on your Raspberry Pi. Now, you can connect to your emulated Rpi using SSH.</p><p><strong>Connecting via ssh (and using password)</strong></p><p><em>Set a password for user pi</em></p><p>Since we start QEMU with port 22 in guest forwarded to 5555 on host, we can simply access the Rpi OS with ssh from host.</p><p>However, for this, we need to set the password for the pi user in raspberry (remember we removed the password for pi user above). We simply set the password for pi using passwd command in the guest OS.</p><p><em>Configure SSH client</em></p><p>Add this in ~/.ssh/config file in your host:</p><pre>Host rpi<br>  IdentityFile ~/.ssh/rpikey <br>  HostName localhost<br>  User pi<br>  Port 5555</pre><p>The IdentityFile you see above will be used if you decide to go for a password-less login via SSH (see below).</p><p><em>Accessing Raspberry Pi with ssh</em></p><p>Access the Rpi guest from the host using this SSH command:</p><pre>ssh rpi</pre><p><strong>Password-less login via SSH keys</strong></p><p>To enjoy a password-less login via SSH, do this (use these commands on the HOST or RPI):</p><p><strong><em>HOST:</em></strong><em> Generate SSH keys:</em></p><p>We’ll use a password-less private key (hence the -N option below).</p><pre>ssh-keygen -b 2048 -t rsa -q -N &quot;&quot; -f ~/.ssh/rpikey</pre><p><strong><em>HOST:</em></strong><em> Copy the public key into your rpi:</em></p><pre>ssh-copy-id -i ~/.ssh/rpikey rpi</pre><p>Note that the above command worked because you had already configured the ssh client with username and port numbers in the ~/.ssh/config file (see above). If you had not done that, use the following command (the options -p 5555 and the host identity pi@localhost will have to be used for all the rest of the command if the SSH client was not configured in ~/.ssh/config file):</p><pre>ssh-copy-id -p 5555 -i ~/.ssh/rpikey pi@localhost</pre><p><strong><em>RPI:</em></strong><em> Enable password-less on the guest OS in Rapberry Pi</em></p><p>Do this on the original terminal of QEMU (and not on an ssh connected-terminal):</p><p>Edit the file /etc/ssh/sshd_config:</p><pre>sudo vi /etc/ssh/sshd_config</pre><p>Add the following (or uncomment the existing line and make its value to “no”):</p><pre>PasswordAuthentication no</pre><p><strong><em>Optionally,</em></strong> if you also want to login via SSH as root without a password, you will also have to enable this:</p><pre>PermitRootLogin without-password</pre><p>After making these changes, restart your SSH server:</p><pre>sudo /etc/init.d/ssh restart</pre><p><strong><em>HOST:</em></strong><em> Connect to emulated Rpi without password!</em></p><pre>ssh rpi</pre><h3><strong>References</strong></h3><p>There are a lot of places I got all this information. If something does not work for you, there could be additional information added in the original sources. The original sources of information are these:</p><ul><li>Raspberry Pi Native Emulation: <a href="https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/master/native-emulation">qemu-rpi-kernel/native-emulation at master · dhruvvyas90/qemu-rpi-kernel (github.com)</a></li><li>Image conversion to QCow2: <a href="http://codingadventures.org/2020/09/19/raspberry-pi-qemu-and-network-access/">Raspberry Pi, qemu and network access — coding adventures</a></li><li>Increasing Size of SD Card: <a href="https://forums.raspberrypi.com/viewtopic.php?t=42279">QEmu and raspbian, how to increase image size. — Raspberry Pi Forums</a></li><li>Networking on QEMU + Rpi: <a href="https://stackoverflow.com/questions/61562014/qemu-kernel-for-raspberry-pi-3-with-networking-and-virtio-support">QEMU kernel for raspberry pi 3 with networking and virtio support — Stack Overflow</a></li><li>SSH Connections to QEMU: <a href="https://fadeevab.com/how-to-setup-qemu-output-to-console-and-automate-using-shell-script/">How to Setup QEMU Output to Console and Automate Using Shell Script (fadeevab.com)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=951283daf2bd" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/emulating-raspberry-pi-on-with-qemu-951283daf2bd">Emulating Raspberry Pi on with QEMU</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[F# — Debugging tests with VS Code]]></title>
            <link>https://blog.ramdoot.in/f-debugging-tests-with-vs-code-f22a8ff4bc4d?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f22a8ff4bc4d</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[fsharp]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Mon, 16 Aug 2021 04:11:03 GMT</pubDate>
            <atom:updated>2021-08-16T04:11:03.444Z</atom:updated>
            <content:encoded><![CDATA[<h3>F# — Debugging tests with VS Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mp2bdiyB9bL7LtilH8nnFQ.png" /><figcaption>F# — Debugging a test</figcaption></figure><p>It is not a surprise that <a href="https://code.visualstudio.com/">Visual Studio Code</a> has garnered quite some followers in the developer community.</p><p>.NET Support, especially for C#, is very good — right from editing your code, building it, executing it, debugging it, and deployments in cloud platforms such as Azure.</p><p>Support for F# in many areas mentioned above is not really lagging behind — and I personally use VS Code for all my F# needs. <a href="https://ionide.io/index.html">Ionide</a> extension in VSCode has made it all possible — so, thanks a million it!</p><h3>There is one aspect missing…</h3><p>Well, there has to be. All is not rosy, atleast at the time of writing this article. But I don’t call it very bad, though.</p><p>Although it is entirely possible to create XUnit / NUnit test projects using VSCode, there is no direct ways to run those tests from the IDE, or even debug them.</p><h3>Debug F# tests like a pro</h3><p>In my setup, though, I’ve found some ways that work very nicely, albeit some small irritants — you need to run the test, and then again attach to the running test.</p><p>Let’s break that down: the two important files that control the way VSCode actually runs and launches your programs are via the “launch.json” and the “tasks.json” files — so, all of our additions go into one of these files.</p><p><strong>launch.json</strong></p><p>You can open the launch.json file (or create one if not there) in any of the following ways:</p><ol><li>Directly open/create it from the.vscode folder seen at the root of your workspace.</li><li>Click on “Run -&gt; Open Configurations” from your menu. This creates the file above if it is not present.</li></ol><p>In the launch.json, add the bolded text as one of the configurations. This simply adds an “attach” as one of the configurations you will use later to attach to the running tests and begin debugging.</p><pre>{<br>  // Use IntelliSense to learn about possible attributes.<br>  // Hover to view descriptions of existing attributes.<br>  // For more information, visit: <a href="https://go.microsoft.com/fwlink/?linkid=830387">https://go.microsoft.com/fwlink/?linkid=830387</a><br>  &quot;version&quot;: &quot;0.2.0&quot;,<br>  &quot;configurations&quot;: [<br>   <strong> {<br>      &quot;name&quot;: &quot;.NET Core Attach&quot;,<br>      &quot;type&quot;: &quot;coreclr&quot;,<br>      &quot;request&quot;: &quot;attach&quot;<br>    },</strong></pre><pre>    ...<br>  ]<br>}</pre><pre>  &quot;configurations&quot;: [<br>{<br> “name”: “.NET Core Attach”,<br> “type”: “coreclr”,<br> “request”: “attach”<br> },</pre><p><strong>tasks.json</strong></p><p>You can open the tasks.json file (or create one if not there) in any of the following ways:</p><ol><li>Directly open/create it from the.vscode folder seen at the root of your workspace.</li><li>Click on “Terminal -&gt; Configure Tasks” from your menu. This will ask you to select a specific task (if tasks.json is already existing) so that you can configure it, or, offer to create a new task configuration based on a template. In any case, it just does not matter — you can just select one of the tasks to simply open the tasks.json and add the following in the file:</li></ol><pre>{<br>  // See <a href="https://go.microsoft.com/fwlink/?LinkId=733558">https://go.microsoft.com/fwlink/?LinkId=733558</a><br>  // for the documentation about the tasks.json format<br>  &quot;version&quot;: &quot;2.0.0&quot;,<br>  &quot;tasks&quot;: [<br>    {<br>      &quot;label&quot;: &quot;build tests&quot;,<br>      &quot;command&quot;: &quot;dotnet&quot;,<br>      &quot;type&quot;: &quot;shell&quot;,<br>      &quot;args&quot;: [<br>        &quot;build&quot;,<br>        &quot;/property:GenerateFullPaths=true&quot;,<br>        &quot;/consoleloggerparameters:NoSummary&quot;<br>      ],<br>      &quot;group&quot;: {<br>        &quot;kind&quot;: &quot;build&quot;,<br>        &quot;isDefault&quot;: true<br>      },<br>      &quot;presentation&quot;: {<br>        &quot;reveal&quot;: &quot;silent&quot;<br>      },<br>      &quot;options&quot;: {<br>        &quot;cwd&quot;: &quot;${workspaceFolder}/test&quot;<br>      },<br>      &quot;problemMatcher&quot;: &quot;$msCompile&quot;<br>    },<br>    <br><strong>    {<br>      &quot;label&quot;: &quot;run tests&quot;,<br>      &quot;command&quot;: &quot;dotnet&quot;,<br>      &quot;type&quot;: &quot;shell&quot;,<br>      &quot;args&quot;: [<br>        &quot;test&quot;,<br>        &quot;/property:GenerateFullPaths=true&quot;,<br>        &quot;/consoleloggerparameters:NoSummary&quot;<br>      ],<br>      &quot;options&quot;: {<br>        &quot;cwd&quot;: &quot;${workspaceFolder}/test&quot;,<br>      },<br>      &quot;problemMatcher&quot;: &quot;$msCompile&quot;<br>    },</strong></pre><pre>    {<br>      &quot;label&quot;: &quot;debug tests&quot;,<br>      &quot;command&quot;: &quot;dotnet&quot;,<br>      &quot;type&quot;: &quot;shell&quot;,<br>      &quot;args&quot;: [<br>        &quot;test&quot;,<br>        &quot;/property:GenerateFullPaths=true&quot;,<br>        &quot;/consoleloggerparameters:NoSummary&quot;<br>      ],<br>      &quot;options&quot;: {<br>        &quot;cwd&quot;: &quot;${workspaceFolder}/test&quot;,<br>        <strong>&quot;env&quot;: {<br>          &quot;VSTEST_HOST_DEBUG&quot;: &quot;1&quot;<br>        }</strong><br>      },<br>      &quot;problemMatcher&quot;: &quot;$msCompile&quot;<br>    }    <br>  ]<br>}</pre><p>As you see above, the first configuration is simply to build the tests — and this is what VSCode will already generate if you had created tasks.json via the configuration menus and selecting the appropriate build task template.</p><p>The second configuration — with the label “run tests” — is what you should add if you would like to start the test using the menu — Terminal -&gt; Run Task. It simply runs “dotnet test” on your terminal, and the results of the test are also shown on the terminal. You pretty-much do not have much of control on what is run — but this is good for a quick run of all tests.</p><p>The last configuration — with the label “debug tests” — is what will help in debugging your tests. It looks very similar to “run tests” — with just one addition — the environment variable <strong>VSTEST_HOST_DEBUG</strong> is made as <strong>1</strong>.</p><p>When <strong>VSTEST_HOST_DEBUG</strong> is <strong>1</strong>, VS code starts the tests and waits for a debugger to attach (you start the test with— Terminal -&gt; Run Task -&gt; select the “debug tests”). It also prints the process id of the tests:</p><pre>Microsoft (R) Test Execution Command Line Tool Version 16.10.0<br>Copyright (c) Microsoft Corporation.  All rights reserved.</pre><pre>Starting test execution, please wait...<br>A total of 1 test files matched the specified pattern.<br>Host debugging is enabled. Please attach debugger to testhost process to continue.<br>Process Id: <strong>2870</strong>, Name: dotnet</pre><p>Additionally, you now have to attach to the tests to start your debugging session — Run -&gt; Start Debugging (or press F5), select “.NET Core Attach”, and the above process ID for attaching. On subsequent “Start debugging”, you will not need to select “.NET Core Attach” — VS Code will directly give you a list of process ids to select from.</p><p>Once you select the process ID, VS Code attaches to your test, but stays in the “break” mode — so you basically need to “Continue” the execution in the debug-mode for your debugging sessions. Note that the tests will simply run and the process ends if you did not have any breakpoints — but that’s the usual debugging, right?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f22a8ff4bc4d" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/f-debugging-tests-with-vs-code-f22a8ff4bc4d">F# — Debugging tests with VS Code</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developer environments — on-spot!]]></title>
            <link>https://blog.ramdoot.in/devlab-d50cba40578f?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/d50cba40578f</guid>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Wed, 26 May 2021 15:39:55 GMT</pubDate>
            <atom:updated>2021-05-26T22:36:22.008Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developer environments — on-spot!</h3><p><strong>TL; DR: For quickly setting up your (containerised) development environment for working with Python, Julia language, Java, Scala, Rust, or Haskell, just do this:</strong></p><p><strong>First, install docker / docker desktop</strong></p><p>and then:</p><pre>For Linux / Windows Sub-system for Linux:</pre><pre>curl -sSL <a href="https://raw.githubusercontent.com/onspot-tools/devlab/master/scripts/install.sh">https://raw.githubusercontent.com/onspot-tools/devlab/master/scripts/install.sh</a> | sh</pre><p>OR</p><pre>For Powershell:</pre><pre>iex ((New-Object System.Net.WebClient).DownloadString(&#39;<a href="https://raw.githubusercontent.com/onspot-tools/devlab/master/scripts/install.ps1&#39;">https://raw.githubusercontent.com/onspot-tools/devlab/master/scripts/install.ps1&#39;</a>))</pre><p><strong>Now, what are devlabs?</strong></p><p>Ok, your day job is a developer, and you are also a night geek. You are a polyglot. And you play your games with software, your blood is made of software.</p><p>You keep learning new languages and keep experimenting with new stuff. Today it is C#, tomorrow Haskell, and the day after Python. And then you jump into Julia. Well, anything.</p><p>And whenever you jump like a frog, and whenever you want to contribute to that ecosystem, the first thing you need to crack is:</p><h4><strong>Installing development tools and the tool ecosystem</strong></h4><p>Yes, this is the first big thing, before you even start your work on that language.</p><p>Enter <a href="https://github.com/onspot-tools/devlab">devlab</a> — a quick and on-spot development environment setup for various languages. All with a consistent look and feel, and all with a Jupyter lab/notebook for a quick test of the language features, a quick test of that algorithm, and a fast-track into your road for your next big thing.</p><p>Each devlab is a base-set of language tools for different languages, all packed into a container. All of these are available as <a href="https://hub.docker.com/u/onspot">images in the dockerhub</a>, waiting for you to pull them, and just start!</p><p>Starting a devlab starts the juputer-lab server, and you can simply start using your language of interest — either from Jupyter itself, or starting it as a shell/terminal for command-line tools.</p><p><strong>A taste of devlab-haskell</strong></p><p>What I’ve done here is started devlab-haskell, and used it for explaining Haskell syntax in 60 seconds. Just like it is done for <a href="https://fsharpforfunandprofit.com/posts/fsharp-in-60-seconds/">F# by fsharp for fun and profit</a>.</p><p>Check out this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/835cbe922b63d38a17fe70f4f6da4736/href">https://medium.com/media/835cbe922b63d38a17fe70f4f6da4736/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d50cba40578f" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/devlab-d50cba40578f">Developer environments — on-spot!</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Course list]]></title>
            <link>https://arvindd.medium.com/course-list-87fdf71292a7?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/87fdf71292a7</guid>
            <category><![CDATA[k-12-education]]></category>
            <category><![CDATA[course]]></category>
            <category><![CDATA[physics]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Tue, 13 Apr 2021 14:05:49 GMT</pubDate>
            <atom:updated>2021-04-13T14:05:49.307Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JTC8VgeBr7YUnm9aWg-Ow.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@timmossholder?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tim Mossholder</a> on <a href="https://unsplash.com/s/photos/learn?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Since there is a need for K-12 courses that are both affordable and need for a greater reach across India, we keep a Work-In-Progress (WIP) list of 4 courses.</p><p>Ok, because they have to be affordable, there is nothing more affordable than being FREE! Yes, you heard it right — all these courses are FREE — so look for the FREE coupon mentioned in the enrol page of these courses.</p><p>What is the catch? Of course, we cannot have all FREE and still keep paying for our hosting. What we have is a first-cum-first-served list: the first 300 students are only enrolled, and no more (even if they are willing to pay, as we DO NOT OFFER paid courses).</p><p>The following courses are in the current WIP list:</p><p><a href="https://cbsephy11.learn.ramdoot.in/">C01 Physics — 11th Standard CBSE</a></p><p><a href="https://cbsephy12.learn.ramdoot.in/">C02 Physics — 12th Standard CBSE</a></p><p><a href="https://cbsetests.learn.ramdoot.in/">C03 CBSE Tests-only, up to 9th Standard CBSE</a></p><p><a href="https://cbsephy10.learn.ramdoot.in/">C04 Science (only Physics-related lessons) — 10th Standard CBSE</a></p><p>The following are the status of these courses:</p><p>C01 — Started relatively earlier, details status is here</p><p>C02 — Started with only tests, video content will be added after C01 is done to a large extent.</p><p>C03 — Started with 7th Standard’s Mathematics tests, no video content will be added in this course — even in the future</p><p>C04 — Thoughts only, not started yet. Will contain both videos and tests</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87fdf71292a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple JS image browser]]></title>
            <link>https://blog.ramdoot.in/simple-js-image-browser-f249b1e871f3?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f249b1e871f3</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 02:21:18 GMT</pubDate>
            <atom:updated>2021-04-03T02:23:00.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJQe5lpi156iOJEWnuBPsw.png" /></figure><p>Do you have a folder full of images? Do you just want a good image browser to browse them?</p><p>You can either use popular photo viewers to do that or simply use your browser. I dropped an HTML file with these contents, and that’s it. Going forward and backward is just by using your arrow keys (use your intuition :-)).</p><p>To adapting this is as simple as putting the list of images you have in the imgsrc array. Of course, this is a tedious process if you have a lot of images — but for me this is ok. For handling that case, you may need to automatically generate that array externally and then paste it here (use some shell script to generate it, for example). That’s an exercise for you :-)</p><p>None of this is very new and original (how can this simple thing be?). Code for a lot of this is from other places — so credits go to our internet community!</p><pre>&lt;html&gt;</pre><pre>&lt;head&gt;<br>    &lt;title&gt;Image browser&lt;/title&gt;<br>    &lt;style&gt;<br>        html,<br>        body {<br>            height: 100%;<br>            margin: 0;<br>            padding: 0;<br>        }</pre><pre>#board {<br>            padding: 0;<br>            display: block;<br>            margin: 0 auto;<br>            max-height: 100%;<br>            max-width: 100%;<br>        }</pre><pre>#fname {<br>            position: fixed;<br>            left: 0;<br>            bottom: 0;<br>        }<br>    &lt;/style&gt;<br>    &lt;script type=&quot;text/javascript&quot;&gt;<br>        var i = 0, imgsrc = new Array(), preload = new Array();</pre><pre>//if you have another AudioContext class use that one, as some browsers have a limit<br>        var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);</pre><pre>imgsrc[0] = &quot;board01.svg&quot;;<br>        imgsrc[1] = &quot;board02.svg&quot;;<br>        imgsrc[2] = &quot;board03.svg&quot;;<br>        imgsrc[3] = &quot;board04.svg&quot;;<br>        imgsrc[4] = &quot;board05.svg&quot;;<br>        imgsrc[5] = &quot;board06.svg&quot;;<br>        imgsrc[6] = &quot;board07.svg&quot;;<br>        imgsrc[7] = &quot;board08.svg&quot;;<br>        imgsrc[8] = &quot;board09.svg&quot;;<br>        imgsrc[9] = &quot;board10.svg&quot;;<br>        imgsrc[10] = &quot;board11.svg&quot;;<br>        imgsrc[11] = &quot;board12.svg&quot;;<br>        imgsrc[12] = &quot;board13.svg&quot;;<br>        imgsrc[13] = &quot;board14.svg&quot;;</pre><pre>for (var j = 0; j &lt; imgsrc.length; j++) {<br>            preload[j] = new Image;<br>            preload[j].src = imgsrc[j];<br>        }</pre><pre>document.onkeydown = function (event) {<br>            switch (event.keyCode) {<br>                case 37: // Left key<br>                case 38: // Up key<br>                    if (i == 0) {<br>                        beep();<br>                        message(&#39;First image - cannot go further behind!&#39;);<br>                        sleep(3000).then(() =&gt; {<br>                            setFname();<br>                        });<br>                        break;<br>                    }<br>                    i--; // Move to the previous image<br>                    document.getElementById(&quot;board&quot;).src = imgsrc[i];<br>                    setFname();<br>                    break;<br>                case 39: // Right key<br>                case 40: // Down key</pre><pre>if (i == (imgsrc.length - 1)) {<br>                        beep();<br>                        message(&#39;Last image - cannot go further!&#39;);<br>                        sleep(3000).then(() =&gt; {<br>                            setFname();<br>                        });<br>                        break;<br>                    }<br>                    i++; // Move to the next image<br>                    document.getElementById(&quot;board&quot;).src = imgsrc[i];<br>                    setFname();<br>                    break;<br>            }<br>        };</pre><pre>function setFname() {<br>            document.getElementById(&quot;fname&quot;).style.color = &quot;black&quot;;<br>            document.getElementById(&quot;fname&quot;).innerHTML = imgsrc[i];<br>        }</pre><pre>function message(msg) {<br>            document.getElementById(&quot;fname&quot;).innerHTML = msg;<br>            document.getElementById(&quot;fname&quot;).style.color = &#39;red&#39;;<br>        }</pre><pre>function sleep(ms) {<br>            return new Promise(resolve =&gt; setTimeout(resolve, ms));<br>        }</pre><pre>//All arguments are optional:<br>        //duration of the tone in milliseconds. Default is 500<br>        //frequency of the tone in hertz. default is 440<br>        //volume of the tone. Default is 1, off is 0.<br>        //type of tone. Possible values are sine, square, sawtooth, triangle, and custom. Default is sine.<br>        //callback to use on end of tone<br>        function beep(duration, frequency, volume, type, callback) {<br>            var oscillator = audioCtx.createOscillator();<br>            var gainNode = audioCtx.createGain();</pre><pre>oscillator.connect(gainNode);<br>            gainNode.connect(audioCtx.destination);</pre><pre>if (volume) { gainNode.gain.value = volume; }<br>            if (frequency) { oscillator.frequency.value = frequency; }<br>            if (type) { oscillator.type = type; }<br>            if (callback) { oscillator.onended = callback; }</pre><pre>oscillator.start(audioCtx.currentTime);<br>            oscillator.stop(audioCtx.currentTime + ((duration || 500) / 1000));<br>        };<br>    &lt;/script&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>    &lt;img id=&quot;board&quot; alt=&quot;&quot; /&gt;<br>    &lt;script type=&quot;text/javascript&quot;&gt;document.getElementById(&quot;board&quot;).src = imgsrc[0];&lt;/script&gt;<br>    &lt;label id=&quot;fname&quot; /&gt;<br>    &lt;script type=&quot;text/javascript&quot;&gt;document.getElementById(&quot;fname&quot;).innerHTML = imgsrc[0];&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f249b1e871f3" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/simple-js-image-browser-f249b1e871f3">Simple JS image browser</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Physics — CBSE 11th Standard]]></title>
            <link>https://arvindd.medium.com/physics-cbse-11th-standard-31c81461bf08?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/31c81461bf08</guid>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 16:30:37 GMT</pubDate>
            <atom:updated>2021-04-04T11:48:40.576Z</atom:updated>
            <content:encoded><![CDATA[<h3>Physics — CBSE 11th Standard</h3><p>Course link: <a href="https://cbsephy11.learn.ramdoot.in/">Physics (CBSE 11th Standard)</a></p><p>In the link above, just click on “Enrol”, and enrol yourself. The course is <strong>FREE </strong>— just use the coupon <strong>CBSEPHY11FREE </strong>to avail of a 100% discount on the price!</p><p>Also, please be informed that the course is a work-in-progress, and you are one of the “early adopters” of the course. You can expect incomplete videos but be assured that you will never have any wrong information. I thank you for considering helping me to improve the contents of the course! So, any feedback is welcome!</p><p>Once you get your enrolment done, <a href="https://cbsephy11.learn.ramdoot.in/">click here to access the course</a>.</p><p>Following are the topics and the structure of the course (more topics are slowly being added, this is just the initial structure). The completed topics are marked with <strong>[COMPLETED]</strong>:</p><pre><strong>SECTION-1 - Introduction</strong></pre><pre>1. <strong>[COMPLETED] </strong>Introduction to physics <br>A whirlwind tour of what we learn in the course. This lesson can be seen without enrolling right on the <a href="https://cbsephy11.learn.ramdoot.in/">course-page</a>.</pre><pre>2. Visualise your way into the phy-land!<br>Well, a picture is worth a 1000 words. We will get a little creative, and show how to visualise stuff while working with physics. You&#39;ll learn drawing :-)</pre><pre>3. Units and dimensions<br>Units and dimensions define our world in numbers. 5 donkeys? Monkeys? Well, we&#39;ll find out here. </pre><pre><strong>SECTION-2 - MOTION</strong></pre><pre>1. Motion in a straight line<br>We will understand basic physical quantities associated with a moving object. We assume the object (such as a box) moves on a straight line - so we talk about its speed, velocity, etc.</pre><pre>2. <strong>[COMPLETED]</strong> Vectors<br>Before we get deeper into motion in a two-dimensional space, it is important to understand &quot;vectors&quot; as a mathematical and a graphical forumulation. Don&#39;t worry, we&#39;ll guide you in that here.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31c81461bf08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ramdoot Innovations]]></title>
            <link>https://arvindd.medium.com/ramdoot-innovations-cceda9cdc22c?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/cceda9cdc22c</guid>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Tue, 02 Mar 2021 01:26:54 GMT</pubDate>
            <atom:updated>2021-04-15T14:03:49.197Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to Ramdoot Innovations! First, before you jump to any conclusions: <strong>this is a non-commercial site</strong>! No ads, no commercial mumbo-jumbo :-)</p><p><strong>Why then, is the name “ramdoot”? What is the significance of this?</strong><br>When I decided to get on to the web — in the year 2007, I did not want to reveal my name out (crazy idea, but this was what it was). I needed a fancy name by which I run my blogs, my thoughts, etc. on the web. This name happened to be “ramdoot”.</p><p><strong>And what’s that “innovations” doing here?</strong><br>Blame it on the domain name of this site :-)</p><p>Having got the name “ramdoot”, I wanted a website that I could call mine. Did not want a “.com” site as that will paint this commercial. No, not a “.org” — I run no foundations, and no charity institutions — left that for somebody who might want. “.in” was a choice offered to me — and I took it. Now, how can I make people remember this? “.in” is not very common among non-Indians — and I needed some way to make that click. “Innovations” was born out of that — it starts with “in”, and fitted the theme of the content that I planned to put in here.</p><p><strong>So, what can you find here?<br></strong>Pretty much my online presence — which in direct terms means my blogs on the topics of Software Engineering and Technology.</p><p><strong>Ok, got it. One final question — is this a personal site?<br></strong>Well, sort of.</p><p>Year 2020 — and I am now joined (occasionally) by my family members to help in my next big mission: Ramdoot Innovations has an additional purpose, but before I get there, a bit of history.</p><p>It was started with a passion for teaching, the seeds of which, as mentioned before, were sown in the year 2007. Originally, it contained only blog articles in the field of Software Engineering and Technology.</p><p>In the year 2020, when there was a large-scale need for quality distance education (thanks to COVID-19) at affordable prices, in keeping with the original theme of the site, we started a huge project of creating online-courses in Physics for 10, 11 and 12th Standard CBSE syllabus. The prevailing rates for taking a tutoring class, especially for Physics, was very high — in the range of ₹300-₹400/hr — and a minimum of 12hrs per month. And that comes to ₹50,400 annually — only for Physics! When you compare this with the fees paid for a regular school (which offer much more than just a subject), these rates are exorbitant!</p><p>This high price puts a great deterrent in front of a student wanting to take that additional help to prepare for an exam. And we set out to break this — a mission to bring quality education affordable to all students, regardless of where they are.</p><p>In early 2021 was born Eduscape — our brand new site for offering affordable video courses for Physics.</p><p><strong>What is more affordable than FREE? Well, that’s our mission — so this continues to be a non-commercial venture!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cceda9cdc22c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn with passion]]></title>
            <link>https://arvindd.medium.com/learn-with-passion-6a8597c56a6f?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a8597c56a6f</guid>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 16:55:19 GMT</pubDate>
            <atom:updated>2021-03-09T13:48:59.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IfjuElqWpt6vd7sDiTSY8g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dotjpg?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jennifer Griffin</a> on <a href="https://unsplash.com/s/photos/physics?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Many who know me, either personally or via my <a href="https://blog.ramdoot.in/">blog</a>, can easily guess how obsessed I am with sharing what I know. My blog has existed since 2007.</p><p>I am, of course, a Software Engineer by profession. A proud one at that — striving to bring engineering back to Software.</p><p>What are my other hobbies? Well, Software is my day job, and largely also my tinker-job at home. Apart from hobbies, I discovered that I have another great interest — teaching. Not a surprise, but I am talking about teaching Physics!</p><p>Teaching Physics requires some special skills that I recently discovered I have. It is a combination of logical thinking and art — well, almost nothing in Physics can be understood without drawing. Vectors, especially force you to draw (ok, Force is a vector :-)). You need to be extremely creative to visualise problems, and at the same time, need to hone your logical skills to get to the solution. I call it the left-brain-right-brain subject — a holistic treatment of your brainpower!</p><p>I am creating video courses for teaching Physics — CBSE Syllabus. Not really on commercial basis, but more like a serious hobby. Of course, I have my day-job, so I do not need to make money with this.</p><p>As a software engineer, the courses will be developed in an agile way :-) One-increment-at-a-time, and will be available for enrolling as soon as the first part is done.</p><p>So, learn with passion!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a8597c56a6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deriving not-so-complex types]]></title>
            <link>https://blog.ramdoot.in/deriving-not-so-complex-types-ec5987f6d95c?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec5987f6d95c</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Tue, 12 Mar 2019 02:29:19 GMT</pubDate>
            <atom:updated>2019-03-15T00:33:02.759Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*HziAobO3pmhdGTclsTvN8A.png" /><figcaption>(Wonderful image was modified from: <a href="https://openclipart.org/detail/123259/professeur-teacher">https://openclipart.org/detail/123259/professeur-teacher</a>)</figcaption></figure><p>Often times, I get to read Haskell code with these patterns: (fmap . fmap), fmap (&lt;*&gt;), etc. I’ve just taken three of these types, and break these into their intuitions here in the hopes that somebody out there can understand when to use these.</p><p>First we go with plain derivations of the final outcome, then we talk about the intuition behind, so that one does not need to derive these to understand them.</p><p><strong>fmap (&lt;*&gt;)</strong></p><p>What we are doing here is applying the function fmap to another function &lt;*&gt;. Lets start from the first principles:</p><pre>(&lt;*&gt;) :: (Applicative f1) =&gt; f1 (a -&gt; b) -&gt; f1 a -&gt; f1 b ----- (1)</pre><p>re-writing, with grouping parenthesis:</p><pre>(&lt;*&gt;) :: (Applicative f1) =&gt; (f1 (a -&gt; b)) -&gt; (f1 a -&gt; f1 b) -- (1a)<br><br> fmap :: (Functor f2) =&gt; (c -&gt; d) -&gt; f2 c -&gt; f2 d         ----- (2)</pre><p>For fmap (&lt;*&gt;), since fmap is applied to (&lt;*&gt;):</p><blockquote><em>Applying </em><em>(&lt;*&gt;) to </em><em>fmap, by substituting:</em></blockquote><pre>c ==&gt; f1 (a -&gt; b)<br>d ==&gt; (f1 a -&gt; f1 b)</pre><blockquote><em>in </em><em>fmap:</em></blockquote><pre>fmap :: -- Applying (&lt;*&gt;), by substituting c and d<br>        (f1 (a -&gt; b) -&gt; (f1 a -&gt; f1 b)) -&gt; </pre><pre>        -- Result<br>        f2 (f1 (a -&gt; b)) -&gt;  f2 (f1 a -&gt; f1 b)  ----- (3)</pre><p>Therefore, fmap (&lt;*&gt;) is the result from above:</p><pre>fmap (&lt;*&gt;) :: (Functor f2, Applicative f1) =&gt; f2 (f1 (a -&gt; b)) -&gt; f2 (f1 a -&gt; f1 b)</pre><p><strong>fmap . fmap</strong></p><p><em>This one is got straight from here: </em><a href="https://stackoverflow.com/questions/40055333/applying-compose-to-fmap"><em>https://stackoverflow.com/questions/40055333/applying-compose-to-fmap</em></a></p><p>First, we start with definitions of fmap from the first principles. Just to make it easy, we elaborate both fmaps:</p><pre>fmap :: (Functor f1) =&gt; (x -&gt; y) -&gt; f1 x -&gt; f1 y      ----- (1)<br>fmap :: (Functor f2) =&gt; (a -&gt; b) -&gt; f2 a -&gt; f2 b      ----- (2)<br>(.) :: (a1 -&gt; a2) -&gt; (r -&gt; a1) -&gt; (r -&gt; a2)           ----- (3)</pre><p>Re-writing fmap with grouped parenthesis:</p><pre>fmap :: (Functor f1) =&gt; (x -&gt; y) -&gt; (f1 x -&gt; f1 y)    ----- (1a)<br>fmap :: (Functor f2) =&gt; (a -&gt; b) -&gt; (f2 a -&gt; f2 b)    ----- (2a)</pre><p>What we want is:</p><pre>(.) fmap fmap</pre><p>In (.), substituting:</p><blockquote><em>From the first </em><em>fmap and the first operand to </em><em>(.), i.e. </em><em>(a1 -&gt; a2):</em></blockquote><pre>a1 ==&gt; (x -&gt; y)       ----- (4)<br>a2 ==&gt; (f1 x -&gt; f1 y) ----- (5)</pre><blockquote><em>From the second </em><em>fmap and the second operand to </em><em>(.), i.e. </em><em>(r -&gt; a1):</em></blockquote><pre>r ==&gt; (a -&gt; b)        ----- (6)<br>a1 ==&gt; (f2 a -&gt; f2 b) ----- (7)</pre><blockquote><em>From (4) and (7), we have:</em></blockquote><pre>x ==&gt; f2 a            ----- (8) <br>y ==&gt; f2 b            ----- (9)</pre><p>Therefore, putting all of these in (3), we have:</p><pre>(.) :: (f2 a -&gt; f2 b) -&gt; (f1 x -&gt; f1 y) -&gt; (r -&gt; (f2 a -&gt; f2 b)) -&gt; (r -&gt; (f1 x -&gt; f1 y))</pre><p>Further substituting x, y and r:</p><pre>(.) :: -- Applying first fmap:<br>       (f2 a -&gt; f2 b) -&gt; (f1 (f2 a) -&gt; f1 (f2 b)) -&gt; <br><br>       -- Applying second fmap<br>       ((a -&gt; b) -&gt; (f2 a -&gt; f2 b)) -&gt; <br><br>       -- Result<br>       ((a -&gt; b) -&gt; (f1 (f2 a) -&gt; f1 (f2 b)))</pre><p>Hence, the final result is:</p><pre>fmap . fmap :: (Functor f1, Functor f2) =&gt; (a -&gt; b) -&gt; f1 (f2 a) -&gt; f1 (f2 b)</pre><p><strong>(fmap . fmap) (&lt;*&gt;)</strong></p><p>Now, we come to the last of the (not-so) complex types we deal here. Starting with what we know:</p><pre>(fmap . fmap) :: (Functor f2, Functor f3) =&gt; (x -&gt; y) -&gt; f2 (f3 x) -&gt; f2 (f3 y)  ----- (1)<br>(&lt;*&gt;) :: (Applicative f1) =&gt; f1 (a -&gt; b) -&gt; f1 a -&gt; f1 b                 ----- (2)</pre><p>Re-writing via regrouping:</p><pre>(&lt;*&gt;) :: (f1 (a -&gt; b)) -&gt; (f1 a -&gt; f1 b)        ----- (2a)</pre><p>Since we are applying (fmap . fmap) to (&lt;*&gt;) as the first argument, substituting (from (1) and (2a)):</p><pre>x ==&gt; f1 (a -&gt; b)<br>y ==&gt; f1 a -&gt; f1 b</pre><pre>(fmap . fmap) :: -- First fmap<br>              f1 (a -&gt; b) -&gt; </pre><pre>              -- Second fmap<br>              f1 a -&gt; f1 b -&gt; </pre><pre>              -- Result<br>              f2 (f3 (f1 (a -&gt; b))) -&gt; f2 (f3 (f1 a -&gt; f1 b))</pre><p>Therefore, result of application:</p><pre>(fmap . fmap) (&lt;*&gt;) :: (Applicative f1, Functor f2, Functor f3) =&gt; f2 (f3 (f1 (a -&gt; b))) -&gt; f2 (f3 (f1 a -&gt; f1 b))</pre><p><strong>Intuition and examples</strong></p><p>Now that we have these derivations in place, we need some intuitions on when to use these. We need examples, and we need practical situations for these.</p><p>The concept of “Monad Transformers” is completely based on these results, and this will be the subject of my next article.</p><p>Until then, keep the claps flowing in!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec5987f6d95c" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/deriving-not-so-complex-types-ec5987f6d95c">Deriving not-so-complex types</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IHaskell on Windows!]]></title>
            <link>https://blog.ramdoot.in/ihaskell-on-windows-c549e6442262?source=rss-dc5808fb1cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c549e6442262</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[jupyter]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <dc:creator><![CDATA[Arvind Devarajan]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 08:57:56 GMT</pubDate>
            <atom:updated>2018-11-18T10:37:16.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HmnBoDrQmdXb_abVgEBnnw.png" /><figcaption>IHaskell on WSL (OpenSUSE) on Windows 10</figcaption></figure><p>If you ever have wanted <a href="https://github.com/gibiansky/IHaskell">IHaskell</a>, and also wanted that on Windows, the first thing that can disappoint you are these wordings in the installation page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9Gh2FTok_KKfV-FvMIOvg.png" /><figcaption>IHaskell on Windows from <a href="https://github.com/gibiansky/IHaskell">https://github.com/gibiansky/IHaskell</a></figcaption></figure><p>Of course, a VirtualBox is a good choice. On professional version of Windows, installation of a complete Linux distribution on Hyper-V is also a choice, if you are successful in actually doing so.</p><p>But nothing comes close to getting IHaskell on the Windows Subsystem for Linux (WSL). Which is what this article is about. The obvious advantage of using IHaskell on WSL is the fact that it looks very natural on a Windows system, not to forget that you have no need to depend on third-party solutions like VirtualBox to get your Linux on. And, of course, for low-memory systems (even with about 4GB RAM), IHaskell on WSL could be your only best choice.</p><p>So, what does it take to get IHaskell on Windows?</p><p>We first should make some priliminary adjustments to the WSL environment to push our home-directories to a non-system drive on Windows. As of this writing WSL installs only on the system-drive C:, and since hence all Haskell-installations get into our root-filesystem / home directory in Linux, all these fall into the system-drive C:. Since C: is a precious drive that you would not want to mess with, I find it safer to move our WSL home to a non-system drive that is mounted in /mnt. For doing so, and getting the Haskell and Haskell-Stack on your WSL, we have a <a href="https://blog.ramdoot.in/my-windows-haskell-setup-6bd769e9c51d">separate article here — go there</a> and follow the instructions to get Haskell on your system.</p><p><strong>Installation of Jupyter (via Anaconda)</strong></p><p>Having done that, we need to install <a href="http://jupyter.org/index.html">Jupyter on WSL</a> as IHaskell needs it. I simply went the Anaconda way, and <a href="https://www.anaconda.com/download/#download">downloaded the Anaconda distribution</a> which comes with Jupyter. Before actually installing Jupyter in my system, add these in your ~/.profile to make sure Jupyter installs its files in the right directories (i.e., not in C:). Substitute the directories with your own locations.</p><pre>export JUPYTER_HOME=/mnt/e/opensuse/tools/jupyter<br>export JUPYTER_CONFIG_DIR=${JUPYTER_HOME}/config<br>export JUPYTER_DATA_DIR=${JUPYTER_HOME}/data<br>export JUPYTER_RUNTIME_DIR=${JUPYTER_HOME}/runtime</pre><p>Finally, just go ahead and install Anaconda. Additionally, I also keep my Jupyter notebooks in a specific directory: ${JUPYTER_HOME}/notebook. If you also want to do this, you need to first create a jupyter configuration, and then set the location of the notebooks in the generated configuration file.</p><pre># Generate Jupyter configuration for notebooks<br>jupyter notebook --generate-config</pre><pre># Inside the generated config file jupyter_notebook_config.py <br># uncomment this line and add the notebook location</pre><pre>c.NotebookApp.notebook_dir = &#39;/mnt/e/opensuse/tools/jupyter/notebooks&#39;</pre><p><strong>Installation of IHaskell</strong></p><p>Having done that, we move on to getting IHaskell. Most of the instructions are clear already in IHaskell’s page: <a href="https://github.com/gibiansky/IHaskell">https://github.com/gibiansky/IHaskell</a>. I just have made small changes to this since I use OpenSuSE on WSL.</p><p>First, install the necessary packages on OpenSUSE (at the time of writing this, I had OpenSUSE Leap 15):</p><pre>sudo zypper install -n python3-pip git ncurses-devel zeromq-devel cairo-devel pango-devel file-devel blas-devel lapack-devel</pre><p>Finally, here are the instructions for installing IHaskell on OpenSuSE on WSL</p><pre>cd /mnt/e/opensuse/tools<br>git clone https://github.com/gibiansky/IHaskell<br>cd IHaskell<br>sudo pip3 install -r requirements.txt<br>stack install gtk2hs-buildtools<br>stack install --fast<br>ihaskell install --stack</pre><p>The stack install --fast seemed to fail during the build of cryptonite-0.25:</p><pre>--  While building package cryptonite-0.25 using:<br>      /mnt/e/opensuse/tools/haskellstack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1 build --ghc-options &quot; -ddump-hi -ddump-to-file -fdiagnostics-color=always&quot;<br>    Process exited with code: ExitFailure 1<br>    Logs have been written to: /mnt/e/opensuse/tools/IHaskell/.stack-work/logs/cryptonite-0.25.log</pre><pre>Configuring cryptonite-0.25...<br>    Preprocessing library for cryptonite-0.25..<br>    Building library for cryptonite-0.25..<br>    [  1 of 123] Compiling Crypto.Cipher.DES.Primitive ( Crypto/Cipher/DES/Primitive.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Cipher/DES/Primitive.o )<br>    [  2 of 123] Compiling Crypto.Data.Padding ( Crypto/Data/Padding.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Data/Padding.o )<br>    [  3 of 123] Compiling Crypto.Internal.Compat ( Crypto/Internal/Compat.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Internal/Compat.o )<br>    .....<br> .....<br>    [120 of 123] Compiling Crypto.ECC       ( Crypto/ECC.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/ECC.o )<br>    [121 of 123] Compiling Crypto.PubKey.ECIES ( Crypto/PubKey/ECIES.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/PubKey/ECIES.o )<br>    [122 of 123] Compiling Crypto.Data.AFIS ( Crypto/Data/AFIS.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Data/AFIS.o )<br>    [123 of 123] Compiling Crypto.Tutorial  ( Crypto/Tutorial.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Tutorial.o )<br>    /mnt/e/opensuse/tools/haskellstack/snapshots/x86_64-linux-tinfo6/lts-12.18/8.4.4/pkgdb/package.cache: openBinaryFile: invalid argument (Invalid argument)</pre><p>However, on simply running stack install --fast solved this. Since it just worked, I simply did not investigate on why this failed in the first place — so any hints on this will be appreciated.</p><p><strong>Starting Jupyter and using IHaskell</strong></p><p>Simply start juputer like this:</p><pre>jupyter notebook --no-browser</pre><p>On firing up a browser and navigating to <a href="http://localhost:8888,">http://localhost:8888,</a> you’ll be pleasantly surprised seeing IHaskell on your Windows machine with all its glory!</p><p><strong>Making this all look “natural” on Windows</strong></p><p>I like to start Jupyter via the start-menu. All I did was to create batch-file with these contents:</p><pre><a href="http://twitter.com/echo">@echo</a> off<br>start /min bash --login -c &#39;jupyter notebook --no-browser&#39;<br>timeout /t 5 /nobreak &gt; NUL<br>start <a href="http://localhost:8888/">http://localhost:8888</a></pre><p>And created a shortcut to this batch-file in the start-menu. Lo and behold! Jupyter now starts “naturally” on Windows! The command-prompt it opens for starting Jupyter is, although looking out-of-place, is important because that’s the way to stop jupyter when your work is done.</p><p>Enjoy IHaskell on Windows! <strong><em>And make sure to clap if you find this useful!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c549e6442262" width="1" height="1" alt=""><hr><p><a href="https://blog.ramdoot.in/ihaskell-on-windows-c549e6442262">IHaskell on Windows!</a> was originally published in <a href="https://blog.ramdoot.in/">Techscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>