<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Shakthimaan's blog.</title>
        <link>http://www.shakthimaan.com</link>
        <description><![CDATA[RSS feed for Shakthimaan's blog.]]></description>
        <atom:link href="http://www.shakthimaan.com/news.xml" rel="self"
                   type="application/rss+xml" />
        <lastBuildDate>Sat, 11 Apr 2020 18:30:00 UT</lastBuildDate>
        <item>
    <title>Using Docker with Ansible</title>
    <link>http://www.shakthimaan.com/posts/2020/04/11/docker-with-ansible/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, October 2017 edition.]</em></p>
<p>This article is the eighth in the DevOps series. In this issue, we shall learn to set up Docker in the host system and use it with Ansible.</p>
<h1 id="introduction">Introduction</h1>
<p>Docker provides operating system level virtualisation in the form of containers. These containers allow you to run standalone applications in an isolated environment. The three important features of Docker containers are isolation, portability and repeatability. All along we have used Parabola GNU/Linux-libre as the host system, and executed Ansible scripts on target Virtual Machines (VM) such as CentOS and Ubuntu.</p>
<p>Docker containers are extremely lightweight and fast to launch. You can also specify the amount of resources that you need such as CPU, memory and network. The Docker technology was launched in 2013, and released under the Apache 2.0 license. It is implemented using the Go programming language. A number of frameworks have been built on top of Docker for managing these cluster of servers. The Apache Mesos project, Google’s Kubernetes, and the Docker Swarm project are popular examples. These are ideal for running stateless applications and help you to easily scale them horizontally.</p>
<h1 id="setup">Setup</h1>
<p>The Ansible version used on the host system (Parabola GNU/Linux-libre x86_64) is 2.3.0.0. Internet access should be available on the host system. The <em>ansible/</em> folder contains the following file:</p>
<pre><code>ansible/playbooks/configuration/docker.yml</code></pre>
<h1 id="installation">Installation</h1>
<p>The following playbook is used to install Docker on the host system:</p>
<pre><code>---
- name: Setup Docker
  hosts: localhost
  gather_facts: true
  become: true
  tags: [setup]

  tasks:
    - name: Update the software package repository
      pacman:
        update_cache: yes

    - name: Install dependencies
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - python2-docker
        - docker

    - service:
        name: docker
        state: started

    - name: Run the hello-world container
      docker_container:
        name: hello-world
        image: library/hello-world</code></pre>
<p>The Parabola package repository is updated before proceeding to install the dependencies. The <em>python2-docker</em> package is required for use with Ansible. Hence, it is installed along with the <em>docker</em> package. The Docker daemon service is then started and the <em>library/hello-world</em> container is fetched and executed. A sample invocation and execution of the above playbook is shown below:</p>
<pre><code>$ ansible-playbook playbooks/configuration/docker.yml -K --tags=setup
SUDO password: 

PLAY [Setup Docker] *************************************************************

TASK [Gathering Facts] **********************************************************
ok: [localhost]

TASK [Update the software package repository] ***********************************
changed: [localhost]

TASK [Install dependencies] *****************************************************
ok: [localhost] =&gt; (item=python2-docker)
ok: [localhost] =&gt; (item=docker)

TASK [service] ******************************************************************
ok: [localhost]

TASK [Run the hello-world container] ********************************************
changed: [localhost]

PLAY RECAP **********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0   </code></pre>
<p>With verbose ’-v’ option to ansible-playbook, you will see an entry for LogPath, such as <em>/var/lib/docker/containers/<container-id>/<container-id>-json.log</em>. In this log file you will see the output of the execution of the <em>hello-world</em> container. This output is the same when you run the container manually as shown below:</p>
<pre><code>$ sudo docker run hello-world

Hello from Docker!

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the &quot;hello-world&quot; image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/</code></pre>
<h1 id="example">Example</h1>
<p>A Deep Learning (DL) Docker project is available (<a href="https://github.com/floydhub/dl-docker">https://github.com/floydhub/dl-docker</a>) with support for frameworks, libraries and software tools. We can use Ansible to build the entire DL container from the source code of the tools. The base OS of the container is Ubuntu 14.04, and will include the following software packages:</p>
<ul>
<li>Tensorflow</li>
<li>Caffe</li>
<li>Theano</li>
<li>Keras</li>
<li>Lasagne</li>
<li>Torch</li>
<li>iPython/Jupyter Notebook</li>
<li>Numpy</li>
<li>SciPy</li>
<li>Pandas</li>
<li>Scikit Learn</li>
<li>Matplotlib</li>
<li>OpenCV</li>
</ul>
<p>The playbook to build the DL Docker image is given below:</p>
<pre><code>- name: Build the dl-docker image
  hosts: localhost
  gather_facts: true
  become: true
  tags: [deep-learning]

  vars:
    DL_BUILD_DIR: &quot;/tmp/dl-docker&quot;
    DL_DOCKER_NAME: &quot;floydhub/dl-docker&quot;

  tasks:
    - name: Download dl-docker
      git:
        repo: https://github.com/saiprashanths/dl-docker.git 
        dest: &quot;{{ DL_BUILD_DIR }}&quot;

    - name: Build image and with buildargs
      docker_image:
         path: &quot;{{ DL_BUILD_DIR }}&quot;
         name: &quot;{{ DL_DOCKER_NAME }}&quot;
         dockerfile: Dockerfile.cpu
         buildargs:
           tag: &quot;{{ DL_DOCKER_NAME }}:cpu&quot;</code></pre>
<p>We first clone the Deep Learning docker project sources. The <em>docker_image</em> module in Ansible helps us to build, load and pull images. We then use the <em>Dockerfile.cpu</em> file to build a Docker image targeting the CPU. If you have a GPU in your system, you can use the <em>Dockerfile.gpu</em> file. The above playbook can be invoked using the following command:</p>
<pre><code>$ ansible-playbook playbooks/configuration/docker.yml -K --tags=deep-learning</code></pre>
<p>Depending on the CPU and RAM you have, it will take considerable amount of time to build the image with all the software. So be patient!</p>
<h2 id="jupyter-notebook">Jupyter Notebook</h2>
<p>The built <em>dl-docker</em> image contains Jupyter notebook which can be launched when you start the container. An Ansible playbook for the same is provided below:</p>
<pre><code>- name: Start Jupyter notebook
  hosts: localhost
  gather_facts: true
  become: true
  tags: [notebook]

  vars:
    DL_DOCKER_NAME: &quot;floydhub/dl-docker&quot;

  tasks:
    - name: Run container for Jupyter notebook
      docker_container:
        name: &quot;dl-docker-notebook&quot;
        image: &quot;{{ DL_DOCKER_NAME }}:cpu&quot;
        state: started
        command: sh run_jupyter.sh</code></pre>
<p>You can invoke the playbook using the following command:</p>
<pre><code>$ ansible-playbook playbooks/configuration/docker.yml -K --tags=notebook</code></pre>
<p>The Dockerfile already exposes the port 8888, and hence you do not need to specify the same in the above <em>docker_container</em> configuration. After you run the playbook, using the ‘docker ps’ command on the host system, you can obtain the container ID as indicated below:</p>
<pre><code>$ sudo docker ps
CONTAINER ID        IMAGE                    COMMAND               CREATED             STATUS              PORTS                NAMES
a876ad5af751        floydhub/dl-docker:cpu   &quot;sh run_jupyter.sh&quot;   11 minutes ago      Up 4 minutes        6006/tcp, 8888/tcp   dl-docker-notebook</code></pre>
<p>You can now login to the running container using the following command:</p>
<pre><code>$ sudo docker exec -it a876 /bin/bash</code></pre>
<p>You can then run an ‘ifconfig’ command to find the local IP address (“172.17.0.2” in this case), and then open <em>http://172.17.0.2:8888</em> in a browser on your host system to see the Jupyter Notebook. A screenshot is shown in Figure 1:</p>
<img alt="Jupyter Notebook" src="https://gallery.shakthimaan.com/_datas/k/d/s/kdszajl69v/i/uploads/k/d/s/kdszajl69v//2020/04/11/20200411135131-a8f02b56-me.jpg"></a>
<h2 id="tensorboard">TensorBoard</h2>
<p>TensorBoard consists of a suite of visualization tools to understand the TensorFlow programs. It is installed and available inside the Docker container. After you login to the Docker container, at the root prompt, you can start Tensorboard by passing it a log directory as shown below:</p>
<pre><code># tensorboard --logdir=./log</code></pre>
<p>You can then open <em>http://172.17.0.2:6006/</em> in a browser on your host system to see the Tensorboard dashboard as shown in Figure 2:</p>
<img alt="TensorBoard" src="https://gallery.shakthimaan.com/_datas/k/d/s/kdszajl69v/i/uploads/k/d/s/kdszajl69v//2020/04/11/20200411135132-fc7afd8b-me.jpg"></a>
<h2 id="docker-image-facts">Docker Image Facts</h2>
<p>The <em>docker_image_facts</em> Ansible module provides useful information about a Docker image. We can use it to obtain the image facts for our <em>dl-docker</em> container as shown below:</p>
<pre><code>- name: Get Docker image facts
  hosts: localhost
  gather_facts: true
  become: true
  tags: [facts]

  vars:
    DL_DOCKER_NAME: &quot;floydhub/dl-docker&quot;

  tasks:
    - name: Get image facts
      docker_image_facts:
        name: &quot;{{ DL_DOCKER_NAME }}:cpu&quot;</code></pre>
<p>The above playbook can be invoked as follows:</p>
<pre><code>$ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook playbooks/configuration/docker.yml -K --tags=facts </code></pre>
<p>The ANSIBLE_STDOUT_CALLBACK environment variable is set to ‘json’ to produce a JSON output for readability. Some important image facts from the invocation of the above playbook are shown below:</p>
<pre><code>&quot;Architecture&quot;: &quot;amd64&quot;, 
&quot;Author&quot;: &quot;Sai Soundararaj &lt;saip@outlook.com&gt;&quot;, 

&quot;Config&quot;: {

&quot;Cmd&quot;: [
   &quot;/bin/bash&quot;
], 

&quot;Env&quot;: [
   &quot;PATH=/root/torch/install/bin:/root/caffe/build/tools:/root/caffe/python:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin&quot;, 
   &quot;CAFFE_ROOT=/root/caffe&quot;, 
   &quot;PYCAFFE_ROOT=/root/caffe/python&quot;, 
   &quot;PYTHONPATH=/root/caffe/python:&quot;, 
   &quot;LUA_PATH=/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/root/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua&quot;, 
   &quot;LUA_CPATH=/root/torch/install/lib/?.so;/root/.luarocks/lib/lua/5.1/?.so;/root/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so&quot;, 
   &quot;LD_LIBRARY_PATH=/root/torch/install/lib:&quot;, 
   &quot;DYLD_LIBRARY_PATH=/root/torch/install/lib:&quot;
], 

&quot;ExposedPorts&quot;: {
   &quot;6006/tcp&quot;: {}, 
   &quot;8888/tcp&quot;: {}
}, 

&quot;Created&quot;: &quot;2016-06-13T18:13:17.247218209Z&quot;, 
&quot;DockerVersion&quot;: &quot;1.11.1&quot;, 

&quot;Os&quot;: &quot;linux&quot;, 

&quot;task&quot;: { &quot;name&quot;: &quot;Get image facts&quot; }</code></pre>
<p>You are encouraged to read the ‘Getting Started with Docker’ user guide available at <a href="http://docs.ansible.com/ansible/latest/guide_docker.html">http://docs.ansible.com/ansible/latest/guide_docker.html</a> to know more about using Docker with Ansible.</p>]]></description>
    <pubDate>Sat, 11 Apr 2020 18:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2020/04/11/docker-with-ansible/news.html</guid>
</item>
<item>
    <title>TeX User Group Conference 2019, Palo Alto</title>
    <link>http://www.shakthimaan.com/posts/2019/10/31/tug-conference/news.html</link>
    <description><![CDATA[<p>The <a href="http://tug.org/tug2019/">Tex User Group 2019 conference</a> was held between August 9-11, 2019 at <a href="https://www.marriott.com/hotels/travel/sjcsi-sheraton-palo-alto-hotel/">Sheraton Palo Alto Hotel</a>, in <a href="https://en.wikipedia.org/wiki/Palo_Alto,_California">Palo Alto</a>, California.</p>
<img alt="Stanford" src="http://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/10/30/20191030104443-0933cb50.jpg"></img>
<p>I wanted to attend <a href="http://tug.org/tug2019/program.html">TUG 2019</a> for two main reasons - to present my work on the <a href="https://gitlab.com/shakthimaan/xetex-book-template">“XeTeX Book Template”</a>, and also to meet my favourite computer scientist, <a href="https://en.wikipedia.org/wiki/Donald_Knuth">Prof. Donald Knuth</a>. He does not travel much, so, it was one of those rare opportunities for me to meet him in person. His creation of the TeX computer typesetting system, where you can represent any character mathematically, and also be able to program and transform it is beautiful, powerful and the best typesetting software in the world. I have been using TeX extensively for my documentation and presentations over the years.</p>
<h1 id="day-i">Day I</h1>
<p>I reached the hotel venue only in the afternoon of Friday, August 9, 2019, as I was also visiting Mountain View/San Jose on official work. I quickly checked into the hotel and completed my conference registration formalities. When I entered the hall, Rishi T from <a href="https://stmdocs.in/about.html">STM Document Engineering Private Limited</a>, Thiruvananthapuram was presenting a talk on “Neptune - a proofing framework for LaTeX authors”. His talk was followed by an excellent poetic narration by <a href="https://tug.org/interviews/arora.html">Pavneet Arora</a>, who happened to be a Vim user, but, also mentioned that he was eager to listen to my talk on <a href="http://xetex.sourceforge.net/">XeTeX</a> and <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a>.</p>
<p>After a short break, Shreevatsa R, shared his experiences on trying to understand the TeX source code, and the lessons learnt in the process. It was a very informative, user experience report on the challenges he faced in navigating and learning the TeX code. <a href="https://www.fi.muni.cz/usr/sojka/">Petr Sojka</a>, from <a href="https://www.muni.cz/en">Masaryk University</a>, Czech Republic, shared his students’ experience in using TeX with a detailed field report. I then proceeded to give my talk on the “XeTeX Book Template” on creating multi-lingual books using GNU Emacs and XeTeX. It was well received by the audience. The final talk of the day was by <a href="https://en.wikipedia.org/wiki/Jim_Hefferon">Jim Hefferon</a>, who analysed different LaTeX group questions from newbies and in StackExchange, and gave a wonderful summary of what newbies want. He is a professor of Mathematics at <a href="https://www.smcvt.edu/">Saint Michael’s College</a>, and is well-known for his book on <a href="http://joshua.smcvt.edu/linearalgebra/">Linear Algebra</a>, prepared using LaTeX. It was good to meet him, as he is also a Free Software contributor.</p>
<p>The TUG Annual General Meeting followed with discussions on how to grow the TeX community, the challenges faced, membership fees, financial reports, and plan for the next TeX user group conference.</p>
<h1 id="day-ii">Day II</h1>
<p>The second day of the conference began with <a href="https://www.fi.muni.cz/usr/sojka/">Petr Sojka</a> and <a href="https://github.com/tensojka">Ondřej Sojka</a> presenting on “The unreasonable effectiveness of pattern generation”. They discussed the Czech hyphenation patterns along with a pattern generation case study. This talk was followed by <a href="https://tug.org/interviews/reutenauer.html">Arthur Reutenauer</a> presenting on “Hyphenation patterns in TeX Live and beyond”. <a href="https://tug.org/interviews/fuchs.html">David Fuchs</a>, a student who worked with Prof. Donald Knuth on the TeX project in 1978, then presented on “What six orders of magnitude of space-time buys you”, where he discussed the design trade-offs in TeX implementation between olden days and present day hardware.</p>
<p>After a short break, <a href="https://tomas.rokicki.com/">Tom Rokicki</a>, who was also a student at Stanford and worked with Donald Knuth on TeX, gave an excellent presentation on searching and copying text in PDF documents generated by TeX for Type-3 bitmap fonts. This session was followed by <a href="https://www.cs.hm.edu/die_fakultaet/ansprechpartner/professoren/ruckert/index.de.html">Martin Ruckert’s</a> talk on “The design of the HINT file format”, which is intended as a replacement of the DVI or PDF file format for on-screen reading of TeX output. He has also authored a book on the subject - <a href="https://www.amazon.com/HINT-File-Format-Reflowable-Output/dp/1079481591">“HINT: The File Format: Reflowable Output for TeX”</a>. Doug McKenna had implemented an interactive iOS math book with his own TeX interpreter library. This allows you to dynamically interact with the typeset document in a PDF-free ebook format, and also export the same. We then took a group photo:</p>
<img alt="Group photo" src="http://tug.org/tug2019/photos/group-photo.jpg" width="800"></img>
<p>I then had to go to Stanford, so missed the post-lunch sessions, but, returned for the banquet dinner in the evening. I was able to meet and talk with Prof. Donald E. Knuth in person. Here is a memorable photo!</p>
<img alt="With Prof. Donald Knuth" src="http://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/10/30/20191030104450-c775c925.jpg"></img>
<p>He was given a few gifts at the dinner, and he stood up and thanked everyone and said that “He stood on the shoulders of giants like Isaac Newton and Albert Einstein.”</p>
<p><img alt="Gift to Prof. Donald Knuth" src="http://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/10/30/20191030104446-2e594eab.jpg">&lt; /&gt;</p>
<p>I had a chance to meet a number of other people who valued the beauty, precision and usefulness of TeX. Douglas Johnson had come to the conference from Savannah, Georgia and is involved in the publishing industry. <a href="https://en.wikipedia.org/wiki/Rohit_Khare">Rohit Khare</a>, from Google, who is active in the Representational State Transfer (ReST) community shared his experiences with typesetting. <a href="https://github.com/natestemen">Nathaniel Stemen</a> is a software developer at Overleaf, which is used by a number of university students as an online, collaborative LaTeX editor. <a href="https://hertzfoundation.org/fellows/fellow-profile/10750/Joseph-Weening">Joseph Weening</a>, who was also once a student to Prof. Donald Knuth, and is at present a Research Staff member at the Institute for Defense Analyses Center for Communications Research in La Jolla, California (IDA/CCR-L) shared his experiences in working with the TeX project.</p>
<h1 id="day-iii">Day III</h1>
<p>The final day of the event began with <a href="https://www.sci.kanagawa-u.ac.jp/info/abossard/">Antoine Bossard</a> talking on “A glance at CJK support with XeTeX and LuaTeX”. He is an Associate Professor of the <a href="https://www.kanagawa-u.ac.jp/english/faculties/gs_science.html">Graduate School of Science, Kanagawa University</a>, Japan. He has been conducting research regarding Japanese characters and their memorisation. This session was followed by a talk by Jaeyoung Choi on “FreeType MF Module 2: Integration of Metafont and TeX-oriented bitmap fonts inside FreeType”. Jennifer Claudio then presented the challenges in improving Hangul to English translation.</p>
<p>After a short break, Rishi T presented “TeXFolio - a framework to typeset XML documents using TeX”. <a href="http://boris.lk.net/">Boris Veytsman</a> then presented the findings on research done at the <a href="https://www.cics.umass.edu/">College of Information and Computer Science, University of Massachusetts, Amherst</a> on “BibTeX-based dataset generation for training citation parsers”. The last talk before lunch was by <a href="https://www.lrde.epita.fr/~didier/about/news.php">Didier Verna</a> on “Quickref: A stress test for Texinfo”. He teaches at <a href="https://en.wikipedia.org/wiki/%C3%89cole_pour_l%27informatique_et_les_techniques_avanc%C3%A9es">École Pour l’Informatique et les Techniques Avancées</a>, and is a maintainer of XEmacs, Gnus and BBDB. He also an avid Lisper and one of the organizers of the <a href="https://www.european-lisp-symposium.org/">European Lisp Symposium</a>!</p>
<p>After lunch, <a href="https://github.com/UweZiegenhagen">Uwe Ziegenhagen</a> demonstrated on using LaTeX to prepare and automate exams. This was followed by a field report by <a href="https://doratex.hatenablog.jp/">Yusuke Terada</a>, on how they use TeX to develop a digital exam grading system at large scale in Japan. Chris Rowley, from the LaTeX project, then spoke on “Accessibility in the LaTeX kernel - experiments in tagged PDF”. <a href="https://tug.org/interviews/moore.html">Ross Moore</a> joined remotely for the final session of the day to present on “LaTeX 508 - creating accessible PDFs”. The videos of both of these <a href="http://web.science.mq.edu.au/~ross/TaggedPDF/TUG2019-movies/index.html">last two talks</a> are available online.</p>
<p>A number of TeX books were made available for free for the participants, and I grabbed quite a few, including a LaTeX manual written by <a href="https://en.wikipedia.org/wiki/Leslie_Lamport">Leslie Lamport</a>. Overall, it was a wonderful event, and it was nice to meet so many like-minded Free Software people.</p>
<p>A special thanks to <a href="http://tug.org/interviews/berry.html">Karl Berry</a>, who put in a lot of effort in organizing the conference, but, could not make it to due to a car accident.</p>
<p>The TeX User Group Conference in 2020 is scheduled to be held at my alma mater, <a href="https://www.rit.edu/">Rochester Institute of Technology</a>.</p>]]></description>
    <pubDate>Thu, 31 Oct 2019 15:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2019/10/31/tug-conference/news.html</guid>
</item>
<item>
    <title>Git workshop, R V College of Engineering, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2019/09/29/git-workshop/news.html</link>
    <description><![CDATA[<p>I had organized a <a href="https://www.git-scm.com/">Git</a> workshop for students who are pursuing their Master of Computer Applications (MCA) from in and around Bengaluru at <a href="https://www.rvce.edu.in/">R V College of Engineering</a>. I am sharing their anonymous feedback:</p>
<img alt="Doubts solved" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065147-b4b78b0f.jpg"></img>
<img alt="Interesting session" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065148-644e6972.jpg">
<img alt="Useful for beginners" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065149-77c3f7fa.jpg">
<img alt="Helpful for final year project" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065150-41f7cb66.jpg">
<img alt="Great session" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065151-5aa73b38.jpg">
<img alt="Good training" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065152-9f79626b.jpg">
<img alt="Very good" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065153-71463050.jpg">
<img alt="Informative session" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065154-9af6af01.jpg">
<img alt="Teaching with patience" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065155-bed9a8e0.jpg">
<img alt="Way of teaching" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065156-217f1b12.jpg">
<img alt="Concepts of Git" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065156-b21dd863.jpg">
<img alt="Debugging errors" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065157-a0c20c2d.jpg">
<img alt="Way of solving doubts" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065158-0c85968e.jpg">
<img alt="Learn about Git" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/09/29/20190929065159-74eacdec.jpg">]]></description>
    <pubDate>Sun, 29 Sep 2019 11:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2019/09/29/git-workshop/news.html</guid>
</item>
<item>
    <title>Aerospike Wireshark Lua plugin workshop, Rootconf 2019, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2019/07/22/rootconf/news.html</link>
    <description><![CDATA[<p><a href="https://rootconf.in/2019/">Rootconf 2019</a> was held on June 21-22, 2019 at NIMHANS Convention Centre, in Bengaluru on topics ranging from infrastructure security, site reliability engineering, DevOps and distributed systems.</p>
<a data-flickr-embed="true" href="https://www.flickr.com/photos/hasgeek/48125351246/in/album-72157709244493203/" title="Rootconf 2019 Day 1"><img src="https://live.staticflickr.com/65535/48125351246_9c93cccc35_z.jpg" width="640" height="427" alt="Rootconf 2019 Day 1"></a>
<script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>

<h1 id="day-i">Day I</h1>
<p>I had proposed a workshop titled <a href="https://hasgeek.com/rootconf/2019/proposals/shooting-the-trouble-down-to-the-wireshark-lua-plu-78tKrEaA8wCRiiQorcgtWd">“Shooting the trouble down to the Wireshark Lua Plugin”</a> for the event, and it was selected. I have been working on the <a href="https://github.com/aerospike/aerospike-wireshark-plugin">“Aerospike Wireshark Lua plugin”</a> for dissecting Aerospike protocols, and hence I wanted to share the insights on the same. The plugin source code is released under the AGPLv3 license.</p>
<p><a href="https://www.wireshark.org/">“Wireshark”</a> is a popular Free/Libre and Open Source Software protocol analyzer for analyzing protocols and troubleshooting networks. The <a href="https://www.lua.org/">“Lua programming language”</a> is useful to extend C projects to allow developers to do scripting. Since Wireshark is written in C, the plugin extension is provided by Lua. Aerospike uses the PAXOS family and custom built protocols for distributed database operations, and the plugin has been quite useful for packet dissection, and solving customer issues.</p>
<a data-flickr-embed="true" href="https://www.flickr.com/photos/hasgeek/48125457642/" title="Rootconf 2019 Day 1"><img src="https://live.staticflickr.com/65535/48125457642_b785f3da76_z.jpg" width="640" height="427" alt="Rootconf 2019 Day 1"></a>
<script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>

<p>The workshop had both theory and lab exercises. I began with an overview of Lua, Wireshark GUI, and the essential Wireshark Lua interfaces. The Aerospike Info protocol was chosen and exercises were given to dissect the version, type and size fields. I finished the session with real-world examples, future work and references. Around 50 participants attended the workshop, and those who had laptops were able to work on the exercises. The workshop presentation and lab exercises are available in the <a href="https://github.com/aerospike/aerospike-wireshark-plugin/tree/master/docs/workshop">aerospike-wireshark-plugin/docs/workshop</a> GitHub repository.</p>
<p>I had follow-up discussions with the participants before moving to the main auditorium. <a href="https://hasgeek.com/rootconf/2019/proposals/using-pod-security-policies-to-harden-your-kuberne-DdDFAC3Yo99YbjjoX6jEAG">“Using pod security policies to harden your Kubernetes cluster”</a> by <a href="https://suraj.io/">Suraj Deshmukh</a> was an interesting talk on the level of security that should be employed with containers. After lunch, I started my role as emcee in the main auditorium.</p>
<p>The keynote of the day was by <a href="http://www.gethash.org/">Bernd Erk</a>, the CEO at Netways GmbH, who is also the co-founder of the Icinga project. He gave an excellent talk on <a href="https://hasgeek.com/rootconf/2019/proposals/how-convenience-is-killing-open-standards-rW23MHu8VaVkgiekhAdKJj">“How convenience is killing open standards”</a>. He gave numerous examples on how people are not aware of open standards, and take proprietary systems for granted. This was followed by flash talks from the audience. Jaskaran Narula then spoke on <a href="https://hasgeek.com/rootconf/2019/proposals/securing-infrastructure-with-openscap-the-automati-6oAnRM3CZQJV5GUpSLL7Dk">“Securing infrastructure with OpenScap: the automation way”</a>, and also shared a demo of the same.</p>
<p>After the tea break, Shubham Mittal gave a talk on <a href="https://hasgeek.com/rootconf/2019/proposals/osint-for-proactive-defense-KnwMGWp8KBuuQ4ZLD95RcJ">“OSINT for Proactive Defense”</a> in which he shared the Open Source Intelligence (OSINT) tools, techniques and procedures to protect the perimeter security for an organization. The last talk of the day was by Shadab Siddiqui on <a href="https://hasgeek.com/rootconf/2019/proposals/devil-lies-in-the-details-running-a-successful-bug-XooB33RJJKQqNrYLpVHCHa">“Running a successful bug bounty programme in your organization”</a>.</p>
<h1 id="day-ii">Day II</h1>
<p><a href="https://anantshri.info/">Anant Shrivastava</a> started the day’s proceedings with a recap on the talks from day one.</p>
<p>The first talk of the day was by Jiten Vaidya, co-founder and CEO at Planetscale who spoke on <a href="https://hasgeek.com/rootconf/2019/proposals/oltp-or-olap-why-not-both-hScyhPzGitYkbiybShtK3U">“OLTP or OLAP: why not both?”</a>. He gave an architectural overview of vitess.io, a Free/Libre and Open Source sharding middleware for running OLTP workloads. The design looked like they were implementing the Kubernetes features on a MySQL cluster. <a href="https://github.com/rtnpro">Ratnadeep Debnath</a> then spoke on <a href="https://hasgeek.com/rootconf/2019/proposals/scale-mysql-beyond-limits-with-proxysql-aZUmJCNCScSdwYCK4k8j4V">“Scaling MySQL beyond limits with ProxySQL”</a>.</p>
<p>After the morning break, <a href="https://brianmckenna.org/blog/">Brian McKenna</a> gave an excellent talk on <a href="https://hasgeek.com/rootconf/2019/proposals/functional-programming-and-nix-for-reproducible-im-o2UxJAGjfy8evQdGA96uj3">“Functional programming and Nix for reproducible, immutable infrastructure”</a>. I have listened to his talks at the Functional Programming conference in Bengaluru, and they have been using Nix in production. The language constructs and cases were well demonstrated with examples. This was followed by yet another excellent talk by Piyush Verma on <a href="https://hasgeek.com/rootconf/2019/proposals/software-site-reliability-of-distributed-systems-jUMKh38AaeCf6Xb2xV8HuN">“Software/Site Reliability of Distributed Systems”</a>. He took a very simple request-response example, and incorporated site reliability features, and showed how complex things are today. All the major issues, pitfalls, and troubles were clearly explained with beautiful illustrations.</p>
<p>Aaditya Talwai presented his talk on <a href="https://hasgeek.com/rootconf/2019/proposals/virtuous-cycles-enabling-sre-via-automated-feedbac-qkNJRcuSp9pbRos44VT2tH">“Virtuous Cycles: Enabling SRE via automated feedback loops”</a> after the lunch break. This was followed by Vivek Sridhar’s talk on <a href="https://hasgeek.com/rootconf/2019/proposals/virtual-nodes-to-auto-scale-applications-on-kubern-aRmD3838atCTXi7HqY7nRC">“Virtual nodes to auto-scale applications on Kubernetes”</a>. Microsoft has been investing heavily on Free/Libre and Open Source, and have been hiring a lot of Python developers as well. Satya Nadella has been bringing in lot of changes, and it will be interesting to see their long-term progress. After Vivek’s talk, we had few slots for flash talks from the audience, and then Deepak Goyal gave his talk on <a href="https://hasgeek.com/rootconf/2019/proposals/kafka-streams-at-scale-yik2Kzo4vx3zDeQqnX3F3n">“Kafka streams at scale”</a>.</p>
<p>After the evening beverage break, Øystein Grøvlen, gave an excellent talk on <a href="https://hasgeek.com/rootconf/2019/proposals/polardb-a-database-architecture-for-the-cloud-zuxWbc3xhgQjwXbdCbRU2H">PolarDB - A database architecture for the cloud</a>. They are using it with Alibaba in China to handle petabytes of data. The computing layer and shared storage layers are distinct, and they use RDMA protocol for cluster communication. They still use a single master and multiple read-only replicas. They are exploring parallel query execution for improving performance of analytical queries.</p>
<a data-flickr-embed="true" href="https://www.flickr.com/photos/hasgeek/48125465926/" title="Rootconf 2019 Day 2"><img src="https://live.staticflickr.com/65535/48125465926_14504a4d03_z.jpg" width="640" height="427" alt="Rootconf 2019 Day 2"></a>
<script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>

<p>Overall, the talks and presentations were very good for 2019. Time management is of utmost importance at Rootconf, and we have been very consistent. I was happy to emcee again for Rootconf!</p>]]></description>
    <pubDate>Mon, 22 Jul 2019 15:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2019/07/22/rootconf/news.html</guid>
</item>
<item>
    <title>Building Erlang/OTP sources with Ansible</title>
    <link>http://www.shakthimaan.com/posts/2019/06/02/devops-ansible-erlang/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, September 2017 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>Erlang is a programming language designed by Ericsson primarily for soft real-time systems. The Open Telecom Platform (OTP) consists of libraries, applications and tools to be used with Erlang to implement services that require high availability. In this article, we will create a test Virtual Machine (VM) to compile, build, and test Erlang/OTP from its source code. This allows you to create VMs with different Erlang release versions for testing.</p>
<p>The Erlang programming language was developed by Joe Armstrong, Robert Virding and Mike Williams in 1986 and released as free and open source software in 1998. It was initially designed to work with telecom switches, but is widely used today in large scale, distributed systems. Erlang is a concurrent and functional programming language, and is released under the Apache License 2.0.</p>
<h1 id="setup">Setup</h1>
<p>A CentOS 6.8 Virtual Machine (VM) running on KVM will be used for the installation. Internet access should be available from the guest machine. The VM should have at least 2 GB of RAM alloted to build the Erlang/OTP documentation. The Ansible version used on the host (Parabola GNU/Linux-libre x86_64) is 2.3.0.0. The ansible/ folder contains the following files:</p>
<pre><code>ansible/inventory/kvm/inventory
ansible/playbooks/configuration/erlang.yml</code></pre>
<p>The IP address of the guest CentOS 6.8 VM is added to the <em>inventory</em> file as shown below:</p>
<pre><code>erlang ansible_host=192.168.122.150 ansible_connection=ssh ansible_user=bravo ansible_password=password</code></pre>
<p>An entry for the <em>erlang</em> host is also added to the /etc/hosts file as indicated below:</p>
<pre><code>192.168.122.150 erlang</code></pre>
<p>A ‘bravo’ user account is created on the test VM, and is added to the ‘wheel’ group. The /etc/sudoers file also has the following line uncommented, so that the ‘bravo’ user will be able to execute sudo commands:</p>
<pre><code>## Allows people in group wheel to run all commands
%wheel	ALL=(ALL)	ALL</code></pre>
<p>We can obtain the Erlang/OTP sources from a stable tarball, or clone the Git repository. The steps involved in both these cases are discussed below:</p>
<h1 id="building-from-the-source-tarball">Building from the source tarball</h1>
<p>The Erlang/OTP stable releases are available at <a href="http://www.erlang.org/downloads">http://www.erlang.org/downloads</a>. The build process is divided into many steps, and we shall go through each one of them. The version of Erlang/OTP can be passed as an argument to the playbook. Its default value is the release 19.0, and is defined in the variable section of the playbook as shown below:</p>
<pre><code>vars:
  ERL_VERSION: &quot;otp_src_{{ version | default('19.0') }}&quot;
  ERL_DIR: &quot;{{ ansible_env.HOME }}/installs/erlang&quot;
  ERL_TOP: &quot;{{ ERL_DIR }}/{{ ERL_VERSION }}&quot;
  TEST_SERVER_DIR: &quot;{{ ERL_TOP }}/release/tests/test_server&quot;</code></pre>
<p>The ERL_DIR variable represents the directory where the tarball will be downloaded, and the ERL_TOP variable refers to the top-level directory location containing the source code. The path to the test directory from where the tests will be invoked is given by the TEST_SERVER_DIR variable.</p>
<p>Erlang/OTP has mandatory and optional package dependencies. Let’s first update the software package repository, and then install the required dependencies as indicated below:</p>
<pre><code>tasks:
  - name: Update the software package repository
    become: true
    yum:
      name: '*'
      update_cache: yes

  - name: Install dependencies
    become: true
    package:
      name: &quot;{{ item }}&quot;
      state: latest
    with_items:
      - wget
      - make
      - gcc
      - perl
      - m4
      - ncurses-devel
      - sed
      - libxslt
      - fop</code></pre>
<p>The Erlang/OTP sources are written using the ‘C’ programming language. The GNU C Compiler (GCC) and GNU Make are used to compile the source code. The ‘libxslt’ and ‘fop’ packages are required to generate the documentation. The build directory is then created, the source tarball is downloaded and it is extracted to the directory mentioned in ERL_DIR.</p>
<pre><code>- name: Create destination directory
  file: path=&quot;{{ ERL_DIR }}&quot; state=directory

- name: Download and extract Erlang source tarball
  unarchive:
    src: &quot;http://erlang.org/download/{{ ERL_VERSION }}.tar.gz&quot;
    dest: &quot;{{ ERL_DIR }}&quot;
    remote_src: yes</code></pre>
<p>The ‘configure’ script is available in the sources, and it is used to generate the Makefile based on the installed software. The ‘make’ command will build the binaries from the source code.</p>
<pre><code>- name: Build the project
  command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
  with_items:
    - ./configure
    - make
  environment:
    ERL_TOP: &quot;{{ ERL_TOP }}&quot;</code></pre>
<p>After the ‘make’ command finishes, the ‘bin’ folder in the top-level sources directory will contain the Erlang ‘erl’ interpreter. The Makefile also has targets to run tests to verify the built binaries. We are remotely invoking the test execution from Ansible and hence <em>-noshell -noinput</em> are passed as arguments to the Erlang interpreter, as show in the .yaml file.</p>
<pre><code>- name: Prepare tests
  command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
  with_items:
    - make release_tests
  environment:
    ERL_TOP: &quot;{{ ERL_TOP }}&quot;

- name: Execute tests
  shell: &quot;cd {{ TEST_SERVER_DIR }} &amp;&amp; {{ ERL_TOP }}/bin/erl -noshell -noinput -s ts install -s ts smoke_test batch -s init stop&quot;</code></pre>
<p>You need to verify that the tests have passed successfully by checking the $ERL_TOP/release/tests/test_server/index.html page in a browser. A screenshot of the test results is shown in Figure 1:</p>
<img alt="Erlang test results" src="https://gallery.shakthimaan.com/i?/uploads/k/d/s/kdszajl69v//2019/06/02/20190602132850-d844ed54-la.jpg">
<p>The built executables, libraries can then be installed on the system using the <em>make install</em> command. By default, the install directory is /usr/local.</p>
<pre><code>- name: Install
  command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
  with_items:
    - make install
  become: true
  environment:
    ERL_TOP: &quot;{{ ERL_TOP }}&quot;</code></pre>
<p>The documentation can also be generated and installed as shown below:</p>
<pre><code>- name: Make docs
  shell: &quot;cd {{ ERL_TOP }} &amp;&amp; make docs&quot;
  environment:
    ERL_TOP: &quot;{{ ERL_TOP }}&quot;
    FOP_HOME: &quot;{{ ERL_TOP }}/fop&quot;
    FOP_OPTS: &quot;-Xmx2048m&quot;

- name: Install docs
  become: true
  shell: &quot;cd {{ ERL_TOP }} &amp;&amp; make install-docs&quot;
  environment:
    ERL_TOP: &quot;{{ ERL_TOP }}&quot;</code></pre>
<p>The total available RAM (2 GB) is specified in the FOP_OPTS environment variable. The complete playbook to download, compile, execute the tests, and also generate the documentation is given below:</p>
<pre><code>---
- name: Setup Erlang build
  hosts: erlang
  gather_facts: true
  tags: [release]

  vars:
    ERL_VERSION: &quot;otp_src_{{ version | default('19.0') }}&quot;
    ERL_DIR: &quot;{{ ansible_env.HOME }}/installs/erlang&quot;
    ERL_TOP: &quot;{{ ERL_DIR }}/{{ ERL_VERSION }}&quot;
    TEST_SERVER_DIR: &quot;{{ ERL_TOP }}/release/tests/test_server&quot;

  tasks:
    - name: Update the software package repository
      become: true
      yum:
        name: '*'
        update_cache: yes

    - name: Install dependencies
      become: true
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - wget
        - make
        - gcc
        - perl
        - m4
        - ncurses-devel
        - sed
        - libxslt
        - fop

    - name: Create destination directory
      file: path=&quot;{{ ERL_DIR }}&quot; state=directory

    - name: Download and extract Erlang source tarball
      unarchive:
        src: &quot;http://erlang.org/download/{{ ERL_VERSION }}.tar.gz&quot;
        dest: &quot;{{ ERL_DIR }}&quot;
        remote_src: yes

    - name: Build the project
      command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
      with_items:
        - ./configure
        - make
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;

    - name: Prepare tests
      command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
      with_items:
        - make release_tests
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;

    - name: Execute tests
      shell: &quot;cd {{ TEST_SERVER_DIR }} &amp;&amp; {{ ERL_TOP }}/bin/erl -noshell -noinput -s ts install -s ts smoke_test batch -s init stop&quot;

    - name: Install
      command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
      with_items:
        - make install
      become: true
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;

    - name: Make docs
      shell: &quot;cd {{ ERL_TOP }} &amp;&amp; make docs&quot;
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;
        FOP_HOME: &quot;{{ ERL_TOP }}/fop&quot;
        FOP_OPTS: &quot;-Xmx2048m&quot;

    - name: Install docs
      become: true
      shell: &quot;cd {{ ERL_TOP }} &amp;&amp; make install-docs&quot;
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;</code></pre>
<p>The playbook can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/erlang.yml -e &quot;version=19.0&quot; --tags &quot;release&quot; -K</code></pre>
<h1 id="build-from-git-repository">Build from Git repository</h1>
<p>We can build the Erlang/OTP sources from the Git repository. The complete playbook is given below for reference:</p>
<pre><code>- name: Setup Erlang Git build
  hosts: erlang
  gather_facts: true
  tags: [git]

  vars:
    GIT_VERSION: &quot;otp&quot;
    ERL_DIR: &quot;{{ ansible_env.HOME }}/installs/erlang&quot;
    ERL_TOP: &quot;{{ ERL_DIR }}/{{ GIT_VERSION }}&quot;
    TEST_SERVER_DIR: &quot;{{ ERL_TOP }}/release/tests/test_server&quot;

  tasks:
    - name: Update the software package repository
      become: true
      yum:
        name: '*'
        update_cache: yes

    - name: Install dependencies
      become: true
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - wget
        - make
        - gcc
        - perl
        - m4
        - ncurses-devel
        - sed
        - libxslt
        - fop
        - git
        - autoconf

    - name: Create destination directory
      file: path=&quot;{{ ERL_DIR }}&quot; state=directory

    - name: Clone the repository
      git:
        repo: &quot;https://github.com/erlang/otp.git&quot;
        dest: &quot;{{ ERL_DIR }}/otp&quot;

    - name: Build the project
      command: &quot;{{ item }} chdir={{ ERL_TOP }}&quot;
      with_items:
        - ./otp_build autoconf
        - ./configure
        - make
      environment:
        ERL_TOP: &quot;{{ ERL_TOP }}&quot;</code></pre>
<p>The ‘git’ and ‘autoconf’ software packages are required for downloading and building the sources from the Git repository. The Ansible Git module is used to clone the remote repository. The source directory provides an <em>otp_build</em> script to create the <em>configure</em> script. You can invoke the above playbook as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/erlang.yml --tags &quot;git&quot; -K</code></pre>
<p>You are encouraged to read the complete installation documentation at: <a href="https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md">https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md</a>.</p>]]></description>
    <pubDate>Sun, 02 Jun 2019 19:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2019/06/02/devops-ansible-erlang/news.html</guid>
</item>
<item>
    <title>"Opportunities in FLOSS" at Computer Society of India, Madras</title>
    <link>http://www.shakthimaan.com/posts/2019/03/28/foss-session-csi/news.html</link>
    <description><![CDATA[<p>I had given a talk on <a href="http://ieeecs-madras.managedbiz.com/pgms/2019/mm-190302-open-source.pdf">“Opportunities in Free (Libre) and Open Source Software”</a>(FLOSS) on Saturday, March 2, 2019 at the Computer Society of India, Madras Chapter, jointly organized by the IEEE Computer Society, Madras Chapter and ACM India Chennai Professional Chapter. The Computer Society of India, Education Directorate is located opposite to the Institute of Mathematical Sciences in Taramani, close to the Tidel Park. Students, IT professionals and professors from IIT Madras, Anna University and engineering colleges in and around Chennai attended the event.</p>
<img alt="Session in progress" src="http://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/03/08/20190308155249-176a8585.jpg"></img>
<p>At around 6:00 p.m. people had assembled for networking, snacks and beverage. I started the <a href="http://www.shakthimaan.com/downloads.html#building-careers-with-floss">“Building Careers with FLOSS”</a> presentation at 6:30 p.m. <a href="http://dos.iitm.ac.in/djwebsite/">Prof. Dr. D. Janakiram</a>, CSE, IIT Madras also shared his insights on the benefits of learning from source code available under a FLOSS license. The session was very interactive and the audience asked a lot of good questions. Dr. B. Govindarajulu, author of the famous <a href="https://www.amazon.in/IBM-PC-CLONES-Troubleshooting-Maintenance/dp/0070482861">“IBM PC and Clones: Hardware, Troubleshooting and Maintenance”</a> book then presented his views on creating a Computer History Museum in Chennai. Dinner was served around 8:00 p.m. at the venue.</p>
<img alt="Group photo" src="http://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2019/03/08/20190308155250-3f3f7229.jpg"></img>
<p>A <a href="http://ieeecs-madras.managedbiz.com/icnl/19q1/p30-p32.pdf">review of my book</a> has been published in <a href="http://ieeecs-madras.managedbiz.com/icnl/19q1/index.html">Volume 14: No. 1, January-March 2019 IEEE India Council Newsletter</a>. The excerpts of Chapter 4 of my book on <a href="http://ieeecs-madras.managedbiz.com/icnl/19q1/p147-p150.pdf">“Project Guidelines”</a> is also available. I had also written an article on <a href="http://ieeecs-madras.managedbiz.com/icnl/19q1/p121-p122.pdf">“Seasons of Code”</a> which is published in this edition of the IEEE newsletter.</p>
<p>Special thanks to Mr. H. R. Mohan, Editor, IEEE India and Chairman, ACM Professional Chapter, Chennai for organizing the event and for the logistics support.</p>]]></description>
    <pubDate>Thu, 28 Mar 2019 13:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2019/03/28/foss-session-csi/news.html</guid>
</item>
<item>
    <title>Ansible deployment of Jenkins</title>
    <link>http://www.shakthimaan.com/posts/2018/12/26/devops-ansible-jenkins/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, August 2017 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>In this sixth article in the DevOps series, we will install Jenkins using Ansible and set up a Continuous Integration (CI) build for a project that uses Git. Jenkins is Free and Open Source automation server software that is used to build, deploy and automate projects. It is written in Java and released under the MIT license. A number of plugins are available to integrate Jenkins with other tools such as version control systems, APIs and databases.</p>
<h1 id="setting-it-up">Setting it up</h1>
<p>A CentOS 6.8 Virtual Machine (VM) running on KVM will be used for the installation. Internet access should be available from the guest machine. The Ansible version used on the host (Parabola GNU/Linux-libre x86_64) is 2.3.0.0. The ansible/ folder contains the following files:</p>
<pre><code>ansible/inventory/kvm/inventory
ansible/playbooks/configuration/jenkins.yml
ansible/playbooks/admin/uninstall-jenkins.yml</code></pre>
<p>The IP address of the guest CentOS 6.8 VM is added to the <em>inventory</em> file as shown below:</p>
<pre><code>jenkins ansible_host=192.168.122.120 ansible_connection=ssh ansible_user=root ansible_password=password</code></pre>
<p>An entry for the <em>jenkins</em> host is also added to the /etc/hosts file as indicated below:</p>
<pre><code>192.168.122.120 jenkins</code></pre>
<h1 id="installation">Installation</h1>
<p>The playbook to install the Jenkins server on the CentOS VM is given below:</p>
<pre><code>---
- name: Install Jenkins software
  hosts: jenkins
  gather_facts: true
  become: yes
  become_method: sudo
  tags: [jenkins]

  tasks:
    - name: Update the software package repository
      yum:
        name: '*'
        update_cache: yes

    - name: Install dependencies
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - java-1.8.0-openjdk
        - git
        - texlive-latex
        - wget

    - name: Download jenkins repo
      command: wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

    - name: Import Jenkins CI key
      rpm_key:
        key: http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
        state: present

    - name: Install Jenkins
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - jenkins

    - name: Allow port 8080
      shell: iptables -I INPUT -p tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT

    - name: Start the server
      service:
        name: jenkins
        state: started

    - wait_for:
        port: 8080</code></pre>
<p>The playbook first updates the Yum repository and installs the Java OpenJDK software dependency required for Jenkins. The Git and Tex Live LaTeX packages are required to build our project, github.com/shakthimaan/di-git-ally-managing-love-letters (now at https://gitlab.com/shakthimaan/di-git-ally-managing-love-letters). We then download the Jenkins repository file, and import the repository GPG key. The Jenkins server is then installed, port 8080 is allowed through the firewall, and the script waits for the server to listen on port 8080. The above playbook can be invoked using the following command:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/jenkins.yml -vv</code></pre>
<h1 id="configuration">Configuration</h1>
<p>You can now open <a href="http://192.168.122.120:8080"><code class="url">http://192.168.122.120:8080</code></a> in the browser on the host to start configuring Jenkins. The web page will prompt you to enter the initial Administrator password from /var/lib/jenkins/secrets/initialAdminPassword to proceed further. This is shown in Figure 1:</p>
<img width="800" alt="Unlock Jenkins" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063626-d6f1d056.jpg">
<p>The second step is to install plugins. For this demonstration, you can select the “Install suggested plugins” option, and later install any of the plugins that you require. Figure 2 displays the selected option:</p>
<img width="800" alt="Customize Jenkins" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063629-a48d34b1.jpg">
<p>After you select the “Install suggested plugins” option, the plugins will get installed as shown in Figure 3:</p>
<img width="800" alt="Getting Started" src="https://gallery.shakthimaan.com/i?/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063629-5d4ddfb3-sm.jpg">
<p>An admin user is required for managing Jenkins. After installing the plugins, a form is shown for you to enter the user name, password, name and e-mail address of the administrator. A screenshot of this is shown in Figure 4:</p>
<img width="800" alt="Create First Admin User" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063630-72d69918.jpg">
<p>Once the administrator credentials are stored, a “Jenkins is ready!” page will be displayed, as depicted in Figure 5:</p>
<img alt="Jenkins is ready!" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063631-f693b286.jpg">
<p>You can now click on the “Start using Jenkins” button to open the default Jenkins dashboard shown in Figure 6:</p>
<img width="800" alt="Jenkins Dashboard" src="https://gallery.shakthimaan.com/i?/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063632-6faba2d6-me.jpg">
<h1 id="an-example-of-a-new-project">An example of a new project</h1>
<p>Let’s now create a new build for the github.com/shakthimaan/di-git-ally-managing-love-letters project. Provide a name in the “Enter an item name” text box and select the “Freestyle project”. Figure 7 provides shows the screenshot for creating a new project:</p>
<img width="800" alt="Enter an item name" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063633-cc1f9eed.jpg">
<p>The next step is to add the GitHub repo to the “Repositories” section. The GitHub https URL is provided as we are not going to use any credentials in this example. By default, the master branch will be built. The form to enter the GitHub URL is shown in Figure 8:</p>
<img width="800" alt="Add GitHub repo" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063634-55b76053.jpg">
<p>A Makefile is available in the project source code, and hence we can simply invoke “make” to build the project. The “Execute shell” option is chosen in the “Build” step, and the “make clean; make” command is added to the build step as shown in Figure 9.</p>
<img width="800" alt="Build step" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063634-e0f36412.jpg">
<p>From the left panel, you can click on the “Build Now” link for the project to trigger a build. After a successful build, you should see a screenshot similar to Figure 10.</p>
<img width="800" alt="Build success" src="https://gallery.shakthimaan.com/uploads/k/d/s/kdszajl69v//2018/11/15/20181115063635-7d2cd758.jpg">
<h1 id="uninstall">Uninstall</h1>
<p>An uninstall script to remove the Jenkins server is available in playbooks/admin folder. It is given below for reference:</p>
<pre><code>---
---
- name: Uninstall Jenkins
  hosts: jenkins
  gather_facts: true
  become: yes
  become_method: sudo
  tags: [remove]

  tasks:
    - name: Stop Jenkins server
      service:
        name: jenkins
        state: stopped

    - name: Uninstall packages
      package:
        name: &quot;{{ item }}&quot;
        state: absent
      with_items:
        - jenkins</code></pre>
<p>The script can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/admin/uninstall-jenkins.yml</code></pre>]]></description>
    <pubDate>Wed, 26 Dec 2018 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2018/12/26/devops-ansible-jenkins/news.html</guid>
</item>
<item>
    <title>Emacs Meetup (virtual), February-March, 2018</title>
    <link>http://www.shakthimaan.com/posts/2018/07/25/emacs-apac-february-march-2018-meetup/news.html</link>
    <description><![CDATA[<p>I have been trying to have regular monthly Emacs meetups online, starting from 2018.</p>
<p>The following are the meeting minutes and notes from the Jitsi meetings held online in the months of February and March 2018.</p>
<h1 id="february-2018">February 2018</h1>
<p>The February 2018 meetup was primarily focussed on using Emacs for publishing.</p>
<p>Using Emacs with <a href="https://jaspervdj.be/hakyll/">Hakyll</a> to build websites and resumes were discussed. It is also possible to output in muliple formats (PDF, YAML, text) from the same source.</p>
<p>I shared my <a href="https://gitlab.com/shakthimaan/shakthimaan-blog">shakthimaan-blog</a> sources that uses Hakyll to generate the web site. We also discussed the advantanges of using static site generators, especially when you have large user traffic to your web site.</p>
<p>I had created the <a href="https://gitlab.com/shakthimaan/xetex-book-template">xetex-book-template</a>, for creating multilingual book PDFs. The required supported features in the same, and its usage were discussed in the meeting.</p>
<p><a href="https://kushaldas.in/">Kushal Das</a> asked about keyboards use in Emacs, and in particular for Control and Alt, as he was using the Kinesis. The best Emacs keyboard options available at <a href="http://ergoemacs.org/emacs/emacs_best_keyboard.html">http://ergoemacs.org/emacs/emacs_best_keyboard.html</a> was shared. The advantage of using thumb keys for Control and Alt was obvious with the bowl shaped keyboard layout in Kinesis.</p>
<p>We also talked about the <a href="https://en.wikipedia.org/wiki/Eww_(web_browser)">Emacs Web Browser (eww)</a>, and suggested the use of <a href="https://www.emacswiki.org/emacs/mu4e">mu4e</a> for checking e-mails with Emacs.</p>
<h1 id="march-2018">March 2018</h1>
<p>At the beginning of the meetup, the participants asked if there was a live stream available, but, we are not doing so at this point in time with Jitsi.</p>
<p>For drawing inside Emacs, I had suggested ASCII art using <a href="https://www.emacswiki.org/emacs/ArtistMode">Artist Mode</a>.</p>
<p>Emacs has support for rendering PDFs inside, as the following old blog post shows <a href="http://www.idryman.org/blog/2013/05/20/emacs-and-pdf/">http://www.idryman.org/blog/2013/05/20/emacs-and-pdf/</a>. nnnick then had a question on “Why Emacs?”:</p>
<pre><code>nnnick 19:23:00
Can you tell me briefly why emacs is preferred over other text editors</code></pre>
<p>The discussion then moved to the customization features and extensibility of Emacs that makes it well suited for your needs.</p>
<p>For people who want to start with a basic configuration for Emacs, the following repository was suggested <a href="https://github.com/technomancy/emacs-starter-kit">https://github.com/technomancy/emacs-starter-kit</a>.</p>
<p>I had also shared links on using Org mode and scrum-mode for project management:</p>
<ul>
<li><p><a href="https://github.com/ianxm/emacs-scrum">https://github.com/ianxm/emacs-scrum</a></p></li>
<li><p><a href="https://gitlab.com/shakthimaan/operation-blue-moon">https://gitlab.com/shakthimaan/operation-blue-moon</a></p></li>
</ul>
<p>I shared my <a href="https://github.com/cask/cask">Cask</a> setup link <a href="https://gitlab.com/shakthimaan/cask-dot-emacs">https://gitlab.com/shakthimaan/cask-dot-emacs</a> and mentioned that with a rolling distribution like <a href="https://www.parabola.nu/">Parabola GNU/Linux-libre</a>, it was quite easy to re-run install.sh for newer Emacs versions, and get a consistent setup.</p>
<p>In order to SSH into local or remote systems (VMs), <a href="https://www.emacswiki.org/emacs/TrampMode">Tramp mode</a> was suggested.</p>
<p>I also shared my presentation on “Literate DevOps” inspired by Howardism <a href="https://gitlab.com/shakthimaan/literate-devops-using-gnu-emacs/blob/master/literate-devops.org">https://gitlab.com/shakthimaan/literate-devops-using-gnu-emacs/blob/master/literate-devops.org</a>.</p>
<p>Org entries can also be used to keep track of personal journal entries. The Date Trees are helpful in this context as shown in the following web page <a href="http://members.optusnet.com.au/~charles57/GTD/datetree.html">http://members.optusnet.com.au/~charles57/GTD/datetree.html</a>.</p>
<p>Tejas asked about using Org files for executing code in different programming languages. This can be done using Org Babel, and the same was discussed.</p>
<pre><code>Tejas 19:38:23
can org mode files be used to keep executable code in other languages apart from elisp?

mbuf 19:38:42
Yes

mbuf 19:39:15
https://orgmode.org/worg/org-contrib/babel/languages.html</code></pre>
<p>The other useful tools that were discussed for productivity are given below:</p>
<ul>
<li><p>Magit for VCS: <a href="https://github.com/magit/magit">https://github.com/magit/magit</a>.</p></li>
<li><p>Workgroups for workspace management: <a href="https://github.com/pashinin/workgroups2">https://github.com/pashinin/workgroups2</a>.</p></li>
<li><p>Winner mode to switch between sessions in windows: <a href="https://www.emacswiki.org/emacs/WinnerMode">https://www.emacswiki.org/emacs/WinnerMode</a>.</p></li>
<li><p>Emacs Code Browser is like a full flown IDE-like environment: <a href="http://ecb.sourceforge.net/">http://ecb.sourceforge.net/</a>.</p></li>
</ul>
<p>Tejas said that he uses <a href="https://github.com/nex3/perspective-el">perspective-el</a>, but it does not have the save option - just separate workspaces to switch between them - for different projects basically.</p>
<p>A screenshot of the session in progress is shown below:</p>
<img width="800" alt="Emacs APAC March 2018 meetup" src="http://www.shakthimaan.com/images/emacs/emacs-apac-mar-19-2018-screenshot.png"></img><br />
<p>Arun also suggested using <a href="https://github.com/larstvei/Try">Try</a> for trying out Emacs packages without installation, and <a href="https://github.com/pierre-lecocq/cycle-resize">cycle-resize</a> package for managing windows.</p>
<p>Tejas and Arun then shared their Emacs configuration files.</p>
<pre><code>Arun 19:51:37
https://github.com/aruntakkar/emacs.d

Tejas 19:51:56
https://github.com/tejasbubane/dotemacs</code></pre>
<p>We closed the session with few references on learning Emacs Lisp:</p>
<pre><code>Tejas 20:02:42
before closing off, can you guys quickly point me to some resources for learning elisp?

mbuf 20:03:59
Writing GNU Emacs Extensions.

mbuf 20:04:10
Tejas: Emacs Lisp manual

Tejas 20:04:35
Thanks </code></pre>]]></description>
    <pubDate>Wed, 25 Jul 2018 16:25:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2018/07/25/emacs-apac-february-march-2018-meetup/news.html</guid>
</item>
<item>
    <title>Elixir Workshop: MVJ College of Engineering, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2018/07/20/elixir-scripting-workshop-mvj/news.html</link>
    <description><![CDATA[<p>I had organized a hands-on scripting workshop using the <a href="https://elixir-lang.org/">Elixir</a> programming language for the Computer Science and Engineering department, <a href="https://www.mvjce.edu.in/">MVJ College of Engineering, Whitefield, Bengaluru</a> on May 5, 2018.</p>
<img alt="Elixir scripting session" src="http://shakthimaan.com/images/2018/elixir-scripting-workshop-mvj/elixir-workshop-session.png"><br />
<p>The department were interested in organizing a scripting workshop, and I felt using a new programming language like Elixir with the power of the <a href="https://www.erlang.org/">Erlang</a> Virtual Machine (VM) will be a good choice. The syntax and semantics of the Elixir language were discussed along with the following topics:</p>
<ul>
<li>Basic types</li>
<li>Basic operators</li>
<li>Pattern matching</li>
<li>case, cond and if</li>
<li>Binaries, strings and char lists</li>
<li>Keywords and maps</li>
<li>Modules and functions</li>
</ul>
<p>Students had setup Erlang and Elixir on their laptops, and tried the code snippets in the Elixir interpreter. The complete set of examples are available in the following repo:</p>
<p><a href="https://gitlab.com/shakthimaan/elixir-scripting-workshop">https://gitlab.com/shakthimaan/elixir-scripting-workshop</a></p>
<p>A group photo was taken at the end of the workshop.</p>
<img alt="Elixir scripting session" src="http://shakthimaan.com/images/2018/elixir-scripting-workshop-mvj/elixir-workshop-group.png"><br />
<p>I would like to thank Prof. Karthik Myilvahanan J for working with me in organizing this workshop.</p>]]></description>
    <pubDate>Fri, 20 Jul 2018 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2018/07/20/elixir-scripting-workshop-mvj/news.html</guid>
</item>
<item>
    <title>Travel - Udupi, Karnataka</title>
    <link>http://www.shakthimaan.com/posts/2018/02/14/udupi/news.html</link>
    <description><![CDATA[<img alt="Resort" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/1-resort.jpg"></img><br />
<img alt="Infinity pool" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/2-infinity-pool.jpg"></img><br />
<img alt="Floating restaurant" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/3-floating-restaurant.jpg"></img><br />
<img alt="Rich and poor boats" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/4-rich-poor-boats.jpg"></img><br />
<img alt="Udupi temple" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/5-udupi-temple.jpg"></img><br />
<img alt="Lagoon" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/6-lagoon.jpg"></img><br />
<img alt="St. Mary's island" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/7-st-marys-island.jpg"></img><br />
<img alt="Sunset" src="http://shakthimaan.com/images/2018/paradise-lagoon-udupi/8-sunset.jpg"></img><br />]]></description>
    <pubDate>Wed, 14 Feb 2018 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2018/02/14/udupi/news.html</guid>
</item>
<item>
    <title>Emacs Meetup (virtual), January 15, 2018</title>
    <link>http://www.shakthimaan.com/posts/2018/01/22/emacs-meetup-virtual/news.html</link>
    <description><![CDATA[<p>I wanted to start the New Year (2018) by organizing an Emacs meetup session in the APAC time zone. Since there are a number of users in different cities, I thought a virtual session will be ideal. An online Google Hangout session was scheduled for Monday, January 15, 2018 at 1000 IST.</p>
<img alt="Hangout announcement" src="http://shakthimaan.com/images/2018/emacs-hangout-announcement/emacs-hangout-announcement.png"><br />
<p>Although I announced the same only on Twitter and IRC (#emacs on irc.freenode.net), we had a number of Emacsers join the session. The chat log with the useful web links that were shared are provided below for reference.</p>
<p>We started our discussion on organizing Org files and maintaining TODO lists.</p>
<pre><code>9:45 AM Suraj Ghimire: it is clear and loud :) video quality is good too 
                       yes. is there any session today on hangouts ?
                       wow thats nice thanks you for introducing me to emacs :). I am happy emacs user
                       should we add bhavin and vharsh for more testing
                       oh you already shared :)
	
9:55 AM Suraj Ghimire:  working on some of my todos https://i.imgur.com/GBylmeQ.png</code></pre>
<p>For few Vim users who wanted to try Emacs Org mode, it was suggested to get started with <a href="http://spacemacs.org/">Spacemacs</a>. Other project management and IRC tools with Emacs were also shared:</p>
<pre><code>  HARSH VARDHAN can now join this call.
  HARSH VARDHAN joined group chat.
  Google Apps can now join this call.
  Google Apps joined group chat.
	
10:05 AM Shakthi Kannan: http://spacemacs.org/
                         https://github.com/ianxm/emacs-scrum
                         https://github.com/ianxm/emacs-scrum/blob/master/example-report.txt
                         https://www.emacswiki.org/emacs/CategoryWebBrowser
                         ERC for IRC chat
                         https://www.emacswiki.org/emacs/InternetRelayChat

10:13 AM Shakthi Kannan: https://github.com/skeeto/elfeed
                         https://www.emacswiki.org/emacs/EmacsMailingLists
	
10:18 AM Suraj Ghimire: I started using emacs after your session on emacs, before that i used to 
                        get scared due to lot of shortcuts. I will work on improvements you told me.
	
10:19 AM Shakthi Kannan: M - Alt, C - Control
                         http://www.tldp.org/HOWTO/Emacs-Beginner-HOWTO-3.html

  Google Apps left group chat.
  Google Apps joined group chat.
  Sacha Chua can now join this call.
  Sacha Chua joined group chat.</code></pre>
<p>We then discussed on key bindings, available modes, and reading material to learn and master Emacs:</p>
<pre><code>10:27 AM Shakthi Kannan: http://shop.oreilly.com/product/9780596006488.do
	
10:31 AM Shakthi Kannan: https://www.masteringemacs.org/
                         http://shakthimaan.com/tags/emacs.html
                         http://shakthimaan.com/posts/2016/04/04/introduction-to-gnu-emacs/news.html

  Dhavan Vaidya can now join this call.
  Dhavan Vaidya joined group chat.
  Sacha Chua left group chat.
	
10:42 AM Shakthi Kannan: https://www.finseth.com/craft/
                         http://shop.oreilly.com/product/9781565922617.do

  Rajesh Deo can now join this call.
  Rajesh Deo joined group chat.</code></pre>
<p>Users also wanted to know of language modes for Erlang:</p>
<pre><code>10:52 AM Shakthi Kannan: http://www.lambdacat.com/post-modern-emacs-setup-for-erlang/

  HARSH VARDHAN left group chat.
  Aaron Hall can now join this call.
	
10:54 AM Shakthi Kannan: https://github.com/elixir-editors/emacs-elixir</code></pre>
<p>Aaron Hall joined the channel and had few interesting questions. After an hour, we ended the call.</p>
<pre><code>  Aaron Hall joined group chat.
	
10:54 AM Aaron Hall: hi!
10:54 AM Dhavan Vaidya: hi!
	
10:55 AM Aaron Hall: This is really cool!

Maikel Yugcha can now join this call.
Maikel Yugcha joined group chat.
	
10:57 AM Aaron Hall: Anyone here using Emacs as their window manager?
	
10:57 AM Suraj Ghimire: not yet :)
	
10:57 AM Shakthi Kannan: I am &quot;mbuf&quot; on IRC. http://stumpwm.github.io/
	
10:58 AM Aaron Hall: What about on servers? I just played around, but I like tmux for persistence and emacs inside of tmux.
	
10:59 AM Shakthi Kannan: https://github.com/pashinin/workgroups2
	
11:00 AM Aaron Hall: Is anyone compiling emacs from source?

Zsolt Botykai can now join this call.
Zsolt Botykai joined group chat.
	
11:00 AM Aaron Hall: yay, me too!

Zsolt Botykai left group chat.
	
11:00 AM Aaron Hall: it wasn't easy to start, the config options are hard
                     I had trouble especially with my fonts until I got my configure right

Maikel Yugcha left group chat.
	
11:03 AM Shakthi Kannan: https://github.com/shakthimaan/cask-dot-emacs
	
11:04 AM Aaron Hall anyone using Haskell? With orgmode? I've been having a lot of trouble with that...
                    code blocks are hard to get working
                    ghci
                    inferior?
                    not really sure
                    it's been a while since I worked on it
                    I had a polyglot file I was working on, I got a lot of languages working
                    Python, Bash, R, Javascript,
                    I got C working too
	
11:06 AM Shakthi Kannan: Rajesh: http://company-mode.github.io/
	
11:07 AM Aaron Hall: cheers, this was fun!

Aaron Hall left group chat.
Dhavan Vaidya left group chat.
Rajesh Deo left group chat.
Google Apps left group chat.
Suraj Ghimire left group chat.</code></pre>
<p>A screenshot of the Google Hangout session is shown below:</p>
<img width="800" alt="Google Hangout screenshot" src="http://shakthimaan.com/images/2018/emacs-hangout-announcement/emacs-jan-15-2018.png"><br />
<p>We can try a different online platform for the next meetup (Monday, February, 19, 2018). I would like to have the meetup on the third Monday of every month. Special thanks to <a href="http://sachachua.com/">Sacha Chua</a> for her valuable inputs in organizing the online meetup session.</p>]]></description>
    <pubDate>Mon, 22 Jan 2018 17:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2018/01/22/emacs-meetup-virtual/news.html</guid>
</item>
<item>
    <title>Ansible deployment of Graphite</title>
    <link>http://www.shakthimaan.com/posts/2017/12/28/devops-ansible-graphite/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, July 2017 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>In this fifth article in the DevOps series we will learn to install and set up Graphite using Ansible. Graphite is a monitoring tool that was written by Chris Davis in 2006. It has been released under the Apache 2.0 license and comprises three components:</p>
<ol style="list-style-type: decimal">
<li>Graphite-Web</li>
<li>Carbon</li>
<li>Whisper</li>
</ol>
<p>Graphite-Web is a Django application and provides a dashboard for monitoring. Carbon is a server that listens to time-series data, while Whisper is a database library for storing the data.</p>
<h1 id="setting-it-up">Setting it up</h1>
<p>A CentOS 6.8 Virtual Machine (VM) running on KVM is used for the installation. Please make sure that the VM has access to the Internet. The Ansible version used on the host (Parabola GNU/Linux-libre x86_64) is 2.2.1.0. The <em>ansible/</em> folder contains the following files:</p>
<pre><code>ansible/inventory/kvm/inventory
ansible/playbooks/configuration/graphite.yml
ansible/playbooks/admin/uninstall-graphite.yml</code></pre>
<p>The IP address of the guest CentOS 6.8 VM is added to the <em>inventory</em> file as shown below:</p>
<pre><code>graphite ansible_host=192.168.122.120 ansible_connection=ssh ansible_user=root ansible_password=password</code></pre>
<p>Also, add an entry for the <em>graphite</em> host in <em>/etc/hosts</em> file as indicated below:</p>
<pre><code>192.168.122.120 graphite</code></pre>
<h1 id="graphite">Graphite</h1>
<p>The playbook to install the Graphite server is given below:</p>
<pre><code>---
- name: Install Graphite software
  hosts: graphite
  gather_facts: true
  tags: [graphite]

  tasks:
    - name: Import EPEL GPG key
      rpm_key:
        key: http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
        state: present

    - name: Add YUM repo
      yum_repository:
        name: epel
        description: EPEL YUM repo
        baseurl: https://dl.fedoraproject.org/pub/epel/$releasever/$basearch/
        gpgcheck: yes

    - name: Update the software package repository
      yum:
        name: '*'
        update_cache: yes

    - name: Install Graphite server
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - graphite-web</code></pre>
<p>We first import the keys for the Extra Packages for Enterprise Linux (EPEL) repository and update the software package list. The ‘graphite-web’ package is then installed using Yum. The above playbook can be invoked using the following command:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/graphite.yml --tags &quot;graphite&quot;</code></pre>
<h1 id="mysql">MySQL</h1>
<p>A backend database is required by Graphite. By default, the SQLite3 database is used, but we will install and use MySQL as shown below:</p>
<pre><code>- name: Install MySQL
  hosts: graphite
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [database]

  tasks:
    - name: Install database
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - mysql
        - mysql-server
        - MySQL-python
        - libselinux-python

    - name: Start mysqld server
      service:
        name: mysqld
        state: started

    - wait_for:
        port: 3306

    - name: Create graphite database user
      mysql_user:
        name: graphite
        password: graphite123
        priv: '*.*:ALL,GRANT'
        state: present

    - name: Create a database
      mysql_db:
        name: graphite
        state: present

    - name: Update database configuration
      blockinfile:
        path: /etc/graphite-web/local_settings.py
        block: |
          DATABASES = {
            'default': {
            'NAME': 'graphite',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'graphite',
            'PASSWORD': 'graphite123',
           }
          }

    - name: syncdb
      shell: /usr/lib/python2.6/site-packages/graphite/manage.py syncdb --noinput

    - name: Allow port 80
      shell: iptables -I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT

    - name:
      lineinfile:
        path: /etc/httpd/conf.d/graphite-web.conf
        insertafter: '           # Apache 2.2'
        line: '           Allow from all'

    - name: Start httpd server
      service:
        name: httpd
        state: started</code></pre>
<p>As a first step, let’s install the required MySQL dependency packages and the server itself. We then start the server and wait for it to listen on port 3306. A graphite user and database is created for use with the Graphite Web application. For this example, the password is provided as plain text. In production, use an encrypted Ansible Vault password.</p>
<p>The database configuration file is then updated to use the MySQL credentials. Since Graphite is a Django application, the <em>manage.py</em> script with <em>syncdb</em> needs to be executed to create the necessary tables. We then allow port 80 through the firewall in order to view the Graphite dashboard. The <em>graphite-web.conf</em> file is updated to allow read access, and the Apache web server is started.</p>
<p>The above playbook can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/graphite.yml --tags &quot;database&quot;</code></pre>
<h1 id="carbon-and-whisper">Carbon and Whisper</h1>
<p>The Carbon and Whisper Python bindings need to be installed before starting the <em>carbon-cache</em> script.</p>
<pre><code>- name: Install Carbon and Whisper
  hosts: graphite
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [carbon]

  tasks:
    - name: Install carbon and whisper
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - python-carbon
        - python-whisper

    - name: Start carbon-cache
      shell: /etc/init.d/carbon-cache start</code></pre>
<p>The above playbook is invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/graphite.yml --tags &quot;carbon&quot;</code></pre>
<h1 id="dashboard">Dashboard</h1>
<p>You can open <a href="http://192.168.122.120"><code class="url">http://192.168.122.120</code></a> in the browser on the host to view the Graphite dashboard. A screenshot of the Graphite web application is shown below:</p>
<img width="800" alt="Graphite dashboard" src="http://shakthimaan.com/images/2017/osfy-devops/5-graphite/graphite-screenshot.png">
<h1 id="uninstall">Uninstall</h1>
<p>An uninstall script to remove the Graphite server and its dependency packages is required for administration. The Ansible playbook for the same is available in <em>playbooks/admin</em> folder and is given below:</p>
<pre><code>---
- name: Uninstall Graphite and dependencies
  hosts: graphite
  gather_facts: true
  tags: [remove]

  tasks:
    - name: Stop the carbon-cache server
      shell: /etc/init.d/carbon-cache stop

    - name: Uninstall carbon and whisper
      package:
        name: &quot;{{ item }}&quot;
        state: absent
      with_items:
        - python-whisper
        - python-carbon

    - name: Stop httpd server
      service:
        name: httpd
        state: stopped

    - name: Stop mysqld server
      service:
        name: mysqld
        state: stopped

    - name: Uninstall database packages
      package:
        name: &quot;{{ item }}&quot;
        state: absent
      with_items:
        - libselinux-python
        - MySQL-python
        - mysql-server
        - mysql
        - graphite-web</code></pre>
<p>The script can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/admin/uninstall-graphite.yml</code></pre>
<h1 id="references">References</h1>
<ol style="list-style-type: decimal">
<li><p>Graphite documentation. <a href="https://graphite.readthedocs.io/en/latest/"><code class="url">https://graphite.readthedocs.io/en/latest/</code></a></p></li>
<li><p>Carbon. <a href="https://github.com/graphite-project/carbon"><code class="url">https://github.com/graphite-project/carbon</code></a></p></li>
<li><p>Whisper database. <a href="http://graphite.readthedocs.io/en/latest/whisper.html"><code class="url">http://graphite.readthedocs.io/en/latest/whisper.html</code></a></p></li>
</ol>]]></description>
    <pubDate>Thu, 28 Dec 2017 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/12/28/devops-ansible-graphite/news.html</guid>
</item>
<item>
    <title>Ansible deployment of RabbitMQ</title>
    <link>http://www.shakthimaan.com/posts/2017/12/01/devops-ansible-rabbitmq/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, June 2017 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>In this fourth article in the DevOps series, we will learn to install RabbitMQ using Ansible. RabbitMQ is a free and open source message broker system that supports a number of protocols such as the Advanced Message Queuing Protocol (AMQP), Streaming Text Oriented Messaging Protocol (STOMP) and Message Queue Telemetry Transport (MQTT). The software has support for a large number of client libraries for different programming languages. RabbitMQ is written using the Erlang programming language and is released under the Mozilla Public License.</p>
<h1 id="setting-it-up">Setting it up</h1>
<p>A CentOS 6.8 virtual machine (VM) running on KVM is used for the installation. Do make sure that the VM has access to the Internet. The Ansible version used on the host (Parabola GNU/Linux-libre x86_64) is 2.2.1.0. The ansible/ folder contains the following files:</p>
<pre><code>ansible/inventory/kvm/inventory
ansible/playbooks/configuration/rabbitmq.yml
ansible/playbooks/admin/uninstall-rabbitmq.yml</code></pre>
<p>The IP address of the guest CentOS 6.8 VM is added to the <em>inventory</em> file as shown below:</p>
<pre><code>rabbitmq ansible_host=192.168.122.161 ansible_connection=ssh ansible_user=root ansible_password=password</code></pre>
<p>Also, add an entry for the <em>rabbitmq</em> host in the <em>/etc/hosts</em> file as indicated below:</p>
<pre><code>192.168.122.161 rabbitmq</code></pre>
<h1 id="installation">Installation</h1>
<p>RabbitMQ requires the Erlang environment, and uses the Open Telecom Platform (OTP) framework. There are multiple sources for installing Erlang - the EPEL repository, Erlang Solutions, zero-dependency Erlang provided by RabbitMQ. In this article, we will use the EPEL repository for installing Erlang.</p>
<pre><code>---
- name: Install RabbitMQ server
  hosts: rabbitmq
  gather_facts: true
  tags: [server]

  tasks:
    - name: Import EPEL GPG key
      rpm_key:
        key: http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
        state: present

    - name: Add YUM repo
      yum_repository:
        name: epel
        description: EPEL YUM repo
        baseurl: https://dl.fedoraproject.org/pub/epel/$releasever/$basearch/
        gpgcheck: yes

    - name: Update the software package repository
      yum:
        name: '*'
        update_cache: yes

    - name: Install RabbitMQ server
      package:
        name: &quot;{{ item }}&quot;
        state: latest
      with_items:
        - rabbitmq-server

    - name: Start the RabbitMQ server
      service:
        name: rabbitmq-server
        state: started

    - wait_for:
        port: 5672</code></pre>
<p>After importing the EPEL GPG key and adding the EPEL repository to the system, the <em>yum update</em> command is executed. The RabbitMQ server and its dependencies are then installed. We wait for the RabbitMQ server to start and to listen on port 5672. The above playbook can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/rabbitmq.yml --tags &quot;server&quot;</code></pre>
<h1 id="dashboard">Dashboard</h1>
<p>The RabbitMQ management user interface (UI) is available through plugins.</p>
<pre><code>- name: Start RabbitMQ Management UI
  hosts: rabbitmq
  gather_facts: true
  tags: [ui]

  tasks:
    - name: Start management UI
      command: /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management

    - name: Restart RabbitMQ server
      service:
        name: rabbitmq-server
        state: restarted

    - wait_for:
        port: 15672

    - name: Allow port 15672
      shell: iptables -I INPUT 5 -p tcp --dport 15672 -m state --state NEW,ESTABLISHED -j ACCEPT</code></pre>
<p>After enabling the management plugin, the server needs to be restarted. Since we are running it inside the VM, we need to allow the management user interface (UI) port 15672 through the firewall. The playbook invocation to set up the management UI is given below:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/rabbitmq.yml --tags &quot;ui&quot;</code></pre>
<p>The default user name and password for the dashboard are ‘guest:guest’. From your host system, you can start a browser and open <em>http://192.168.122.161:15672</em> to view the login page as shown in Figure 1. The default ‘Overview’ page is shown in Figure 2.</p>
<img alt="RabbitMQ Login" src="http://shakthimaan.com/images/2017/osfy-devops/4-rabbitmq/1-rabbitmq-ui-login.png"><br />
<img width="800" alt="RabbitMQ Overview" src="http://shakthimaan.com/images/2017/osfy-devops/4-rabbitmq/2-rabbitmq-ui-overview.png">
<h1 id="ruby">Ruby</h1>
<p>We will use a Ruby client example to demonstrate that our installation of RabbitMQ is working fine. The Ruby Version Manager (RVM) will be used to install Ruby as shown below:</p>
<pre><code>- name: Ruby client
  hosts: rabbitmq
  gather_facts: true
  tags: [ruby]

  tasks:
    - name: Import key
      command: gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

    - name: Install RVM
      shell: curl -sSL https://get.rvm.io | bash -s stable

    - name: Install Ruby
      shell: source /etc/profile.d/rvm.sh &amp;&amp; rvm install ruby-2.2.6

    - name: Set default Ruby
      command: rvm alias create default ruby-2.2.6

    - name: Install bunny client
      shell: gem install bunny --version &quot;&gt;= 2.6.4&quot;</code></pre>
<p>After importing the required GPG keys, RVM and Ruby 2.2.6 are installed on the CentOS 6.8 VM. The <em>bunny</em> Ruby client for RabbitMQ is then installed. The Ansible playbook to setup Ruby is given below:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/rabbitmq.yml --tags &quot;ruby&quot;</code></pre>
<p>We shall create a ‘temperature’ queue to send the values in Celsius. The <em>consumer.rb</em> code to receive the values from the queue is given below:</p>
<pre><code>#!/usr/bin/env ruby

require &quot;bunny&quot;

conn = Bunny.new(:automatically_recover =&gt; false)
conn.start

chan  = conn.create_channel
queue = chan.queue(&quot;temperature&quot;)

begin
  puts &quot; ... waiting. CTRL+C to exit&quot;
  queue.subscribe(:block =&gt; true) do |info, properties, body|
    puts &quot; Received #{body}&quot;
  end
rescue Interrupt =&gt; _
  conn.close

  exit(0)
end</code></pre>
<p>The <em>producer.rb</em> code to send a sample of five values in degree Celsius is as follows:</p>
<pre><code>#!/usr/bin/env ruby

require &quot;bunny&quot;

conn = Bunny.new(:automatically_recover =&gt; false)
conn.start

chan   = conn.create_channel
queue   = chan.queue(&quot;temperature&quot;)

values = [&quot;33.5&quot;, &quot;35.2&quot;, &quot;36.7&quot;, &quot;37.0&quot;, &quot;36.4&quot;]

values.each do |v|
  chan.default_exchange.publish(v, :routing_key =&gt; queue.name)
end
puts &quot;Sent five temperature values.&quot;

conn.close</code></pre>
<p>As soon as you start the consumer, you will get the following output:</p>
<pre><code>$ ruby consumer.rb 
 ... waiting. CTRL+C to exit</code></pre>
<p>You can then run the <em>producer.rb</em> script that writes the values to the queue:</p>
<pre><code>$ ruby producer.rb

Sent five temperature values.</code></pre>
<p>The received values at the consumer side are printed out as shown below:</p>
<pre><code>$ ruby consumer.rb 
 ... waiting. CTRL+C to exit
 Received 33.5
 Received 35.2
 Received 36.7
 Received 37.0
 Received 36.4</code></pre>
<p>We can observe the available connections and the created queue in the management user interface as shown in Figure 3 and Figure 4, respectively.</p>
<img width="800" alt="RabbitMQ Connections" src="http://shakthimaan.com/images/2017/osfy-devops/4-rabbitmq/3-rabbitmq-ui-connections.png">
<img width="800" alt="RabbitMQ Queues" src="http://shakthimaan.com/images/2017/osfy-devops/4-rabbitmq/4-rabbitmq-ui-queues.png">
<h1 id="uninstall">Uninstall</h1>
<p>It is good to have an uninstall script to remove the RabbitMQ server for administrative purposes. The Ansible playbook for the same is available in the <em>playbooks/admin</em> folder and is shown below:</p>
<pre><code>---
- name: Uninstall RabbitMQ server
  hosts: rabbitmq
  gather_facts: true
  tags: [remove]

  tasks:
    - name: Stop the RabbitMQ server
      service:
        name: rabbitmq-server
        state: stopped

    - name: Uninstall rabbitmq
      package:
        name: &quot;{{ item }}&quot;
        state: absent
      with_items:
        - rabbitmq-server</code></pre>
<p>The script can be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/admin/uninstall-rabbitmq.yml</code></pre>
<p>You are encouraged to read the detailed documentation at <a href="https://www.rabbitmq.com/documentation.html">https://www.rabbitmq.com/documentation.html</a> to know more about the usage, configuration, client libraries and plugins available for RabbitMQ.</p>]]></description>
    <pubDate>Fri, 01 Dec 2017 13:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/12/01/devops-ansible-rabbitmq/news.html</guid>
</item>
<item>
    <title>Ansible deployment of Cacti for Monitoring</title>
    <link>http://www.shakthimaan.com/posts/2017/11/20/devops-ansible-cacti/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, May 2017 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>In this third article in the DevOps series, we will install and set up Cacti, a free and open source Web-based network monitoring and graphing tool, using Ansible. Cacti is written in PHP and uses the MySQL database as a backend. It uses the RRDtool (Round-Robin Database tool) to handle time series data and has built-in SNMP support. Cacti has been released under the GNU General Public License.</p>
<h1 id="setting-up-cacti">Setting up Cacti</h1>
<p>We will use a CentOS 6.8 virtual machine (VM) running on KVM to setup Cacti. Just for this demonstration, we will disable SELinux. You will need to set the following in <em>/etc/selinux/config</em> and reboot the VM.</p>
<pre><code>SELINUX=disabled</code></pre>
<p>When using in production, it is essential that you enable SELinux. You should then test for Internet connectivity from within the VM.</p>
<p>The Ansible version used on the host Parabola GNU/Linux-libre x86_64 is 2.2.1.0. The <em>ansible/inventory/kvm/</em> directory structure is shown below:</p>
<pre><code>ansible/inventory/kvm/inventory
ansible/inventory/kvm/group_vars/all/all.yml</code></pre>
<p>The IP address of the guest CentOS 6.8 VM is provided in the inventory file as shown below:</p>
<pre><code>centos ansible_host=192.168.122.98 ansible_connection=ssh ansible_user=root ansible_password=password</code></pre>
<p>Add an entry for ‘centos’ in the /etc/hosts file as indicated below:</p>
<pre><code>192.168.122.98 centos</code></pre>
<p>The contents of the <em>all.yml</em> for use with the playbook are as follows:</p>
<pre><code>---
mysql_cacti_password_hash: &quot;{{ vault_mysql_cacti_password_hash }}&quot;

mysql_username: &quot;{{ vault_mysql_user }}&quot;
mysql_password: &quot;{{ vault_mysql_password }}&quot;</code></pre>
<p>The cacti.yml playbook is located in the <em>ansible/playbooks/configuration</em> folder.</p>
<h1 id="vault">Vault</h1>
<p>Ansible provides the Vault feature, which allows you to store sensitive information like passwords in encrypted files. You can set the EDITOR environment variable to the text editor of your choice, as shown below:</p>
<pre><code>$ export EDITOR=nano</code></pre>
<p>In order to store our MySQL database credentials, we will create a <em>vault.yml</em> file as indicated below:</p>
<pre><code>$ ansible-vault create inventory/kvm/group_vars/all/vault.yml</code></pre>
<p>Provide a password when prompted, following which, the Nano text editor will open. You can enter the following credentials and save the file.</p>
<pre><code>---
vault_mysql_cacti_password_hash: &quot;*528573A4E6FE4F3E8B455F2F060EB6F63ECBECAA&quot;

vault_mysql_user: &quot;cacti&quot;
vault_mysql_password: &quot;cacti123&quot;</code></pre>
<p>You can edit the same file, if you wish, using the following command:</p>
<pre><code>$ ansible-vault edit inventory/kvm/group_vars/all/vault.yml</code></pre>
<p>It will prompt you for a password, and on successful authentication, your text editor will open with the decrypted file contents for editing.</p>
<h1 id="apache">Apache</h1>
<p>Cacti has many dependency packages, and the first software that we will install is the Apache HTTP server.</p>
<pre><code>---
- name: Install web server
  hosts: centos
  gather_facts: true
  tags: [httpd]

  tasks:
    - name: Update the software package repository
      yum:
	name: '*'
	update_cache: yes

    - name: Install HTTP packages
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- wget
	- nano
	- httpd
	- httpd-devel

    - name: Start the httpd server
      service:
	name: httpd
	state: started

    - wait_for:
	port: 80</code></pre>
<p>A ‘yum update’ is first performed to sync with the package repositories. The <em>httpd</em> Web server and a few other packages are then installed. The server is started, and the Ansible playbook waits for the server to listen on port 80.</p>
<h1 id="mysql-and-php">MySQL and PHP</h1>
<p>The MySQL, PHP and RRDTool packages are then installed, following which the SNMP and MySQL servers are started as shown below:</p>
<pre><code>- name: Install MySQL, PHP packages
  hosts: centos
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [database-web]

  tasks:
    - name: Install database/web packages
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- mysql
	- mysql-server
	- MySQL-python
	- php-mysql
	- php-pear
	- php-common
	- php-gd
	- php-devel
	- php
	- php-mbstring
	- php-cli
	- php-process
	- php-snmp
	- net-snmp-utils
	- net-snmp-libs
	- rrdtool

    - name: Start snmpd server
      service:
	name: snmpd
	state: started

    - name: Start mysqld server
      service:
	name: mysqld
	state: started

    - wait_for:
	port: 3306</code></pre>
<h1 id="cacti">Cacti</h1>
<p>Cacti is available in the EPEL repository for CentOS. The GPG key for the CentOS repositories is enabled before installing the EPEL repository. A ‘yum update’ is performed and the Cacti package is installed. A ‘cacti’ user is then created in the MySQL database.</p>
<pre><code>- name: Install Cacti
  hosts: centos
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [cacti]

  tasks:
    - name: Import EPEL GPG key
      rpm_key:
	key: http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
	state: present

    - name: Add YUM repo
      yum_repository:
	name: epel
	description: EPEL YUM repo
	baseurl: https://dl.fedoraproject.org/pub/epel/$releasever/$basearch/
	gpgcheck: yes

    - name: Update the software package repository
      yum:
	name: '*'
	update_cache: yes

    - name: Install cacti
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- cacti

    - name: Create cacti database user
      mysql_user:
	name: cacti
	password: &quot;{{ mysql_cacti_password_hash }}&quot;
	encrypted: yes
	priv: '*.*:ALL,GRANT'
	state: present</code></pre>
<h1 id="fixing-a-bug">Fixing a bug</h1>
<p>The time zone data is missing in this MySQL version (5.1.73-8). In order to resolve this bug, the <em>mysql_test_data_timezone.sql</em> file needs to be imported and the ‘cacti’ user needs to be given the SELECT privilege to do this.</p>
<pre><code>- name: For bug https://github.com/Cacti/cacti/issues/242
  hosts: centos
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [bug]

  tasks:
    - name: Import mysql_test_data_timezone.sql
      mysql_db:
	state: import
	name: mysql
	target: /usr/share/mysql/mysql_test_data_timezone.sql

    - name: Grant privileges
      mysql_user:
	name: cacti
	append_privs: true
	priv: 'mysql.time_zone_name:SELECT'
	state: present</code></pre>
<p>It is a good practice to have a separate playbook for such exceptional cases. In future, when you upgrade to newer versions that have bug fixes, you can simply skip this step.</p>
<h1 id="configuration">Configuration</h1>
<p>The last step involves configuring Cacti.</p>
<pre><code>- name: Configuration
  hosts: centos
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [config]

  tasks:
    - name: Create a database for cacti
      mysql_db:
	name: cacti
	state: present

    - name: Import cacti.sql
      mysql_db:
	state: import
	name: cacti
	target: /usr/share/doc/cacti-1.0.4/cacti.sql

    - name: Update database credentials in config file
      lineinfile:
	dest: /etc/cacti/db.php
	regexp: &quot;{{ item.regexp }}&quot;
	line: &quot;{{ item.line }}&quot;
      with_items:
	- { regexp: '^\$database_username', line: &quot;$database_username = '{{ mysql_username }}';&quot; }
	- { regexp: '^\$database_password', line: &quot;$database_password = '{{ mysql_password }}';&quot; }

    - name: Allow port 80
      shell: iptables -I INPUT 5 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT

    - name: Update access in cacti.conf for httpd
      replace:
	dest: /etc/httpd/conf.d/cacti.conf
	regexp: &quot;{{ item.regexp }}&quot;
	replace: &quot;{{ item.replace }}&quot;
      with_items:
	- { regexp: 'Require host localhost', replace: 'Require all granted' }
	- { regexp: 'Allow from localhost', replace: 'Allow from all' }

    - lineinfile:
	dest: /etc/cron.d/cacti
	regexp: '^#(.*)$'
	line: '\1'
	backrefs: yes    

    - name: Start mysqld server
      service:
	name: mysqld
	state: restarted

    - wait_for:
	port: 3306

    - name: Start the httpd server
      service:
	name: httpd
	state: restarted

    - wait_for:
	port: 80</code></pre>
<p>A database called ‘cacti’ is created for the application, and the <em>cacti.sql</em> file is imported into it. The database credentials are updated for the Cacti application. The firewall rules are then updated to allow incoming HTTP requests for port 80. The periodic cron poller is then enabled in <em>/etc/cron.d/cacti</em>:</p>
<pre><code>*/5 * * * *     cacti   /usr/bin/php /usr/share/cacti/poller.php &gt; /dev/null 2&gt;&amp;1</code></pre>
<p>The MySQL and HTTP servers are then restarted.</p>
<h1 id="the-result">The result</h1>
<p>The entire playbook can now be invoked as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/cacti.yml --ask-vault-pass</code></pre>
<p>It will prompt you for the Vault password, following which all the playbooks will be completed. You can then open <a href="http://192.168.122.98/cacti"><code class="url">http://192.168.122.98/cacti</code></a> to accept the GNU General Public License agreement. After you agree to the terms of the license, click ‘Next’. The Cacti installation wizard shows the pre-installation checks, which should not have any errors. This is followed by the selection of the installation type, binary location, version, and the directory permission checks. You can then decide on the templates you would like to set up, following which a user login is provided. The default user name and password is ‘admin:admin’, and you will be immediately prompted to change the password after logging in. You can then proceed to log in to the Cacti dashboard. Figures 1 to 8 give the screenshots of the Cacti Web UI installation for reference.</p>
<img width="800" alt="License Agreement" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/1-License-agreement.png"><br />
<img width="800" alt="Pre-installation checks" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/2-Pre-installation-checks.png"><br />
<img width="800" alt="Installation type" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/3-Installation-type.png"><br />
<img width="800" alt="Binary location and version" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/4-Binary-location-and-version.png"><br />
<img width="800" alt="Directory permission checks" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/5-Directory-permission-checks.png"><br />
<img width="800" alt="Template setup" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/6-Template-setup.png"><br />
<img width="800" alt="User login" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/7-User-login.png"><br />
<img width="800" alt="Change password" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/8-Change-password.png"><br />
<p>A screenshot of Cacti graphing for memory usage is shown in Figure 9.</p>
<img width="800" alt="Cacti Web UI" src="http://www.shakthimaan.com/images/2017/osfy-devops/3-cacti/9-Cacti.png">]]></description>
    <pubDate>Mon, 20 Nov 2017 19:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/11/20/devops-ansible-cacti/news.html</guid>
</item>
<item>
    <title>Science Hack Day India 2017, Belgaum</title>
    <link>http://www.shakthimaan.com/posts/2017/10/30/shd-2017-belgaum/news.html</link>
    <description><![CDATA[<h1 id="day-0">Day 0</h1>
<p>I arrived at <a href="https://en.wikipedia.org/wiki/Belgaum">Belgaum</a> on Friday, October 13, 2017 morning by train, and headed to the <a href="http://sankalphospitality.in/">Sankalp Bhumi</a> resort. I was given the <a href="http://sankalphospitality.in/lens_portfolio/cottages-tapas-dhyan">Rock Cottage Dhyan</a> (“meditation”) for my stay. After freshening up and having breakfast, I started to explore the resort. The place was an abandoned stone quarry that has been converted into a beautiful resort spread over an area of eight acres. It is a very quiet, peaceful place with trees, lawns, and water bodies. A number of fellow hackers and mentors also started arriving at the venue, and we were just getting ready for the day’s events.</p>
<img alt="Banner" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125247-b8bee464.jpg"></img>
<p>After lunch, we headed to the large function hall where volunteers were to be trained on soldering. <a href="http://jithinbp.in/">Jithin B. P.</a> had prepared a simple PCB layout with LEDs and potentiometers for volunteers to practice soldering. These volunteers will help school students in the soldering workshops in the coming two days at the event.</p>
<img alt="Training volunteers for soldering" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125315-12487dbe.jpg"></img>
<p>In the evening, I had suggested to <a href="https://www.gnovi.in/">Praveen Patil</a> and <a href="http://mason.gmu.edu/~hdharmda/">Hitesh Dharmdasani</a> to have an informal BoF session. So, everyone got together under one roof, and Hitesh explained how and why they started SHD. There were a round of introductions followed by open discussions. After dinner, some of our fellow hackers headed to the hackerspace (“cafeteria”) to test the Wi-Fi, and prepare for the next day’s hacks.</p>
<h1 id="day-1">Day 1</h1>
<p>The volunteers arrived in the morning to ready the registration desk and prepare the name cards. Science Hack Day banners were placed at various locations in the premises. After breakfast, everyone gathered at the function hall for an informal inauguration. This was followed by a 30-minute introduction on Aeromodelling by Mr. Arjun Bilawar (retired trainer, NCC Karnataka and Goa Directorate). It had rained heavily last evening and hence a nearby playground was not suitable to demo the aeroplane. Mr. Arjun then took us to a nearby open area, and with a short runway, he was able to lift off the model plane, and flew it for few minutes to the loud cheers from the students.</p>
<img alt="Aeromodelling session" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125332-3759fc1e.jpg"></img>
<p>We then headed to the hackerspace to start work on our projects. <a href="https://siddhesh.in/">Siddhesh</a> and other hackers began to build a 3D printer. Shreyas K was building an image detector to be used in his college to detect students jumping off the wall in his college premises. This was covered in the news, <a href="http://epaper.tarunbharat.com/m5/1395867/Tarun-Bharat/BELGAUM#page/7/1">Tarun Bharat</a>.</p>
<img alt="Ganesh Kumar and Shreyas K" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125344-f0fbe7a5.jpg"></img>
<p>Students from Kerala were working on a Bat detector. Few students were creating 3D artefacts using the 3D pen from <a href="https://reserved-bit.com/">reserved-bit</a>. Hitesh Dharmdasani had brought his company’s (<a href="https://informantnetworks.com/">Informant Networks</a>) Banana Pi based-router for hacking. <a href="http://vaishalithakkar.in/">Vaishali Thakkar</a> was working on the <a href="https://tessel.io/">Tessel</a> board and <a href="https://www.rust-lang.org/en-US/">Rust</a>. I was setting up the <a href="http://icoboard.org/">Icoboard</a> with <a href="https://www.raspberrypi.org/products/raspberry-pi-3-model-b/">Raspberry Pi 3 Model B</a> to demonstrate chip design on free and open source hardware.</p>
<p>The school students were divided into two groups. One group attended the soldering workshop in the function hall, and the other group participated in the science toys workshop in an open arena. The groups will swap the workshops the following day. In another sit out area, biology students had brought specimens from the labs to showcase them. A team of architects were also creating a geodesic dome that can be used as a makerspace.</p>
<p>In the evening at 1830 IST, we had lightning talks, and I had presented the latest version of <a href="http://shakthimaan.com/downloads.html#nursery-rhymes">“Nursery Rhymes”</a>. There were other interesting talks on embedded hardware, security, product design, mechanics of a bicycle, biogas etc. It was a long day!</p>
<img alt="Gautam Samant" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125405-619f7e62.jpg"></img>
<h1 id="day-2">Day 2</h1>
<p>The second day of the event began with a video conferencing session with <a href="http://sf.sciencehackday.org/">Science Hack Day, San Francisco</a>. Their event was scheduled on October 14-15, 2017 at the GitHub office. <a href="http://arielwaldman.com/">Ariel Waldman</a> used the webcam to show around their hackerspace. The students then headed to their respective soldering and science toys workshops. Some of the toys and experiments were from <a href="http://www.arvindguptatoys.com/toys.html">Arvind Gupta</a>. The hackers at the makerspace continued working on their projects. All the hacks had to be completed by noon, as they have to be demoed and voted for in the evening.</p>
<img alt="Science toys workshop" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125428-b24e02c2.jpg"></img>
<p>After lunch, there was a rocket session where students launched rockets prepared by experts. We also had a group photo session, and headed to the function hall. All the hacks were presented to the students, and parents were also invited to attend the evening session. There was also an audience voting poll to choose their favourite science hack. After demonstrating the Icoboard, I had to rush to catch the train back to Bengaluru, so I did miss the closing ceremony.</p>
<img alt="Group photo" src="https://www.shakthimaan.in/gallery/upload/2017/10/30/20171030125449-15c704c9.jpg"></img>
<p>My hearty congratulations to the organizers of Science Hack Day India 2017, Belgaum for a wonderful event that motivates students to learn and experiment with science.</p>
<p>I have uploaded over 80 photos during the trip to my new <a href="https://www.shakthimaan.in/gallery/index.php?/category/24">gallery</a>. Do browse through them leisurely!</p>]]></description>
    <pubDate>Mon, 30 Oct 2017 16:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/10/30/shd-2017-belgaum/news.html</guid>
</item>
<item>
    <title>Ansible deployment of (G/)LAMP and WordPress</title>
    <link>http://www.shakthimaan.com/posts/2017/09/27/devops-ansible-glamp-wordpress/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, April 2017 edition.]</em></p>
<p>This is the second article in the DevOps series, and covers the installation of a (G/)LAMP stack and WordPress, using Ansible.</p>
<h1 id="introduction">Introduction</h1>
<p>In this article, we are going to learn how to automate the deployment of a (G/)LAMP stack and install WordPress. (G/)LAMP stands for GNU/Linux, Apache (a web server), MySQL (a database) and PHP (server-side scripting). It is a technology stack on which you can deploy different web applications. We are also going to explore the installation of WordPress, which is free and open source software for creating websites and blogs.</p>
<h1 id="linux">Linux</h1>
<p>A Parabola GNU/Linux-libre x86_64 system is used as the host system. An Ubuntu 15.04 image runs as a guest OS using KVM/QEMU. Ansible is installed on the host system using the distribution package manager. You should be able to issue commands from Ansible to the guest OS. For example:</p>
<pre><code>$ ansible ubuntu -m ping

ubuntu | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}</code></pre>
<p>The <em>/etc/hosts</em> file already has an entry for the guest Ubuntu VM.</p>
<pre><code>192.168.122.250 ubuntu</code></pre>
<p>On the host system, we will create a project for our playbooks. It has the following directory structure:</p>
<pre><code>ansible/inventory/kvm/
       /playbooks/configuration/
       /playbooks/admin/</code></pre>
<p>An ‘inventory’ file is created inside the <em>inventory/kvm</em> folder that contains the following:</p>
<pre><code>ubuntu ansible_host=192.168.122.250 ansible_connection=ssh ansible_user=xetex</code></pre>
<h1 id="installing-apache">Installing Apache</h1>
<p>We will first install and test the Apache web server on the guest Ubuntu system. Let’s then create a <em>playbooks/configuration/apache.yml</em> file with the following content:</p>
<pre><code>---
- name: Install Apache web server
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [web]

  tasks:
    - name: Update the software package repository
      apt:
	update_cache: yes

    - name: Install Apache
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- apache2

    - wait_for:
	port: 80</code></pre>
<p>On the Ubuntu guest system, the playbook runs <em>apt-get update</em> and then installs the <em>apache2</em> package. The playbook finishes after the server has started, and is listening on port 80. Open a terminal, enter the ansible/ folder, and execute the playbook as shown below:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/apache.yml -K 
SUDO password: 

PLAY [Install Apache web server] ***********************************************

TASK [setup] *******************************************************************
ok: [ubuntu]

TASK [Update the software package repository] **********************************
changed: [ubuntu]

TASK [Install Apache] **********************************************************
changed: [ubuntu] =&gt; (item=[u'apache2'])

TASK [wait_for] ****************************************************************
ok: [ubuntu]

PLAY RECAP *********************************************************************
ubuntu                     : ok=4    changed=2    unreachable=0    failed=0   </code></pre>
<p>The ’-K’ option is to prompt for the sudo password for the ‘xetex’ user. You can increase the level of verbosity in the Ansible output by passing ’-vvvv’ at the end of the <em>ansible-playbook</em> command. The more number of times ‘v’ occurs, the greater is the verbosity level.</p>
<p>If you now open <em>http://192.168.122.250</em>, you should be able to see the default Apache2 <em>index.html</em> page as shown in Figure 1:</p>
<img alt="Apache2 Ubuntu default page" src="http://www.shakthimaan.com/images/2017/osfy-devops/apache2-default-index-page.png"></img>
<h1 id="installing-mysql">Installing MySQL</h1>
<p>The next step is to install the MySQL database server. The corresponding playbook is provided below:</p>
<pre><code>---
- name: Install MySQL database server
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [database]

  tasks:
    - name: Update the software package repository
      apt:
	update_cache: yes

    - name: Install MySQL
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- mysql-server
	- mysql-client
	- python-mysqldb

    - name: Start the server
      service:
	name: mysql
	state: started

    - wait_for:
	port: 3306

    - mysql_user:
	name: guest
	password: '*F7B659FE10CA9FAC576D358A16CC1BC646762FB2'
	encrypted: yes
	priv: '*.*:ALL,GRANT'
	state: present</code></pre>
<p>The package repository is updated and the necessary MySQL packages are installed. The database server is then started, and we wait for the server to be up and running. A ‘guest’ user account with ‘osfy’ as the password is created for use in our web application. The chosen password is just for demonstration purposes. When used in production, please select a strong password with special characters and numerals.</p>
<p>You can compute the hash for a password from the MySQL client, as shown below:</p>
<pre><code>mysql&gt; SELECT PASSWORD('osfy');
+-------------------------------------------+
| PASSWORD('osfy')                          |
+-------------------------------------------+
| *F7B659FE10CA9FAC576D358A16CC1BC646762FB2 |
+-------------------------------------------+
1 row in set (0.00 sec)</code></pre>
<p>An execution run to install MySQL is as follows:</p>
<pre><code>$ ansible-playbook -i inventory/kvm/inventory playbooks/configuration/mysql.yml -K 
SUDO password: 

PLAY [Install MySQL database server] *******************************************

TASK [setup] *******************************************************************
ok: [ubuntu]

TASK [Update the software package repository] **********************************
changed: [ubuntu]

TASK [Install MySQL] ***********************************************************
changed: [ubuntu] =&gt; (item=[u'mysql-server', u'mysql-client', u'python-mysqldb'])

TASK [Start the server] ********************************************************
ok: [ubuntu]

TASK [wait_for] ****************************************************************
ok: [ubuntu]

TASK [mysql_user] **************************************************************
ok: [ubuntu]

PLAY RECAP *********************************************************************
ubuntu                     : ok=6    changed=2    unreachable=0    failed=0   </code></pre>
<p>Note: The default MySQL root password is empty. You should change it after installation.</p>
<h1 id="installing-php">Installing PHP</h1>
<p>PHP is a server-side programming language and stands for PHP: Hypertext Preprocessor (a recursive acronym). Although we have used PHP5 in ths example, it is recommended that you use the latest PHP for security reasons. The Ansible playbook for installing PHP is given below:</p>
<pre><code>---
- name: Install PHP
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [web]

  tasks:
    - name: Update the software package repository
      apt:
	update_cache: yes

    - name: Install PHP
      package:
	name: &quot;{{ item }}&quot;
	state: latest
      with_items:
	- php5
	- php5-mysql</code></pre>
<p>We update the software repository and install PHP5. An execution output of the Ansible playbook is shown below:</p>
<pre><code>$  ansible-playbook -i inventory/kvm/inventory playbooks/configuration/php.yml -K 
SUDO password: 

PLAY [Install PHP] *************************************************************

TASK [setup] *******************************************************************
ok: [ubuntu]

TASK [Update the software package repository] **********************************
changed: [ubuntu]

TASK [Install PHP] *************************************************************
changed: [ubuntu] =&gt; (item=[u'php5', u'php5-mysql'])

PLAY RECAP *********************************************************************
ubuntu                     : ok=3    changed=2    unreachable=0    failed=0  </code></pre>
<h1 id="installing-wordpress">Installing WordPress</h1>
<p>As a final step, we will download, install and set up WordPress. The complete playbook is as follows:</p>
<pre><code>---
- name: Setup Wordpress
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [database]

  vars:
    wordpress_file: &quot;/home/{{ ansible_user }}/Downloads/wordpress-latest.zip&quot;
    wordpress_dest: &quot;/var/www/html&quot;

  tasks:
    - name: Update the software package repository
      apt:
	update_cache: yes

    - name: Create a database for wordpress
      mysql_db:
	name: wordpress
	state: present

    - name: Create downloads directory
      file:
	path: &quot;/home/{{ ansible_user }}/Downloads&quot;
	state: directory

    - name: Create target directory
      file:
	path: &quot;{{ wordpress_dest }}/wordpress&quot;
	state: directory

    - name: Download latest wordpress
      get_url:
	url: https://wordpress.org/latest.zip
	dest: &quot;{{ wordpress_file }}&quot;

    - name: Extract to /var/www/html
      unarchive:
	src: &quot;{{ wordpress_file }}&quot;
	dest: &quot;{{ wordpress_dest}}&quot;
	remote_src: True

    - name: Copy wp-config-sample.php to wp-config.php
      command: cp &quot;{{ wordpress_dest }}/wordpress/wp-config-sample.php&quot; &quot;{{ wordpress_dest }}/wordpress/wp-config.php&quot;

    - name: Update database credentials in the file
      replace:
	dest: &quot;{{ wordpress_dest }}/wordpress/wp-config.php&quot;
	regexp: &quot;{{ item.regexp }}&quot;
	replace: &quot;{{ item.replace }}&quot;
      with_items:
	- { regexp: 'database_name_here', replace: 'wordpress' }
	- { regexp: 'username_here', replace: 'guest' }
	- { regexp: 'password_here', replace: 'osfy'}

    - name: Restart apache2 server
      service:
	name: apache2
	state: restarted</code></pre>
<p>We create variables to store the downloaded file for WordPress, and the target installation path. After updating the software repository, a database is created for the WordPress application. The download and target directories are created on the guest system, before actually downloading the latest WordPress sources. A configuration file is then created, and the database settings are updated. Although we explicitly specify the password here, the recommended practice is to store the encrypted passwords in an Ansible Vault file, and reference the same in the playbook. In future articles, I will demonstrate this use case. After completing the configuration, the web server is restarted. An execution run of the playbook is shown below:</p>
<pre><code> $  ansible-playbook -i inventory/kvm/inventory playbooks/configuration/wordpress.yml -K 
SUDO password: 

PLAY [Setup Wordpress] *********************************************************

TASK [setup] *******************************************************************
ok: [ubuntu]

TASK [Update the software package repository] **********************************
changed: [ubuntu]

TASK [Create a database for wordpress] *****************************************
changed: [ubuntu]

TASK [Create downloads directory] **********************************************
ok: [ubuntu]

TASK [Create target directory] *************************************************
changed: [ubuntu]

TASK [Download latest wordpress] ***********************************************
ok: [ubuntu]

TASK [Extract to /var/www/html] ************************************************
changed: [ubuntu]

TASK [Copy wp-config-sample.php to wp-config.php] ******************************
changed: [ubuntu]

TASK [Update database credentials in the file] *********************************
changed: [ubuntu] =&gt; (item={u'regexp': u'database_name_here', u'replace': u'wordpress'})
changed: [ubuntu] =&gt; (item={u'regexp': u'username_here', u'replace': u'guest'})
changed: [ubuntu] =&gt; (item={u'regexp': u'password_here', u'replace': u'osfy'})

TASK [Restart apache2 server] **************************************************
changed: [ubuntu]

PLAY RECAP *********************************************************************
ubuntu                     : ok=10   changed=7    unreachable=0    failed=0   </code></pre>
<p>If you open the URL <em>http://192.168.122.250/wordpress</em> in a browser on the host system, you will see a screenshot as shown in Figure 2:</p>
<img alt="WordPress default page" src="http://www.shakthimaan.com/images/2017/osfy-devops/wordpress-default.png"></img>
<p>You can now proceed to complete the installation process from the browser. It is recommended that you follow the security best practices as recommended by the WordPress and PHP projects to harden this deployment.</p>
<h1 id="writing-clean-up-playbooks">Writing clean-up playbooks</h1>
<p>It is essential to write clean-up playbooks to revert whatever changes you have made, so that you can roll back the system if things fail. Uninstalling should be done in the reverse order. For example, remove WordPress first, followed by PHP, MySQL and Apache.</p>
<p>The removal of WordPress could depend on your data retention policy. You might want to backup your PHP files, or you may decide to discard them. You might also want to retain the database. A complete removal of WordPress and the (G/)LAMP stack in the playbooks/admin folder is provided below for reference:</p>
<pre><code>---
- name: Uninstall Wordpress
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [web]

  vars:
    wordpress_dest: &quot;/var/www/html&quot;

  tasks:
    - name: Delete wordpress folder
      file:
	path: &quot;{{ wordpress_dest }}/wordpress&quot;
	state: absent

    - name: Drop database
      mysql_db:
	name: wordpress
	state: absent

---
- name: Uninstall PHP
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [web]

  tasks:
    - name: Uninstall PHP packages
      package:
	name: &quot;{{ item }}&quot;
	state: absent
      with_items:
	- php5-mysql
	- php5

---
- name: Uninstall MySQL
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [database]

  tasks:
    - name: Stop the database server
      service:
	name: mysql
	state: stopped

    - name: Uninstall MySQL packages
      package:
	name: &quot;{{ item }}&quot;
	state: absent
      with_items:
	- python-mysqldb
	- mysql-client
	- mysql-server

---
- name: Uninstall Apache web server
  hosts: ubuntu
  become: yes
  become_method: sudo
  gather_facts: true
  tags: [server]

  tasks:
    - name: Stop the web server
      service:
	name: apache2
	state: stopped

    - name: Uninstall apache2
      package:
	name: &quot;{{ item }}&quot;
	state: absent
      with_items:
	- apache2</code></pre>
<p>The entire suite of playbooks is also available in my GitHub project ( <em>https://github.com/shakthimaan/introduction-to-ansible</em> ) for your reference.</p>]]></description>
    <pubDate>Wed, 27 Sep 2017 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/09/27/devops-ansible-glamp-wordpress/news.html</guid>
</item>
<item>
    <title>Introduction to Ansible</title>
    <link>http://www.shakthimaan.com/posts/2017/09/05/devops-ansible-introduction/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, March 2017 edition.]</em></p>
<p>With this article, we begin a new series on DevOps, starting out with Ansible, which helps you to build a strong foundation. As the Ansible website proclaims, proudly, “Deploy apps. Manage systems. Crush complexity.”</p>
<h1 id="introduction">Introduction</h1>
<p>Ansible is an IT automation tool that is used for provisioning, configuration, deployment and managing infrastructure. The project was first released in 2012, and is written in Python. The main objective of the tool is to be simple and easy to use. It is based on an agent-less (push-based) architecture, and the playbooks are written in plain English. Today, it also supports pull-based deployments. Ansible uses SSH to execute commands on remote machines. It is available under the GNU General Public License.</p>
<h1 id="installation">Installation</h1>
<p>You can install Ansible using your GNU/Linux distribution package manager.</p>
<p>On Fedora, you can use Yum to install Ansible, as follows:</p>
<pre><code>$ sudo yum install ansible</code></pre>
<p>If you are using RHEL or CentOS, install the epel-release, and then use the Yum command to install Ansible.</p>
<p>On Ubuntu, you need to add the <em>ppa</em> repository before installing the tool, as shown below:</p>
<pre><code>$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible

$ sudo apt-get update
$ sudo apt-get install ansible</code></pre>
<p>The Ansible documentation encourages Debian users to access the Ubuntu repository to obtain Ansible. You need to add the following line to <em>/etc/apt/sources.list</em>:</p>
<pre><code>deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main</code></pre>
<p>You can then install the software using the following commands:</p>
<pre><code>$ sudo apt-get update
$ sudo apt-get install ansible</code></pre>
<p>The Parabola GNU/Linux-libre distribution is a derivative of Arch Linux, without the binary blobs. You can install Ansible using the <em>pacman</em> utility:</p>
<pre><code>$ pacman -S ansible</code></pre>
<p>The latest Ansible version 2.2 (as of date) is what we will use in this article. Ansible is also available for BSD variants, Mac OS X, and Windows. You are encouraged to refer to the Ansible documentation for more information.</p>
<h1 id="virtualisation">Virtualisation</h1>
<p>Ansible can be used to provision new machines and also configure them. Instead of using bare metal machines, you can create multiple Virtual Machines (VMs) on your system. Lots of Free and Open Source Software (F/OSS) virtualization software is available.</p>
<p>QEMU is a machine emulator and virtualiser. It can also use host CPU support to run guest VMs for better performance. It is written by Fabrice Bellard, and released under the GNU General Public License (GPL). You can install it on Parabola GNU/Linux-libre, using the following command:</p>
<pre><code>$ sudo pacman -S qemu</code></pre>
<p>KVM or Kernel-based Virtual Machine (KVM) has direct support in the Linux kernel. It requires hardware support to be able to run guest operating systems. It is written in C, and is released under the GNU General Public License.</p>
<p>You need to check if your hardware first supports KVM. The ‘lscpu’ command will show an entry for ‘Virtualization’ if there is hardware support. For example:</p>
<pre><code>$ lscpu

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 78
Model name:            Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Stepping:              3
CPU MHz:               2275.341
CPU max MHz:           2800.0000
CPU min MHz:           400.0000
BogoMIPS:              4801.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp</code></pre>
<p>You can also check the /proc/cpuinfo output as shown below:</p>
<pre><code>$ grep -E &quot;(vmx|svm)&quot; --color=always /proc/cpuinfo

flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp</code></pre>
<p>The Libvirt project provides APIs to manage guest machines on KVM, QEMU and other virtualisation software. It is written in C, and is released under the GNU Lesser GPL. The Virtual Machine Manager (VMM) provides a graphical user interface for managing the guest VMs and is written in Python.</p>
<p>You can install all this software on Parabola GNU/Linux-libre using the following command:</p>
<pre><code>$ sudo pacman -S libvirt virt-manager</code></pre>
<p>A screenshot of Virtual Machine Manager is provided below:</p>
<img alt="Virtual Machine Manager" width="800" src="http://shakthimaan.com/images/2017/osfy-devops/vmm-screenshot.png"></img>
<p>Check your distribution documentation to install the appropriate virtualisation software packages.</p>
<p>You can use the VMM to create a new virtual machine, and install a GNU/Linux distribution using an <em>.iso</em> image. You can specify RAM, disk size and follow the installation steps for your particular distro. You can also import an existing <em>.qcow2</em> disk image to use it as a virtual machine.</p>
<h1 id="ansible-with-libvirt-vm">Ansible with libvirt-VM</h1>
<p>The version of Ansible used for this article is given below:</p>
<pre><code>$ ansible --version

ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides</code></pre>
<p>If you have the <em>sshd</em> daemon running on your local machine, you can use Ansible to test it. For example, a ping test on the localhost is shown below:</p>
<pre><code>$ ansible localhost -m ping

localhost | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}</code></pre>
<p>You can also check how long the system has been up and running using the following command:</p>
<pre><code>$ ansible localhost -a uptime

localhost | SUCCESS | rc=0 &gt;&gt;
 11:00:20 up  4:09,  0 users,  load average: 0.18, 0.14, 0.11</code></pre>
<p>You can execute a shell command on the remote machine (localhost, in this case) as illustrated below:</p>
<pre><code>$  ansible localhost -a &quot;date&quot;

localhost | SUCCESS | rc=0 &gt;&gt;
Sun Feb  5 11:24:53 IST 2017</code></pre>
<p>The ‘setup’ command provides details of the remote target machine. A snippet output is provided below:</p>
<pre><code>$  ansible localhost -m setup

localhost | SUCCESS =&gt; {
    &quot;ansible_facts&quot;: {
        &quot;ansible_all_ipv4_addresses&quot;: [
            &quot;192.168.10.1&quot;, 
            &quot;192.168.5.6&quot;
        ], 
        &quot;ansible_all_ipv6_addresses&quot;: [
            &quot;fe90::fc24:ff:feb9:cb61&quot;, 
            &quot;ff80::5846:fac1:6afc:2e30&quot;
        ], 
        &quot;ansible_architecture&quot;: &quot;x86_64&quot;, 
        &quot;ansible_bios_date&quot;: &quot;06/12/2016&quot;, 
        &quot;ansible_bios_version&quot;: &quot;R00ET45W (1.20 )&quot;, 
        &quot;ansible_cmdline&quot;: {
            &quot;BOOT_IMAGE&quot;: &quot;/vmlinuz-linux-libre&quot;, 
            &quot;cryptdevice&quot;: &quot;/dev/sda1:cryptroot&quot;, 
            &quot;quiet&quot;: true, 
            &quot;root&quot;: &quot;/dev/mapper/cryptroot&quot;, 
            &quot;rw&quot;: true
        }, 
        ....</code></pre>
<p>An Ubuntu 15.04 instance with VMM is used in the following examples with Ansible. The IP address of the instance is added to <em>/etc/hosts</em>:</p>
<pre><code>192.168.122.250 ubuntu</code></pre>
<p>The <em>/etc/ansible/hosts</em> file contains the following:</p>
<pre><code>ubuntu</code></pre>
<p>You can now do a ping test from the host to the Ubuntu VM using the following command sequence for the user ‘xetex’:</p>
<pre><code>$  ansible ubuntu -m ping -u xetex --ask-pass
SSH password: 
ubuntu | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}</code></pre>
<p>To avoid prompting for the password, you can add the localhost public SSH key to the VM, as follows:</p>
<pre><code>$  ssh-copy-id -i ~/.ssh/id_rsa.pub xetex@ubuntu

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: &quot;/home/user/.ssh/id_rsa.pub&quot;
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
xetex@ubuntu's password: 

Number of key(s) added: 1</code></pre>
<p>Now try logging into the machine, with <em>ssh xetex@ubuntu</em> and check to make sure that only the key you wanted was added.</p>
<p>You can now issue the following command to get the same result:</p>
<pre><code>$ ansible ubuntu -m ping -u xetex

ubuntu | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}</code></pre>
<p>For the Ubuntu system, you can also add the defined user in the <em>/etc/ansible/hosts</em> file as follows:</p>
<pre><code>ubuntu ansible_ssh_host=ubuntu ansible_ssh_user=xetex</code></pre>
<p>The ping command is now simplified to:</p>
<pre><code>$  ansible ubuntu -m ping

ubuntu | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}</code></pre>
<p>You can now try the earlier Ansible commands on the target Ubuntu VM as illustrated below:</p>
<pre><code>$ ansible ubuntu -a uptime

ubuntu | SUCCESS | rc=0 &gt;&gt;
 12:32:14 up 25 min,  3 users,  load average: 0.02, 0.07, 0.06

$ ansible ubuntu -a date

ubuntu | SUCCESS | rc=0 &gt;&gt;
Sun Feb  5 12:32:45 IST 2017

$  ansible ubuntu -m setup
ubuntu | SUCCESS =&gt; {
    &quot;ansible_facts&quot;: {
        &quot;ansible_all_ipv4_addresses&quot;: [
            &quot;192.168.122.250&quot;
        ], 
        &quot;ansible_all_ipv6_addresses&quot;: [
            &quot;ff20::5034:ff:fa9f:6123&quot;
        ], 
        &quot;ansible_architecture&quot;: &quot;x86_64&quot;, 
        &quot;ansible_bios_date&quot;: &quot;04/01/2014&quot;, 
        &quot;ansible_bios_version&quot;: &quot;1.10.1-20151022_124906-anatol&quot;, 
        &quot;ansible_cmdline&quot;: {
            &quot;BOOT_IMAGE&quot;: &quot;/boot/vmlinuz-3.19.0-15-generic&quot;, 
            &quot;quiet&quot;: true, 
            &quot;ro&quot;: true, 
            &quot;root&quot;: &quot;UUID=f43c2c72-5bc7-4a97-9a43-12e634ae232af&quot;, 
            &quot;splash&quot;: true, 
            &quot;vt.handoff&quot;: &quot;7&quot;
        }, 
        ...</code></pre>]]></description>
    <pubDate>Tue, 05 Sep 2017 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/09/05/devops-ansible-introduction/news.html</guid>
</item>
<item>
    <title>StumpWM on Parabola GNU/Linux-libre</title>
    <link>http://www.shakthimaan.com/posts/2017/08/11/stumpwm-parabola/news.html</link>
    <description><![CDATA[<p>I have installed and configured <a href="https://stumpwm.github.io/">StumpWM</a> (v1.0.0) on <a href="https://www.parabola.nu/">Parabola GNU/Linux-libre</a>. StumpWM is a keyboard driven, tiling Window Manager written in Common Lisp (CL). It is thus very hackable, and you can customize its configuration by writing Lisp code and reload it dynamically. The installation and configuration steps are provided below for reference.</p>
<p>Firstly, the <a href="http://sbcl.org/">Steel Bank Common Lisp</a> (SBCL) compiler needs to be installed on the system using Pacman.</p>
<pre><code>$ sudo pacman -S sbcl 
$ sudo pacman -S acpi xtrlock emacs mate-terminal iceweasel</code></pre>
<p>The <em>acpi</em> utility is installed to show the battery status in the modeline. The <em>xtrlock</em> utility is used to lock the screen. When the screen is locked, you will need to enter your user password to unlock the same. GNU Emacs, Iceweasel and Mate-terminal software packages are also installed. <a href="https://www.quicklisp.org/beta/">Quicklisp</a> is a package manager for Common Lisp and is used to install the StumpWM dependencies with SBCL.</p>
<p>An installation directory is created at ~/downloads/quicklisp, and the quicklisplisp file is fetched as follows:</p>
<pre><code>$ mkdir ~/downloads/quicklisp
$ cd ~/downloads/quicklisp
$ curl -O https://beta.quicklisp.org/quicklisp.lisp</code></pre>
<p>The quicklisp.lisp file is loaded using the SBCL interpreter. The installation steps and output are shown below:</p>
<pre><code>~/downloads/quicklisp $ sbcl --load quicklisp.lisp 

    This is SBCL 1.3.17, an implementation of ANSI Common Lisp.
    More information about SBCL is available at &lt;http://www.sbcl.org/&gt;.

    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.

      ==== quicklisp quickstart 2015-01-28 loaded ====

        To continue with installation, evaluate: (quicklisp-quickstart:install)

        For installation options, evaluate: (quicklisp-quickstart:help)

* (quicklisp-quickstart:install)

    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/client/quicklisp.sexp&quot;&gt;
    ; 0.82KB
    ==================================================
    838 bytes in 0.00 seconds (0.00KB/sec)
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/client/2017-03-06/quicklisp.tar&quot;&gt;
    ; 250.00KB
    ==================================================
    256,000 bytes in 0.16 seconds (1602.56KB/sec)
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/client/2015-09-24/setup.lisp&quot;&gt;
    ; 4.94KB
    ==================================================
    5,054 bytes in 0.00 seconds (0.00KB/sec)
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/asdf/2.26/asdf.lisp&quot;&gt;
    ; 194.07KB
    ==================================================
    198,729 bytes in 0.09 seconds (2086.79KB/sec)
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/dist/quicklisp.txt&quot;&gt;
    ; 0.40KB
    ==================================================
    408 bytes in 0.00 seconds (0.00KB/sec)
    Installing dist &quot;quicklisp&quot; version &quot;2017-07-25&quot;.
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/dist/quicklisp/2017-07-25/releases.txt&quot;&gt;
    ; 372.80KB
    ==================================================
    381,744 bytes in 0.15 seconds (2485.31KB/sec)
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/dist/quicklisp/2017-07-25/systems.txt&quot;&gt;
    ; 241.23KB
    ==================================================
    247,022 bytes in 0.10 seconds (2297.45KB/sec)

      ==== quicklisp installed ====

        To load a system, use: (ql:quickload &quot;system-name&quot;)

        To find systems, use: (ql:system-apropos &quot;term&quot;)

        To load Quicklisp every time you start Lisp, use: (ql:add-to-init-file)

        For more information, see http://www.quicklisp.org/beta/

    NIL

* (ql:add-to-init-file)

    I will append the following lines to #P&quot;/home/guest/.sbclrc&quot;:

      ;;; The following lines added by ql:add-to-init-file:
      #-quicklisp
      (let ((quicklisp-init (merge-pathnames &quot;quicklisp/setup.lisp&quot;
                                             (user-homedir-pathname))))
        (when (probe-file quicklisp-init)
          (load quicklisp-init)))

    Press Enter to continue.

    #P&quot;/home/guest/.sbclrc&quot;

* (ql:quickload &quot;clx&quot;)

    To load &quot;clx&quot;:
      Install 1 Quicklisp release:
        clx
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/archive/clx/2017-06-30/clx-20170630-git.tgz&quot;&gt;
    ; 452.92KB
    ==================================================
    463,786 bytes in 0.12 seconds (3806.02KB/sec)
    ; Loading &quot;clx&quot;
    [package xlib]....................................
    ..................................................
    ..................................................
    ..................................................
    ..................................................
    ..................................................
    ..................................................
    ..................................................
    [package xlib/glx]................................
    [package xlib/gl].................................
    [package xlib/dpms]...............................
    [package xlib/xtest]..............................
    [package xlib/xinerama]...........................
    [package xlib-demo/clclock].......................
    [package xlib-demo/clipboard].....................
    [package xlib-demo/demos].........................
    [package xlib-demo/gl-test].......................
    [package xlib-demo/mandel].............
    (&quot;clx&quot;)

* (ql:quickload &quot;cl-ppcre&quot;)

    To load &quot;cl-ppcre&quot;:
      Install 1 Quicklisp release:
        cl-ppcre
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/archive/cl-ppcre/2015-09-23/cl-ppcre-2.0.11.tgz&quot;&gt;
    ; 156.08KB
    ==================================================
    159,829 bytes in 0.08 seconds (1903.45KB/sec)
    ; Loading &quot;cl-ppcre&quot;
    [package cl-ppcre]................................
    ................
    (&quot;cl-ppcre&quot;)

* (ql:quickload &quot;alexandria&quot;)

    To load &quot;alexandria&quot;:
      Install 1 Quicklisp release:
        alexandria
    ; Fetching #&lt;URL &quot;http://beta.quicklisp.org/archive/alexandria/2017-06-30/alexandria-20170630-git.tgz&quot;&gt;
    ; 49.97KB
    ==================================================
    51,168 bytes in 0.04 seconds (1135.65KB/sec)
    ; Loading &quot;alexandria&quot;
    [package alexandria.0.dev].......................
    (&quot;alexandria&quot;)

* (exit)

~/downloads/quicklisp $ </code></pre>
<p>The StumpWM v1.0.0 sources are fetched to ~/downloads/stumpwm directory, extracted and compiled using the following steps:</p>
<pre><code>$ mkdir ~/downloads/stumpwm
$ cd ~/downloads/stumpwm
$ wget https://github.com/stumpwm/stumpwm/archive/1.0.0.tar.gz
$ tar xzvf 1.0.0.tar.gz
$ cd stumpwm-1.0.0/
$ ./autogen.sh 
$ ./configure 
$ make</code></pre>
<p>You can then install the built <em>stumpwm</em> binary, which will get copied to /usr/local/bin/stumpwm as shown below:</p>
<pre><code>$ sudo make install

$ which stumpwm
/usr/local/bin/stumpwm</code></pre>
<p>I use the Lightweight X11 Display Manager (lxdm), and thus created a /usr/share/xsessions/stumpwm.desktop file to login to StumpWM from the login manager:</p>
<pre><code>[Desktop Entry]
Encoding=UTF-8
Name=StumpWM
Comment=StumpWM
Exec=/usr/local/bin/stumpwm
Type=Application</code></pre>
<p>A sample ~/.stumpwmrc configuration file is given below (should be self-explanatory):</p>
<pre><code>;; -*-lisp-*-

(in-package :stumpwm)

;; Startup message: display the machine's name
(setf *startup-message* (machine-instance))

;; Turn on the modeline
(if (not (head-mode-line (current-head)))
    (toggle-mode-line (current-screen) (current-head)))

;; Lock screen
(define-key *root-map* (kbd &quot;L&quot;) &quot;exec xtrlock&quot;)

;; I like messages to be centered on the screen.
(setf *message-window-gravity* :center)
(setf *input-window-gravity* :center)

;; I thought that this mode-line was fabulous!
(defvar *battery-status-command*
  &quot;acpi -b | awk -F '[ ,]' '{printf \&quot;%s%s\&quot;, $3, $5}' | sed s/Discharging/\-/ | sed s/Unknown// | sed s/Full// | sed s/Charging/+/&quot;)

(defvar *vol-status-command*
  &quot;amixer get Master | grep \&quot;[[:digit:]]\\+%\&quot; -o | tr -d \&quot;\\n\&quot;&quot;)

(setf *screen-mode-line-format*
      (list &quot;%w [^B%n^b] ^&gt;&quot;
      '(:eval (run-shell-command *battery-status-command* t))
      &quot; | Vol. &quot;
      '(:eval (run-shell-command *vol-status-command* t))
      &quot; | %d&quot;))

;; urxvt
(define-key *root-map* (kbd &quot;c&quot;) 
  &quot;exec urxvt +sb -fn \&quot;xft:Ubuntu Mono:pixelsize=15,style=regular\&quot;&quot;)

;; Window information format
(setf *window-info-format* &quot;%wx%h %n (%t - %c)&quot;)

;; Window format
(setf *window-format* &quot;%m%n%s%10t&quot;)

;; Emacs
(defvar *emacs-command* nil
  &quot;Start an emacs client frame. Starts an emacs daemon if necessary.&quot;)
(setf *emacs-command* &quot;bash -c -i 'emacsclient -c -a \&quot;\&quot;'&quot;)

(define-key *root-map* (kbd &quot;e&quot;) &quot;run-emacs&quot;)

(defcommand run-emacs () ()
    (run-shell-command (concat &quot;exec &quot; *emacs-command*)))

;; iceweasel
(defcommand iceweasel-browser () ()
  &quot;run iceweasel&quot;
  (run-or-raise &quot;iceweasel&quot; '(:instance &quot;iceweasel&quot;)))
(define-key *root-map* (kbd &quot;b&quot;) &quot;iceweasel-browser&quot;)

;; mate-terminal
(defcommand mate-terminal () ()
  (run-or-raise &quot;mate-terminal --hide-menubar&quot; '(:class &quot;mate-terminal&quot;)))

(define-key *root-map* (kbd &quot;C&quot;) &quot;mate-terminal&quot;)

;; Clear rules
(clear-window-placement-rules)

(define-frame-preference &quot;Default&quot;
  ;; frame raise lock (lock AND raise == jumpto)
  (0 t   t :instance &quot;emacs&quot;)
  (1 t   t :instance &quot;iceweasel-browser&quot;))

;; dvorak and தமிழ்
(stumpwm:run-shell-command &quot;sh -c 'setxkbmap us,in dvorak,tam_unicode grp:ctrls_toggle'&quot;)

;; Start default applications
(run-emacs)
(iceweasel-browser)</code></pre>
<p>On logging into StumpWM, GNU Emacs and Iceweasel browser are opened automatically. I also switch between English and Tamil keyboard layouts when required, and the two Control keys are used to toggle between them. A StumpWM screenshot is shown below:</p>
<img alt="StumpWM screenshot" width="800" src="http://shakthimaan.com/images/2017/misc/stumpwm-screenshot.png"></img>
<p>You are encouraged to read the <a href="https://stumpwm.github.io/1.0.0/stumpwm-1.0.0.pdf">StumpWM manual</a> to know more about its usage and configuration.</p>]]></description>
    <pubDate>Fri, 11 Aug 2017 21:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/08/11/stumpwm-parabola/news.html</guid>
</item>
<item>
    <title>"i want 2 do project. tell me wat 2 do" workshop, reserved-bit, Pune</title>
    <link>http://www.shakthimaan.com/posts/2017/07/05/iw2dptmw2d-workshop/news.html</link>
    <description><![CDATA[<p>I had organized a one-day workshop based on my book <a href="http://www.shakthimaan.com/what-to-do.html">i want 2 do project. tell me wat 2 do</a> at <a href="https://reserved-bit.com">reserved-bit</a>, Pune on Saturday, June 3, 2017. Thanks to <a href="https://twitter.com/Nisha_Poyarekar">Nisha Poyarekar</a> and <a href="https://twitter.com/siddhesh_p">Siddhesh Poyarekar</a> for providing their makerspace as venue for the workshop.</p>
<img alt="Workshop in progress" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/workshop-in-progress.png"></img>
<p>The objective of the workshop is to share the methodology and best practices on working with Free and Open Source Software projects, and also to guide the participants on career options. Although there is plenty of free documentation (including my own) available on the subject, some people prefer a formal, systematic approach to learning in a private coaching environment. Hence, this workshop is tailored for the same and is made a paid workshop, similar to personal tutoring.</p>
<p>The book has been in circulation for many years. So, I had to give two options - pay only for the workshop, or pay for both the workshop and the book (if they have not already bought the book). I have also kept additional copies of my book at the reserved-bit makerspace if people are interested. I had covered the following topics:</p>
<ol style="list-style-type: decimal">
<li>Careers with F/OSS</li>
<li>“i want 2 do project. tell me wat 2 do” best practices</li>
<li>Introduction to Git</li>
<li>Hands-on problem solving exercises</li>
<li>Real-world project example</li>
<li>Goal-driven development</li>
</ol>
<p>The feedback has been positive and I am sharing the same below:</p>
<img alt="Feedback 1" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/1-feedback.png"></img><br />
<img alt="Feedback 2" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/2-feedback.png"></img><br />
<img alt="Feedback 3" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/3-feedback.png"></img><br />
<img alt="Feedback 4" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/4-feedback.png"></img><br />
<img alt="Feedback 5" width="400" src="http://shakthimaan.com/images/2017/book-workshop-reserved-bit/5-feedback.png"></img><br />
<p>If you are interested in attending such a workshop, do write to me: author at shakthimaan dot com.</p>]]></description>
    <pubDate>Wed, 05 Jul 2017 13:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/07/05/iw2dptmw2d-workshop/news.html</guid>
</item>
<item>
    <title>Rootconf 2017</title>
    <link>http://www.shakthimaan.com/posts/2017/06/20/rootconf/news.html</link>
    <description><![CDATA[<h1 id="introduction">Introduction</h1>
<p>I attended <a href="https://rootconf.in/2017/">Rootconf 2017</a> on May 11-12, 2017 at <a href="http://mlr.in/mlr-convention-centre-jp-nagar/mlr-jpnagar.html">MLR Convention Centre, JP Nagar</a>, Bengaluru.</p>
<img alt="Sponsors" width="400" src="http://shakthimaan.com/images/2017/rootconf/2-sponsors.jpg"></img>
<p>The event had two parallel tracks, the Rootconf track at the main conference hall, and the DevConf.in track sponsored by Red Hat. A number of infrastructure hosting companies had sponsored the event. The selected talks had good diversity with topics ranging from monitoring, databases, networking, security etc.</p>
<h1 id="day-i">Day I</h1>
<p>The day’s proceedings began with the talk on the <a href="https://rootconf.talkfunnel.com/2017/63-state-of-the-open-source-monitoring-landscape">“State of open source monitoring landscape”</a> by <a href="https://twitter.com/gethash">Bernd Erk</a>. He gave a good overview of the available monitoring tools. He is involved in the <a href="https://www.icinga.com/products/icinga-2/">Icinga2</a> project, which is re-written in C++ for performance. It is an alternative for the Nagios tool.</p>
<p><a href="http://adityapatawari.com/">Aditya Patawari</a> then provided an introduction to Kubernetes with a demo, as Spencer Krum could not make it to his talk on the “Anatomy of an alert”. After a short break, I attended <a href="https://rootconf.talkfunnel.com/2017/7-a-little-bot-for-big-cause">“A little bot for big cause”</a> session by <a href="https://p00j4.github.io/">Pooja Shah</a>. The talk basically demonstrated how to create a bot by integrating various APIs.</p>
<p>I attended <a href="https://twitter.com/mananbharara">Manan Bharara’s</a> talk on <a href="https://speakerdeck.com/manan/necessary-tooling-and-monitoring-for-performance-critical-applications-rootconf-2017">“Monitoring performance critical applications”</a> where he had explained how they had used Clojure for monitoring at Otto in Germany. The presentation was very good, and the <a href="https://github.com/otto-de/oscillator">Oscillator</a> Clojure code is available. He had provided good illustrations and code snippets in his presentation.</p>
<img alt="Manan Bharara' oscillator visualization" src="http://shakthimaan.com/images/2017/rootconf/1-manan-visualization.png"></img>
<p>A number of stalls were available in the hallway, and I spent considerable time talking with the sponsors. At the Red Hat stall, I learnt some of the features and use cases for the <a href="https://www.theforeman.org/">Foreman</a> provisioning tool. I was pictured with the Foreman helmet:</p>
<img alt="Shakthimaan with Foreman helmet" height="400" src="http://shakthimaan.com/images/2017/rootconf/4-shakthimaan-foreman.png"></img>
<p>After lunch, I attended <a href="https://rootconf.talkfunnel.com/devconf-2017/82-selinux-a-deep-dive">“SELinux: A deep dive”</a> by <a href="https://fedoraproject.org/wiki/User:Rejymc">Rejy M Cyriac</a>. He gave an excellent introduction to SELinux, explaining the underlying concepts and rationale for the same. We also did basic hands-on exercises, but, I could not attend the last section as I had to move to the main conference hall for the flash talks. I sang the Nursery Rhymes version for DevOps. The <a href="https://www.youtube.com/watch?v=87_1FCiHkK4#t=27m15s">video</a> is available.</p>
<p>We then headed to the Rootconf party sponsored by Go-Jek!</p>
<h1 id="day-ii">Day II</h1>
<p>The second day started with the talk by <a href="https://crondev.wordpress.com/">Kunal Grover</a> on <a href="https://rootconf.talkfunnel.com/2017/29-failure-resilient-architecture-with-microservice-d">“Failure resilient architecture with microservice dependencies”</a>. He presented the ways by which disruptions are performed in cloud infrastructure and how recovery mechanisms are tested. <a href="https://twitter.com/atramya">Ramya A</a> then gave an interesting talk on <a href="https://rootconf.talkfunnel.com/2017/64-asynchronous-integration-tests-for-microservices">“Asynchronous integration tests for microservices”</a>. She had explained the <a href="https://docs.pact.io/">pact.io</a> family of frameworks to support Consumer Driven Contracts testing. Laxmi Nagarajan then gave a high level overview of <a href="https://rootconf.talkfunnel.com/2017/34-a-quick-how-to-on-capacity-planning-for-an-applica">“Capacity planning for AWS and configuring AWS autoscaling policies”</a> sharing her Industry experience. After a short break, <a href="http://www.bytebot.net/">Colin Charles</a> presented his story on <a href="https://rootconf.talkfunnel.com/2017/65-capacity-planning-for-your-data-stores">“Capacity planning for your data stores”</a> citing real world examples.</p>
<p>I then moved to the DevConf.in track to attend <a href="https://github.com/ruchi15">Ruchi Singh’s</a> talk on <a href="https://rootconf.talkfunnel.com/devconf-2017/88-migration-of-300-microservices-from-aws-cloud-to-s">“Migration of 300 microservices from AWS cloud to Snapdeal cloud”</a>. The time was too short for such a talk, and it was an overview. I would have liked to see more details, given that they use Chef for provisioning and handle more than 16 TB of data as mentioned by Ruchi Singh.</p>
<p>After a quick lunch, I attended <a href="https://rootconf.talkfunnel.com/2017/1-adventures-in-postgres-management">“Adventures in Postgres management”</a> by <a href="https://github.com/ramananbalakrishnan">Ramanan Balakrishnan</a>. It was a good technical talk going over the failures and experiences learnt. After the talk I went to the hallway to listen to the Off-The-Record (OTR) session on mistakes to avoid when planning your infrastructure.</p>
<img alt="OTR session" width="400" src="http://shakthimaan.com/images/2017/rootconf/3-OTR-session.jpg"></img>
<p>I returned to the main conference hall for doing some stretching exercises. In my opinion, all conferences should make this session mandatory, especially after you have been sitting for a long period of time. This session was then followed by the <a href="https://rootconf.talkfunnel.com/2017/58-working-with-secrets">“Working with Secrets”</a> talk by <a href="https://github.com/shreyagarwal">Shrey Agarwal</a>, who gave an overview of using Hashicorp’s Vault for managing passwords. It was a very short introduction on the topic.</p>
<p>After a short beverage break, <a href="http://www.toshaan.com/">Toshaan Bharvani</a> presented <a href="https://rootconf.talkfunnel.com/2017/50-living-with-selinux">“Living with SELinux”</a>, which was an excellent presentation on the subject. The initial slides had some material that Rejy M Cyriac had introduced the previous day, but, the content and presentation were good. With proper SELinux policies, he said that root in his production servers cannot do much. Rejy and Toshaan both asked people to use permissive mode instead of disabling SELinux altogether, so that you at least know what is being audited.</p>
<p>The last talk of the day was by <a href="https://anuragbhatia.com/">Anurag Bhatia</a> on <a href="https://rootconf.talkfunnel.com/2017/76-understanding-eyeball-routing-via-ripe-atlas">“Understanding eyeball routing via RIPE Atlas”</a>. He gave an overview of the <a href="https://atlas.ripe.net/">RIPE Atlas</a> project and how network metrics are measured and monitored wherever the RIPE device is installed. It is a TP-Link hardware whose firmware can be flashed using Libre software. Unfortunately, at this point the source of the firmware is not released as Free and Open Source Software. I was told that there is still an ongoing discussion on the same.</p>
<h1 id="conclusion">Conclusion</h1>
<p>The talk by Manan Bharara and Rejy’s SELinux workshop were the highlights for day one for me. The content on the second day was much better and had greater depth in my opinion. Overall, it was a useful technical conference, and a good place to meet like-minded people.</p>
<p>I would like to thank <a href="http://www.aerospike.com/">Aerospike</a> for sponsoring me to attend the conference.</p>]]></description>
    <pubDate>Tue, 20 Jun 2017 14:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/06/20/rootconf/news.html</guid>
</item>
<item>
    <title>GNU Emacs Lisp</title>
    <link>http://www.shakthimaan.com/posts/2017/05/01/gnu-emacs-lisp/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, June 2016 edition.]</em></p>
<p>We have covered a lot of ground in our quest to learn the intricacies of GNU Emacs and we trust that you have found your long journey fulfilling. This is the last article in the series.</p>
<h1 id="introduction">Introduction</h1>
<p>The GNU Emacs editor is written using Emacs Lisp and the C programming language. You can use GNU Emacs as an editor without knowing Emacs Lisp, but, being familiar with it will help you customize it or extend it to your needs. Emacs Lisp is a dialect of the Lisp programming language and is inspired by Maclisp and Common Lisp. The source files end with the filename extension .el and the byte-compiled files end with the .elc filename extension. You can also write scripts using Emacs Lisp and execute them as a batch operation. The code can thus be executed from the command line or from an executable file. Byte-compiling the source files can help you speed up the execution.</p>
<h1 id="comments">Comments</h1>
<p>All comments begin with a semi-colon. An Emacs Lisp file usually has the following sections in the code, specified with three semi-colons. These always start in the left margin as shown below:</p>
<pre><code>;;; Module --- Summary

;;; Commentary:

;;; Code:

;;; Module ends here</code></pre>
<p>All comments outside functions begin with two semi-colons. The contents of the scratch buffer, shown below, are an example:</p>
<pre><code>;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.</code></pre>
<p>Comments inside functions use a single semi-colon, and if they span multiple lines, they must be neatly aligned. For example:</p>
<pre><code>...
(let* ((sexp (read (current-buffer)))    ; using `read' here
                                         ; easier than regexp
                                         ; matching, esp. with
                                         ; different forms of
                                         ; MONTH
 ...
 ))</code></pre>
<h1 id="literals">Literals</h1>
<p>The basic data types are available in Emacs Lisp. Numbers can be represented by integers or floats. Integers can have their sign representation before the digit (+1, -2). Floating point numbers can be represented using a decimal point (3.1415) or with an exponent (314.15e-2). A character (S) is represented by its integer code (83), while a string is a list of characters enclosed within double quotes (“A string”).</p>
<p>A symbol is an object with a name. A keyword symbol is one that starts with a colon (:). A vector is an array and can contain different types ([1 “two” :three]). The Boolean values for true and false are ’t’ and ‘nil’ respectively. A <em>cons</em> cell is an object with two slots. The first slot is called the CAR (Contents of the Address part of the Register number) and the second slot is called the CDR (Contents of the Decrement part of the Register number). A list is a series of linked cons cells. For example, in the list ‘(A B)’, the CAR is A and the CDR is B.</p>
<h1 id="sexp">Sexp</h1>
<p>Emacs Lisp uses prefix notation which consists of an operation followed by operands (arguments). All programs are represented as symbolic expressions (sexp). For example, the ‘+’ operation is applied to its arguments ‘1’ and ‘2’ in the following sexp:</p>
<pre><code>(+ 1 2)</code></pre>
<p>If you copy the above code in an Emacs buffer, you can evaluate the same by placing the cursor at the end of the expression and using the C-x C-e shortcut. The output ‘3’ will be displayed in the minibuffer.</p>
<p>You can also have nested sexps, wherein the innermost expressions are evaluated first.</p>
<pre><code>(+ 1 (* 2 3))</code></pre>
<p>Similar to the ‘+’ operation, you can use pre-defined keywords or functions in Emacs Lisp programs. The <em>format</em> function is similar to your <em>printf</em> statement in the C programming language.</p>
<pre><code>(format &quot;Hello, World!&quot;)</code></pre>
<p>You can store a value in a variable using the <em>setq</em> operation as shown below:</p>
<pre><code>(setq IST &quot;Indian Standard Time&quot;)

IST     ; No enclosing parenthesis!
        ; produces &quot;Indian Standard Time&quot;</code></pre>
<p>You can find the data type, using the <em>type-of</em> function. A few examples are shown below:</p>
<pre><code>(type-of 1)                ; produces integer

(type-of 3.1415)           ; produces float

(type-of &quot;A string&quot;)       ; produces string

(type-of :foo)             ; produces symbol

(type-of t)                ; produces symbol

(type-of '(1 2))           ; produces cons

(type-of [1 &quot;two&quot; :three]) ; produces vector</code></pre>
<p>In the Bash shell, you can escape evaluation by using the backslash. Similarly, you can prevent the Emacs Lisp interpreter from evaluating an expression using quotes. For example:</p>
<pre><code>(+ 1 2)     ; produces 3

'(+ 1 2)    ; produces the list (+ 1 2)</code></pre>
<h1 id="progn">progn</h1>
<p>The <em>progn</em> statement is used to execute several sexps. For example:</p>
<pre><code>(progn
  (setq title &quot;Introduction to Emacs Lisp&quot;)
  (setq author &quot;Robert J. Chassell&quot;)
  (format &quot;%s by %s&quot; title author))  ; produces &quot;Introduction to Emacs Lisp by Robert J. Chassell&quot;</code></pre>
<h1 id="functions">Functions</h1>
<p>You can define your own function using the <em>defun</em> built-in keyword. The ‘say’ function simply prints the string “Hello, World!”&quot; in the following example:</p>
<pre><code>(defun say ()
  (format &quot;Hello, World!&quot;))</code></pre>
<p>In order to execute the function, invoke it inside parenthesis as shown below:</p>
<pre><code>(say)    ; produces &quot;Hello, World!&quot;</code></pre>
<p>Arguments can be passed to a function. The ‘square’ function is demonstrated below:</p>
<pre><code>(defun square (x)
  (* x x))

(square 3)  ; produces 9</code></pre>
<p>You can also store a list of names and retrieve them using the <em>car</em> and <em>cdr</em> functions as illustrated below:</p>
<pre><code>(setq teams '(&quot;GL&quot; &quot;DD&quot; &quot;KKR&quot; &quot;MI&quot; &quot;SRH&quot; &quot;RPS&quot; &quot;RCB&quot; &quot;KXIP&quot;))

(car teams)       ; produces &quot;GL&quot;

(cdr teams)       ; produces &quot;DD&quot; &quot;KKR&quot; &quot;MI&quot; &quot;SRH&quot; &quot;RPS&quot; &quot;RCB&quot; &quot;KXIP&quot;

(car (cdr teams)) ; produces &quot;DD&quot;</code></pre>
<h1 id="let">let</h1>
<p>The <em>let</em> statement allows you to bind a value to a variable in a local context. GNU Emacs 24 has lexical binding support. An example is given below:</p>
<pre><code>(defun hello (name)
  (let ((new-name (concat &quot;Hello &quot; name)))
    new-name
      ))

(hello &quot;Mark&quot;)   ; produces &quot;Hello Mark&quot;</code></pre>
<h1 id="conditions">Conditions</h1>
<p>Conditions can be checked using the <em>if</em> and <em>cond</em> statements. The <em>if</em> statement takes a condition, and if the condition evaluates to true, the sexp immediately following the condition is executed. Otherwise, the else-form is evaluated. The syntax is</p>
<pre><code>(if condition then-form else-form)</code></pre>
<p>An example:</p>
<pre><code>(if t
    (format &quot;True&quot;)
  (format &quot;False&quot;))  ; produces &quot;True&quot;</code></pre>
<p>The <em>when</em> condition statement is a variant of the <em>if</em> statement written as a macro. Macros are an important feature of Lisp programming that allow you to extend the language. They are primarily code generators. If the ‘when’ condition is true, then it evaluates the then-forms. The syntax and an example are given below:</p>
<pre><code>(when condition then-forms)

(when t
  (print &quot;Abracadabra!&quot;))  ; produces &quot;Abracadabra!&quot;</code></pre>
<h1 id="looping">Looping</h1>
<p>You can use the <em>while</em> statement to perform looping in Emacs Lisp. The body of the ‘while’ loop is executed as long as the condition is true. An example that prints the numbers 0 to 4 is shown below:</p>
<pre><code>(progn
  (setq i 0)
  (while (&lt; i 5)
    (print i)
    (setq i (+ i 1))))</code></pre>
<p>The <em>dolist</em> and <em>dotimes</em> macros can also be used for looping. The other approach is to use recursion. A literal definition in Emacs Lisp for computing the Fibonacci series is given below:</p>
<pre><code>(defun fib (n)
  (cond ((= n 0) 0)
        ((= n 1) 1)
        (t (+ (fib (- n 1))
              (fib (- n 2))))))</code></pre>
<p>The <em>cond</em> control structure takes a series of clauses, each has a condition and a body-form. If any condition evaluates to true, the body-form is executed. Otherwise, it proceeds to the next clause.</p>
<p>An iterative version of the Fibonacci series is given below:</p>
<pre><code>(defun fib (n)
  (fib-helper n 0 1))

(defun fib-helper (n a b)
  (if (= n 0)
      a
    (fib-helper (- n 1) b (+ a b))))

(fib 10) ; produces 55</code></pre>
<p>The Emacs Lisp Cookbook is very handy <a href="https://www.emacswiki.org/emacs/ElispCookbook"><code class="url">https://www.emacswiki.org/emacs/ElispCookbook</code></a>.</p>
<p>You are encouraged to read ‘An Introduction to Programming in Emacs Lisp’ at <a href="https://www.gnu.org/software/emacs/manual/eintr.html"><code class="url">https://www.gnu.org/software/emacs/manual/eintr.html</code></a> and the Emacs Lisp Reference Manual at <a href="https://www.gnu.org/software/emacs/manual/elisp.html"><code class="url">https://www.gnu.org/software/emacs/manual/elisp.html</code></a>.</p>]]></description>
    <pubDate>Mon, 01 May 2017 18:15:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/05/01/gnu-emacs-lisp/news.html</guid>
</item>
<item>
    <title>Pune GNU/Linux Users Group ClipArt Hackathon 2017</title>
    <link>http://www.shakthimaan.com/posts/2017/04/05/pune-clipart-hackathon/news.html</link>
    <description><![CDATA[<p>I had a chance to attend the <a href="http://www.plug.org.in/">Pune GNU/Linux Users Group (PLUG)</a> ClipArt Hackathon on Sunday, March 12, 2017 at <a href="https://www.bprim.org/">Bhaskaracharya Pratishthana</a>. The hackathon was an initiative to start organizing different kinds of F/OSS events.</p>
<p><a href="http://www.opensourcecook.in/trainers">Gaurav (“dexter”) Pant</a> started the day’s proceedings with a quick demo of <a href="https://inkscape.org/en/">Inkscape</a>. He also provided the participants with an Inkscape quick reference sheet. The advantage of creating Scalable Vector Graphics (SVG) is that it can be used on a web page as well as enlarged for printing on posters and banners, without any distortion.</p>
<p>I took this time to create some illustrations. The first image was a logo with the letter “S”, whose shape was modified to fit into a boundary. The <a href="https://openclipart.org/detail/202673/stick-figure-pushing">stick-figure-push</a> SVG is already available in <a href="https://openclipart.org/">Openclipart</a>. I modified it for a stick-figure-pull image. Few icons were then created for use in web pages. Finally, I completed an SVG of <a href="https://en.wikipedia.org/wiki/The_Common_Man">“The Common Man”</a>.</p>
<img alt="S logo" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/S-logo.svg"></img><br /><br />
<img alt="Stick figure pull" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/Stick-figure-pull.svg"></img><br /><br />
<img alt="Envelope icon" width="384" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/Envelope-icon.svg"></img><br /><br />
<img alt="Monitor icon" width="384" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/Monitor-icon.svg"></img><br /><br />
<img alt="Telephone icon" width="384" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/Telephone-icon.svg"></img><br /><br />
<img alt="The Common Man" width="384" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/Common-man.svg"></img><br /><br />
<p>All the images are available in Creative Commons Attribution-Share Alike 4.0 International license at Wikimedia ( <a href="https://commons.wikimedia.org/w/index.php?title=Special:ListFiles/Shakthimaan">https://commons.wikimedia.org/w/index.php?title=Special:ListFiles/Shakthimaan</a> ).</p>
<p>The hackathon was a good initiative to encourage creative contributions to F/OSS. I was happy to see a number of excellent designers who were creating beautiful SVGs. Participants used both GIMP and Inkscape for their work. It was also good to have met the PLUG members.</p>
<p><img alt="Group photo" src="http://shakthimaan.com/gallery/2017/plug-clipart-hackathon-apr-5-2017/plug-clipart-hackathon-march-12-2017.png"></img><br /> PC: Siddharth Subramaniam</p>
<p>Such events help grow the activities in a region, and also showcases the diversity in a F/OSS group.</p>]]></description>
    <pubDate>Wed, 05 Apr 2017 22:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/04/05/pune-clipart-hackathon/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Org Mode</title>
    <link>http://www.shakthimaan.com/posts/2017/03/31/emacs-org-mode/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, May 2016 edition.]</em></p>
<p>Keeping notes, maintaining to-do lists, planning projects and author documents with a fast and effective plain-text system - that’s what Emacs Org mode helps you do. There’s even a mobile version available as FOSS so that your favourite note-taking tool remains with you always.</p>
<p>In this next article in the GNU Emacs series, let’s learn about Org mode.</p>
<h1 id="introduction">Introduction</h1>
<p>Org-mode is an outline, major mode in GNU Emacs that can be used for taking notes, planning and documentation. It was written by Carsten Dominik in 2003. The Org file is written in plain text and markdown, and it can be exported into multiple output formats (TeX, HTML, PDF, etc.). Org-mode ships with GNU Emacs and this tutorial uses GNU Emacs 24.4.1 (<em>M-x version</em>) and Org mode version 8.2.10 (<em>M-x org-version</em>).</p>
<h1 id="structure">Structure</h1>
<p>An Org file ends with the .org filename extension. The top-level headlines are marked using an asterisk (‘*’). For example, a college student may have the following high-level topics:</p>
<pre><code>* College
* Home
* Recreation</code></pre>
<p>You can create topics in the sub-section with more asterisks. For example:</p>
<pre><code>* College
** Assignments
** Lab
** Exams
* Home
* Recreation</code></pre>
<p>If you wish to hide the multiple asterisks at the sub-section level, you can add the following to your ~/.emacs:</p>
<pre><code>(setq org-hide-leading-stars t)</code></pre>
<p>The resultant Org file will look like what follows:</p>
<pre><code>* College
 * Assignments
 * Lab
 * Exams
* Home
* Recreation</code></pre>
<p>You can add unnumbered (use minus or plus symbols) or numbered lists as shown below:</p>
<pre><code>* College
 * Assignments
 * Lab
   1. Compiler Design
   2. Programming Languages
 * Exams
   - Mathematics
   - Operating Systems
   - Databases
   - Compilers
* Home
* Recreation</code></pre>
<p>You can cycle through the various levels in the Org file using the <em>Tab</em> and <em>Shift-Tab</em> keys.</p>
<p>A checkbox with a ‘/’ or a ‘%’ symbol can be used next to a topic name to indicate the completion status of the task. The lists under a topic can each have a checkbox too. Using <em>C-c C-c</em> will mark a checkbox for completion (‘X’) and will also update the statistics in the top-level checkbox. An example is shown below:</p>
<pre><code>* College...
* Home [2/2]
  - [X] Read book
  - [X] Take print-out
* Recreation [50%]
  - [X] Read newspaper
  - [ ] Meditate</code></pre>
<p>If a task is completed, you can move it out of the Org file using <em>C-c C-x C-a</em>. This will create an archive file with the completed items.</p>
<h1 id="planner">Planner</h1>
<p>An Org mode file can be used as a planner. Each task can be marked with any of the following states - {TODO, DONE} using <em>C-c C-t</em> key combination. For example:</p>
<pre><code>* TODO College...
* DONE Home [2/2]...
* Recreation [50%]...</code></pre>
<p>You can also customize the TODO states depending on your workflow by setting <em>org-todo-keywords</em> in your Emacs startup file. For example:</p>
<pre><code>(setq org-todo-keywords
  '((sequence &quot;TODO(t)&quot; &quot;NEXT(n)&quot; &quot;STARTED(s)&quot; &quot;WAITING(w)&quot; &quot;|&quot; &quot;DONE(d)&quot; &quot;CANCELED(c)&quot;)))</code></pre>
<p>The tasks can be scheduled using <em>C-c C-s</em>. A date is prompted for using the <em>Calendar</em> and is placed below the list entry. For example:</p>
<pre><code>* TODO College
 * Assignments
 * Lab
   SCHEDULED: &lt;2016-04-06 Wed&gt;
   1. Compiler Design
   2. Programming Languages
 * Exams...</code></pre>
<p>You can also add the time interval during which you intend to complete the task. The above example with a scheduled time is shown below:</p>
<pre><code>* TODO College
 * Assignments
 * Lab
   SCHEDULED: &lt;2016-04-06 Wed 14:00-16:00&gt;
   1. Compiler Design
   2. Programming Languages
 * Exams...</code></pre>
<p>A deadline can be added to a task using <em>C-c C-d</em> shortcut. An example is given below:</p>
<pre><code>* TODO College
 * Assignments
 * Lab...
 * Exams
   DEADLINE: &lt;2016-04-08 Fri&gt;
   - Mathematics
   - Operating Systems
   - Databases
   - Compilers
* DONE Home [2/2]...
* Recreation [50%]...</code></pre>
<p>You can have multiple Org files stored in your system, and you can instruct GNU Emacs where to find them by setting <em>org-agenda-files</em> in your Emacs start-up file as shown below:</p>
<pre><code>(setq org-agenda-files (quote (&quot;/tmp&quot;)))</code></pre>
<p>Additionally, if you want an agenda view to see the scheduled items and deadlines, add the following to your GNU Emacs startup init file:</p>
<pre><code>(define-key global-map &quot;\C-ca&quot; 'org-agenda)</code></pre>
<p>In the Org file, when you press <em>C-c a</em>, the following agenda will show up in a new buffer:</p>
<pre><code>Week-agenda (W14):
Monday      4 April 2016 W14
  test:       In   4 d.:  Exams
Tuesday     5 April 2016
Wednesday   6 April 2016
  test:       14:00-16:00 Scheduled:  Lab
Thursday    7 April 2016
Friday      8 April 2016
  test:       Deadline:   Exams
Saturday    9 April 2016
Sunday     10 April 2016</code></pre>
<h1 id="tables">Tables</h1>
<p>Org-mode has a built-in table editor which neatly aligns the column data. For example:</p>
<pre><code>* TODO College...
* DONE Home [2/2]...
* Recreation [50%]
  - [X] Read newspaper
  - [ ] Meditate
  | Day       | Time | Status |
  |-----------+------+--------|
  | Monday    | 1.25 | Done   |
  | Tuesday   | 1.50 | Done   |
  | Wednesday |      |        |
  | Thursday  |      |        |
  | Friday    |      |        |
  | Saturday  |      |        |
  | Sunday    |      |        |</code></pre>
<p>You can also use spreadsheet formula on these tables to perform calculations. For example:</p>
<pre><code>* TODO College...
* DONE Home [2/2]...
* Recreation [50%]
  - [X] Read newspaper
  - [ ] Meditate
  | Day       | Time | Status |
  |-----------+------+--------|
  | Monday    | 1.25 | Done   |
  | Tuesday   | 1.50 | Done   |
  | Wednesday |      |        |
  | Thursday  |      |        |
  | Friday    |      |        |
  | Saturday  |      |        |
  | Sunday    |      |        |
  |-----------+------+--------|
  | Total     | 2.75 |        |
  #+TBLFM: @9$2=vsum(@2$2..@8$2)</code></pre>
<h1 id="exporting">Exporting</h1>
<p>The Org file can be exported to multiple output formats (TeX, HTML, ASCII, PDF, etc.). Using <em>C-c C-e</em> will produce a buffer with the ‘Org Export Dispatcher’ menu to select an exporter. This is shown in the following figure:</p>
<img alt="Org Export Dispatcher" src="http://www.shakthimaan.com/gallery/2017/osfy-emacs-mode-mar-31-2017/000-org-export-dispatch.png"></img>
<p>You can also write your own backend customisations to suit your needs.</p>
<h1 id="literate-programming">Literate programming</h1>
<p>Donald Knuth coined the term ‘Literate Programming’ in 1984. To quote him:</p>
<blockquote>
<p>&quot;I believe that the time is ripe for significantly better documentation of programs, and that we can best achieve this by considering programs to be works of literature. Hence, my title: ‘Literate Programming’.</p>
<p>Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.&quot;</p>
</blockquote>
<p>Org mode supports this style of programming using Babel. You need to activate the support for the programming languages in your GNU Emacs startup file. For example, the following code snippet helps to execute Bash shell scripts.</p>
<pre><code>(org-babel-do-load-languages
 'org-babel-load-languages
 '((sh . t)
   ))</code></pre>
<p>Consider a shell command to find the disk usage. You can create an Org file, and enclose the command in a Babel code block as shown below:</p>
<pre><code>#+BEGIN_SRC sh
  df -h
#+END_SRC</code></pre>
<p>When you press <em>C-c C-c</em> on this code block, you will be prompted with the string “Evaluate this sh code block on your system? (yes/no).” If you input “yes”, the output is produced in a <em>Results</em> section as shown below:</p>
<pre><code>#+RESULTS:
| Filesystem | Size | Used | Avail | Use% | Mounted        | on |
| udev       | 1.9G | 0    | 1.9G  |   0% | /dev           |    |
| tmpfs      | 384M | 6.0M | 378M  |   2% | /run           |    |
| /dev/sda1  | 913G | 75G  | 792G  |   9% | /              |    |
| tmpfs      | 1.9G | 57M  | 1.9G  |   3% | /dev/shm       |    |
| tmpfs      | 5.0M | 4.0K | 5.0M  |   1% | /run/lock      |    |
| tmpfs      | 1.9G | 0    | 1.9G  |   0% | /sys/fs/cgroup |    |
| tmpfs      | 384M | 64K  | 384M  |   1% | /run/user/1000 |    |</code></pre>
<p>You can learn more on Babel from their web page <a href="http://orgmode.org/worg/org-contrib/babel/">http://orgmode.org/worg/org-contrib/babel/</a>.</p>
<p>A mobile version of Org mode is also available as Free and Open Source Software. You can use a third party service to sync your Org files between your mobile and system. Since the files are plain text, they can also be revision controlled using Git or any version control software.</p>
<p>Please refer to the Org reference manual at <a href="http://orgmode.org/#docs">http://orgmode.org/#docs</a> for more tips, customisation options and documentation.</p>]]></description>
    <pubDate>Fri, 31 Mar 2017 22:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/03/31/emacs-org-mode/news.html</guid>
</item>
<item>
    <title>PyCon Pune 2017</title>
    <link>http://www.shakthimaan.com/posts/2017/03/10/pycon-pune-2017/news.html</link>
    <description><![CDATA[<p>I attended <a href="https://pune.pycon.org/">PyCon Pune 2017</a> conference between February 16-17 (Thursday-Friday), 2017 at <a href="http://amanora.com/township-project-in-pune-about-parktown">Amanora - The Ferns Hotels and Club</a>, Pune.</p>
<img alt="Ferns Hotel" src="http://shakthimaan.com/images/2017/pycon-pune-2017/1-ferns-hotel.jpg"></img>
<h1 id="day-i">Day I</h1>
<p>I reached the venue early in the morning, to be of any help to the volunteers. The projector had to be checked, and I used my laptop to test the same. After changing couple of cables and adapters, the clarity on the screen was good.</p>
<p>This event had a single track where everyone sat in one big hall. I welcome this change!</p>
<p><a href="https://github.com/HonzaKral">Honza Král</a> started the conference with his keynote, titled “(My) OSS Life”. He shared his experiences and learning in the Free and Open Source Software (F/OSS) world. At present, he maintains the Python drivers for <a href="https://www.elastic.co/">Elasticsearch</a>.</p>
<img alt="Honza Král" src="http://shakthimaan.com/images/2017/pycon-pune-2017/2-honza-key-note.jpg"></img>
<p>The keynote was followed by <a href="http://anandology.com/">Anand Chitipotu’s</a> talk on “Writing Beautiful Code”. He illustrated code examples on how to write simple, elegant, readable Python code. The use of meaningful variable names, comments were emphasized a lot. It was a short list of collated points on basic mistakes that newbie programmers make, and how to effectively write beautiful code.</p>
<p><a href="https://goldmag.de/">Florian Fuchs</a> then spoke on “Hacking Mailing Lists - The Mailman 3 API Ecosystem”. He explained the new architecture and API with code examples. He has been hacking on the new Mailman 3 web UI and the Python API bindings.</p>
<p>After attending these talks, I made a visit to the three booths at the conference - <a href="https://www.redhat.com">Red Hat</a>, <a href="https://www.python.org/psf/">Python Software Foundation</a> and <a href="https://reserved-bit.com/">reserved-bit</a>. I also signed copies of <a href="http://shakthimaan.com/what-to-do.html">my book</a> that people had brought.</p>
<p>After lunch, I attended the “i18n-ise Django Apps” talk by <a href="http://sundeep.co.in/">Sundeep Anand</a>, where he showed the internationalization processes for a Django application. All the relevant file modifications and commands involved were demonstrated.</p>
<p><a href="https://github.com/warthog9">John ‘warthog9’ Hawley</a> is a Perl guy and gave an interesting keynote on building your own hardware, and why you should do that. He explained the various challenges he had faced, the process involved in the same. He had exclusively designed and produced a “Battle Bunny” embedded micro-Python kit for the conference and development sprints.</p>
<p>The “Building Trust in Releases” talk by <a href="https://nigelb.me/">Nigel Babu</a> was very informative. He explained four important aspects in release management - cadence, documentation, testing, and empathy. This was also an experience report on DevOps practices, and was quite detailed and useful.</p>
<p>The last keynote of the day was by a Physics teacher, <a href="http://www.gnovi.in/">Praveen Patil</a>. He shared his exploration on using Python to teach Physics to high school students. He is actively involved in <a href="http://expeyes.in">ExpEYES Project</a>, teacher training programs and also contributes content to National Repository of Open Educational Resources (NROER).</p>
<img alt="Praveen Patil system setup" src="http://shakthimaan.com/images/2017/pycon-pune-2017/3-praveen-demo.jpg">
<h1 id="day-ii">Day II</h1>
<p>The morning keynote was by <a href="http://therealkatie.net/">Katie Cunningham</a>. She was initially testing the microphone and laptop by singing nursery rhymes. While the organizers decided to wait for people to arrive and settle down, there was time for lightning talks. So, I volunteered to start the day with the resounding <a href="http://shakthimaan.com/downloads.html#nursery-rhymes">“Nursery Rhymes”</a>. After a couple of other lightning talks, Katie started her keynote on accessibility guidelines. It was quite an informative session.</p>
<p>“You can help develop Python - and you should!” talk by <a href="http://turnbull.sk.tsukuba.ac.jp/Blog/">Stephen Turnbull</a> was on the history of Python, PEP guidelines and the functioning of the community. I also had a chance to talk with him personally on the story of <a href="https://www.xemacs.org/">XEmacs</a>.</p>
<p><a href="https://farhaanbukhsh.wordpress.com/">Farhaan Bukhsh</a> and <a href="http://www.vivekanand.xyz/">Vivek Anand</a> presented their Google Summer of Code (GSoC) work on the project <a href="https://pagure.io/">Pagure</a>, which is an alternative to GitHub and GitLab. They shared the past, present and future roadmap for the project. In the “Testing native binaries using CFFI” talk, <a href="http://nibrahim.net.in/">Noufal Ibrahim</a> demonstrated how to write Python bindings using CFFI.</p>
<p>After lunch, there was time for lightning talks. Different Python user group communities (PyDelhi, HydPy, PythonPune, PyLadies Pune) pitched about their work . I had prepared the sequel to <a href="http://shakthimaan.com/downloads.html#yet-another-lightning-talk">“The Yet Another Lightning Talk”</a> and requested the audience to sing on my behalf. The feedback was positive, as usual. The latest addition to the nursery rhyme is as follows:</p>
<pre><code>Twinkle, Twinkle, unit tests,
How I wonder, where you exist!
I will write unit tests,
Until the project is laid to rest.</code></pre>
<p>The afternoon keynote was by <a href="http://www.curiousefficiency.org/">Nick Coghlan</a>. He also shared his know-how on Free and Open Source Software and community best practices. “Django on Steroids - Lessons from Scale” by <a href="https://sanketsaurav.com/">Sanket Saurav</a> was a good technical, intermediate-level talk on Django customization, nginx settings, scaling and deployment.</p>
<p>The last keynote of the day and the conference was by <a href="http://terri.zone12.com/">Terri Oda</a> on “Is OSS more secure?”. She presented the various dimensions on which one needs to answer the question. She concluded by saying that there is definitely more scope in F/OSS to be more secure given the number of people involved, and the transparency in the process.</p>
<h1 id="conclusion">Conclusion</h1>
<p>The number of participants at the conference was more than five hundred, and they all came on a week day to attend! For a first-time event, that is quite impressive. This clearly shows that there is a demand for such events across India.</p>
<p><img alt="PyCon Pune 2017 group photo" src="http://shakthimaan.com/images/2017/pycon-pune-2017/4-group-photo.jpg"></img><br /> PC: <a href="http://www.shakthimaan.com/posts/2017/03/10/pycon-pune-2017/kushaldas.in">Kushal Das</a></p>
<p>Initially, there was a lot of <a href="https://mail.python.org/pipermail/inpycon/2016-October/010755.html">resistance</a> (follow the thread) to this event, including the name of the event. Communities are meant for innovation, and stifling is futile. You can learn a lot in a community, and there are guidelines and best practices that are followed.</p>
<p>It was a four day event with development sprints, and hence it had to be a PyCon. Legally, the Python Software Foundation allows using the name “PyCon” for regional events too. Given the context and the necessity, I am happy that the Python Software Foundation (PSF) got the message right, and understood the need for the conference and supported it in a big way!</p>
<p>The development sprints had a limited seating capacity, and the registration got over early. I was informed that there were hundred more requests for the development sprints, which again emphasizes the need for such events! I also had a chance to meet some of the #dgplug (irc.freenode.net) folks with whom I have been interacting online on IRC.</p>
<p>It does take a lot of effort to organize a conference, and I congratulate the PyCon Pune team on their first event.</p>]]></description>
    <pubDate>Fri, 10 Mar 2017 07:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/03/10/pycon-pune-2017/news.html</guid>
</item>
<item>
    <title>GNU Emacs - HTML mode, indentation and Magit</title>
    <link>http://www.shakthimaan.com/posts/2017/02/07/emacs-html-indentation-magit/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, April 2016 edition.]</em></p>
<p>This article in the GNU Emacs series takes readers on how to use HTML mode, do indentation, and use the Magit interface.</p>
<h1 id="html-mode">HTML mode</h1>
<p>You can use HTML mode to effectively edit HTML and CSS files using GNU Emacs. To start the mode, use <em>M-x html-mode</em>. You will see the string ‘HTML’ in the mode line.</p>
<h2 id="default-template">Default template</h2>
<p>A default HTML template can be started by opening a test.html file, and using <em>C-c C-t html</em>. It will produce the following content:</p>
<pre><code>&lt;html&gt;
  &lt;head&gt;
&lt;title&gt;</code></pre>
<p>You will then be prompted with the string ‘Title:’ to input the title of the HTML page. After you type ‘Hello World’, the default template is written to the buffer, as follows:</p>
<pre><code>&lt;html&gt;
  &lt;head&gt;
&lt;title&gt;Hello World&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Hello World&lt;/h1&gt;

&lt;address&gt;
&lt;a href=&quot;mailto:user@hostname&quot;&gt;shakthi&lt;/a&gt;
&lt;/address&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<h2 id="tags">Tags</h2>
<p>You can enter HTML tags using <em>C-c C-t</em>. GNU Emacs will prompt you with the available list of tags. A screenshot of the available tags is shown in Figure 1:</p>
<img alt="HTML tags" width="800" src="http://www.shakthimaan.com/images/emacs/tags.png"></img>
<p>The anchor tag can be inserted using ‘a’. You will then receive a message prompt: ‘Attribute:’. You can provide the value as ‘href’. It will then prompt you for a value, and you can enter a URL, say, ‘http://www.shakthimaan.com’. The anchor tag will be constructed in the buffer as you input values in the mini-buffer. You will be prompted for more attributes. If you want to finish, simply hit the <em>Enter</em> key, and the anchor tag will be completed. The final output is shown below:</p>
<pre><code>&lt;a href=&quot;http://www.shakthimaan.com&quot;&gt;&lt;/a&gt;</code></pre>
<p>You can insert a <em>h2</em> tag by specifying the same after <em>C-c C-t</em>. You can also add any attributes, as required. Otherwise, simply hitting the <em>Enter</em> key will complete the tag. The rendered text is as follows:</p>
<pre><code>&lt;h2&gt;&lt;/h2&gt;</code></pre>
<p>You can insert images using the <em>alt</em> tag. You can specify the <em>src</em> attribute and a value for the same. It is also a good practice to specify the <em>alt</em> attribute for the image tag. An example is shown below:</p>
<pre><code>&lt;img alt=&quot;image&quot; src=&quot;http://shakthimaan.com/images/ShakthiK-workshop-A4-poster.png&quot;&gt;</code></pre>
<p>Unordered lists can be created using <em>C-c C-t</em> followed by ‘ul’. It will then prompt you for any attributes that you want included in the tag. You can hit the <em>Enter</em> key, which will prompt you with the string ‘List item:’ to key in list values. An example of the output is shown below:</p>
<pre><code>&lt;ul&gt;
  &lt;li&gt;One
    &lt;li&gt;Two
      &lt;li&gt;Three
&lt;/ul&gt;</code></pre>
<p>You can neatly align the code by highlighting the above text and indenting the region using <em>C-M-\</em>. The resultant output is shown below:</p>
<pre><code>&lt;ul&gt;
  &lt;li&gt;One
  &lt;li&gt;Two
  &lt;li&gt;Three
&lt;/ul&gt;</code></pre>
<p>If you wish to comment out text, you can select the region and type <em>M-q</em>. The text is enclosed using “&lt;!--” and “--&gt;”. For example, the commented address tags in the above example look like what follows:</p>
<pre><code>&lt;!-- &lt;address&gt; --&gt;
&lt;!-- &lt;a href=&quot;mailto:shakthi@achilles&quot;&gt;shakthi&lt;/a&gt; --&gt;
&lt;!-- &lt;/address&gt; --&gt;</code></pre>
<p>A number of major modes exist for different programming environments. You are encouraged to try them out and customize them to your needs.</p>
<h2 id="accents">Accents</h2>
<p>In HTML mode, you can insert special characters, accents, symbols and punctuation marks. These characters are mapped to Emacs shortcuts. Some of them are listed in the following table:</p>
<table>
<col width="12%"></col>
<col width="12%"></col>
<thead>
<tr class="header">
<th align="left">Shortcut</th>
<th align="left">Character</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">C-x 8 ’ a</td>
<td align="left">á</td>
</tr>
<tr class="even">
<td align="left">C-x 8 &quot; e</td>
<td align="left">ë</td>
</tr>
<tr class="odd">
<td align="left">C-x 8 / E</td>
<td align="left">Æ</td>
</tr>
<tr class="even">
<td align="left">C-x 8 3/4</td>
<td align="left">¾</td>
</tr>
<tr class="odd">
<td align="left">C-x 8 C</td>
<td align="left">©</td>
</tr>
<tr class="even">
<td align="left">C-x 8 L</td>
<td align="left">£</td>
</tr>
<tr class="odd">
<td align="left">C-x 8 P</td>
<td align="left">¶</td>
</tr>
<tr class="even">
<td align="left">C-x 8 u</td>
<td align="left">µ</td>
</tr>
<tr class="odd">
<td align="left">C-x 8 R</td>
<td align="left">®</td>
</tr>
<tr class="even">
<td align="left">C-x / /</td>
<td align="left">÷</td>
</tr>
</tbody>
</table>
<h1 id="indentation">Indentation</h1>
<p>Consider the following paragraph:</p>
<p>“When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.”</p>
<p>You can neatly fit the above text into 80 columns and 25 rows inside GNU Emacs using <em>M-q</em>. The result is shown below:</p>
<pre><code>When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.</code></pre>
<p>You can also neatly indent regions using the <em>C-M-\</em> shortcut. For example, look at the following HTML snippet:</p>
<pre><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;Tamil Nadu&lt;/td&gt;
&lt;td&gt;Chennai&lt;/td&gt; 
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Karnataka&lt;/td&gt;
&lt;td&gt;Bengaluru&lt;/td&gt; 
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Punjab&lt;/td&gt;
&lt;td&gt;Chandigarh&lt;/td&gt; 
&lt;/tr&gt;
&lt;/table&gt;</code></pre>
<p>After indenting the region with <em>C-M-\</em>, the resultant output is shown below:</p>
<pre><code>&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;Tamil Nadu&lt;/td&gt;
    &lt;td&gt;Chennai&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Karnataka&lt;/td&gt;
    &lt;td&gt;Bengaluru&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Punjab&lt;/td&gt;
    &lt;td&gt;Chandigarh&lt;/td&gt; 
  &lt;/tr&gt;
&lt;/table&gt;</code></pre>
<p>If you have a long line which you would like to split, you can use the <em>C-M-o</em> shortcut. Consider the quote:</p>
<blockquote>
<p>“When you’re running a startup, your competitors decide how hard you work.” ~ Paul Graham</p>
</blockquote>
<p>If you keep the cursor after the comma, and use <em>C-M-o</em>, the result is shown below:</p>
<pre><code>&quot;When you're running a startup, 
                                your competitors decide how hard you work.&quot; ~ Paul Graham</code></pre>
<h1 id="magit">Magit</h1>
<p>Magit is a fantastic interface to Git inside GNU Emacs. There are many ways in which you can install Magit. To install from the Melpa repository, add the following to your ~/.emacs:</p>
<pre><code>(require 'package)
(add-to-list 'package-archives
             '(&quot;melpa&quot; . &quot;http://melpa.org/packages/&quot;) t)</code></pre>
<p>When you do <em>M-x list-packages</em>, you will see ‘magit’ in the list. You can press ‘i’ to mark Magit for installation, followed by ‘x’ to actually install it. This will install Magit in ~/.emacs.d/elpa. The version installed on my system is magit-20160303.502.</p>
<p>When you open any file inside GNU Emacs that is version controlled using Git, you can start the Magit interface using <em>M-x magit-status</em>. I have bound this key to <em>C-x g</em> shortcut in ~/.emacs using the following:</p>
<pre><code>(global-set-key (kbd &quot;C-x g&quot;) 'magit-status)</code></pre>
<p>The default magit screenshot for the GNU Emacs project README file is shown in Figure 2.</p>
<img alt="Magit" src="http://www.shakthimaan.com/images/emacs/magit-default.png"></img>
<p>Pressing ‘l’ followed by ‘l’ will produce the history log in the magit buffer. A screenshot is provided in Figure 3.</p>
<img alt="History" width="800" src="http://www.shakthimaan.com/images/emacs/magit-history.png"></img>
<p>You can make changes to the project sources and stage them to the index using the ’s’ shortcut. You can unstage the changes using the ‘u’ shortcut. After making changes to a file, you need to use <em>M-x magit-status</em> to update the Magit buffer status.</p>
<p>A sample screenshot of the modified files and staged changes is shown in Figure 4.</p>
<img alt="Staged" src="http://www.shakthimaan.com/images/emacs/magit-staged-unstaged.png"></img>
<p>You can hit <em>TAB</em> and <em>Shift-TAB</em> to cycle through the different sections in the Magit buffer. To commit a message, press ‘c’ followed by ‘c’. It will pop up a buffer where you can enter the commit message.</p>
<p>You can create and checkout branches using the ‘b’ shortcut. A screenshot of the magit branch pop-up menu is shown in Figure 5.</p>
<img alt="Branch" src="http://www.shakthimaan.com/images/emacs/magit-branch.png"></img>
<p>All the basic Git commands are supported in Magit - diffing, tagging, resetting, stashing, push-pull, merging and rebasing. You are encourged to read the Magit manual ( <a href="https://magit.vc/">https://magit.vc/</a> ) to learn more.</p>]]></description>
    <pubDate>Tue, 07 Feb 2017 19:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/02/07/emacs-html-indentation-magit/news.html</guid>
</item>
<item>
    <title>Parabola GNU/Linux Libre on Lenovo E460</title>
    <link>http://www.shakthimaan.com/posts/2017/02/02/parabola-gnu-linux-on-lenovo-e460/news.html</link>
    <description><![CDATA[<p>I wanted to buy a laptop for my personal use, and exclusively for Free Software. I have mostly used Lenovo Thinkpads because of their good support for GNU/Linux. I neither wanted an expensive one nor did I want to pay for Windows. The use of SSD would help speed up the boot time. A wide screen laptop will be helpful to split the Emacs frame. I looked at various Netbooks in the market, but, the processing power was not good enough. I really need computing power, with at least four CPUs. 8 GB of RAM with room for expansion will be helpful in future. I prefer to use anti-glare matte displays as they are easy on the eyes. Also, I wanted a laptop that is less than 2kg, and is easy to carry around.</p>
<p>After reviewing many models and configurations, I purchased the <a href="http://www3.lenovo.com/in/en/laptops/thinkpad/thinkpad-e-series/E460/p/22TP2TEE460">Lenovo E460</a> model that comes with <a href="http://www.freedos.org/">FreeDOS</a>, and swapped the default HDD for SSD (&lt; 500 GB).</p>
<img alt="Lenovo E460 screen" src="http://shakthimaan.com/images/2017/lenovo-e460/lenovo-e460-screen.png"></img>
<h1 id="specification">Specification</h1>
<ul>
<li>Intel(R) Core(TM) i5-6200 CPU @ 2.30 GHz (4 processors).</li>
<li>14&quot; display</li>
<li>437 GB SSD disk</li>
<li>8 GB RAM</li>
<li>Intel Corporation HD Graphics 520</li>
<li>Intel Dual Band Wireless-AC 3165 Plus Bluetooth</li>
<li>Intel I219-V Ethernet Controller</li>
<li>3 USB ports</li>
<li>1 HDMI port</li>
<li>4-in-1 Card Reader</li>
<li>FreeDOS</li>
<li>1.81 kg</li>
</ul>
<h1 id="parabola-gnulinux-libre">Parabola GNU/Linux Libre</h1>
<p>I tried <a href="https://trisquel.info/">Trisquel GNU/Linux</a> first on on this laptop. It is a derivative of Ubuntu without non-free software. I experimented with <a href="https://www.qubes-os.org/">Qubes OS</a>, but, its dom0 has proprietary blobs. <a href="https://www.gnu.org/software/guix/">GNU Guix</a> is an interesting project, but, it does not have all the packages that I need (yet). I liked rolling distributions, and hence decided to try <a href="https://www.parabola.nu/">Parabola GNU/Linux Libre</a>, a derivative of <a href="https://www.archlinux.org/">Arch</a>, without the binary blobs.</p>
<p>There is no CD/DVD drive on this laptop, but, you can boot from USB. I first checked if all the software that I need are available in the Parabola GNU/Linux Libre repository, and then proceeded to install the same. I always encrypt the disk during installation. I have the <a href="https://mate-desktop.org/">Mate desktop environment</a> with <a href="http://xmonad.org/">XMonad</a> setup as a tiling window manager.</p>
<img alt="Lenovo E460 screen" src="http://shakthimaan.com/images/2017/lenovo-e460/lenovo-e460-screenshot.png"></img>
<p>Audio works out of the box. I do not use the web cam. I had to use the package scripts to install <a href="http://grisbi.org/">Grisbi</a> as it was not available in the base repository. Virtualization support exists on this hardware, and hence I use <a href="https://virt-manager.org/">Virtual Machine Manager</a>, <a href="http://wiki.qemu.org/Main_Page">QEMU</a> and <a href="https://libvirt.org/">libvirt</a>.</p>
<h1 id="command-output">Command Output</h1>
<p>All the hardware worked out of the box, except for the wireless which requires a binary blob. So, I purchased a <a href="https://www.thinkpenguin.com/gnu-linux/penguin-wireless-n-usb-adapter-gnu-linux-tpe-n150usb">ThinkPenguin Wireless N USB Adapter for GNU/Linux</a> which uses the free ath9k Atheros wireless driver.</p>
<p>As mandatory, I am providing some command outputs.</p>
<pre class="shell"><code>$ lspci

00:00.0 Host bridge: Intel Corporation Skylake Host Bridge/DRAM Registers (rev 08)
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 520 (rev 07)
00:14.0 USB controller: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller (rev 21)
00:14.2 Signal processing controller: Intel Corporation Sunrise Point-LP Thermal subsystem (rev 21)
00:16.0 Communication controller: Intel Corporation Sunrise Point-LP CSME HECI #1 (rev 21)
00:17.0 SATA controller: Intel Corporation Sunrise Point-LP SATA Controller [AHCI mode] (rev 21)
00:1c.0 PCI bridge: Intel Corporation Device 9d12 (rev f1)
00:1c.5 PCI bridge: Intel Corporation Sunrise Point-LP PCI Express Root Port #6 (rev f1)
00:1f.0 ISA bridge: Intel Corporation Sunrise Point-LP LPC Controller (rev 21)
00:1f.2 Memory controller: Intel Corporation Sunrise Point-LP PMC (rev 21)
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
00:1f.4 SMBus: Intel Corporation Sunrise Point-LP SMBus (rev 21)
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection I219-V (rev 21)
01:00.0 Network controller: Intel Corporation Intel Dual Band Wireless-AC 3165 Plus Bluetooth (rev 99)
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS522A PCI Express Card Reader (rev 01)

$ uname -a

Linux aether 4.8.17-gnu-1 #1 SMP PREEMPT Wed Jan 18 05:04:13 UYT 2017 x86_64 GNU/Linux

$ df -h

Filesystem             Size  Used Avail Use% Mounted on
dev                    3.7G     0  3.7G   0% /dev
run                    3.7G  920K  3.7G   1% /run
/dev/mapper/cryptroot  437G   95G  321G  23% /
tmpfs                  3.7G   26M  3.7G   1% /dev/shm
tmpfs                  3.7G     0  3.7G   0% /sys/fs/cgroup
tmpfs                  3.7G  196K  3.7G   1% /tmp
/dev/sda1              976M   45M  865M   5% /boot
tmpfs                  745M   28K  745M   1% /run/user/1000

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.3G        2.4G        3.2G         83M        1.7G        4.6G
Swap:          2.1G          0B        2.1G

$ lscpu

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 78
Model name:            Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Stepping:              3
CPU MHz:               499.951
CPU max MHz:           2800.0000
CPU min MHz:           400.0000
BogoMIPS:              4801.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp</code></pre>
<h1 id="conclusion">Conclusion</h1>
<img alt="Lenovo E460 screen" src="http://shakthimaan.com/images/2017/lenovo-e460/lenovo-e460-sticker.png"></img>
<p>I have been using the laptop for more than three months, and it has really been a smooth experience. It costed less than ₹ 55,000. The battery life is decent. I printed couple of Free Software stickers to identify my laptop. The <a href="https://static.fsf.org/nosvn/stickers/GNU-Linux.png">“Inside GNU/Linux”</a> sticker covers the web cam, and the <a href="http://static.fsf.org/nosvn/stickers/fsf.svg">“Free Software Foundation”</a> sticker is pasted behind the screen. The folks at #parabola IRC channel on irc.freenode.net are quite helpful. The <a href="https://wiki.parabola.nu/">Parabola GNU/Linux Libre Wiki</a> has excellent documentation for your reference.</p>]]></description>
    <pubDate>Thu, 02 Feb 2017 16:15:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/02/02/parabola-gnu-linux-on-lenovo-e460/news.html</guid>
</item>
<item>
    <title>Travel - Gurugram (Gurgaon), Haryana</title>
    <link>http://www.shakthimaan.com/posts/2017/01/24/gurgaon/news.html</link>
    <description><![CDATA[<img alt="DLF I" src="http://www.shakthimaan.com/images/gurgaon-2017/1_DLF.jpg"></img><br />
<img alt="DLF II" src="http://www.shakthimaan.com/images/gurgaon-2017/2_DLF.jpg"></img><br />
<img alt="DLF III" src="http://www.shakthimaan.com/images/gurgaon-2017/3_DLF.jpg"></img><br />]]></description>
    <pubDate>Tue, 24 Jan 2017 13:15:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2017/01/24/gurgaon/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Calendar, Macros and Drawing</title>
    <link>http://www.shakthimaan.com/posts/2016/12/28/emacs-calendar-macros-drawing/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, March 2016 edition.]</em></p>
<p>In this next article in the GNU Emacs series, you will learn how to use its calendar, center text, macros and drawing tools.</p>
<h1 id="calendar">Calendar</h1>
<p>You can use and display a calendar inside GNU Emacs using the following command (also see figure below):</p>
<pre><code>M-x calendar</code></pre>
<img alt="Calendar" src="http://www.shakthimaan.com/images/emacs/calendar.png"></img>
<h2 id="day">Day</h2>
<p>You can move forward by a day using the <em>C-f</em> shortcut, and move back a day using the <em>C-b</em> keys. You can move to the current date using the ’.’ key.</p>
<p>To start the week on a Monday, set the following in your ~/.emacs.</p>
<pre><code>(setq calendar-week-start-day 1)</code></pre>
<h2 id="week">Week</h2>
<p>If you wish to move forward by a week, you can use the <em>C-n</em> shortcut, and to move back by a week, use the <em>C-p</em> shortcut. The <em>C-a</em> shortcut can be used to move to the beginning of the week, while the <em>C-e</em> shortcut can be used to move to the end of the week.</p>
<h2 id="month">Month</h2>
<p>You can move to the beginning of a month using the <em>M-a</em> shortcut. To move to the end of the month, use <em>M-e</em>.</p>
<p>You can move forward and backward a month using the <em>M-}</em> and <em>M-{</em> shortcuts, respectively.</p>
<p>If you wish to scroll forward three months, use the <em>C-v</em> shortcut. To scroll backward three months, use the <em>M-v</em> shortcut.</p>
<h2 id="year">Year</h2>
<p>In order to move forward a year, you can use the <em>C-x ]</em> shortcut, and to move back a year, you can use the <em>C-x [</em> shortcut.</p>
<p>You can go to a specified date using the <em>g d</em> key combination. It will then prompt you with the messages “Year (&gt;0):”, “Month name:” and “Day (1-31):”, and will take you to the specified date.</p>
<p>You can move to the beginning of the year using the <em>M-&lt;</em> shortcut, and to the end of the year using the <em>M-v</em> shortcut.</p>
<p>You are encouraged to read the ‘Calendar’ section in the GNU Emacs manual at <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Calendar_002fDiary.html#Calendar_002fDiary">https://www.gnu.org/software/emacs/manual/html_node/emacs/Calendar_002fDiary.html#Calendar_002fDiary</a>, to learn more.</p>
<h1 id="centering">Centering</h1>
<p>Consider the following poem that I wrote in 2015:</p>
<pre><code>Poem

Project issues in the way, 
In the way, in the way. 
Project issues in the way, 
My fair user. 

Fixing bugs right way, 
Right away, right away. 
Fixing bugs right way, 
My fair user. 

Merging pull requests as I say, 
As I say, as I say. 
Merging pull requests as I say, 
My fair user. 

All the tests are passing, hey! 
Passing, hey! Passing, hey! 
All the tests are passing, hey! 
My fair user. 

As a client, you should pay, 
You should pay, you should pay. 
As a client, you should pay, 
My fair user. 

Python really saved the day, 
Saved the day, saved the day. 
Python really saved the day, 
My fair user.</code></pre>
<p>You can center the title “Poem” by placing the cursor on it, and typing “M-x set-justification-center”.</p>
<p>Marking and highlighting the poem, and using <em>M-x center-region</em> will center the poem. The output is shown below:</p>
<pre><code>         Poem

Project issues in the way, 
 In the way, in the way. 
Project issues in the way, 
      My fair user. 

 Fixing bugs right way, 
Right away, right away. 
 Fixing bugs right way, 
     My fair user. 

Merging pull requests as I say, 
      As I say, as I say. 
Merging pull requests as I say, 
         My fair user. 

All the tests are passing, hey! 
  Passing, hey! Passing, hey! 
All the tests are passing, hey! 
         My fair user. 

  As a client, you should pay, 
You should pay, you should pay. 
  As a client, you should pay, 
         My fair user. 

 Python really saved the day, 
Saved the day, saved the day. 
 Python really saved the day, 
        My fair user. </code></pre>
<h1 id="macros">Macros</h1>
<p>Macros are recorded key strokes that can be stored and replayed. You can start defining a keyboard macro using <em>C-x (</em> command or the <em>F3</em> key. You can then type a series of keys that constitute the macro. To finish defining the macro, you can use <em>C-x )</em> or the <em>F4</em> key. In order to execute the previous defined macro, you can use <em>C-x e</em> shortcut or <em>F4</em>.</p>
<p>Consider the following text in a buffer that contains a serial number, date and an examination subject list:</p>
<pre><code>1,2015-03-02,English
2,2015-03-03,Physics
3,2015-03-05,Mathematics
4,2015-03-08,Biology
5,2015-03-10,Chemistry</code></pre>
<p>Suppose you wish to add a space after each comma, you can define the following macro (exclude the semi-colon followed by the text) for the first line using the following key strokes:</p>
<pre><code>F3    ; Start macro definition
C-s   ; Search for
,     ;   comma
Enter ;
Space ;
C-s   ; Search again for
,     ;   comma
Enter ;
Space ;
C-n   ; Move to next line
C-a   ; Move to beginning of line
F4    ; End macro definition</code></pre>
<p>Using <em>C-x e</em> or <em>F4</em> repeatedly will turn the above input CSV text into the following:</p>
<pre><code>1, 2015-03-02, English
2, 2015-03-03, Physics
3, 2015-03-05, Mathematics
4, 2015-03-08, Biology
5, 2015-03-10, Chemistry</code></pre>
<p>You can give a name (say, ‘comma’) to the previously defined macro using <em>C-x C-k n</em>. You can then execute the macro using <em>M-x comma</em>. You can also insert the named macro into a file using <em>M-x insert-kbd-macro</em> command. You can bind a macro to a key using <em>C-x C-k b</em> shortcut.</p>
<p>If you wish to apply the macro to each line in a region, you can use <em>C-x C-k r</em> keys. In order to cycle between the previous and next macros in the macro ring, you can use <em>C-x C-k C-p</em> and <em>C-x C-k C-n</em> shortcuts respectively. You can also delete a macro using <em>C-x C-k C-d</em> key combination.</p>
<h1 id="picture-mode">Picture mode</h1>
<p>You can draw diagrams inside Emacs using Picture mode. To start Picture mode, use <em>M-x picture-mode</em> command, and to exit use the <em>C-c C-c</em> shortcut.</p>
<p>The cursor movement keys in a buffer are also applicable in picture mode. To move the cursor right, you can use the <em>C-f</em> keys, and to move left by one character, you can use the <em>C-b</em> shortcut. To move the cursor up and down by one character, use the <em>C-p</em> and <em>C-n</em> shortcuts, respectively. The <em>C-d</em> shortcut is used to delete a character.</p>
<p>Before you move the cursor to draw in the buffer, you need to set the drawing direction. The following table summarizes the shortcut keys, and their associated drawing direction.</p>
<table>
<col width="11%"></col>
<col width="11%"></col>
<thead>
<tr class="header">
<th align="left">Shortcut</th>
<th align="left">Direction</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">C-c ^</td>
<td align="left">Up</td>
</tr>
<tr class="even">
<td align="left">C-c .</td>
<td align="left">Down</td>
</tr>
<tr class="odd">
<td align="left">C-c &gt;</td>
<td align="left">Right</td>
</tr>
<tr class="even">
<td align="left">C-c &lt;</td>
<td align="left">Left</td>
</tr>
<tr class="odd">
<td align="left">C-c `</td>
<td align="left">Northwest</td>
</tr>
<tr class="even">
<td align="left">C-c ’</td>
<td align="left">Northeast</td>
</tr>
<tr class="odd">
<td align="left">C-c /</td>
<td align="left">Southwest</td>
</tr>
<tr class="even">
<td align="left">C-c <br /></td>
<td align="left">Southeast</td>
</tr>
</tbody>
</table>
<p>If you want to move the cursor forward in the drawing direction, you can use the <em>C-c C-f</em> shortcut. To move the cursor backward, use the <em>C-c C-b</em> key combination. If you want to delete a line, use the <em>C-k</em> command. You can insert a new line using the <em>C-o</em> shortcut. You can also draw a rectangle around a region using the <em>C-c C-r</em> shortcut. A drawing done using Picture mode is shown in Figure 2.</p>
<img alt="Diagram using Picture mode" src="http://shakthimaan.com/images/emacs/picture-mode.png"></img>
<h1 id="artist-mode">Artist mode</h1>
<p>Artist mode can also be used to draw diagrams in GNU Emacs. You can enter this mode using <em>M-x artist-mode</em>, and exit the same using <em>C-c C-c</em>.</p>
<p>You can draw pictures using the keyboard alone or also use the mouse in Artist mode. In order to start and stop drawing, use the <em>Enter</em> key. This is equivalent to putting the pen down when drawing, and lifting it up when you want to perform a different action.</p>
<p>The buffer navigation commands to move right and left are the same as <em>C-f</em> and <em>C-b</em> shortcuts respectively. You can move up a column using the <em>C-p</em> shortcut, and move down a column using the <em>C-n</em> key.</p>
<p>You can draw geometric shapes using Artist mode. To select a shape or operation you can use <em>C-c C-a C-o</em> key combination. This will provide a list of shapes and actions you can perform. This list is shown in Figure 3:</p>
<img alt="Artist mode operations" src="http://shakthimaan.com/images/emacs/artist-select-operation.png"></img>
<p>The shortcuts listed in the following table are available for drawing specific shapes:</p>
<table>
<col width="12%"></col>
<col width="12%"></col>
<thead>
<tr class="header">
<th align="left">Shortcut</th>
<th align="left">Shape</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">C-c C-a e</td>
<td align="left">Ellipse</td>
</tr>
<tr class="even">
<td align="left">C-c c-a p</td>
<td align="left">Polylines</td>
</tr>
<tr class="odd">
<td align="left">C-c C-a r</td>
<td align="left">Rectangles</td>
</tr>
<tr class="even">
<td align="left">C-c C-a l</td>
<td align="left">Lines</td>
</tr>
</tbody>
</table>
<p>Figure 4 depicts an ellipse drawn using Artist mode:</p>
<img alt="Ellipse" src="http://shakthimaan.com/images/emacs/artist-ellipse.png"></img>
<p>Figure 5 is an example of polylines:</p>
<img alt="Polylines" src="http://shakthimaan.com/images/emacs/artist-polyline.png"></img>
<p>You can fill a shape using <em>C-c C-a f</em> key combination. The following Figure 6 shows a circular representation filled with dots.</p>
<img alt="Circle fill" src="http://shakthimaan.com/images/emacs/artist-circle-fill.png"></img>
<p>You can also spray characters in the buffer using the <em>C-c C-a S</em> shortcut keys. An example is shown in Figure 7:</p>
<img alt="Spray" src="http://shakthimaan.com/images/emacs/artist-spray.png"></img>
<p>The character to be used for drawing can be changed using <em>C-c C-a C-l</em> shortcut. The character to fill shapes can be set using <em>C-c C-a C-f</em> key combination.</p>
<p>If you want to cut an area, you can draw a rectangle around it using <em>C-c C-a C-k</em> key combination. You can also copy the image area using the <em>C-c C-a M-w</em> keys, and paste the same using <em>C-c C-a C-y</em> or <em>C-x r y</em> shortcuts. To set the operation to erase text, you can use <em>C-c C-a C-d</em> key combination.</p>
<p>You can refer to the Emacs Wiki Artist mode for more documentation and help - <a href="http://www.emacswiki.org/emacs/ArtistMode"><code class="url">http://www.emacswiki.org/emacs/ArtistMode</code></a>.</p>]]></description>
    <pubDate>Wed, 28 Dec 2016 16:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/12/28/emacs-calendar-macros-drawing/news.html</guid>
</item>
<item>
    <title>Functional Conference 2016, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2016/11/26/functional-conf-2016/news.html</link>
    <description><![CDATA[<p>I attended <a href="http://functionalconf.com/2016/">Functional Conf 2016</a> at <a href="http://chanceryhotels.com/accommodation/chancerypavilion/index.htm">Hotel Chancery Pavilion, Bengaluru</a> between October 13-16, 2016. The conference was on October 14-15, 2016 and there were pre- and post-conference workshops.</p>
<p>After arriving early on the day of the workshop, I checked-in to my hotel accommodation. A view of the Kanteerva stadium from the hotel.</p>
<img alt="Kanteerva Stadium" src="http://www.shakthimaan.com/images/functionalconf-2016/1-kanteerva-stadium.png"></img>
<p>Pre-Conference Workshop</p>
<p>I had registered for the <a href="https://confengine.com/functional-conf-2016/proposal/3150/deep-dive-into-erlang-ecosystem">“Deep Dive into Erlang Ecosystem” workshop</a> by <a href="https://github.com/rvirding">Robert Virding</a>, one of the creators of the <a href="https://www.erlang.org/">Erlang programming language</a>. He started the day’s proceedings with an introduction to Erlang basics and covered both sequential and concurrent programming. He also gave an overview of the <a href="https://en.wikipedia.org/wiki/Open_Telecom_Platform">Open Telecom Platform (OTP)</a> and answered a number of questions from the participants. He, along with Joe Armstrong and Mike Williams, designed the Erlang programming language for telecommunication, keeping the system in mind and all the way from the ground-up.</p>
<p>He also mentioned how WhatsApp was able to handle two million concurrent connections on a single box, and they would peak at three million at times. As another Emacs and Lisp user, he wrote <a href="http://lfe.io/">Lisp Flavoured Erlang (LFE)</a>. He did not have much time to talk about it during the workshop, but, he did share differences between Erlang, Elixir and other languages that are being built around the Erlang ecosystem.</p>
<p>Day I</p>
<img alt="Robert Virding" src="http://www.shakthimaan.com/images/functionalconf-2016/2-robert-erlang.png"></img>
<p>The keynote of the day was from Robert Virding on <a href="https://confengine.com/functional-conf-2016/proposal/2964/the-erlang-ecosystem">“The Erlang Ecosystem”</a>. He gave a good overview and history of the Erlang programming language, and the rationale for designing the same. He elaborated on the challenges they faced in the early days of computing, and the first principles that they had to adhere to. They did not intend the language to be functional, but, it turned out to be so, and greatly helped their use case. One of the beautiful expressions in Erlang to represent bit-level protocol formats in an expressive format is shown below:</p>
<pre class="sourceCode erlang"><code class="sourceCode erlang"><span class="er">&lt;&lt;?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, </span>
<span class="er">      ID:16, Flgs:3, FragOff:13,</span>
<span class="er">      TTL:8, Proto:8, HdrChkSum:16,</span>
<span class="er">      SrcIP:32,</span>
<span class="er">      DestIP:32, RestDgram/binary&gt;&gt;</span></code></pre>
<p>Robert’s keynote was followed by another keynote by <a href="https://brianmckenna.org/blog/">Brian McKenna</a> on <a href="https://confengine.com/functional-conf-2016/proposal/3137/no-silver-bullets-in-functional-programming">“No Silver Bullets in Functional Programming”</a>. He gave the pros and cons of using Functional and other programming paradigms, and discussed the trade-offs. A number of code examples were shown to illustrate the concepts.</p>
<p>The next talk that I attended was by <a href="https://github.com/aloiscochard">Aloïs Cochard</a> on <a href="https://confengine.com/functional-conf-2016/proposal/2957/welcome-to-the-machines">“Welcome to the Machines”</a>. He gave an overview on the history of various Haskell libraries for data stream processing (pipes, conduit) and finally provided a tutorial on <a href="https://hackage.haskell.org/package/machines">machines</a>.</p>
<p><a href="https://bimorphic.com/">Abdulsattar Mohammed</a> introduced the need for dependent types using <a href="http://www.idris-lang.org/">Idris</a> with simple examples in his <a href="https://confengine.com/functional-conf-2016/proposal/2205/dependently-typed-programming-with-idris">“Dependently Typed Programming with Idris”</a> talk. The concepts were well narrated with numerous code snippets.</p>
<p>The next talk by <a href="https://twitter.com/debasishg">Debasish Ghosh</a> on <a href="https://confengine.com/functional-conf-2016/proposal/2761/an-algebraic-approach-to-functional-domain-modeling">“An algebraic approach to functional domain modeling”</a> was a modelling exercise on how to map business logic into functional algebra. He demonstrated a real world step-by-step process on the transformation from a problem domain to the solution domain consisting of algebraic data types, functions that operate on them, and business rules.</p>
<p>Ravi Mohan started his talk titled, <a href="https://confengine.com/functional-conf-2016/proposal/2920/equational-reasoning-from-code-to-math-and-back-again">“Equational Reasoning - From Code To Math and Back Again”</a>, with his learning in the Functional Programming (FP) world, and an overview of how to go about reasoning from code to math. His laptop had ran out of battery power, and he did not have his laptop charger. Before his scheduled talk, he had re-created plain text notes of his slides and walked us through the content.</p>
<p><a href="https://confengine.com/functional-conf-2016/proposal/2365/implementing-spark-like-system-in-haskell">“Implementing Spark like system in Haskell”</a> was an interesting session by <a href="https://github.com/yogeshsajanikar">Yogesh Sajanikar</a> on his attempt to create a DSL for map-reduce jobs. He did cover much of the internals in his implementation and the challenges faced. The hspark code is available at <a href="https://github.com/yogeshsajanikar/hspark">https://github.com/yogeshsajanikar/hspark</a>.</p>
<p>Day II</p>
<p>The second day began with the keynote by <a href="http://www.shakthimaan.com/posts/2016/11/26/functional-conf-2016/">John Hughes</a> on <a href="http://www.cse.chalmers.se/~rjmh/">“Why Functional Programming Matters”</a>. This was the best keynote of the conference, where John gave a very good historical perspective of FP and the experiences learnt in the process. His slide deck was excellent and covered all the necessary points that were part of his <a href="http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf">famous paper</a> with the same title.</p>
<p>This was followed by a series of demos on cool features in Functional Programming languages - Erlang, Idris, APL, F# and Julia.</p>
<p><a href="https://confengine.com/functional-conf-2016/proposal/3168/using-f-in-production-a-retrospective">“Using F# in production: A retrospective”</a> was a talk by <a href="https://ankitsolanki.com/">Ankit Solanki</a> on the lessons learned in using a functional language in implementing a tax e-filing application. They heavily use F# Type Providers to handle the variation in input CSV files.</p>
<p><a href="https://confengine.com/functional-conf-2016/proposal/3132/real-world-functional-programming-in-ads-serving">“Real world functional programming in Ads serving”</a> was a talk by <a href="https://github.com/sathish316">Sathish Kumar</a> from Flipkart on how they used functional programming in Java 8 for their product. They initially prototyped with Haskell, and used the constructs in Java.</p>
<p>I skipped the next talks, and spent time with Robert Virding in the Erlang booth.</p>
<p><a href="https://confengine.com/functional-conf-2016/proposal/2724/rethinking-state-management">Rethinking “State Management.”</a> was presented by Tamizhvendan S. He narrated examples on state management for a cafe application using F#. He also gave a demo of <a href="http://ionide.io/">Ionide</a> text editor and its features.</p>
<p>Post-conference workshop</p>
<p>I attended <a href="https://en.wikipedia.org/wiki/John_Hughes_(computer_scientist)">John Hughes</a> workshop on <a href="https://confengine.com/functional-conf-2016/proposal/3152/property-based-testing">Property-based Testing</a>. Initially, I thought he would be using <a href="https://hackage.haskell.org/package/QuickCheck">Haskell QuickCheck</a>, but, in the workshop he used the Erlang implementation. John mentioned that the Haskell and Erlang implementations are different, and their interests have diverged.</p>
<img alt="John Hughes" src="http://www.shakthimaan.com/images/functionalconf-2016/3-john-hughes.png"></img>
<p>He started the workshop by taking an example of writing property tests for encoded SMS messages using Erlang. He also demonstrated on how a minimal test example is produced when a test fails. The choice of deciding on what properties to test is still an active research problem. He also demonstrated how to collect statistics from the test results to analyse and improve them.</p>
<p>The property-based testing has been used by his company, <a href="http://www.quviq.com/">QuviQ</a>, to test C protocols for the automobile industry. They were able to generate tests to detect bugs in the CAN bus implementation. Here is a summary of the statistics for a project:</p>
<pre class="sh"><code>3,000 pages of specification
20,000 lines of QuickCheck
1,000,000 LoC, 6 suppliers
200 problems
100 problems in the standard</code></pre>
<p>He also shared his experience in generating tests for Klarna - an invoicing service web shop that uses <a href="http://erlang.org/doc/man/mnesia.html">Mnesia</a> - the distributed Erlang database. He concluded by saying that we should not write tests, but, they shoud be generated.</p>
<p>Overall, the workshops were quite useful. It was good to have met both Robert Virding and John Hughes.</p>]]></description>
    <pubDate>Sat, 26 Nov 2016 16:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/11/26/functional-conf-2016/news.html</guid>
</item>
<item>
    <title>GNU Emacs - News Reader</title>
    <link>http://www.shakthimaan.com/posts/2016/10/18/emacs-news-reader/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, February 2016 edition.]</em></p>
<p>In this next article in the GNU Emacs series, we shall learn how to use GNU Emacs as a news reader.</p>
<h1 id="elfeed">Elfeed</h1>
<p>Elfeed is an Emacs web feed reader that is extensible and supports both Atom and RSS feeds. It has written by Christopher Wellons.</p>
<h2 id="installation">Installation</h2>
<p>We shall use Milkypostman’s Experimental Lisp Package Archive (MELPA) to install Elfeed. Create an initial GNU Emacs start-up file that contains the following:</p>
<pre><code>(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '(&quot;melpa&quot; . &quot;https://melpa.org/packages/&quot;))

(when (&lt; emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '(&quot;gnu&quot; . &quot;http://elpa.gnu.org/packages/&quot;)))
(package-initialize) ;; You might already have this line</code></pre>
<p>The above code snippet has been taken from the MELPA project documentation website <a href="http://melpa.org/#/getting-started"><code class="url">http://melpa.org/#/getting-started</code></a>, and has been tested on GNU Emacs 24.5.2.</p>
<p>You can now start GNU Emacs using the following command:</p>
<pre><code>$ emacs -Q -l ~/elfeed-start.el</code></pre>
<p>You can obtain the list of available packages using <em>M-x list-packages</em>, which will search the melpa.org and elpa.gnu.org repositories. You can search for ‘elfeed’ in this buffer, and select the same for installation by pressing the ‘i’ key. To actually install the package, press the ‘x’ (execute) key, and Elfeed will be installed in ~/.emacs.d/elpa directory.</p>
<h2 id="configuration">Configuration</h2>
<p>You can create a shortcut to start Elfeed using the following code snippet in your ~/elfeed-start.el file.</p>
<pre><code>(global-set-key (kbd &quot;C-x w&quot;) 'elfeed)</code></pre>
<p>The list of feeds can be defined as shown below:</p>
<pre><code>(setq elfeed-feeds
      '((&quot;http://www.shakthimaan.com/news.xml&quot; people)
        (&quot;http://arduino.cc/blog/feed/&quot; projects)
        (&quot;http://planet-india.randomink.org/rss10.xml&quot; people planet)
        ))</code></pre>
<p>Tags can be added at the end of the feed. The above feeds include ‘people’, ‘projects’ and ‘planet’ tags.</p>
<h2 id="usage">Usage</h2>
<p>You can use the <em>C-x w</em> shortcut to start Elfeed. If you press ‘G’, it will fetch the latest news feeds from the servers, starting with the message ‘3 feeds pending, 0 in process …’. A screenshot of Elfeed in GNU Emacs is shown below:</p>
<img alt="Elfeed" width="800" src="http://www.shakthimaan.com/images/emacs/1-elfeed.png"></img>
<p>The RSS entries are stored in ~/.elfeed directory on your system.</p>
<p>You can read a blog entry by pressing the ‘Enter’ key. If you would like to open an entry in a browser, you can use the ‘b’ key. In order to copy the selected URL entry, you can use the ‘y’ key. To mark an entry as read, you can use the ‘r’ key, and to unmark an entry, press the ‘u’ key. You can add and remove tags for an entry using the ‘+’ and ’-’ keys, respectively.</p>
<p>You can also filter the feeds based on search critera. Pressing ’s’ will allow you to update the filter that you want to use. There are many filter options available. You can use ‘+’ to indicate that a tag must be present, and ’-’ to indicate that the tag must be absent. For example, “+projects -people”.</p>
<p>The filter text starting with ‘@’ represents a relative time. It can contain plain English text combined with dashes – for example, ‘@1-month-ago +unread’. The ’!’ notation can be used to negate a filter. To limit the number of entries to be displayed, you can use the ‘#’ pattern. For example, ‘+unread #5’ will list five unread blog articles. A screenshot of Elfeed with a filter applied is shown in the following figure:</p>
<img alt="Elfeed filter" width="800" src="http://www.shakthimaan.com/images/emacs/2-elfeed-search.png"></img>
<p>You can also use regular expressions as part of your filter text. The default search filter can be changed by modifying the value of <em>elfeed-search-filter</em>. For example:</p>
<pre><code>(setq-default elfeed-search-filter &quot;@1-month-ago +unread&quot;)</code></pre>
<p>The search format date can be customized as shown below:</p>
<pre><code>(defun elfeed-search-format-date (date)
  (format-time-string &quot;%Y-%m-%d %H:%M&quot; (seconds-to-time date)))</code></pre>
<p>Elfeed also has an export option to view the feeds in a browser. If you install the <em>elfeed-web</em> package from the packages list, you can then start it using <em>M-x elfeed-web-start</em>. You can then start a browser, and open <a href="http://localhost:8080/elfeed/"><code class="url">http://localhost:8080/elfeed/</code></a> to view the feeds. A screenshot is shown below:</p>
<img alt="Elfeed web" width="800" src="http://www.shakthimaan.com/images/emacs/3-elfeed-web.png"></img>
<p>The entire contents of the elfeed-start.el configuration file are shown below:</p>
<pre><code>(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '(&quot;melpa&quot; . &quot;https://melpa.org/packages/&quot;))

(when (&lt; emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '(&quot;gnu&quot; . &quot;http://elpa.gnu.org/packages/&quot;)))
(package-initialize) ;; You might already have this line

(global-set-key (kbd &quot;C-x w&quot;) 'elfeed)

(defun elfeed-search-format-date (date)
  (format-time-string &quot;%Y-%m-%d %H:%M&quot; (seconds-to-time date)))

(setq elfeed-feeds
      '((&quot;http://www.shakthimaan.com/news.xml&quot; people)
        (&quot;http://arduino.cc/blog/feed/&quot; projects)
        (&quot;http://planet-india.randomink.org/rss10.xml&quot; people planet)
        ))</code></pre>
<h1 id="gnus">Gnus</h1>
<h2 id="configuration-1">Configuration</h2>
<p>Gnus is an Emacs package for reading e-mail and Usenet news. The nnrss backend supports reading RSS feeds. Gnus is available by default in GNU Emacs. After launching emacs using <em>emacs -Q</em> in the terminal, you can start Gnus using <em>M-x gnus</em>. To add a new RSS entry, you can use ‘G R’. It will prompt you with the message ‘URL to Search for RSS:’. You can then provide the feed, for example, http://www.shakthimaan.com/news.xml. It will try to connect to the server and will provide you the message ‘Contacting host: www.shakthimaan.com:80’. After a successful connect, it will prompt for the title, ‘Title: Shakthimaan’s blog.’ You can simply hit Enter. You will then be prompted for a description, ‘Description: RSS feed for Shakthimaan’s blog.’ You can hit Enter to proceed. Now, the blog entry has been added to Gnus. In this fashion, you can add the other blog entries too. A screenshot of the main Gnus group buffer is shown below:</p>
<img alt="Gnus" width="800" src="http://www.shakthimaan.com/images/emacs/4-gnus.png"></img>
<h2 id="usage-1">Usage</h2>
<p>You can press ‘g’ to refresh the buffer and ask Gnus to check for latest blog entries. Using the ‘Enter’ key will open the feed, and the list of blogs for a feed. A screenshot is shown in Figure 5.</p>
<img alt="Gnus articles" width="800" src="http://www.shakthimaan.com/images/emacs/5-gnus-articles.png"></img>
<p>You can press ‘Enter’ on a blog entry, and it will open the contents in a new buffer. It will then be marked as read, indicated by ‘R’. A screenshot of a blog entry rendering text and image is shown in the following figure:</p>
<img alt="Gnus blog entry" width="800" src="http://www.shakthimaan.com/images/emacs/6-gnus-blog-entry.png"></img>
<p>You can press ‘q’ to quit from any level inside Gnus. You are encouraged to read the Gnus tutorial ( http://www.emacswiki.org/emacs/GnusTutorial ) and manual ( http://www.gnus.org/manual/big-gnus.html ) to learn more, and to customize it for your needs.</p>]]></description>
    <pubDate>Tue, 18 Oct 2016 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/10/18/emacs-news-reader/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Shells, spell-checkers, abbreviations and printing</title>
    <link>http://www.shakthimaan.com/posts/2016/09/25/emacs-shells-spells-abbrev-printing/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, January 2016 edition.]</em></p>
<p>In this next article in the GNU Emacs series, we shall learn how to execute shell commands, run shells, use spell-checkers and abbreviations, and print from GNU Emacs.</p>
<h1 id="shell-mode-commands">Shell mode commands</h1>
<p>You can run a shell command from GNU Emacs using the <em>M-!</em> shortcut. For example, typing ‘M-!’ will prompt you with the message ‘Shell command:’ in the minibuffer. If you then type ‘date’, it will produce the output ‘Tue Dec 8 21:19:24 IST 2015’ in the minibuffer. But, if you want the output to be inserted in the current buffer you can use the <em>C-u M-!</em> command sequence.</p>
<p>Consider the following poem that I wrote:</p>
<pre><code>&quot;Water, water everywhere
Little power and aid to spare
Really tough for us to bear
We will face it with Chennaites' flair.

Lakes and rivers overflowing everywhere
No road, rail or plane to go anywhere
People really are in big despair
But we will ride it with Chennaites' flair.

More storms are forecast to be aware
Nothing like this in 100 years to compare
Stay indoors and please do take care
And we will take it with Chennaites' flair.&quot;</code></pre>
<p>Suppose I want to know the number of words used, I can mark the poem as a region in the GNU Emacs buffer, and execute a shell command for the region using <em>M-|</em> shortcut. It then prompts with the string ‘Shell command on region’, and when I type in ‘wc -w’ it returns ‘90’.</p>
<h1 id="shells">Shells</h1>
<p>There are three shells available in GNU Emacs - shell, ansi-term and eshell. Using <em>M-x shell</em> will invoke a shell for you. This starts a new buffer with the name ‘<em>shell</em>’ in it. You can use all the GNU Emacs buffer commands in this window. For example, <em>C-p</em> will move the cursor up, and <em>C-n</em> will move the cursor down. In order to interrupt a current job in the shell buffer, you can use <em>C-c C-c</em>. If you want to suspend the current job, you can use <em>C-c C-z</em>. You can also clear the output from the previous command using <em>C-c C-o</em>. For example, the output of ‘ifconfig’ command is shown below:</p>
<pre><code>/tmp $ ifconfig docker0
docker0   Link encap:Ethernet  HWaddr 56:84:7a:fe:97:99
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
/tmp $</code></pre>
<p>After executing ‘C-c C-o’, the previous command output gets cleared as shown below:</p>
<pre><code>/tmp $ ifconfig docker0
 *** output flushed ***
/tmp $</code></pre>
<p>You can move the cursor up to the previously executed commands using <em>C-c C-p</em> and move down using <em>C-c C-n</em>. You can also cycle backwards and forwards through the command history using the <em>M-p</em> and <em>M-n</em> shortcuts respectively. The <em>C-c C-r</em> shortcut moves to the first line of the output to the top of the window. You can move the cursor to the bottom of the window using <em>C-c C-e</em>. The <em>C-r</em> key binding allows you to search for a previously typed command from history.</p>
<p>The default shell is Bash, but, you can change it to use other shells like ksh, csh or zsh. You can open another shell buffer using <em>C-u M-x shell</em>. The new shell buffer will be called ’<em>shell</em>&lt;2&gt;&quot;. You can, of course, rename this buffer. You can thus open multiple shells to work inside GNU Emacs.</p>
<p>GNU Emacs also has a terminal emulator that you can invoke using <em>M-x ansi-term</em>. You can start a Bash session with this command to get the actual colours that you see in a terminal session. This is like a fallback shell if you do not want to use ‘M-x shell’. Eshell is the Emacs built-in shell written completely in Emacs Lisp (Elisp). You can start it using <em>M-x eshell</em>. The advantage of using this is that you can extend it, write your own customized Elisp functions and use it similar to shell scripting.</p>
<p>Screenshots of shell, ansi-term and eshells in GNU Emacs are shown in Figure 1, 2 and 3 respectively:</p>
<img alt="shell" src="http://www.shakthimaan.com/images/emacs/emacs-shell.png"></img>
<img alt="ansi-term" src="http://www.shakthimaan.com/images/emacs/emacs-ansi-term.png"></img>
<img alt="eshell" src="http://www.shakthimaan.com/images/emacs/emacs-eshell.png"></img>
<h1 id="spell-check-commands">Spell check commands</h1>
<p>You can check the spelling of a word by placing the cursor on it and using <em>M-$</em> shortcut. For example, for the word ‘hte’, GNU Emacs provides the following spelling options:</p>
<pre><code>(0) hate (1) HT (2) ht (3) GTE (4) the (5) He (6) Te (7) he (8) Hts
(9) hie (:) hoe (;) hue (&lt;) Rte (=) Ste (&gt;) Ute (@) ate (B) rte</code></pre>
<p>It also lists some options in the minibuffer:</p>
<pre><code>C-h or ? for more options; SPC to leave unchangedo Character to
replace word</code></pre>
<p>On pressing the number 4, the word is replaced with the correct spelling. If the spelling is already correct, then GNU Emacs will tell you that the word is correct. You can also spell check a region using <em>M-x ispell-region</em> and a buffer using <em>M-x ispell-buffer</em>. If you would like to stop the spell checker while it is running, you can use <em>M-x ispell-kill-ispell</em>. There is a flyspell mode that can check your spelling as you type. You can enable it using <em>M-x flyspell-mode</em>. If you want this mode only in a buffer, you can use <em>M-x flyspell-buffer</em>.</p>
<h1 id="word-abbreviation">Word abbreviation</h1>
<p>GNU Emacs can complete words for you. If you type ‘ba’ and then hit <em>M-/</em>, then GNU Emacs will try to complete the word for you. If you continue to use ‘M-/’, it will cycle through the various options such as ‘backwards’, ‘ball’, ‘bash’, ‘bar’, ‘back’, ‘based’ etc. To enter into the abbreviation mode, you need to use <em>M-x abbrev-mode</em> followed by the Enter key.</p>
<p>The abbreviations can either be local or global. Suppose, you want to define a local abbreviation for ‘international’, you can type in ‘intl’ and use <em>C-x a i l</em> to define the expansion. It will prompt you with the message ‘Mode expansion for “intl”:’. You can then type the word ‘international’. The next time you enter ‘intl’ followed by the space key, GNU Emacs will automatically expand the same for you. In order to define a global expansion, you need to use <em>C-x a i g</em> command sequence. If you would like to remove all abbreviations for the current session, you can use <em>M-x kill-all-abbrevs</em> followed by the Enter key.</p>
<p>You can save the abbreviations to a file, say ~/.emacs.d/.abbrev_defs, using <em>M-x write-abbrev-file</em> for future use. You can also edit the stored abbreviations using <em>M-x edit-abbrevs</em> shortcut. If you would like to view all the defined abbreviations, you can use <em>M-x list-abbrevs</em>. The relevant contents of ~/.emacs.d/.abbrev_defs are shown below:</p>
<pre><code>;;-*-coding: utf-8;-*-
(define-abbrev-table 'Buffer-menu-mode-abbrev-table '())

(define-abbrev-table 'completion-list-mode-abbrev-table '())

(define-abbrev-table 'edit-abbrevs-mode-abbrev-table '())

(define-abbrev-table 'emacs-lisp-mode-abbrev-table
  '(
    (&quot;intl&quot; &quot;international&quot; nil 2)
   ))

(define-abbrev-table 'fundamental-mode-abbrev-table '())

(define-abbrev-table 'global-abbrev-table '())

(define-abbrev-table 'lisp-mode-abbrev-table '())

(define-abbrev-table 'sh-mode-abbrev-table '())

(define-abbrev-table 'shell-mode-abbrev-table '())</code></pre>
<h1 id="printing">Printing</h1>
<p>You can print the buffer contents from GNU Emacs using <em>M-x print-buffer</em> command. If you would like to print a selected region, you can use <em>M-x print-region</em> command. These will be printed with page numbers and headers. You can also print a buffer without page numbers using <em>M-x lpr-buffer</em>. Similarly, to print a region without page numbers, use <em>M-x lpr-region</em>. If you are already using the Dired mode, you can select the files that you want to print using the <em>P</em> shortcut, and then execute in Dired mode to print them.</p>]]></description>
    <pubDate>Sun, 25 Sep 2016 17:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/09/25/emacs-shells-spells-abbrev-printing/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Games</title>
    <link>http://www.shakthimaan.com/posts/2016/09/06/emacs-games/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, December 2015 edition.]</em></p>
<p>In this article in the GNU Emacs series, we shall learn how to play games and try out some software for fun.</p>
<p>Ten games that are available and can be played easily in GNU Emacs are listed and discussed in this article. We start with the Tetris game.</p>
<h1 id="tetris">Tetris</h1>
<p>Tetris is available in GNU Emacs and you can launch it using <em>M-x tetris</em>. The ‘Up’ arrow key can be used to spin the tile, while the space key can quickly drop the tile. You can pause the game by pressing the ‘p’ key. At the end of the game, a score is displayed in a buffer. For example:</p>
<pre><code>112 shakthi shakthi &lt;author@shakthimaan.com&gt;  Mon Nov  2 21:12:04 2015
52 shakthi Shakthi Kannan &lt;author@shakthimaan.com&gt;  Mon Nov  2 15:24:43 2015
11 shakthi shakthi &lt;author@shakthimaan.com&gt;  Mon Nov  2 15:29:39 2015</code></pre>
<p>A screenshot of Tetris in GNU Emacs:</p>
<img alt="Tetris" src="http://www.shakthimaan.com/images/emacs/tetris.png"></img>
<h1 id="pong">Pong</h1>
<p>You can play Ping Pong in GNU Emacs with two players using <em>M-x pong</em>. One player can use the ‘Up’ and ‘Down’ arrow keys, and the second player can use the number keys - ‘4’ and ‘6’. Each paddle is represented by three square tiles. If the ball hits the edge of the paddle, it changes its direction. You can use the ‘p’ key to pause the game. A live score is displayed during the game. A screenshot of Ping Pong:</p>
<img alt="Pong" src="http://www.shakthimaan.com/images/emacs/pong.png"></img>
<h1 id="doctor">Doctor</h1>
<p>GNU Emacs comes with a psychotherapist with whom you can chat. Simply type <em>M-x doctor</em> and it will start a session with the therapist. After you type in your statement, you need to hit Enter twice, and the therapist will reply. It will usually ask you another question, and you can continue to chat with the doctor. An example of a session is given below:</p>
<pre><code>I am the psychotherapist.  Please, describe your problems.  Each time
you are finished talking, type RET twice.

Hi

How do you do?  What brings you to see me?

I am trying to talk to the doctor.

Why do you say you are trying to talk to the doctor?

I want to share this transcript with my readers.

What makes you believe you might want to share this transcript your
readers?

I can, from GNU Emacs, copy this text and paste it in my article.

Emacs?  Hah!  I would appreciate it if you would continue.

I am looking forward to watching today's cricket match that India is playing.

Is it because india is playing that you came to me?

Yes, who do you think will win?

Earlier you said you would like to share this transcript your readers?

Yes, I am still going to do that.

Can you elaborate on that?

I am writing a GNU Emacs series for the OSFY magazine.

Are you sure?

Yes, I have been writing for the past few months.

Maybe your life has something to do with this.

I want people to learn and use GNU Emacs to improve their productivity.

Are you sure that that?

Absolutely!

Perhaps you could continue.</code></pre>
<h1 id="bubbles">Bubbles</h1>
<p>The objective of the Bubbles game is to remove a series of connected bubbles in the fewest number of moves. The game can be started using <em>M-x bubbles</em>. As you move through the grid of bubbles, the connected bubbles with the same colour get highlighted. You can press the space bar to remove them. A screenshot of bubbles:</p>
<img alt="Bubbles" src="http://www.shakthimaan.com/images/emacs/bubbles.png"></img>
<p>At the end of the game, a summary of the score is shown.</p>
<pre><code>Selected:    9
Score:    1932
Game Over!</code></pre>
<p>GNU Emacs also keeps a record of the scores:</p>
<pre><code>01959   Mon Nov  2 21:26:41 2015        shakthi &lt;author@shakthimaan.com&gt;
01932   Mon Nov  2 21:20:38 2015        shakthi &lt;author@shakthimaan.com&gt;</code></pre>
<h1 id="conways-life">Conway’s life</h1>
<p>The shortcut <em>M-x life</em> will start the Conway’s Game of Life in a new GNU Emacs buffer. The population increases in course of time, and the generation count is shown in the mode line. A screenshot of the cellular automation running inside GNU Emacs:</p>
<img alt="Conway's Life" src="http://www.shakthimaan.com/images/emacs/life.png"></img>
<h1 id="morse-and-nato-conversions">Morse and NATO conversions</h1>
<p>You can convert text to Morse code and vice versa by selecting the text in a buffer and using <em>M-x morse-region</em>. For example, the text ‘morse code’ gets converted to the following:</p>
<pre><code>--/---/.-./.../. -.-./---/-../.</code></pre>
<p>You can get back the text by selecting the Morse text and applying <em>M-x unmorse-region</em>. Similarly, if you have a word that you would like to spell using the NATO phonetic alphabet, you can use <em>M-x nato-region</em>. To convert it back, you need to use <em>M-x denato-region</em>. For example, the text ‘abc’ gets converted to:</p>
<pre><code>Alfa-Bravo-Charlie</code></pre>
<h1 id="snake">Snake</h1>
<p>The Snake game can be started using <em>M-x snake</em>. You can use the arrow keys to move the head. As you play, red boxes appear in the window. If you go over them, the length of the snake increases along with the score. At the end of the game, a summary of the scores is shown. A screenshot of the Snake game:</p>
<img alt="Snake" src="http://www.shakthimaan.com/images/emacs/snake.png"></img>
<h1 id="dunnet">Dunnet</h1>
<p>Dunnet is a text based adventure game that needs to be started in batch mode as shown below:</p>
<pre><code>$ emacs -batch -l dunnet

Dead end
You are at a dead end of a dirt road.  The road goes to the east.
In the distance you can see that it will eventually fork off.  The
trees here are very tall royal palms, and they are spaced equidistant
from each other.
There is a shovel here.</code></pre>
<p>The help command gives you the context of the game:</p>
<pre><code>&gt;help
Welcome to dunnet (2.01), by Ron Schnell (ronnie@driver-aces.com).
Here is some useful information (read carefully because there are one
or more clues in here):
- If you have a key that can open a door, you do not need to explicitly
  open it.  You may just use 'in' or walk in the direction of the door.

- If you have a lamp, it is always lit.

- You will not get any points until you manage to get treasures to a certain
  place.  Simply finding the treasures is not good enough.  There is more
  than one way to get a treasure to the special place.  It is also
  important that the objects get to the special place *unharmed* and
  *untarnished*.  You can tell if you have successfully transported the
  object by looking at your score, as it changes immediately.  Note that
  an object can become harmed even after you have received points for it.
  If this happens, your score will decrease, and in many cases you can never
  get credit for it again.

- You can save your game with the 'save' command, and use restore it
  with the 'restore' command.

- There are no limits on lengths of object names.

- Directions are: north,south,east,west,northeast,southeast,northwest,
                  southwest,up,down,in,out.

- These can be abbreviated: n,s,e,w,ne,se,nw,sw,u,d,in,out.

- If you go down a hole in the floor without an aid such as a ladder,
  you probably won't be able to get back up the way you came, if at all.

- To run this game in batch mode (no Emacs window), use:
     emacs -batch -l dunnet
NOTE: This game *should* be run in batch mode!

If you have questions or comments, please contact ronnie@driver-aces.com
My home page is http://www.driver-aces.com/ronnie.html</code></pre>
<p>You can then give directions and proceed with the game. An example of a session is shown below:</p>
<pre><code>&gt;n
You can't go that way.
&gt;s
You can't go that way.
&gt;e
E/W Dirt road
You are on the continuation of a dirt road.  There are more trees on
both sides of you.  The road continues to the east and west.
There is a large boulder here.
&gt;in
You can't go that way.
&gt;w
Dead end
There is a shovel here.
&gt;d
You can't go that way.
&gt;e
E/W Dirt road
There is a large boulder here.
&gt;n s e
You can't go that way.
&gt;in
You can't go that way.
&gt;e
Fork
You are at a fork of two passages, one to the northeast, and one to the
southeast.  The ground here seems very soft. You can also go back west.
&gt;w
E/W Dirt road
There is a large boulder here.</code></pre>
<p>You can exit the game by typing ‘quit’ at the prompt (&gt;).</p>
<h1 id="gomoku">Gomoku</h1>
<p>Gomoku is a strategy board game where you need to get five pieces in a row (any direction) to win. You and the computer will take turns to play the game. You need to use the <em>Enter</em> key to mark your cross in a position, and the computer will mark its position with a circle. The game ends when either player gets five continuous pieces. A screenshot of Gomoku is shown below:</p>
<img alt="Gomoku" src="http://www.shakthimaan.com/images/emacs/gomoku.png"></img>
<h1 id="le-solitaire">Le Solitaire</h1>
<p>Le Solitaire is a strategy game that consists of stones represented by ‘o’ and holes represented by ’.’ (a dot). The objective of the game is to remove all the stones except the last one. You can jump over another stone to create a hole. You can use the <em>Shift</em> key with the arrow keys to move a stone. A screenshot of the game in progress:</p>
<img alt="Le Solitaire" src="http://www.shakthimaan.com/images/emacs/le-solitaire.png"></img>
<p>All the games and examples were tried on GNU Emacs 24.5.1.</p>]]></description>
    <pubDate>Tue, 06 Sep 2016 16:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/09/06/emacs-games/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Search, Frames and Windows</title>
    <link>http://www.shakthimaan.com/posts/2016/08/18/emacs-search-frames-windows/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, November 2015 edition.]</em></p>
<p>In this next article in the GNU Emacs series, we shall learn how to perform text search in a buffer, and introduce the concept of windows and frames.</p>
<h1 id="search">Search</h1>
<p>You can copy the following poem, which I wrote in 2013, in the <em>scratch</em> buffer or a file inside GNU Emacs to try out the search commands:</p>
<pre><code>Emacs is, an operating system 
Which unlike many others, is truly, a gem 
Its goodies can be installed, using RPM 
Or you can use ELPA, which has already packaged them 

You can customize it, to your needs 
You can also check EmacsWiki, for more leads 
Your changes work, as long as reload succeeds 
And helps you with, your daily deeds 

People say, it lacks a decent editor 
But after using its features, they might want to differ 
Using Magit’s shortcuts, you might infer 
That it is something, you definitely prefer 

Plan your life, with org-mode 
You don’t necessarily need, to write code 
TODO lists and agenda views, can easily be showed 
Reading the documentation, can help you come aboard 

Emacs is, a double-edged sword 
Its powerful features, can never be ignored 
Customization is possible, because of Free Software code 
And this is, my simple ode.</code></pre>
<p>You can search for a word in a buffer using <em>C-s</em> shortcut. You will then be prompted with <em>I-Search:</em> in the minibuffer where you can type any text, and GNU Emacs will try to find words matching it, in the buffer. This is an incremental forward search and is case insensitive. Thus, if you search for the word ‘todo’ in the poem, it will match the string ‘TODO’. You can exit from the incremental search using the <em>Enter</em> key, or abort the search using the <em>C-g</em> key combination. If you want to do an incremental search in the reverse direction - from the cursor position to the top of the buffer – you can use the <em>C-r</em> shortcut.</p>
<p>If you place the cursor on the letter ‘E’ in ‘Emacs’ in the poem’s first line, and press <em>C-s C-w</em>, Emacs will try to find all occurrences of the word ‘Emacs’ in the text. Suppose, you have cut or copied text to the kill ring, you can search for this text by using <em>C-s C-y</em> shortcut. You can repeat the previous forward search using <em>C-s C-s</em>, and the previous backward search using <em>C-r C-r</em> shortcuts.</p>
<p>The first occurrence of a text can be looked up in the forward direction using <em>C-s</em>. This will prompt you in the minibuffer with a <em>Search:</em> string where you can type the text that you want to search for, and then press the <em>Enter</em> key. It will then search for the text and move the cursor to the matching word. This is a non-incremental forward search. Similarily, you can perform a non-incremental backward search using <em>C-r</em>. You can then input the search string to be searched for, followed by the <em>Enter</em> key.</p>
<p>Regular expression searches are very useful too. In order to search forward for an expression, you can use <em>C-M-s</em> followed by the <em>Enter</em> key, which will prompt you in the minibuffer with the string ‘Regexp search:’. You can then enter a regular expression. This will only match the first occurrence of the text and the search will then terminate. You can perform a one-time backward regular expression search using <em>C-M-r</em> shortcut. To perform an incremental forward search, you need to use <em>C-M-s</em> and you will be prompted with the string ‘Regexp I-search:’, where you can provide the pattern to match. For example, ‘[a-z]+-[a-z]+’ will match both the expressions ‘org-mode’ and ‘double-edged’ words in the poem. You can use <em>C-M-r</em> for an incremental backward regex search.</p>
<p>A common use case is to find and replace text in a buffer. The sequence to be used is <em>M-x query-replace</em> followed by the <em>Enter</em> key. You will then be prompted with the string ‘Query replace:’ where you will be asked which word or phrase is to be replaced. For example, if you mention ‘ode’, it will again prompt you with ‘Query replace ode with:’ and then you can enter the replacement string. You can also search and replace text by matching a regular expression with the <em>C-M-%</em> shortcut key combination.</p>
<h1 id="frames">Frames</h1>
<p>The outermost user interface boundary of GNU Emacs is called a frame. In fact, when you split the GNU Emacs user interface, you are actually creating windows. So, in GNU Emacs, you have windows inside a frame. This is in contrast to today’s user applications, where the entire application is contained in a ‘window’. This is an important terminology to remember when using GNU Emacs.</p>
<p>You can create a new frame using <em>C-x 5 2</em> key combination. You can move the cursor to the next frame using <em>C-x 5 o</em> (letter ‘o’), and delete the current frame using <em>C-x 5 0</em> (zero) shortcut. This will not delete the existing buffers, but, only the view. In order to open a file in a new frame, you can use <em>C-x 5 f</em>. You can also open a file in a new frame in read-only mode using <em>C-x 5 r</em>. To switch to the buffer in a new frame, use <em>C-x 5 b</em> key combination.</p>
<h1 id="windows">Windows</h1>
<p>You can split a frame vertically to create two windows using <em>C-x 2</em> (Figure 1).</p>
<img width="800" alt="Split frame vertically" src="http://www.shakthimaan.com/images/emacs/c-x-2.png"></img>
<p>To split horizontally, you can use <em>C-x 3</em> (Figure 2).</p>
<img width="800" alt="Split frame horizontally" src="http://www.shakthimaan.com/images/emacs/c-x-3.png"></img>
<p>To move the cursor to the next window, use <em>C-x o</em> (the letter ‘o’). You can delete the current window using <em>C-x 0</em> (zero). Note that this does not delete the buffer, but, just the view. If you have multiple windows and you want to retain the current window and remove the rest of the windows from the display, you can use <em>C-x 1</em>.</p>
<p>You can open a file in a new window using <em>C-x 4 f</em>. You can also select an existing buffer in another window using <em>C-x 4 b</em>. If you have multiple windows that you would like to be balanced equally, you can use <em>C-x +</em>. Figure 3 shows an Emacs screenshot with three windows that are balanced.</p>
<img width="800" alt="Balanced windows" src="http://www.shakthimaan.com/images/emacs/c-x-plus.png"></img>
<p>You can scroll the contents in the other window using <em>C-M-v</em>. You can scroll backwards using <em>C-M-Shift-v</em>.</p>
<p>You can also use the following shortcuts in your ~/.emacs to simplify the shortcuts used to split and remove windows.</p>
<pre><code>(global-set-key (kbd &quot;C-1&quot;) 'delete-other-windows)
(global-set-key (kbd &quot;C-2&quot;) 'split-window-below)
(global-set-key (kbd &quot;C-3&quot;) 'split-window-right)
(global-set-key (kbd &quot;C-0&quot;) 'delete-window)</code></pre>
<p>If you would like to make a window wider, you can use <em>C-x }</em> shortcut and to reduce it horizontally, you will need to use <em>C-x {</em>. You can use a prefix count to perform the operation ‘n’ times. For example, <em>C-u 5 C-x {</em> to shrink a window horizontally. To make a window taller, you can use <em>C-x ^</em> shortcut; and to make it smaller, you have to use a negative prefix. For example, <em>C-u -1 C-x ^</em>. A screenshot of a custom Emacs frame with three windows is shown in Figure 4.</p>
<img width="800" alt="Custom windows in a frame" src="http://www.shakthimaan.com/images/emacs/custom-windows.png"></img>]]></description>
    <pubDate>Thu, 18 Aug 2016 11:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/08/18/emacs-search-frames-windows/news.html</guid>
</item>
<item>
    <title>Deep Learning Conference 2016, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2016/07/26/deep-learning-conference/news.html</link>
    <description><![CDATA[<p>I attended <a href="https://fifthelephant.in/2016/deep-learning">Deep Learning Conference 2016</a> at <a href="http://www.cmrit.ac.in/">CMR Institute of Technology</a>, Bengaluru on July 1, 2016.</p>
<img alt="Deep Learning Conference 2016 poster" src="http://www.shakthimaan.com/images/deep-learning-2016/deep-learning-conference.jpg"></img>
<p><a href="https://in.linkedin.com/in/anandchandrasekaran">Anand Chandrasekaran</a>, CTO, <a href="http://www.madstreetden.com/">Mad Street Den</a> began the day’s proceedings with his talk on “Deep learning: A convoluted overview with recurrent themes and beliefs”. He gave an overview and history of deep learning. He also discussed about <a href="http://deeplearning.net/tutorial/lenet.html">LeNet</a>, <a href="https://www.cs.toronto.edu/~hinton/absps/fastnc.pdf">Deep Belief Network</a> by <a href="http://www.cs.toronto.edu/~hinton/">Geoffrey Hinton</a>, Backpropagation Algorithm (1974) by Paul Werbos, and Deep Convolutional Neural Networks (2012) by Alex Net, named after Alex Krizhevsky. Mad Street Den primarily work on computer vision problems. In one of their implementations, they extract 17,000 features from a dress, and provide recommendations to customers. They are one of the early users of NVIDIA GPUs. He also briefed on other deep learning tools like Amazon ML, Torch 7, and Google TensorFlow.</p>
<p>The second talk of the day was a sponsored talk on “Recent advancements in Deep Learning techniques using GPUs” by Sundara R Nagalingam from NVIDIA. He talked on the available GPU hardware and platforms for deep learning available from NVIDIA. It was a complete sales pitch. I did ask them if they have free and open source Linux device drivers for their hardware, but, at the moment they are all proprietary (binary blobs).</p>
<p>After a short tea break, <a href="https://www.kaggle.com/abhishek">Abhishek Thakur</a> presented on “Applied Deep Learning”. This was one of two best presentations of the day. Abhishek illustrated binary classification and fine tuning. He also briefed on GoogleNet, DeepNet, and ImageNet Large Scale Visual Recognition Challenge (ILSVRC). Deep learning software such as Theano, Lasagne, and Keras were also discussed. A query can be of three types - navigational, transactional, or informational. Word2vec is a two-layer neural net that can convert text into vectors. You can find a large collection of images for input datasets at <a href="https://www.cs.toronto.edu/~kriz/cifar.html">CIFAR</a>.</p>
<p>The next two sessions were 20-minute each. The first talk was on “Residual Learning and Stochastic Depth in Deep Neural Networks” by Pradyumna Reddy, and the second was on “Expresso - A user-friendly tool for Deep Learning” by Jaley Dholakiya. The Expresso UI needs much work though. I headed early for lunch.</p>
<p>Food was arranged by <a href="http://mealdiaries.com/">Meal Diaries</a> and it was delicious!</p>
<p>The post-lunch session began at 1410 IST with <a href="http://cs.nyu.edu/~ajain/">Arjun Jain</a> talking on “Joint Training of a Convolutional Network and a Graphical Model for Human Pose Estimation”. He gave a number of examples on how difficult it is to train models, especially the human body.</p>
<p><a href="https://in.linkedin.com/in/vijaygabale">Vijay Gabale</a> then spoke on “Deep Dive into building Chat-bots using Deep Learning”. This was the second best presentation of the day. He gave a good overview of chat-bots and the challenges involved in implementing them. There are four building blocks for chat bots - extract intent, show relevant results, contextual interaction and personalization. He also discussed on character-aware neural language models.</p>
<p>I then headed to the BoF session on “Getting Started with Deep Learning”. A panel of experts answered questions asked by the participants. It was suggested to start with toy data and move to big data. Andrew Ng’s <a href="https://www.coursera.org/learn/machine-learning">Machine Learning</a> course and <a href="https://www.udacity.com/course/machine-learning-reinforcement-learning--ud820">Reinforcement Learning</a> course were recommended. <a href="http://cs231n.stanford.edu/">CS231n: Convolutional Neural Networks for Visual Recognition</a> was also recommended for computer vision problems. Keras and Theano are useful tools to begin with. It is important to not just do a proof-of-concept, but, also see how things work in production. It is good to start to use and learn the tools, and subsequently delve into the math. Having references can help you go back and check them when you have the know-how. <a href="http://datanuggets.org/">Data Nuggets</a> and <a href="https://www.kaggle.com/datasets">Kagil</a> are two good sources for datasets. The <a href="https://github.com/dnouri/kfkd-tutorial">Kaggle Facial Keypoints Detection</a> (KFKD) tutorial was also recommended. Data science does involve both programming and math. We then headed for a short tea break.</p>
<p>Nishant Sinha, from <a href="http://magicx.co/">MagicX</a>, then presented his talk on “Slot-filling in Conversations with Deep Learning”. He gave an example of a semantic parser to fill slots using a simple mobile recharge example. He also discussed about CNN, Elman RNN and Jordan RNN. This was followed by the talk on “Challenges and Implications of Deep Learning in Healthcare” by Suthirth Vaidya from <a href="http://predible.co/">Predible Health</a>. He spoke on the difficulties in dealing with medical data, especially biometric images. Their solution won the Multiple Sclerosis Segmentation Challenge in 2015.</p>
<p>The last talk of the day was on “Making Deep Neural Networks smaller and faster” by <a href="https://surajsrinivas.wordpress.com/">Suraj Srinivas</a> from IISc, Bengaluru. He discussed how large model can be mapped to small models using model compression. This involves compressing matrices through four techniques - sparsify, shrink, break, and quantize. The objective is to scale down the solution to run on mobile and embedded platforms, and on CPUs. It was an interesting talk and a number of open research problems exist in this domain.</p>
<p>Overall, it was a very useful one day conference.</p>]]></description>
    <pubDate>Tue, 26 Jul 2016 11:15:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/07/26/deep-learning-conference/news.html</guid>
</item>
<item>
    <title>Karaikudi and Chettinad trip photos</title>
    <link>http://www.shakthimaan.com/posts/2016/07/04/karaikudi-trip/news.html</link>
    <description><![CDATA[<p>Few photos taken on a trip to <a href="http://en.wikipedia.org/wiki/Karaikudi">Karaikudi</a> and <a href="https://en.wikipedia.org/wiki/Chettinad">Chettinad</a>, Tamil Nadu, India. More photos in my <a href="http://www.shakthimaan.com/Mambo/gallery/album95">/gallery</a>.</p>
<img width="320" alt="Courtyard" src="http://www.shakthimaan.com/Mambo/gallery/albums/album95/1_open_space.jpg"></img>
<br />
<img width="320" alt="Corridor" src="http://www.shakthimaan.com/Mambo/gallery/albums/album95/2_corridor.sized.jpg"></img>
<br />
<img width="320" alt="Hall" src="http://www.shakthimaan.com/Mambo/gallery/albums/album95/3_hall.jpg"></img>]]></description>
    <pubDate>Mon, 04 Jul 2016 12:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/07/04/karaikudi-trip/news.html</guid>
</item>
<item>
    <title>GNU Emacs - rcirc IRC client</title>
    <link>http://www.shakthimaan.com/posts/2016/06/23/rcirc/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, October 2015 edition.]</em></p>
<p>Internet Relay Chat (IRC) provides instant communication over the Web. It is generally used for one-to-one communication or group discussion forums, also known as channels. In this next article in the GNU Emacs series, we shall learn how to use GNU Emacs as an Internet Relay Chat (IRC) client.</p>
<h1 id="what-is-irc">What is IRC?</h1>
<p>Internet Relay Chat (IRC) is a messaging protocol that was created by Jarkko Oikarinen in 1988. An IRC server has a number of channels (or rooms, as how they are called in other chat software) where both technical and non-technical discussions take place. Every user requires a nickname to chat. You will need to register your nickname with a password to identify yourself every time you log in to the IRC server. IRC can also be used for file sharing among users.</p>
<p>You can connect to any one of a number of IRC servers that are available worldwide, free. The most popular is Freenode (irc.freenode.net). The other IRC servers, to name a few, are IRCNet, OFTC, and EFNet. The Debian and Ubuntu projects have their own chat servers – irc.debian.org and irc.ubuntu.com. All IRC channel names begin with ‘#’. Some channels begin with ‘##’. Examples of channels are ##linux-india, #dgplug, #emacs, #ruby, #guile, #lisp, and #scheme. You can also create your own channels, or host your own IRC server. Some examples of free and open source IRC server software are IRCd, UnrealIRCd, and Synchronet. Each IRC channel has a topic that can include useful links relevant to the channel. Sometimes announcements, or news updates are also mentioned in the topic.</p>
<h1 id="basic-commands">Basic commands</h1>
<p>A number of commands can be given to the IRC server. A few of them are discussed below:</p>
<ol style="list-style-type: decimal">
<li><p><em>/list</em> is used to provide a list of all the available channels in a server. For example: <em>/list</em> in irc.freenode.net returned the following:</p>
<pre><code>...
#linod           1       
##welding        3       Welcome to ##Welding, We're a little bare at the moment, but will help if we can. Tutorials: https://www.youtube.com/channel/UCJAFY2kKKb5sg79yld7T3hA
#drupal-ph       1       &quot;Drupalista! Welcome to Philippine Drupal Users Group. Have a good time chatting. If you have a question, please don't ask to ask but fire up your question in very specific and constructive way! Please join #drupal or #drupal-support if no one is around&quot;
#orx-project     4       Orx: Portable Game Engine
#tinkerforge     5       
#osi             10      The Open Source Initiative
#xampp           1       
#guitar          8       
#bitcoin-ar      3       Comunidad Bitcoin Argentina
#LargeHadrosaurCollider 19      Welcome to the LHC, est. 2001 | http://www.largehadrosaurcollider.net | August Birthdays: Digby 08/21, Josh 08/31 | At night it is pitch black, often for months. | http://tinyurl.com/psgdagl
* End of /LIST</code></pre></li>
<li><p><em>/msg NickServ REGISTER password e-mail</em> is used to register your nickname to the IRC server. <em>/msg NickServ IDENTIFY password</em> is used to identify yourself to the server.</p></li>
<li><p><em>/me message</em> displays the message for a user. For example:</p>
<pre><code>/me says &quot;Hello, World!&quot;

 * mbuf says &quot;Hello, World!&quot;</code></pre></li>
<li><p><em>/whois nickname</em> provides useful information for a user. For example:</p>
<pre><code> /whois mbuf

* [mbuf] (~shakthi@123.123.123.123): Shakthi Kannan
* [mbuf] #guile #scheme ##linux-india #stumpwm #guix #dgplug #lisp #emacs 
* [mbuf] kornbluth.freenode.net :Frankfurt, Germany
* [mbuf] is connecting from *@123.123.123.123 123.123.123.123
* [mbuf] idle 00:41:52, signon: Thu Sep  3 20:36:52
* [mbuf] is logged in as mbuf
* [mbuf] End of WHOIS list.</code></pre></li>
<li><p><em>/msg nickname</em> is used to send a private message to a nickname and to start a private conversation.</p></li>
<li><p><em>/help</em> provides useful help on basic IRC commands. These commands are:</p>
<pre><code>  ADDBUTTON ALLCHAN   ALLCHANL  ALLSERV   AWAY
  BACK      BAN       CHANOPT   CHARSET   CLEAR
  CLOSE     COUNTRY   CTCP      CYCLE     DCC
  DEBUG     DEHOP     DELBUTTON DEOP      DEVOICE
  DISCON    DNS       ECHO      EXEC      EXECCONT
  EXECKILL  EXECSTOP  EXECWRITE FLUSHQ    GATE
  GETFILE   GETINT    GETSTR    GHOST     GUI
  HELP      HOP       ID        IGNORE    INVITE
  JOIN      KICK      KICKBAN   KILLALL   LAGCHECK
  LASTLOG   LIST      LOAD      MDEHOP    MDEOP
  ME        MENU      MKICK     MODE      MOP
  MSG       NAMES     NCTCP     NEWSERVER NICK
  NOTICE    NOTIFY    OP        PART      PING
  QUERY     QUIT      QUOTE     RECONNECT RECV
  SAY       SEND      SERVCHAN  SERVER    SET
  SETCURSOR SETTAB    SETTEXT   SPLAY     TOPIC
  TRAY      UNBAN     UNIGNORE  UNLOAD    URL
  USELECT   USERLIST  VOICE     WALLCHAN  WALLCHOP

User defined commands:

  ACTION    AME       ANICK     AMSG      BANLIST
  CHAT      DIALOG    DMSG      EXIT      GREP
  J         KILL      LEAVE     M         ONOTICE
  RAW       SERVHELP  SPING     SQUERY    SSLSERVER
  SV        UMODE     UPTIME    VER       VERSION
  WALLOPS   WII       

Plugin defined commands:

  UNLOAD    UNLOAD    LOAD      PY        LOAD
  RELOADALL SOURCE    TCL       RELOADALL UNLOADALL
  PL_RELOAD RELOAD    UNLOAD    LOAD      TIMER


Type /HELP &lt;command&gt; for more information, or /HELP -l</code></pre></li>
<li><p><em>/quit</em> is used to disconnect and exit from IRC.</p></li>
<li><p><em>/join #channel</em> - is used to join a channel. For example: /join #guix.</p></li>
<li><p><em>/nick newnickname</em> changes your nick to newnickname. Suppose, you wish to move away from the computer, you can change your nick to <em>nick|away</em>, or <em>nick|phone</em>.</p></li>
<li><p><em>/part</em> is used to leave a channel.</p></li>
</ol>
<h1 id="using-rcirc">Using rcirc</h1>
<p>If you are using a recent GNU/Linux distribution, you should already have <em>rcirc</em> as part of GNU Emacs. You can simply start it by typing <em>M-x rcirc</em> from inside Emacs. The ‘M’ key represents the Meta key, which is usually mapped to the ‘Alt’ key. After <em>rcirc</em> connects to the IRC server, you can use <em>/nick</em> to change your nickname, register (only the first time) your nick, identify yourself, join channels, and start chatting! Since everything is a buffer in GNU Emacs, each channel is a separate buffer. For example, <em>#emacs@irc.freenode.net</em> is the #emacs IRC channel. All your basic buffer navigation commands will work just like they would on a file!</p>
<h1 id="some-basic-rcirc-commands">Some basic rcirc commands</h1>
<p>The rcirc commands for the above mentioned IRC commands are given in the following table:</p>
<table>
<col width="17%"></col>
<col width="22%"></col>
<thead>
<tr class="header">
<th align="left">IRC</th>
<th align="left">rcirc</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">/list</td>
<td align="left">rcirc-cmd-list</td>
</tr>
<tr class="even">
<td align="left">/msg NickServ</td>
<td align="left">rcirc-authenticate</td>
</tr>
<tr class="odd">
<td align="left">/me</td>
<td align="left">rcirc-cmd-me</td>
</tr>
<tr class="even">
<td align="left">/whois</td>
<td align="left">rcirc-cmd-whois</td>
</tr>
<tr class="odd">
<td align="left">/msg nick</td>
<td align="left">rcirc-cmd-msg</td>
</tr>
<tr class="even">
<td align="left">/help</td>
<td align="left">/help</td>
</tr>
<tr class="odd">
<td align="left">/quit</td>
<td align="left">rcirc-cmd-quit</td>
</tr>
<tr class="even">
<td align="left">/join</td>
<td align="left">rcirc-cmd-join</td>
</tr>
<tr class="odd">
<td align="left">/nick</td>
<td align="left">rcirc-cmd-nick</td>
</tr>
<tr class="even">
<td align="left">/part</td>
<td align="left">rcirc-cmd-part</td>
</tr>
</tbody>
</table>
<h1 id="emacs">~/.emacs</h1>
<p>GNU Emacs is an extensible editor. There are a number of locations where Emacs checks for custom configurations before launching the editor. These are: <em>~/.emacs</em>, <em><sub>/.emacs.el<em>, and</em></sub>/.emacs.d/init.el</em>. The start-up files can be customised, and their locations can also be changed. There are a number of ways to organize, and manage your Emacs configuration. Until we get to learn Emacs lisp, and customize Emacs as a project, we shall use <em>~/.emacs</em> for all our user-specific customizations.</p>
<h1 id="rcirc-customization">rcirc customization</h1>
<p>Create a <em>~/.emacs.d/etc</em> folder in your $HOME directory and an Elisp file called <em>init-rcirc.el</em> in it. It should contain the following (change nick, user-name and full-name to suit your needs):</p>
<pre><code>;; Default user.
(setq rcirc-default-nick &quot;shaks&quot;)
(setq rcirc-default-user-name &quot;shakthimaan&quot;)
(setq rcirc-default-full-name &quot;Shakthi Kannan&quot;)

;; Channels to join at startup.
(setq rcirc-server-alist
      '((&quot;irc.freenode.net&quot; :channels (&quot;##linux-india&quot; &quot;#dgplug&quot; &quot;#rcirc&quot; &quot;#emacs&quot;))))</code></pre>
<p>The above is an example of Emacs Lisp code. Comments begin with two semi-colons. The <em>setq</em> construct sets the second argument value to the first argument, which is a quoted symbol. For example, the symbol ’rcirc-default-nick is set to “shaks”. The <em>rcirc-server-alist</em> defines the initial list of channels to login at startup.</p>
<p>You can now start GNU Emacs from the GNOME terminal using the following command:</p>
<pre><code>$ emacs -q -l ~/.emacs.d/etc/init-rcirc.el</code></pre>
<p>You will then automatically connect to the four IRC channels.</p>
<h1 id="how-to-use-irc">How to use IRC</h1>
<p>People join IRC channels to have their doubts regarding free and open source software clarified. Sometimes, off-topic discussions also happen. It is like live technical support, but has a social context to it. Whenever you are connected online, you must be logged in to IRC. You can have discussions in the channel, or in private, if the other party agrees. It is a good place to learn a lot about free and open source software, and you are bound to make a lot of friends. Since people from all over the world participate, which means they are online in different time zones, some channels log the discussions for future reference. As always, before asking a question, it is important for you to do your homework first. Take sufficient time and put in an effort to debug and identify the problem to the best of your ability.</p>
<p>Some users in the channel may ask you for more information before being able to provide you with any assistance. So, be prepared to provide all the information necessary about the bug or error when you seek help. Sometimes, people might be logged in the channel, but, they might be away from the computer. So, even if you don’t get a response, be patient; come back later and ask again.</p>
<p>You should not paste more than four continuous lines of text in the channel, as it will ‘flood’ the screen for everyone else. Instead, use an external paste service like <em>gist.github.com</em>, or <em>fpaste.org</em>. These services will provide a shortened URL that you can pass around in the channel. Whoever is interested in helping you will view the contents from the link. If you enter text in the channel, it means that it is addressed to everyone in the channel. If you wish to say something to a specific user, mention their nickname first, and then type in the text.</p>
<p>Most IRC client software provide you with panels that list the channels that you are logged in, and show the list of users. If someone mentions your nickname in a channel, then the corresponding channel will change colour or representation to indicate that there is a message for you. A few users are channel operators (or moderators) and they have special privileges. They are similar to ‘root’ users in a system, and they exist to keep the signal-to-noise ratio to a minimum, and keep a vigil on the channel.</p>
<p>An IRC bot is a client software that connects to the IRC server as a user, but can respond to commands. It can thus be programmed to provide many services in a channel. You can customize existing bots, or write your own. Examples of IRC bots are Cerberus, Gambot and irccd. Cinch is an example of an IRC bot building framework written in Ruby. Bots can be used during an IRC meeting session to keep track of user questions. They can evaluate programming language constructs and return meaningful errors to newbies in the channel. They can be used to send a notification to the channel if a project test build fails, or when a new bug has been filed. The possibilities are endless.</p>
<h1 id="irc-meeting-protocol">IRC meeting protocol</h1>
<p>A free and open source software project will have a dedicated IRC channel where the project members will meet to have discussions. Meetings can be scheduled, and can happen in different time zones depending on where the users are located. There is a protocol and etiquette to be followed during such meetings. The speaker or moderator should not be interrupted during the session.</p>
<p>If you wish to ask a question, type ’?’ and wait. When the speaker has finished and feels that you can type in your text, you will be asked to do so. After you have finished typing your content, end with ‘EOF’. Similarly, if you need to speak during the session, type ’!’, and wait. You can give your consent or dissent to statements made in the channel using +1 or -1, respectively.</p>
<p>You are encouraged to read the rcirc manual and customize rcirc to your needs. If you have made it this far, do connect to irc.freenode.net, and feel free to say ‘Hi’ to me. I am ‘mbuf’ on irc.freenode.net. A screenshot of an rcirc session is shown below:</p>
<pre><code>19:35 &lt;mbuf&gt;    http://ecb.sourceforge.net/screenshots/index.html
19:35 ***       Arpita QUIT Client Quit
19:36 &lt;rtnpro&gt;  !
19:36 &lt;mbuf&gt;    rtnpro, shoot!
19:37 &lt;rtnpro&gt;  How do we get the emacs code browser?
19:37 &lt;rtnpro&gt;  &lt;EOF&gt;
19:37 &lt;mbuf&gt;    rtnpro, 1. Need to install &quot;ecb&quot; from your distro package manager
                2. you could have searched this on the Internet :)
19:38 &lt;rtnpro&gt;  It is not in my distro
19:38 &lt;sumitc&gt;  !
19:38 &lt;mbuf&gt;    rtnpro, and which distro are you using?
19:38 &lt;rtnpro&gt;  Its Fedora 9
19:39 &lt;rtnpro&gt;  I have got emacs but not emacs code browser
19:39 &lt;mbuf&gt;    rtnpro, you can always install from source
19:39 &lt;techno_freak&gt;    rtnpro, http://ecb.sourceforge.net/downloads.html
19:39 ***       khushbu QUIT Ping timeout: 244 seconds
19:39 &lt;rtnpro&gt;  ok
19:39 &lt;mbuf&gt;    sumitc, shoot!
19:39 &lt;sumitc&gt;  what is a tag-file?
19:40 &lt;rtnpro&gt;  What factors should decide the choice of our editor?
19:40 &lt;mbuf&gt;    rtnpro, wait!
19:40 ***       pushkal JOIN
19:40 &lt;mbuf&gt;    sumitc, the TAGS file contains the details of the reference count,
                and locations of variables/functions et. al.
19:41 &lt;sumitc&gt;  So, a tag file is always associated with a specific file?
19:41 &lt;mbuf&gt;    sumitc, no, it can have information of files in a directory
19:41 &lt;sumitc&gt;  ok
19:41 &lt;sumitc&gt;  &lt;eof&gt;
19:42 &lt;mbuf&gt;    sumitc, think of it as a database that answers all your queries
               regarding code references</code></pre>
<h1 id="references">References</h1>
<ol style="list-style-type: decimal">
<li><p>Freenode. <a href="https://freenode.net/"><code class="url">https://freenode.net/</code></a></p></li>
<li><p>rcirc manual. <a href="https://www.gnu.org/software/emacs/manual/html_mono/rcirc.html"><code class="url">https://www.gnu.org/software/emacs/manual/html_mono/rcirc.html</code></a></p></li>
<li><p>IRC Help. <a href="http://www.irchelp.org/"><code class="url">http://www.irchelp.org/</code></a></p></li>
<li><p>Fedora project - How to use IRC. <a href="https://fedoraproject.org/wiki/How_to_use_IRC"><code class="url">https://fedoraproject.org/wiki/How_to_use_IRC</code></a></p></li>
</ol>]]></description>
    <pubDate>Thu, 23 Jun 2016 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/06/23/rcirc/news.html</guid>
</item>
<item>
    <title>GNU Emacs - Buffer navigation and Help</title>
    <link>http://www.shakthimaan.com/posts/2016/06/01/buffer-navigation-help/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, September 2015 edition.]</em></p>
<p>Continuing with our series on Emacs, in this article, let’s explore basic buffer navigation, formatting, and help commands.</p>
<h1 id="buffers">Buffers</h1>
<p>You can view a list of buffers in GNU Emacs using the <em>C-x C-b</em> command, and can switch to a buffer using the <em>C-x b</em> shortcut. The default list of buffers as seen in GNU Emacs 24.3.1 on Ubuntu 14.10 is shown below:</p>
<pre><code>CRM Buffer                  Size Mode            File
.   *scratch*               191 Lisp Interaction 
*   *Messages*              485 Fundamental
%   *Completions*           264 Completion List
%   *Help*                 1855 Help</code></pre>
<p>In order to kill (close) a buffer, you can use <em>C-x k</em> key combination. If you have multiple buffers that you would like to close, you can use <em>M-x kill-some-buffers</em> command, which will prompt you for a confirmation for every buffer. You can also rename a buffer using the <em>M-x rename-buffer</em> command. If you would like to save the buffer contents to a file, you can use <em>C-x s</em>, and it will prompt you with many options before proceeding to save the file. You can also save a modified buffer using <em>C-x C-s</em>.</p>
<h1 id="navigation">Navigation</h1>
<p>It is important to learn how to use the Emacs navigation commands instead of the arrow keys. When you learn to use macros, you will find it useful to automate steps. A summary of the basic navigation shortcuts are given in the following table:</p>
<table>
<col width="12%"></col>
<col width="33%"></col>
<thead>
<tr class="header">
<th align="left">Command</th>
<th align="left">Meaning</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">C-f</td>
<td align="left">Move forward one character</td>
</tr>
<tr class="even">
<td align="left">C-b</td>
<td align="left">Move backward one character</td>
</tr>
<tr class="odd">
<td align="left">M-f</td>
<td align="left">Move forward one word</td>
</tr>
<tr class="even">
<td align="left">M-b</td>
<td align="left">Move back one word</td>
</tr>
<tr class="odd">
<td align="left">C-p</td>
<td align="left">Move to previous line</td>
</tr>
<tr class="even">
<td align="left">C-n</td>
<td align="left">Move to next line</td>
</tr>
<tr class="odd">
<td align="left">C-a</td>
<td align="left">Move to beginning of line</td>
</tr>
<tr class="even">
<td align="left">C-e</td>
<td align="left">Move to end of line</td>
</tr>
</tbody>
</table>
<p>You can scroll down a buffer using <em>C-v</em>, and scroll up using <em>M-v</em> shortcut. If you would like to move to the beginning of a file, use <em>M-&lt;</em> command. You can move to the end of a file using <em>M-&gt;</em> shortcut.</p>
<p>In order to move the cursor to a specific line, use <em>M-x goto-line</em> or <em>M-g g</em>. If you would like to position the contents where the cursor is located to the center of the screen, you can use <em>C-l</em>. If you want to repeat a command ‘n’ (‘n’ is an integer) number of times, you can use <em>M-n</em> following by the command. You can also use <em>C-u n</em>, but, if you don’t specify ‘n’ here, the next command, by default, will be executed four times.</p>
<h1 id="clipboard">Clipboard</h1>
<p>You can delete a character where the cursor is located using <em>C-d</em>. To remove a word, you can use <em>M-d</em>. You can remove text from the cursor position till the end of line using <em>C-k</em>. The cut text goes into a kill ring buffer. You can paste whatever you have removed using <em>C-y</em>. You can cycle through the text that has been removed by repeatedly using <em>M-y</em> after <em>C-y</em>. Consider the text:</p>
<pre><code>When you have a question about Emacs, the Emacs manual is often the
best starting point.</code></pre>
<p>If you place the cursor before “about” in the above sentence, and press ‘M-d’, it will remove &quot; about“. You can now see the value of the kill-ring using <em>C-h v</em> (describe variable), and it will prompt you with the message”Describe variable:“, where you can enter <em>kill-ring</em>. You will see an entry for” about“. Now, place the cursor after”question&quot; and press ‘M-d’ again, and “Emacs” will be removed. If you again check the kill-ring value, you will see an entry for &quot; Emacs&quot;.</p>
<p>You can now move the cursor to any location in the buffer, and press ‘C-y’, and it will paste “Emacs”. If you then press <em>M-y</em>, it will paste “about” which was the text that was cut before “Emacs”. This way, you can cycle through the kill ring buffer.</p>
<p>To select a region of text, you first need to mark the starting position with the cursor using <em>C-space</em>. You can then use any of the navigation commands to highlight the text that you want. You can either cut the marked region using <em>C-w</em>, or copy it using <em>M-w</em>. This will get copied to the kill-ring. You can then paste the text to any buffer. You can also select the entire buffer using <em>C-x h</em>.</p>
<h1 id="formatting-text">Formatting text</h1>
<p>It is good to have text within 80 columns and 25 rows (80x25), not just for readability, but, to avoid making any assumptions about the users’ screen size. If you have a really long sentence or paragraph, you can reformat it using the <em>M-q</em> shortcut from anywhere in the sentence or paragraph.</p>
<p>You can transpose two characters using <em>C-t</em> shortcut. For example, if you have misspelt “emacs” as “emcas”, you can place the cursor on ‘a’ and type <em>C-t</em> to swap the letters ‘a’ and ‘c’ to get “emacs”. You can transpose two words using the <em>M-t</em> command. For example, if you have the phrase “morning good” in a buffer, and you type <em>M-t</em> anywhere on the word “morning”, it will swap the words to give you “good morning”. You can also swap lines and sentences using <em>C-x C-t</em> and <em>M-x transpose-sentences</em> commands respectively.</p>
<p>If you would like to capitalize the first character of a word in upper case, you need to place the cursor on it, and key in <em>M-c</em> to make the first letter capital. You can turn all those letters from the cursor location to the rest of the word into capitals using <em>M-u</em> command. For example, if you have the word “sentence”, and you place the cursor on the letter ’t’, and you key in <em>M-u</em> the result will be “senTENCE”. To make all the characters lower case, you can use <em>M-l</em>. You can turn the entire previous word into capital letters using the <em>M - M-c</em> shortcut. Similarily, to make the previous words either upper case and lower case, you can use <em>M - M-u</em> and <em>M - M-l</em> commands, respectively.</p>
<h1 id="info">Info</h1>
<p>You can read manuals written in <em>Info</em> format inside GNU Emacs. When you type <em>M-x info</em>, it opens up a menu with the built-in documentation available from ‘Info’ files. The Info mode is mostly used to read hypertext manuals. You can use <em>Tab</em> and <em>Shift-tab</em> to navigate through the available links. Since the contents are in a buffer, all the basic navigation commands are applicable. To exit from <em>Info</em>, you can use <em>q</em> (quit).</p>
<p>You can press the <em>return</em> key on a link to open its contents. For example, when you click on “Emacs FAQ” it opens “The GNU Emacs FAQ” contents. The following are the sections listed in its buffer:</p>
<pre><code>* Menu
* FAQ notation
* General questions
* Getting help
* Status of Emacs
* Common requests
* Bugs and problems
* Compiling and installing Emacs
* Finding Emacs and related packages
* Key bindings
* Alternate character sets
* Mail and news
* Concept index</code></pre>
<p>Suppose, you hit the <em>return</em> key on “FAQ notation”, it will open its contents with the title “1 FAQ notation”. If you want to cycle through the headings at this level, you can press <em>n</em> (next topic) and <em>p</em> (previous topic). If you want to move one level up, to the “The GNU Emacs FAQ”, you can use the <em>u</em> shortcut.</p>
<p>If you simply want to move to the topmost node (“The GNU Emacs FAQ”), you can use the <em>t</em> shortcut. For example, if you were in the section “3.1 I’m just starting Emacs; how do I do basic editing?” and you pressed ’t’, it will take you to the topmost section - “The GNU Emacs FAQ”.</p>
<p>You can move to the previous node that you visited using the <em>l</em> shortcut. You can also explicitly specify the node you want to move to using the <em>g</em> shortcut. For example, if you are in the “1 FAQ notation” page, and you pressed <em>g</em>, it will then prompt you with the message “Go to node:”. You can then type “Extended” and hit TAB to auto-complete to “Extended commands”, which is one of the links in the page.</p>
<p>You are encouraged to try the built-in info tutorial available by pressing <em>h</em> in the “info” buffer.</p>
<h1 id="help">Help</h1>
<p>You can read manual pages inside GNU Emacs using <em>M-x man</em> command followed by the <em>return</em> key. Suppose, you try this command from the <em>scratch</em> buffer, it will then prompt you with the message “Manual entry:”. You can then input <em>ls</em> (list directory contents), and it will open a new buffer and window titled “Man ls” with the contents of the manual entry for the <em>ls</em> command.</p>
<p>From the scratch buffer, you can scroll forward the other window (‘<em>Man ls</em>’) using <em>C-M-v</em> (Ctrl-Alt-v), and scroll back using <em>C-M-shift-v</em> (Ctrl-Alt-Shift-v).</p>
<p>You can list all the available, active key-bindings using the <em>C-h b</em> command.</p>
<p>The <em>C-h f</em> shortcut is used to provide documentation for a function available in your installed version of GNU Emacs. For example, if you use <em>C-h f</em>, it will prompt you with the message “Describe function:”. If you input <em>scroll-other-window</em>, it will open a new buffer and window titled “Help” with the description and usage of the function. The output as seen in GNU Emacs 24.3.1 is shown below:</p>
<pre><code>scroll-other-window is an interactive built-in function in `C source
code'.

It is bound to &lt;M-next&gt;, C-M-v, ESC &lt;next&gt;.

(scroll-other-window &amp;optional ARG)

Scroll next window upward ARG lines; or near full screen if no ARG.
A near full screen is `next-screen-context-lines' less than a full screen.
The next window is the one below the current one; or the one at the top
if the current one is at the bottom.  Negative ARG means scroll downward.
If ARG is the atom `-', scroll downward by nearly full screen.
When calling from a program, supply as argument a number, nil, or `-'.

If `other-window-scroll-buffer' is non-nil, scroll the window
showing that buffer, popping the buffer up if necessary.
If in the minibuffer, `minibuffer-scroll-window' if non-nil
specifies the window to scroll.  This takes precedence over
`other-window-scroll-buffer'.

[back]</code></pre>
<p>On the other hand, if you know the command, and would like to get help related to it, you can use the <em>C-h k</em> command. This will prompt you with the message “Describe key (or click or menu item):”. You must key in the actual shortcut, for example, <em>C-h b</em>, and it will update the buffer “Help”, and open it in a new window, showing the description for the shortcut as shown below:</p>
<pre><code>C-h b runs the command describe-bindings, which is an interactive
compiled Lisp function.

It is bound to C-h b, &lt;f1&gt; b, &lt;help&gt; b, &lt;menu-bar&gt; &lt;help-menu&gt;
&lt;describe&gt; &lt;list-keybindings&gt;.

(describe-bindings &amp;optional PREFIX BUFFER)

Show a list of all defined keys, and their definitions.
We put that list in a buffer, and display the buffer.

The optional argument PREFIX, if non-nil, should be a key sequence;
then we display only bindings that start with that prefix.
The optional argument BUFFER specifies which buffer's bindings
to display (default, the current buffer).  BUFFER can be a buffer
or a buffer name.

[back]</code></pre>
<p>You are encouraged to try out all the commands so that you understand what actions they perform. When you use GNU Emacs as your main text editor, you will be able to regularly practice these commands, and master them.</p>]]></description>
    <pubDate>Wed, 01 Jun 2016 17:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/06/01/buffer-navigation-help/news.html</guid>
</item>
<item>
    <title>Dired Mode</title>
    <link>http://www.shakthimaan.com/posts/2016/05/09/dired-mode/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, August 2015 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>Dired is a directory editor in GNU Emacs. It opens a buffer containing a list of directories and files to operate on. It is a ‘read-only’ mode and hence you cannot input any text. This article explores some of the basic commands that can be used in Dired mode.</p>
<p>Let us first create a sample directory, sub-directories and files that we can use for our demonstration. Open a terminal and execute the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">mkdir</span> /tmp/test/network -p
$ <span class="kw">mkdir</span> /tmp/test/kernel -p

$ <span class="kw">date</span> <span class="kw">&gt;</span> /tmp/test/date.txt
$ locale <span class="kw">&gt;</span> /tmp/test/locale.txt

$ <span class="kw">cat</span> /etc/resolv.conf <span class="kw">&gt;</span> /tmp/test/network/resolv.conf
$ ifconfig <span class="kw">&gt;</span> /tmp/test/network/ifconfig.output

$ <span class="kw">dmesg</span> <span class="kw">&gt;</span> /tmp/test/kernel/dmesg.txt</code></pre>
<p>In general, filename extensions don’t have any meaning on *nix systems. Some applications do check the filename extension before using them. The extension is only for the benefit of the user, and hence you can have a filename without any extension on *nix.</p>
<h1 id="invocation">Invocation</h1>
<p>After opening GNU Emacs, you can enter Dired mode using <em>M-x dired</em>. It will prompt you for the directory to be opened in the buffer where you can input ‘/tmp/test’. You will see a buffer with the following contents:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">/tmp/test:
total used <span class="kw">in</span> directory 24 available 146721468
drwxrwxr-x  4 shakthi shakthi 4096 Jul  3 11:36 .
drwxrwxrwt 12 root    root    4096 Jul  3 11:38 ..
-rw-rw-r--  1 shakthi shakthi   29 Jul  3 11:36 date.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 kernel
-rw-rw-r--  1 shakthi shakthi  270 Jul  3 11:36 locale.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 network</code></pre>
<p>The contents of the buffer are similar to the <em>ls -al</em> output as observed in the terminal. The files were created by user ‘shakthi’, and this is indicated in the owner and group fields. The ’.’ entry represents the current ‘/tmp/test’ directory. The ’..’ listing represents the parent directory, which is ‘/tmp’ and owned by the ‘root’ user.</p>
<h1 id="exit">Exit</h1>
<p>You can exit from Dired mode by simply pressing <em>q</em> (quit-window) in the Dired buffer.</p>
<h1 id="navigation">Navigation</h1>
<p>You can move to a previous line or the next line in the Dired buffer using the <em>p</em> and <em>n</em> keys, respectively. If you wish to move the cursor to the previous and next directories, you can use the ‘&lt;’ and ‘&gt;’ keys. If the cursor is at ‘kernel’ directory as shown below …</p>
<pre class="sourceCode bash"><code class="sourceCode bash">/tmp/test:
total used <span class="kw">in</span> directory 24 available 146721468
drwxrwxr-x  4 shakthi shakthi 4096 Jul  3 11:36 .
drwxrwxrwt 12 root    root    4096 Jul  3 11:38 ..
-rw-rw-r--  1 shakthi shakthi   29 Jul  3 11:36 date.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 kernel      <span class="kw">&lt;</span>-- CURSOR
-rw-rw-r--  1 shakthi shakthi  270 Jul  3 11:36 locale.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 network</code></pre>
<p>… then, when you press ‘&gt;’, the cursor will move to ‘network’, which is the next directory in the buffer.</p>
<pre class="sourceCode bash"><code class="sourceCode bash">/tmp/test:
total used <span class="kw">in</span> directory 24 available 146721468
drwxrwxr-x  4 shakthi shakthi 4096 Jul  3 11:36 .
drwxrwxrwt 12 root    root    4096 Jul  3 11:38 ..
-rw-rw-r--  1 shakthi shakthi   29 Jul  3 11:36 date.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 kernel      
-rw-rw-r--  1 shakthi shakthi  270 Jul  3 11:36 locale.txt
drwxrwxr-x  2 shakthi shakthi 4096 Jul  3 11:36 network     <span class="kw">&lt;</span>-- CURSOR</code></pre>
<p>You can move to the parent directory using the ‘^’ key. To enter into a directory, move to its listing in the Dired buffer, and simply hit the <em>return</em> key.</p>
<h1 id="viewing-files">Viewing files</h1>
<p>To view a file, you can place the cursor on its entry and use the <em>f</em> or <em>v</em> key, or simply hit the <em>return</em> key. This will open the file in a new buffer (view). To return to the Dired buffer, you can type <em>C-x b</em> and the minibuffer will prompt you with the message “Switch to buffer (…)”. If you then press <em>TAB</em>, it will open a new <em>Completions</em> buffer that will list the available buffers. You can also type the entire ‘test’ buffer name, or type it partially and hit TAB for auto-completion, and hit the return key to get to the ‘test’ buffer. If you wish to close a buffer, you can use <em>C-k</em> to kill it. This will only close the buffer, but, the file will still exist! You can use the ‘+’ key to create a new sub-directory.</p>
<h1 id="marking-and-unmarking-files">Marking and unmarking files</h1>
<p>Dired mode allows you to operate on multiple files and directories. In order to run commands on them, you need to first select the files. The <em>m</em> key can be used to mark a file or directory for subsequent operations. For example, pressing ’m’ on the date.txt entry will mark it, and this is indicated by an asterisk in front of the line, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  /tmp/test:
  total used <span class="kw">in</span> directory 24 available 146933380
  drwxrwxr-x  4 shakthi shakthi 4096 Jul  5 09:53 .
  drwxrwxrwt 10 root    root    4096 Jul  5 09:46 ..
* -rw-rw-r--  1 shakthi shakthi   29 Jul  5 09:46 date.txt
  drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 kernel
  -rw-rw-r--  1 shakthi shakthi  270 Jul  5 09:46 locale.txt
  drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 network</code></pre>
<p>You can unmark the above selection using the <em>u</em> key. This is applicable for both files and directories. To undo a selection, you can also use <em>M-del</em> (<em>M</em> and the <em>Delete</em> key). Suppose, you wish to mark all the directories in the Dired buffer, you can use ‘* /’ key combination. The resultant Dired buffer is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  /tmp/test:
  total used <span class="kw">in</span> directory 24 available 146933432
  drwxrwxr-x  4 shakthi shakthi 4096 Jul  5 09:53 .
  drwxrwxrwt 10 root    root    4096 Jul  5 09:46 ..
  -rw-rw-r--  1 shakthi shakthi   29 Jul  5 09:46 date.txt
* drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 kernel
  -rw-rw-r--  1 shakthi shakthi  270 Jul  5 09:46 locale.txt
* drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 network</code></pre>
<p>If you want to invert the selection, use <em>t</em>. The buffer will look like the following:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  /tmp/test:
  total used <span class="kw">in</span> directory 24 available 146933432
  drwxrwxr-x  4 shakthi shakthi 4096 Jul  5 09:53 .
  drwxrwxrwt 10 root    root    4096 Jul  5 09:46 ..
* -rw-rw-r--  1 shakthi shakthi   29 Jul  5 09:46 date.txt
  drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 kernel
* -rw-rw-r--  1 shakthi shakthi  270 Jul  5 09:46 locale.txt
  drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 network</code></pre>
<p>To mark all the files, you can use ‘* s’ key combination.</p>
<h1 id="modifying-the-buffer">Modifying the buffer</h1>
<p>After you have selected files, you can remove them from the listing by pressing the <em>k</em> key. This does not delete the files! You can always press <em>g</em> to refresh the Dired buffer contents. You can change the ‘ls’ command line options used in the Dired listing using the <em>C-u s</em> key combination.</p>
<h1 id="actions">Actions</h1>
<p>You can perform a number of operations on the marked files and directories. To copy a file, you can press <em>C</em> on a file, and it will prompt you in the minibuffer regarding where you would like to create the new copy. You can use <em>R</em> to rename a file. If you would like to delete a file, you can press <em>D</em>. You can change the mode of a file with the <em>M</em> command. You can compress or uncompress a file with the <em>Z</em> command.</p>
<p>A regular expression search can be done on selected files with the <em>A</em> command. You can create a symbolic link file with the <em>S</em> key. You can run a shell command on marked files using the ’!’ command. For example, if you want to perform a word count (wc) on the date.txt file, you can press ’!’ on the date.txt entry listing, and it will prompt you in the minibuffer with “! on date.txt:” message. If you input ‘wc’, the results will again be shown in the minibuffer. On my system, it returned ‘1 6 29 date.txt’. You can also run asynchronous shell commands on files using the ‘&amp;’ command, and a new buffer will be opened that will contain the results.</p>
<h1 id="deletion">Deletion</h1>
<p>You can mark files for deletion using the <em>d</em> command. After selecting the files or directories, if you press <em>x</em>, the respective actions will be performed on the files. To demonstrate an example, let us use ‘d’ on the ‘kernel’ directory to mark it for deletion. The letter ‘D’ will be added to its entry as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  /tmp/test:
  total used <span class="kw">in</span> directory 24 available 146933432
  drwxrwxr-x  4 shakthi shakthi 4096 Jul  5 09:53 .
  drwxrwxrwt 10 root    root    4096 Jul  5 09:46 ..
  -rw-rw-r--  1 shakthi shakthi   29 Jul  5 09:46 date.txt
D drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 kernel
  -rw-rw-r--  1 shakthi shakthi  270 Jul  5 09:46 locale.txt
  drwxrwxr-x  2 shakthi shakthi 4096 Jul  5 09:46 network</code></pre>
<p>When you press ‘x’, you will be prompted to confirm deletion with the message “Delete kernel (yes or no)”. When you input “yes” and hit the return key, the directory contents will be removed. GNU Emacs will perform auto-save on files, and also create backup files ending with ‘~’. You can mark such files using the ‘~’ command.</p>
<h1 id="regex">Regex</h1>
<p>You can use ‘% d’ to select files based on a regular expression (regex) to mark for deletion. To simply mark files based on regex, you can use ‘% m’ shortcut. To rename the marked files, you can use ‘% R’.</p>
<h1 id="find">Find</h1>
<p>You can search for files matching a pattern using the <em>M-x find-name-dired</em> command. Suppose you wish to find all the .txt files in our original /tmp/test directory, you can use ‘M-x find-name-dired’ in the Dired buffer. It will prompt you in the minibuffer with the following message “Find-name (directory): /tmp/test”. After you press the return key, it will ask for the regex with the message “Find-name (filename wildcard):”. If you input ‘*.txt’, it will return the following contents:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">/tmp/test/:
<span class="kw">find</span> <span class="kw">.</span> <span class="dt">\(</span> -name <span class="dt">\*</span>.txt <span class="dt">\)</span> -ls
6826601    4 -rw-rw-r--   1 shakthi  shakthi        29 Jul  5 09:46 date.txt
6826616   64 -rw-rw-r--   1 shakthi  shakthi     63050 Jul  5 09:46 kernel/dmesg.txt
6826602    4 -rw-rw-r--   1 shakthi  shakthi       270 Jul  5 09:46 locale.txt

<span class="kw">find</span> finished at Sun Jul  5 10:27:02</code></pre>
<p>You can also find files based on regex patterns that exist in the file contents using the <em>M-x find-grep-dired</em>. Suppose, you wish to find the files that have the text ‘eth’ in them, you can use ‘M-x find-grep-dired’, which will prompt you in the minibuffer with the message “Find-grep (directory): /tmp/test”. After you press the return key, it will prompt you for the regex with the message “Find-grep (grep regexp):”, where you can input ‘eth’ and this will return the following results:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">/tmp/test/:
<span class="kw">find</span> <span class="kw">.</span> <span class="dt">\(</span> -type f -exec <span class="kw">grep</span> -q -e eth <span class="dt">\{\}</span> <span class="dt">\;</span> <span class="dt">\)</span> -ls
6826605    4 -rw-rw-r--   1 shakthi  shakthi      1620 Jul  5 09:46 network/ifconfig.output
6826616   64 -rw-rw-r--   1 shakthi  shakthi     63050 Jul  5 09:46 kernel/dmesg.txt

<span class="kw">find</span> finished at Sun Jul  5 10:31:27</code></pre>
<p>You can also execute a find operation on marked files using <em>M-x find-dired</em>.</p>
<h1 id="help">Help</h1>
<p>To open the help menu for Dired, you can use the <em>h</em> shortcut key. To see the Dired log messages, you can press the <em>?</em> key.</p>
<p>You may refer to a quick reference card at <a href="https://www.gnu.org/software/emacs/refcards/pdf/dired-ref.pdf"><code class="url">https://www.gnu.org/software/emacs/refcards/pdf/dired-ref.pdf</code></a>, and try out more Dired commands.</p>]]></description>
    <pubDate>Mon, 09 May 2016 12:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/05/09/dired-mode/news.html</guid>
</item>
<item>
    <title>Introduction to GNU Emacs</title>
    <link>http://www.shakthimaan.com/posts/2016/04/04/introduction-to-gnu-emacs/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, July 2015 edition.]</em></p>
<h1 id="introduction">Introduction</h1>
<p>GNU Emacs is a very popular text editor written in C and Emacs Lisp. It can be run on many platforms, and can be easily customised and extended for user needs. It was created by Richard Stallman, the founder of the GNU project. This article is the first in a series on how to use it. There are a number of tutorials available for GNU Emacs; this series of articles provide one approach to understanding and learning the software. You are encouraged to refer to the official GNU Emacs reference manual for more information, and it supersedes everything. Here are a few interesting quotes on Emacs.</p>
<blockquote>
<p>“I use Emacs, which might be thought of as a thermonuclear word processor” – Neal Stephenson (In the Beginning… Was the Command Line)</p>
</blockquote>
<blockquote>
<p>“Emacs is undoubtedly the most powerful programmer’s editor in existence. It’s a big, feature-laden program with a great deal of flexibility and customizability. … Emacs has an entire programming language inside it that can be used to write arbitrarily powerful editor functions.” – Eric S. Raymond (from ‘The Art of UNIX Programming’)</p>
</blockquote>
<blockquote>
<p>“Personally, I feel inspired whenever I open Emacs. Like a craftsman entering his workshop, I feel a realm of possibility open before me. I feel the comfort of an environment that has evolved over time to fit me perfectly - an assortment of packages and keybindings which help me bring ideas to life day after day.” – Daniel Higginbotham (in ‘Clojure for the Brave and True’)</p>
</blockquote>
<blockquote>
<p>“EMACS could not have been reached by a process of careful design, because such processes arrive only at goals which are visible at the outset, and whose desirability is established on the bottom line at the outset. Neither I nor anyone else visualized an extensible editor until I had made one, nor appreciated its value until he had experienced it. EMACS exists because I felt free to make individually useful small improvements on a path whose end was not in sight.” – Richard Stallman</p>
</blockquote>
<h1 id="installation">Installation</h1>
<p>You can use your favourite GNU/Linux distribution package manager to install GNU Emacs. On Debian/Ubuntu, you can install with the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> apt-get <span class="kw">install</span> emacs</code></pre>
<p>On Fedora, you can use the Yum package manager as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> emacs</code></pre>
<p>The emerge tool can install GNU Emacs on Gentoo, as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># emerge --ask app-editors/emacs</span></code></pre>
<p>On Arch, the Pacman software can help you in installing GNU Emacs:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> pacman -S emacs</code></pre>
<p>Use the Zypper package manager in SUSE as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> zypper <span class="kw">install</span> emacs</code></pre>
<h1 id="startup">Startup</h1>
<p>If you use the Unity interface, you can search for emacs in the Dash, and it will show the Emacs icon that you can click to open the editor. This is illustrated in the following figure.</p>
<img alt="Unity Emacs search image" src="http://www.shakthimaan.com/images/emacs/final-emacs-unity.png"></img><br />
<p>On the Metacity interface or any other desktop environment with a panel, you can open GNU Emacs from “Applications” -&gt; “Accessories” -&gt; “Emacs” as shown below:</p>
<img alt="Metacity Emacs" src="http://www.shakthimaan.com/images/emacs/final-emacs-metacity.png"></img><br />
<p>You can also open the editor from the terminal by simply typing ‘emacs’ and hitting the return key.</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ emacs</code></pre>
<p>The version that I have used for this article is GNU Emacs 24.3.1.</p>
<h1 id="exit">Exit</h1>
<p>To exit from GNU Emacs, you need to use C-c C-q, where ‘C’ stands for the Control key. You can also use your mouse and close the editor by clicking on the ‘x’, but, GNU Emacs was designed to be completely usable with a keyboard, and I am going to encourage you to only use the keyboard shortcuts.</p>
<h1 id="concepts">Concepts</h1>
<p>While you can work using GUI editors, I am going to teach you to work entirely on the keyboard to experience the power of shortcuts in GNU Emacs. You can disconnect the mouse and your touchpad when working on GNU Emacs. Just as an exercise, I’d encourage you to remove your mouse completely and see how you can work with a computer for one day. You will realise that a lot of user interfaces are heavily dependent and designed for mouse interactions! By only using the keyboard, you can be blazingly fast and productive.</p>
<p>The keyboard shortcuts in GNU Emacs may seem to involve many keys. But, please bear with me on this, because the way the shortcuts are designed, you will be able to remember them easily. As you practice, you will gain insight into how consistently they have been defined.</p>
<p>GNU Emacs is a ‘stateless’ editor for the most part. By ‘stateless’, I mean that there are no specific state transitions that need to happen before you can use the commands. There does exist the concept of modes. When you open GNU Emacs, you will see menus, buffer and a mode line as illustrated in the following figure:</p>
<img alt="Emacs default screen" width="650" src="http://www.shakthimaan.com/images/emacs/final-emacs-default-text.png"></img><br />
<p>As mentioned earlier, we will not be clicking on the menus or icons with a mouse, but only use keyboard shortcuts. Everything is a buffer in GNU Emacs. Each buffer can have one major mode and one or more minor modes. The mode determines the keyboard shortcuts that are applicable primarily on the buffer. Examples of major modes are given below:</p>
<table>
<col width="20%"></col>
<col width="42%"></col>
<thead>
<tr class="header">
<th align="left">Mode</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">Text mode</td>
<td align="left">Writing text</td>
</tr>
<tr class="even">
<td align="left">HTML mode</td>
<td align="left">Writing HTML</td>
</tr>
<tr class="odd">
<td align="left">cc mode</td>
<td align="left">Writing C, C++ and C-like programs</td>
</tr>
<tr class="even">
<td align="left">Dired mode</td>
<td align="left">Handling files and directories</td>
</tr>
<tr class="odd">
<td align="left">Shell mode</td>
<td align="left">Working with shell</td>
</tr>
<tr class="even">
<td align="left">LaTeX mode</td>
<td align="left">Formatting TeX and LaTeX files</td>
</tr>
<tr class="odd">
<td align="left">Picture mode</td>
<td align="left">Creating ASCII art</td>
</tr>
<tr class="even">
<td align="left">Outline mode</td>
<td align="left">Writing outlines</td>
</tr>
<tr class="odd">
<td align="left">SQL mode</td>
<td align="left">Interacting with SQL databases</td>
</tr>
<tr class="even">
<td align="left">Lisp mode</td>
<td align="left">Writing Lisp programs</td>
</tr>
</tbody>
</table>
<p>The mode line exists below the buffer and it gives you a lot of information on the status of the buffer, such as what modes are active and other useful information. Below the mode line is the mini-buffer, where any commands you issue are indicated and prompts for user input are shown. This is the overall view of the default GNU Emacs interface.</p>
<p>In today’s user interface applications, an application is treated as a window on a desktop. But, when you open GNU Emacs, you are actually opening a frame. A frame can be split it into many windows. Everything is a buffer in GNU Emacs. So, you can have many frames of GNU Emacs, and inside each you can have one or more windows containing buffers (or files).</p>
<h1 id="features">Features</h1>
<p>Although GNU Emacs was designed primarily for text editing, it can do a lot more. ‘A lot’ is probably a highly simplified term. It has got support for syntax highlighting for a large number of programming languages. You can also generate code snippets from templates using the <em>yasnippet</em> package. You can also enter markup or markdown text. There is support for indentation of text and programs depending on the programming languages and modes. Internationalization support is available, and you can use it to even enter text in Indian languages.</p>
<p>A number of configurations are available for setting it up for your development work, including automating tasks for compiling, executing, testing and deployment. When you become familiar with Emacs Lisp, you can implement your own modules. Since, it is Lisp, it is also easily extensible. You can write your own macros to perform repeated tasks. You can also query an inbuilt help system for information, shortcuts, tutorials and other documentation. You are not at all dependent on the Internet for information, and thus you can work offline too. Version control support is available for many centralized (cvs, svn) and decentralized systems (Git, Hg).</p>
<p>org-mode is a very popular mode for managing your notes. You can use it for planning your day-to-day activities. GNU Emacs can be used as publishing software. You can create wikis, blogs and publish books using it. This article is written using org-mode. Spell-checking modules are also available for your documentation needs. It is also possible to export plain text into a number of formats (PDF, HTML etc.).</p>
<p>A number of Emacs lisp packages are available for networking. You can use Gnus for checking your e-mails, and reading and writing to newsgroups. Emacs Relay Chat (ERC) can be used for connecting to Internet Relay Chat (IRC) channels. There are modules that support the Jabber protocol for communicating with chat servers. There is also support for viewing Web pages inside Emacs. There are a large number of Emacs modules available through package repositories such as MELPA (melpa.org), and Marmalada (marmalade-repo.org).</p>
<h1 id="history">History</h1>
<p>The first version of Emacs (macros) was written by Richard Stallman and Guy L. Steele, Jr. in 1976 for the TECO editor in MIT. It was written in a low-level language for the PDP-10 assembler. People were able to freely hack on the code, make improvements and share their changes. This was the original hacker culture that existed in MIT. Unfortunately, business entities started to make software proprietary and this hacker culture ceased to exist, especially in the MIT AI labs. Richard Stallman wanted to revive the hacker culture and started the GNU project. He wrote the second implementation of the editor entirely in C in 1984, and released it as the first program of the GNU project. Today, it is a very popular editor that is widely used, and has more than 570 contributors. The official web site for GNU Emacs is at <a href="http://www.gnu.org/software/emacs/"><code class="url">http://www.gnu.org/software/emacs/</code></a>.</p>]]></description>
    <pubDate>Mon, 04 Apr 2016 15:15:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/04/04/introduction-to-gnu-emacs/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Web Programming</title>
    <link>http://www.shakthimaan.com/posts/2016/01/27/haskell-web-programming/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, June 2015 edition.]</em></p>
<p>In this final article in the Haskell series, we shall explore how to use it for web programming.</p>
<p><em>Scotty</em> is a web framework written in Haskell, which is similar to Ruby’s Sinatra. You can install it on Ubuntu using the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> apt-get <span class="kw">install</span> cabal-install
$ cabal update
$ cabal <span class="kw">install</span> scotty</code></pre>
<p>Let us write a simple `Hello, World!’ program using the Scotty framework:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- hello-world.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Web.Scotty</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    html <span class="st">&quot;Hello, World!&quot;</span></code></pre>
<p>You can compile and start the server from the terminal using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ runghc hello-world.hs 
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>The service will run on port 3000, and you can open <em>localhost:3000</em> in a browser to see the `Hello, World!’ text. You can then stop the service by pressing <em>Control-c</em> in the terminal. You can also use Curl to make a query to the server. Install and test it on Ubuntu as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> apt-get <span class="kw">install</span> curl

$ curl localhost:3000
Hello, World!</code></pre>
<p>You can identify the user client that made the HTTP request to the server by returning the “User-Agent” header value as illustrated in the following example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- request-header.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Web.Scotty</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/agent&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    agent <span class="ot">&lt;-</span> header <span class="st">&quot;User-Agent&quot;</span>
    <span class="fu">maybe</span> (raise <span class="st">&quot;User-Agent header not found!&quot;</span>) text agent</code></pre>
<p>You can execute the above code in a terminal using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ runghc request-header.hs  
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>If you open the URL <em>localhost:3000/agent</em> in the browser, it returns the following User-Agent information on Ubuntu 14.10 <em>Mozilla/5.0 (X11; Linux x86<sub>64</sub>) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/41.0.2272.76 Chrome/41.0.2272.76 Safari/537.36</em>. The Curl version is returned for the same URL request as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ curl localhost:3000/agent -v

 * Hostname was NOT found <span class="kw">in</span> DNS cache
 *   Trying 127.0.0.1...
 * Connected to localhost <span class="kw">(</span>127.0.0.1<span class="kw">)</span> port 3000 <span class="kw">(</span>#0<span class="kw">)</span>
 <span class="kw">&gt;</span> GET /agent HTTP/1.1
 <span class="kw">&gt;</span> User-Agent: curl/7.37.1
 <span class="kw">&gt;</span> Host: localhost:3000
 <span class="kw">&gt;</span> Accept: */*
 <span class="kw">&gt;</span> 
 <span class="kw">&lt;</span> HTTP/1.1 200 OK
 <span class="kw">&lt;</span> Transfer-Encoding: chunked
 <span class="kw">&lt;</span> Date: Wed, 29 Apr 2015 07:46:21 GMT
 * Server Warp/3.0.12.1 is not blacklisted
 <span class="kw">&lt;</span> Server: Warp/3.0.12.1
 <span class="kw">&lt;</span> Content-Type: text/plain; <span class="ot">charset=</span>utf-8
 <span class="kw">&lt;</span> 
 * Connection <span class="co">#0 to host localhost left intact</span>

 curl/7.37.1</code></pre>
<p>You can also return different content types (HTML, text, JSON) based on the request. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- content-type.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Web.Scotty</span> <span class="kw">as</span> <span class="dt">W</span>
<span class="kw">import</span> <span class="dt">Data.Monoid</span>
<span class="kw">import</span> <span class="dt">Data.Text</span>
<span class="kw">import</span> <span class="dt">Data.Aeson</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/hello&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    html <span class="fu">$</span> mconcat [<span class="st">&quot;&lt;h1&gt;&quot;</span>, <span class="st">&quot;Hello, World!&quot;</span>, <span class="st">&quot;&lt;/h1&gt;&quot;</span>]

  get <span class="st">&quot;/hello.txt&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    text <span class="st">&quot;Hello, World!&quot;</span>

  get <span class="st">&quot;/hello.json&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    W.json <span class="fu">$</span> object [<span class="st">&quot;text&quot;</span> <span class="fu">.=</span> (<span class="st">&quot;Hello, World!&quot;</span><span class="ot"> ::</span> <span class="dt">Text</span>)]</code></pre>
<p>You can start the above server in a terminal as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ runghc content-type.hs 
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>You can then open the three URLs listed above in a browser to see the different output. The respective outputs when used with Curl are shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ curl localhost:3000/hello
<span class="kw">&lt;</span>h<span class="kw">1&gt;</span>Hello, World!<span class="kw">&lt;</span>/h<span class="kw">1&gt;</span>

$ curl localhost:3000/hello.txt
Hello, World!

$ curl localhost:3000/hello.json
{<span class="st">&quot;text&quot;</span>:<span class="st">&quot;Hello, World!&quot;</span>}</code></pre>
<p>You can also pass parameters in the URL when you make a request. The <em>param</em> function can be used to retrieve the parameters as indicated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- params.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Web.Scotty</span>
<span class="kw">import</span> <span class="dt">Data.Monoid</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/user&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    name <span class="ot">&lt;-</span> param <span class="st">&quot;name&quot;</span>
    html <span class="fu">$</span> mconcat [<span class="st">&quot;&lt;h1&gt;Hello &quot;</span>, name, <span class="st">&quot;&lt;/h1&gt;&quot;</span>]</code></pre>
<p>You can start the above server using the <em>runghc</em> command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ runghc params.hs 
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>You can now try the URL requests with and without parameters. The observed outputs are shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ curl localhost:3000/user
<span class="kw">&lt;</span>h<span class="kw">1&gt;</span>500 Internal Server Error<span class="kw">&lt;</span>/h<span class="kw">1&gt;</span>Param: name not found!

$ curl localhost:3000/user?<span class="ot">name=</span>Shakthi
<span class="kw">&lt;</span>h<span class="kw">1&gt;</span>Hello Shakthi<span class="kw">&lt;</span>/h<span class="kw">1&gt;</span></code></pre>
<p>The <em>Hspec</em> testing framework can be used for integration testing the web application. Install the required dependencies as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> happy hspec hspec-wai hspec-wai-json</code></pre>
<p>The content type example has been updated to use <em>Hspec</em>, as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- content-type-spec.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}</span>
<span class="kw">module</span> <span class="dt">Main</span> (main) <span class="kw">where</span>

<span class="kw">import</span> <span class="dt">Data.Monoid</span>
<span class="kw">import</span> <span class="dt">Data.Text</span>

<span class="kw">import</span>           <span class="dt">Network.Wai</span> (<span class="dt">Application</span>)
<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Web.Scotty</span> <span class="kw">as</span> <span class="dt">W</span>
<span class="kw">import</span>           <span class="dt">Data.Aeson</span> (object, (<span class="fu">.=</span>))

<span class="kw">import</span>           <span class="dt">Test.Hspec</span>
<span class="kw">import</span>           <span class="dt">Test.Hspec.Wai</span>
<span class="kw">import</span>           <span class="dt">Test.Hspec.Wai.JSON</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> hspec spec

<span class="ot">app ::</span> <span class="dt">IO</span> <span class="dt">Application</span>
app <span class="fu">=</span> W.scottyApp <span class="fu">$</span> <span class="kw">do</span>
  W.get <span class="st">&quot;/hello.txt&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    W.text <span class="st">&quot;Hello, World!&quot;</span>

  W.get <span class="st">&quot;/hello&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    W.html <span class="fu">$</span> mconcat [<span class="st">&quot;&lt;h1&gt;&quot;</span>, <span class="st">&quot;Hello, World!&quot;</span>, <span class="st">&quot;&lt;/h1&gt;&quot;</span>]

  W.get <span class="st">&quot;/hello.json&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    W.json <span class="fu">$</span> object [<span class="st">&quot;text&quot;</span> <span class="fu">.=</span> (<span class="st">&quot;Hello, World!&quot;</span><span class="ot"> ::</span> <span class="dt">Text</span>)]

<span class="ot">spec ::</span> <span class="dt">Spec</span>
spec <span class="fu">=</span> with app <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;GET /&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;responds with text&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      get <span class="st">&quot;/hello.txt&quot;</span> <span class="ot">`shouldRespondWith`</span> <span class="st">&quot;Hello, World!&quot;</span>

    it <span class="st">&quot;responds with HTML&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      get <span class="st">&quot;/hello&quot;</span> <span class="ot">`shouldRespondWith`</span> <span class="st">&quot;&lt;h1&gt;Hello, World!&lt;/h1&gt;&quot;</span>

    it <span class="st">&quot;responds with JSON&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      get <span class="st">&quot;/hello.json&quot;</span> <span class="ot">`shouldRespondWith`</span> [json<span class="fu">|</span>{text<span class="fu">:</span> <span class="st">&quot;Hello, World!&quot;</span>}<span class="fu">|</span>]</code></pre>
<p>You can compile the above code as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make content-type-spec.hs     
Linking content-type-spec ...</code></pre>
<p>The following output is observed when you run the above built test executable:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./content-type-spec 

GET /
  responds with text
  responds with HTML
  responds with JSON

Finished <span class="kw">in</span> 0.0010 seconds
3 examples, 0 failures</code></pre>
<p>Please refer to the <em>hspec-wai</em> webpage at <a href="https://github.com/hspec/hspec-wai"><code class="url">https://github.com/hspec/hspec-wai</code></a> for more information.</p>
<p>Template support is available through many Haskell packages. The use of the <em>blaze-html</em> package is demonstrated below. Install the package first using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> blaze-html</code></pre>
<p>Consider a simple web page with a header and three unordered lists. Using <em>blaze-html</em>, the template can be written in Haskell DSL as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- template.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Web.Scotty</span> <span class="kw">as</span> <span class="dt">W</span>
<span class="kw">import</span> <span class="dt">Text.Blaze.Html5</span>
<span class="kw">import</span> <span class="dt">Text.Blaze.Html.Renderer.Text</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    W.html <span class="fu">.</span> renderHtml <span class="fu">$</span> <span class="kw">do</span>
      h1 <span class="st">&quot;Haskell list&quot;</span>
      ul <span class="fu">$</span> <span class="kw">do</span>
        li <span class="st">&quot;http://haskell.org&quot;</span>
        li <span class="st">&quot;http://learnyouahaskell.com/&quot;</span>
        li <span class="st">&quot;http://book.realworldhaskell.org/&quot;</span></code></pre>
<p>You can compile the above code using GHC:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make template.hs 
Linking template ...</code></pre>
<p>You can then execute the built executable, which starts the server as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./template 
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>Opening a browser with URL <em>localhost:3000</em> will render the expected HTML file. You can also verify the resultant HTML output using the Curl command as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ curl localhost:3000
<span class="kw">&lt;</span>h<span class="kw">1&gt;</span>Haskell list<span class="kw">&lt;</span>/h<span class="kw">1&gt;&lt;</span>ul<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://haskell.org<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://learnyouahaskell.com/<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://book.realworldhaskell.org/<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>/ul<span class="kw">&gt;</span></code></pre>
<p>It is good to separate the views from the actual application code. You can move the template content to a separate file as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- Haskell.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">module</span> <span class="dt">Haskell</span> <span class="kw">where</span>

<span class="kw">import</span> <span class="dt">Text.Blaze.Html5</span>

<span class="ot">render ::</span> <span class="dt">Html</span>
render <span class="fu">=</span> <span class="kw">do</span>
  html <span class="fu">$</span> <span class="kw">do</span>
    body <span class="fu">$</span> <span class="kw">do</span>
      h1 <span class="st">&quot;Haskell list&quot;</span>
      ul <span class="fu">$</span> <span class="kw">do</span>
        li <span class="st">&quot;http://haskell.org&quot;</span>
        li <span class="st">&quot;http://learnyouahaskell.com/&quot;</span>
        li <span class="st">&quot;http://book.realworldhaskell.org/&quot;</span></code></pre>
<p>The main application code is now simplified as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- template-file.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Haskell</span>
<span class="kw">import</span> <span class="dt">Web.Scotty</span> <span class="kw">as</span> <span class="dt">W</span>
<span class="kw">import</span> <span class="dt">Text.Blaze.Html</span>
<span class="kw">import</span> <span class="dt">Text.Blaze.Html.Renderer.Text</span>

<span class="ot">blaze ::</span> <span class="dt">Text.Blaze.Html.Html</span> <span class="ot">-&gt;</span> <span class="dt">ActionM</span> ()
blaze <span class="fu">=</span> W.html <span class="fu">.</span> renderHtml

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> scotty <span class="dv">3000</span> <span class="fu">$</span> <span class="kw">do</span>
  get <span class="st">&quot;/&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    blaze Haskell.render</code></pre>
<p>You need to place both the source files (<em>Haskell.hs</em> and <em>template-file.hs</em>) in the same top-level directory, and you can then compile the <em>template-file.hs</em> file that will also compile the dependency <em>Haskell.hs</em> source file as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make template-file.hs 

[1 of 2] Compiling Haskell          <span class="kw">(</span> Haskell.hs, Haskell.o <span class="kw">)</span>
[2 of 2] Compiling Main             <span class="kw">(</span> template-file.hs, template-file.o <span class="kw">)</span>
Linking template-file ...</code></pre>
<p>You can now run the server as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./template-file 
Setting phasers to stun..<span class="kw">.</span> <span class="kw">(</span>port 3000<span class="kw">)</span> <span class="kw">(</span>ctrl-c to quit<span class="kw">)</span></code></pre>
<p>Executing <em>template-file</em> produces the same output as in the case of the <em>template.hs</em> example.</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ curl localhost:3000
<span class="kw">&lt;</span>html<span class="kw">&gt;&lt;</span>body<span class="kw">&gt;&lt;</span>h<span class="kw">1&gt;</span>Haskell list<span class="kw">&lt;</span>/h<span class="kw">1&gt;&lt;</span>ul<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://haskell.org<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://learnyouahaskell.com/<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>li<span class="kw">&gt;</span>http://book.realworldhaskell.org/<span class="kw">&lt;</span>/li<span class="kw">&gt;&lt;</span>/ul<span class="kw">&gt;&lt;</span>/body<span class="kw">&gt;&lt;</span>/html<span class="kw">&gt;</span></code></pre>
<p>You can refer the Scotty wiki page at <a href="https://github.com/scotty-web/scotty/wiki"><code class="url">https://github.com/scotty-web/scotty/wiki</code></a> for more information.</p>
<p>The <em>clay</em> package is a CSS preprocessor similar to <em>LESS</em> and <em>Sass</em>. You can install it using the following Cabal command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">    $ cabal <span class="kw">install</span> clay</code></pre>
<p>Let us consider a simple CSS example to generate a list of fonts to be used in the body section of a HTML page. The corresponding Clay Haskell embedded DSL looks like the following:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- clay-simple.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Clay</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> putCss exampleStylesheet

<span class="ot">exampleStylesheet ::</span> <span class="dt">Css</span>
exampleStylesheet <span class="fu">=</span> body <span class="fu">?</span> fontFamily [<span class="st">&quot;Baskerville&quot;</span>, <span class="st">&quot;Georgia&quot;</span>, <span class="st">&quot;Garamond&quot;</span>, <span class="st">&quot;Times&quot;</span>] [serif]</code></pre>
<p>You can compile the above code as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make clay-simple.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> clay-simple.hs, clay-simple.o <span class="kw">)</span>
Linking clay-simple ...</code></pre>
<p>You can then execute <em>clay-simple</em> to generate the required CSS output as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./clay-simple

body
<span class="kw">{</span>
  font-family <span class="kw">:</span> <span class="st">&quot;Baskerville&quot;</span>,<span class="st">&quot;Georgia&quot;</span>,<span class="st">&quot;Garamond&quot;</span>,<span class="st">&quot;Times&quot;</span>, serif;
<span class="kw">}</span>

/* Generated with Clay, http://fvisser.nl/clay */</code></pre>
<p>A more comprehensive example is shown below for the HTML pre tag:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- clay-pre.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Clay</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> putCss <span class="fu">$</span>
  pre <span class="fu">?</span>
    <span class="kw">do</span> border dotted (pt <span class="dv">1</span>) black
       whiteSpace (other <span class="st">&quot;pre&quot;</span>)
       fontSize (other <span class="st">&quot;8pt&quot;</span>)
       overflow (other <span class="st">&quot;auto&quot;</span>)
       padding (em <span class="dv">20</span>) (em <span class="dv">0</span>) (em <span class="dv">20</span>) (em <span class="dv">0</span>)</code></pre>
<p>You can compile the above <em>clay-pre.hs</em> file as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make clay-pre.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> clay-pre.hs, clay-pre.o <span class="kw">)</span>
Linking clay-pre ...</code></pre>
<p>Executing the above complied <em>clay-pre</em> binary produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./clay-pre 

pre
<span class="kw">{</span>
  border      <span class="kw">:</span> dotted 1pt rgb<span class="kw">(</span>0,0,0<span class="kw">)</span>;
  white-space <span class="kw">:</span> pre;
  font-size   <span class="kw">:</span> 8pt;
  overflow    <span class="kw">:</span> auto;
  padding     <span class="kw">:</span> 20em 0em 20em 0em;
<span class="kw">}</span>

/* Generated with Clay, http://fvisser.nl/clay */</code></pre>
<p>You can also add custom values using the <em>Other</em> type class or the fallback operator `-:’ to explicitly specify values. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- clay-custom.hs</span>

<span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Clay</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> putCss <span class="fu">$</span>
  body <span class="fu">?</span>
       <span class="kw">do</span> fontSize (other <span class="st">&quot;11pt !important&quot;</span>)
          <span class="st">&quot;border&quot;</span> <span class="fu">-:</span> <span class="st">&quot;0&quot;</span></code></pre>
<p>Compiling and executing the above code produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make clay-custom.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> clay-custom.hs, clay-custom.o <span class="kw">)</span>
Linking clay-custom ...

$ ./clay-custom 

body
<span class="kw">{</span>
  font-size <span class="kw">:</span> 11pt !important;
  border    <span class="kw">:</span> 0;
<span class="kw">}</span>

/* Generated with Clay, http://fvisser.nl/clay */</code></pre>
<p>You can explore more of clay from the official project homepage <a href="http://fvisser.nl/clay/"><code class="url">http://fvisser.nl/clay/</code></a>.</p>
<p>A number of good books are available for further learning. I recommend the following books available online and in print:</p>
<ol style="list-style-type: decimal">
<li><p>Bryan O’Sullivan, Don Stewart, and John Goerzen. (December 1, 2008). Real World Haskell (<a href="http://book.realworldhaskell.org/"><code class="url">http://book.realworldhaskell.org/</code></a>). O’Reilly.</p></li>
<li><p>Miran Lipovaca. (April 21, 2011). Learn You a Haskell for Great Good! A Beginner’s Guide (<a href="http://learnyouahaskell.com/"><code class="url">http://learnyouahaskell.com/</code></a>). No Starch Press.</p></li>
</ol>
<p>The <a href="https://www.haskell.org"><code class="url">https://www.haskell.org</code></a> website also has plenty of useful resources. You can also join the haskell-cafe@haskell.org and beginners@haskell.org mailing lists ( <a href="https://wiki.haskell.org/Mailing_lists"><code class="url">https://wiki.haskell.org/Mailing_lists</code></a> ) for discussions. The folks in the #haskell channel on irc.freenode.net are also very helpful.</p>
<p>I hope you enjoyed learning Haskell through this series, as much as I did creating them. Please feel free to write to me (author at shakthimaan dot com) with any feedback or suggestions.</p>
<p>Happy Hacking!</p>]]></description>
    <pubDate>Wed, 27 Jan 2016 22:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2016/01/27/haskell-web-programming/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Network Programming</title>
    <link>http://www.shakthimaan.com/posts/2015/12/30/haskell-network-programming/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, May 2015 edition.]</em></p>
<p>In this article we shall explore network programming in Haskell.</p>
<p>Let us begin with a simple TCP (Transmission Control Protocol) client and server example. The <em>network</em> package provides a high-level interface for communication. You can install the same in Fedora, for example, using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> ghc-network</code></pre>
<p>Consider the following simple TCP client code:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- tcp-client.hs</span>

<span class="kw">import</span> <span class="dt">Network</span>
<span class="kw">import</span> <span class="dt">System.IO</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> withSocketsDo <span class="fu">$</span> <span class="kw">do</span>
         handle <span class="ot">&lt;-</span> connectTo <span class="st">&quot;localhost&quot;</span> (<span class="dt">PortNumber</span> <span class="dv">3001</span>)
         hPutStr handle <span class="st">&quot;Hello, world!&quot;</span>
         hClose handle</code></pre>
<p>After importing the required libraries, the <em>main</em> function connects to a localhost server running on port 3001, sends a string “Hello, world!”, and closes the connection.</p>
<p>The <em>connectTo</em> function defined in the Network module accepts a hostname, port number and returns a handle that can be used to transfer or receive data.</p>
<p>The type signatures of the <em>withSocketsdo</em> and <em>connectTo</em> functions are as under:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t withSocketsDo
<span class="ot">withSocketsDo ::</span> <span class="dt">IO</span> a <span class="ot">-&gt;</span> <span class="dt">IO</span> a

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t connectTo
<span class="ot">connectTo ::</span> <span class="dt">HostName</span> <span class="ot">-&gt;</span> <span class="dt">PortID</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">GHC.IO.Handle.Types.Handle</span></code></pre>
<p>The simple TCP server code is illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- tcp-server.hs</span>

<span class="kw">import</span> <span class="dt">Network</span>
<span class="kw">import</span> <span class="dt">System.IO</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> withSocketsDo <span class="fu">$</span> <span class="kw">do</span>
         sock <span class="ot">&lt;-</span> listenOn <span class="fu">$</span> <span class="dt">PortNumber</span> <span class="dv">3001</span>
         <span class="fu">putStrLn</span> <span class="st">&quot;Starting server ...&quot;</span>
         handleConnections sock

<span class="ot">handleConnections ::</span> <span class="dt">Socket</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
handleConnections sock <span class="fu">=</span> <span class="kw">do</span>
  (handle, host, port) <span class="ot">&lt;-</span> accept sock
  output <span class="ot">&lt;-</span> hGetLine handle
  <span class="fu">putStrLn</span> output
  handleConnections sock</code></pre>
<p>The main function starts a server on port 3001 and transfers the socket handler to a <em>handleConnections</em> function. It accepts any connection requests, reads the data, prints it to the server log, and waits for more clients.</p>
<p>Firstly, you need to compile the <em>tcp-server.hs</em> and <em>tcp-client.hs</em> files using GHC:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make tcp-server.hs
[1 of 1] Compiling Main             <span class="kw">(</span> tcp-server.hs, tcp-server.o <span class="kw">)</span>
Linking tcp-server ...

$ ghc --make tcp-client.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> tcp-client.hs, tcp-client.o <span class="kw">)</span>
Linking tcp-client ...</code></pre>
<p>You can now start the TCP server in a terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./tcp-server 
Starting server ...</code></pre>
<p>You can then run the TCP client in another terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./tcp-client</code></pre>
<p>You will now observe the “Hello, world” message printed in the terminal where the server is running:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./tcp-server 
Starting server ...
Hello, world!</code></pre>
<p>The <em>Network.Socket</em> package exposes more low-level socket functionality for Haskell and can be used if you need finer access and control. For example, consider the following UDP (User Datagram Protocol) client code:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- udp-client.hs</span>

<span class="kw">import</span> <span class="dt">Network.Socket</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> withSocketsDo <span class="fu">$</span> <span class="kw">do</span>
         (server<span class="fu">:</span>_) <span class="ot">&lt;-</span> getAddrInfo <span class="kw">Nothing</span> (<span class="kw">Just</span> <span class="st">&quot;localhost&quot;</span>) (<span class="kw">Just</span> <span class="st">&quot;3000&quot;</span>)
         s <span class="ot">&lt;-</span> socket (addrFamily server) <span class="dt">Datagram</span> defaultProtocol
         connect s (addrAddress server)
         send s <span class="st">&quot;Hello, world!&quot;</span>
         sClose s</code></pre>
<p>The <em>getAddrInfo</em> function resolves a host or service name to a network address. A UDP client connection is then requested for the server address, a message is sent, and the connection is closed. The type signatures of <em>getAddrInfo</em>, <em>addrFamily</em>, and <em>addrAddress</em> are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getAddrInfo
getAddrInfo
<span class="ot">  ::</span> <span class="dt">Maybe</span> <span class="dt">AddrInfo</span>
     <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">HostName</span> <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">ServiceName</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> [<span class="dt">AddrInfo</span>]

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t addrFamily
<span class="ot">addrFamily ::</span> <span class="dt">AddrInfo</span> <span class="ot">-&gt;</span> <span class="dt">Family</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t addrAddress
<span class="ot">addrAddress ::</span> <span class="dt">AddrInfo</span> <span class="ot">-&gt;</span> <span class="dt">SockAddr</span></code></pre>
<p>The corresponding UDP server code is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- udp-server.hs</span>

<span class="kw">import</span> <span class="dt">Network.Socket</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> withSocketsDo <span class="fu">$</span> <span class="kw">do</span>
         (server<span class="fu">:</span>_) <span class="ot">&lt;-</span> getAddrInfo <span class="kw">Nothing</span> (<span class="kw">Just</span> <span class="st">&quot;localhost&quot;</span>) (<span class="kw">Just</span> <span class="st">&quot;3000&quot;</span>)
         s <span class="ot">&lt;-</span> socket (addrFamily server) <span class="dt">Datagram</span> defaultProtocol
         bindSocket s (addrAddress server) <span class="fu">&gt;&gt;</span> <span class="fu">return</span> s
         <span class="fu">putStrLn</span> <span class="st">&quot;Server started ...&quot;</span>
         handleConnections s

<span class="ot">handleConnections ::</span> <span class="dt">Socket</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
handleConnections conn <span class="fu">=</span> <span class="kw">do</span>
  (text, _, _) <span class="ot">&lt;-</span> recvFrom conn <span class="dv">1024</span>
  <span class="fu">putStrLn</span> text
  handleConnections conn</code></pre>
<p>The UDP server binds to localhost and starts to listen on port 3000. When a client connects, it reads a maximum of 1024 bytes of data, prints it to <em>stdout</em>, and waits to accept more connections. You can compile the <em>udp-server.hs</em> and <em>udp-client.hs</em> files using the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make udp-server.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> udp-server.hs, udp-server.o <span class="kw">)</span>
Linking udp-server ...

$ ghc --make udp-client.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> udp-client.hs, udp-client.o <span class="kw">)</span>
Linking udp-client ...</code></pre>
<p>You can start the UDP server in one terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./udp-server 
Server started ...</code></pre>
<p>You can then run the UDP client in another terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./tcp-client</code></pre>
<p>You will now see the “Hello, world!” message printed in the terminal where the server is running:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./udp-server 
Server started ...
Hello, world!</code></pre>
<p>The <em>network-uri</em> module has many useful URI (Uniform Resource Identifier) parsing and test functions. You can install the same on Fedora using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> network-uri</code></pre>
<p>The <em>parseURI</em> function takes a string and attempts to convert it into a URI. It returns ‘Nothing’ if the input is not a valid URI, and returns the URI, otherwise. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Network.URI</span>

ghci<span class="fu">&gt;</span> parseURI <span class="st">&quot;http://www.shakthimaan.com&quot;</span>
<span class="kw">Just</span> http<span class="fu">://</span>www<span class="fu">.</span>shakthimaan<span class="fu">.</span>com

ghci<span class="fu">&gt;</span> parseURI <span class="st">&quot;shakthimaan.com&quot;</span>
<span class="kw">Nothing</span></code></pre>
<p>The type signature of the <em>parseURI</em> function is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t parseURI
<span class="ot">parseURI ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">URI</span></code></pre>
<p>A number of functions are available for testing the input URI as illustrated in the following examples:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> isURI <span class="st">&quot;shakthimaan.com&quot;</span>
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> isURI <span class="st">&quot;http://www.shakthimaan.com&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> isRelativeReference <span class="st">&quot;http://shakthimaan.com&quot;</span>
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> isRelativeReference <span class="st">&quot;../about.html&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> isAbsoluteURI <span class="st">&quot;http://www.shakthimaan.com&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> isAbsoluteURI <span class="st">&quot;shakthimaan.com&quot;</span>
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> isIPv4address <span class="st">&quot;192.168.100.2&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> isIPv6address <span class="st">&quot;2001:0db8:0a0b:12f0:0000:0000:0000:0001&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> isIPv6address <span class="st">&quot;192.168.100.2&quot;</span>
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> isIPv4address <span class="st">&quot;2001:0db8:0a0b:12f0:0000:0000:0000:0001&quot;</span>
<span class="kw">False</span></code></pre>
<p>The type signatures of the above functions are as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t isURI
<span class="ot">isURI ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t isRelativeReference
<span class="ot">isRelativeReference ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t isAbsoluteURI
<span class="ot">isAbsoluteURI ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t isIPv4address
<span class="ot">isIPv4address ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t isIPv6address
<span class="ot">isIPv6address ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span></code></pre>
<p>You can make a GET request for a URL and retrieve its contents. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Network</span>
<span class="kw">import</span> <span class="dt">System.IO</span>

main <span class="fu">=</span> withSocketsDo <span class="fu">$</span> <span class="kw">do</span>
    h <span class="ot">&lt;-</span> connectTo <span class="st">&quot;www.shakthimaan.com&quot;</span> (<span class="dt">PortNumber</span> <span class="dv">80</span>)
    hSetBuffering h <span class="dt">LineBuffering</span>
    hPutStr h <span class="st">&quot;GET / HTTP/1.1\nhost: www.shakthimaan.com\n\n&quot;</span>
    contents <span class="ot">&lt;-</span> hGetContents h
    <span class="fu">putStrLn</span> contents
    hClose h</code></pre>
<p>You can now compile and execute the above code, and it returns the <em>index.html</em> contents as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make get-network-uri.hs
[1 of 1] Compiling Main             <span class="kw">(</span> get-network-uri.hs, get-network-uri.o <span class="kw">)</span>
Linking get-network-uri ...

$ ./get-network-uri 
HTTP/1.1 200 OK
Date: Sun, 05 Apr 2015 01:37:19 GMT
Server: Apache
Last-Modified: Tue, 08 Jul 2014 04:01:16 GMT
Accept-Ranges: bytes
Content-Length: 4604
Content-Type: text/html
...</code></pre>
<p>You can refer to the network-uri package documentation at <a href="https://hackage.haskell.org/package/network-uri-2.6.0.1/docs/Network-URI.html"><code class="url">https://hackage.haskell.org/package/network-uri-2.6.0.1/docs/Network-URI.html</code></a> for more detailed information.</p>
<p>The <em>whois</em> Haskell package allows you to query for information about hosting servers and domain names. You can install the package on Ubuntu, for example, using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> whois</code></pre>
<p>The <em>serverFor</em> function returns a whois server that can be queried for obtaining more information regarding an IP or domain name. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Network.Whois</span>

ghci<span class="fu">&gt;</span> serverFor <span class="st">&quot;shakthimaan.com&quot;</span>
<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unix<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package network<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.3</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mtl<span class="dv">-2</span><span class="fu">.</span><span class="fl">2.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package text<span class="dv">-1</span><span class="fu">.</span><span class="fl">2.0</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package parsec<span class="dv">-3</span><span class="fu">.</span><span class="fl">1.9</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package network<span class="fu">-</span>uri<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package split<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package whois<span class="dv">-1</span><span class="fu">.</span><span class="fl">2.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

<span class="kw">Just</span> (<span class="dt">WhoisServer</span> {hostname <span class="fu">=</span> <span class="st">&quot;com.whois-servers.net&quot;</span>, port <span class="fu">=</span> <span class="dv">43</span>, query <span class="fu">=</span> <span class="st">&quot;domain &quot;</span>})</code></pre>
<p>You can use the above specific information with the <em>whois1</em> function to make a DNS (Domain Name System) query:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> whois1 <span class="st">&quot;shakthimaan.com&quot;</span> <span class="dt">WhoisServer</span> {hostname <span class="fu">=</span> <span class="st">&quot;com.whois-servers.net&quot;</span>, port <span class="fu">=</span> <span class="dv">43</span>, query <span class="fu">=</span> <span class="st">&quot;domain &quot;</span>}
<span class="kw">Just</span> <span class="st">&quot;\nWhois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered\n</span>
<span class="st">...</span></code></pre>
<p>You can also use the <em>whois</em> function to return information on the server as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> whois <span class="st">&quot;shakthimaan.com&quot;</span>
<span class="kw">Just</span> <span class="st">&quot;\nWhois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered\n</span>
<span class="st">...</span></code></pre>
<p>The type signatures of <em>serverFor</em>, <em>whois1</em> and <em>whois</em> functions are as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghc<span class="fu">&gt;</span> <span class="fu">:</span>t serverFor
<span class="ot">serverFor ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">WhoisServer</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t whois1
<span class="ot">whois1 ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">WhoisServer</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> (<span class="dt">Maybe</span> <span class="dt">String</span>)

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t whois
<span class="ot">whois ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> (<span class="dt">Maybe</span> <span class="dt">String</span>, <span class="dt">Maybe</span> <span class="dt">String</span>)</code></pre>
<p>The <em>dns</em> package provides a number of useful functions to make Domain Name System queries, and handle the responses. You can install the same on Ubuntu, for example, using the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> apt-get <span class="kw">install</span> zlib1g-dev
$ cabal <span class="kw">install</span> dns</code></pre>
<p>A simple example of finding the IP addresses for the <em>haskell.org</em> domain is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Network.DNS.Lookup</span>
ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Network.DNS.Resolver</span>

ghci<span class="fu">&gt;</span> <span class="kw">let</span> hostname <span class="fu">=</span> Data.ByteString.Char8.pack <span class="st">&quot;www.haskell.org&quot;</span>

ghci<span class="fu">&gt;</span> rs <span class="ot">&lt;-</span> makeResolvSeed defaultResolvConf

ghci<span class="fu">&gt;</span> withResolver rs <span class="fu">$</span> \resolver <span class="ot">-&gt;</span> lookupA resolver hostname
<span class="kw">Right</span> [<span class="fl">108.162</span><span class="fu">.</span><span class="fl">203.60</span>,<span class="fl">108.162</span><span class="fu">.</span><span class="fl">204.60</span>]</code></pre>
<p>The <em>defaultResolvConf</em> is of type <em>ResolvConf</em> and consists of the following default values:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">--     * 'resolvInfo' is 'RCFilePath' \&quot;\/etc\/resolv.conf\&quot;.</span>
<span class="fu">--</span>
<span class="co">--     * 'resolvTimeout' is 3,000,000 micro seconds.</span>
<span class="fu">--</span>
<span class="co">--     * 'resolvRetry' is 3.</span></code></pre>
<p>The <em>makeResolvSeed</em>, and <em>withResolver</em> functions assist in making the actual DNS resolution. The <em>lookupA</em> function obtains all the A records for the DNS entry. Their type signatures are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t makeResolvSeed
<span class="ot">makeResolvSeed ::</span> <span class="dt">ResolvConf</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">ResolvSeed</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t withResolver
<span class="ot">withResolver ::</span> <span class="dt">ResolvSeed</span> <span class="ot">-&gt;</span> (<span class="dt">Resolver</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> a) <span class="ot">-&gt;</span> <span class="dt">IO</span> a

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t lookupA
lookupA
<span class="ot">  ::</span> <span class="dt">Resolver</span>
     <span class="ot">-&gt;</span> dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>
     <span class="ot">-&gt;</span> <span class="dt">IO</span>
          (<span class="dt">Either</span>
             dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.DNSError</span>
             [iproute<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">:</span><span class="dt">Data.IP.Addr.IPv4</span>])</code></pre>
<p>The <em>lookupAAAA</em> function returns all the IPv6 ‘AAAA’ records for the domain. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> withResolver rs <span class="fu">$</span> \resolver <span class="ot">-&gt;</span> lookupAAAA resolver hostname
<span class="kw">Right</span> [<span class="dv">2400</span><span class="fu">:</span>cb00<span class="fu">:</span><span class="dv">2048</span><span class="fu">:</span><span class="dv">1</span><span class="ot">::</span>6ca2<span class="fu">:</span>cc3c,<span class="dv">2400</span><span class="fu">:</span>cb00<span class="fu">:</span><span class="dv">2048</span><span class="fu">:</span><span class="dv">1</span><span class="ot">::</span>6ca2<span class="fu">:</span>cb3c]</code></pre>
<p>Its type signature is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">lookupAAAA
<span class="ot">  ::</span> <span class="dt">Resolver</span>
     <span class="ot">-&gt;</span> dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>
     <span class="ot">-&gt;</span> <span class="dt">IO</span>
          (<span class="dt">Either</span>
             dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.DNSError</span>
             [iproute<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">:</span><span class="dt">Data.IP.Addr.IPv6</span>])</code></pre>
<p>The MX records for the hostname can be returned using the <em>lookupMX</em> function. An example for the shakthimaan.com website is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Network.DNS.Lookup</span>
ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Network.DNS.Resolver</span>

ghci<span class="fu">&gt;</span> <span class="kw">let</span> hostname <span class="fu">=</span> Data.ByteString.Char8.pack <span class="st">&quot;www.shakthimaan.com&quot;</span>

ghci<span class="fu">&gt;</span> rs <span class="ot">&lt;-</span> makeResolvSeed defaultResolvConf

ghci<span class="fu">&gt;</span> withResolver rs <span class="fu">$</span> \resolver <span class="ot">-&gt;</span> lookupMX resolver hostname
<span class="kw">Right</span> [(<span class="st">&quot;shakthimaan.com.&quot;</span>,<span class="dv">0</span>)]</code></pre>
<p>The type signature of the <em>lookupMX</em> function is as under:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t lookupMX
lookupMX
<span class="ot">  ::</span> <span class="dt">Resolver</span>
     <span class="ot">-&gt;</span> dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>
     <span class="ot">-&gt;</span> <span class="dt">IO</span>
          (<span class="dt">Either</span>
             dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.DNSError</span>
             [(dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>, <span class="dt">Int</span>)])</code></pre>
<p>The nameservers for the domain can be returned using the <em>lookupNS</em> function. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> withResolver rs <span class="fu">$</span> \resolver <span class="ot">-&gt;</span> lookupNS resolver hostname
<span class="kw">Right</span> [<span class="st">&quot;ns22.webhostfreaks.com.&quot;</span>,<span class="st">&quot;ns21.webhostfreaks.com.&quot;</span>]</code></pre>
<p>The type signature of the lookupNS function is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t lookupNS
lookupNS
<span class="ot">  ::</span> <span class="dt">Resolver</span>
     <span class="ot">-&gt;</span> dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>
     <span class="ot">-&gt;</span> <span class="dt">IO</span>
          (<span class="dt">Either</span>
             dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.DNSError</span>
             [dns<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.5</span><span class="fu">:</span><span class="dt">Network.DNS.Internal.Domain</span>])</code></pre>
<p>You can also return the entire DNS response using the <em>lookupRaw</em> function as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Network.DNS.Types</span>

ghci<span class="fu">&gt;</span> <span class="kw">let</span> hostname <span class="fu">=</span> Data.ByteString.Char8.pack <span class="st">&quot;www.ubuntu.com&quot;</span>

ghci<span class="fu">&gt;</span> rs <span class="ot">&lt;-</span> makeResolvSeed defaultResolvConf

ghci<span class="fu">&gt;</span> withResolver rs <span class="fu">$</span> \resolver <span class="ot">-&gt;</span> lookupRaw resolver hostname <span class="dt">A</span>
<span class="kw">Right</span> (<span class="dt">DNSFormat</span> 
  {header <span class="fu">=</span> <span class="dt">DNSHeader</span> 
    {identifier <span class="fu">=</span> <span class="dv">29504</span>, 
     flags <span class="fu">=</span> <span class="dt">DNSFlags</span> 
       {qOrR <span class="fu">=</span> <span class="dt">QR_Response</span>, 
        opcode <span class="fu">=</span> <span class="dt">OP_STD</span>, 
        authAnswer <span class="fu">=</span> <span class="kw">False</span>, 
        trunCation <span class="fu">=</span> <span class="kw">False</span>, 
        recDesired <span class="fu">=</span> <span class="kw">True</span>, 
        recAvailable <span class="fu">=</span> <span class="kw">True</span>, 
        rcode <span class="fu">=</span> <span class="dt">NoErr</span>}, 
     qdCount <span class="fu">=</span> <span class="dv">1</span>, 
     anCount <span class="fu">=</span> <span class="dv">1</span>, 
     nsCount <span class="fu">=</span> <span class="dv">3</span>, 
     arCount <span class="fu">=</span> <span class="dv">3</span>}, 
   question <span class="fu">=</span> [
     <span class="dt">Question</span> 
       {qname <span class="fu">=</span> <span class="st">&quot;www.ubuntu.com.&quot;</span>, 
        qtype <span class="fu">=</span> <span class="dt">A</span>}], 
     answer <span class="fu">=</span> [
       <span class="dt">ResourceRecord</span> 
         {rrname <span class="fu">=</span> <span class="st">&quot;www.ubuntu.com.&quot;</span>, 
          rrtype <span class="fu">=</span> <span class="dt">A</span>, 
          rrttl <span class="fu">=</span> <span class="dv">61</span>, 
          rdlen <span class="fu">=</span> <span class="dv">4</span>, 
          rdata <span class="fu">=</span> <span class="fl">91.189</span><span class="fu">.</span><span class="fl">89.103</span>}], 
     authority <span class="fu">=</span> [
       <span class="dt">ResourceRecord</span> 
         {rrname <span class="fu">=</span> <span class="st">&quot;ubuntu.com.&quot;</span>, 
          rrtype <span class="fu">=</span> <span class="dt">NS</span>, 
          rrttl <span class="fu">=</span> <span class="dv">141593</span>, 
          rdlen <span class="fu">=</span> <span class="dv">16</span>, 
          rdata <span class="fu">=</span> ns2<span class="fu">.</span>canonical<span class="fu">.</span>com<span class="fu">.</span>},
       <span class="dt">ResourceRecord</span> 
         {rrname <span class="fu">=</span> <span class="st">&quot;ubuntu.com.&quot;</span>, 
          rrtype <span class="fu">=</span> <span class="dt">NS</span>, 
          rrttl <span class="fu">=</span> <span class="dv">141593</span>, 
          rdlen <span class="fu">=</span> <span class="dv">6</span>, 
          rdata <span class="fu">=</span> ns1<span class="fu">.</span>canonical<span class="fu">.</span>com<span class="fu">.</span>},
       <span class="dt">ResourceRecord</span>
         {rrname <span class="fu">=</span> <span class="st">&quot;ubuntu.com.&quot;</span>, 
          rrtype <span class="fu">=</span> <span class="dt">NS</span>, 
          rrttl <span class="fu">=</span> <span class="dv">141593</span>, 
          rdlen <span class="fu">=</span> <span class="dv">6</span>, 
          rdata <span class="fu">=</span> ns3<span class="fu">.</span>canonical<span class="fu">.</span>com<span class="fu">.</span>}], 
    additional <span class="fu">=</span> [
      <span class="dt">ResourceRecord</span> 
        {rrname <span class="fu">=</span> <span class="st">&quot;ns2.canonical.com.&quot;</span>, 
         rrtype <span class="fu">=</span> <span class="dt">A</span>, 
         rrttl <span class="fu">=</span> <span class="dv">88683</span>, 
         rdlen <span class="fu">=</span> <span class="dv">4</span>, 
         rdata <span class="fu">=</span> <span class="fl">91.189</span><span class="fu">.</span><span class="fl">95.3</span>},
      <span class="dt">ResourceRecord</span> 
        {rrname <span class="fu">=</span> <span class="st">&quot;ns3.canonical.com.&quot;</span>, 
         rrtype <span class="fu">=</span> <span class="dt">A</span>, 
         rrttl <span class="fu">=</span> <span class="dv">88683</span>, 
         rdlen <span class="fu">=</span> <span class="dv">4</span>, 
         rdata <span class="fu">=</span> <span class="fl">91.189</span><span class="fu">.</span><span class="fl">91.139</span>},
      <span class="dt">ResourceRecord</span> 
        {rrname <span class="fu">=</span> <span class="st">&quot;ns1.canonical.com.&quot;</span>, 
         rrtype <span class="fu">=</span> <span class="dt">A</span>, 
         rrttl <span class="fu">=</span> <span class="dv">88683</span>, 
         rdlen <span class="fu">=</span> <span class="dv">4</span>, 
         rdata <span class="fu">=</span> <span class="fl">91.189</span><span class="fu">.</span><span class="fl">94.173</span>}]})</code></pre>
<p>Please refer the Network.DNS hackage web page <a href="https://hackage.haskell.org/package/dns"><code class="url">https://hackage.haskell.org/package/dns</code></a> for more information.</p>]]></description>
    <pubDate>Wed, 30 Dec 2015 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/12/30/haskell-network-programming/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Databases II</title>
    <link>http://www.shakthimaan.com/posts/2015/12/11/haskell-databases-2/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, April 2015 edition.]</em></p>
<p>In this article we shall explore access to Redis and PostgreSQL databases using Haskell modules. The hackage website at <a href="https://hackage.haskell.org/packages/#cat:Database">https://hackage.haskell.org/packages/#cat:Database</a> provides a vast number of database packages that you can use, a couple of which will be covered here..</p>
<p>You will need to install the <em>cabal-install</em> tool on Fedora, for example, using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> cabal-install</code></pre>
<ul>
<li>Connecting to the Redis database</li>
</ul>
<p>Let’s use the hedis package to connect to the Redis server. Install the Fedora dependency package <em>alex</em>, and the Redis server as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> alex redis</code></pre>
<p>You can then install the <em>hedis</em> package using the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal update
$ cabal <span class="kw">install</span> hedis</code></pre>
<p>This installs the latest <em>hedis</em> version 0.6.5. You can now start the Redis server on Fedora using the <em>service</em> command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> service redis start</code></pre>
<p>You can then test connectivity to the Redis server using the <em>redis-cli</em> command by issuing the <em>PING</em> command as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ redis-cli

127.0.0.1:<span class="kw">6379&gt;</span> PING
PONG</code></pre>
<p>You can also test the same using the hedis package inside the GHCi interpreter as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci
<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="dt">Database.Redis</span> 

ghci<span class="fu">&gt;</span> conn <span class="ot">&lt;-</span> connect defaultConnectInfo

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base<span class="fu">-</span>unicode<span class="fu">-</span>symbols<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.2</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package text<span class="dv">-0</span><span class="fu">.</span><span class="fl">11.3</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package stm<span class="dv">-2</span><span class="fu">.</span><span class="fl">4.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="kw">primitive</span><span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package vector<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hashable<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.2</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="fu">-</span>base<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package monad<span class="fu">-</span>control<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.2</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package attoparsec<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.4</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mtl<span class="dv">-2</span><span class="fu">.</span><span class="fl">1.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">BoundedChan</span><span class="dv">-1</span><span class="fu">.</span><span class="fl">0.3</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="fu">-</span>lexing<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.3</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unix<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package network<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package resource<span class="fu">-</span>pool<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.3</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hedis<span class="dv">-0</span><span class="fu">.</span><span class="fl">6.5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

ghci<span class="fu">&gt;</span> runRedis conn ping
<span class="kw">Right</span> <span class="dt">Pong</span></code></pre>
<p>It is recommended that you use <em>defaultConnectInfo</em> to connect to the database, and its type is <em>ConnectInfo</em>:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t defaultConnectInfo
<span class="ot">defaultConnectInfo ::</span> <span class="dt">ConnectInfo</span></code></pre>
<p>The different options that can be used in <em>defaultConnectInfo</em> are as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">connectHost           <span class="fu">=</span> <span class="st">&quot;localhost&quot;</span>
connectPort           <span class="fu">=</span> <span class="dt">PortNumber</span> <span class="dv">6379</span> <span class="co">-- Redis port</span>
connectAuth           <span class="fu">=</span> <span class="kw">Nothing</span>         <span class="co">-- No authentication</span>
connectDatabase       <span class="fu">=</span> <span class="dv">0</span>               <span class="co">-- SELECT database 0</span>
connectMaxConnections <span class="fu">=</span> <span class="dv">10</span>              <span class="co">-- Up to 10 connections</span>
connectMaxIdleTime    <span class="fu">=</span> <span class="dv">20</span>              <span class="co">-- Keep connection open for 20 seconds</span></code></pre>
<p>The types of <em>conn</em>, <em>connect</em>, <em>runRedis</em> and <em>ping</em> are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t conn
<span class="ot">conn ::</span> <span class="dt">Connection</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t connect
<span class="ot">connect ::</span> <span class="dt">ConnectInfo</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Connection</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t runRedis
<span class="ot">runRedis ::</span> <span class="dt">Connection</span> <span class="ot">-&gt;</span> <span class="dt">Redis</span> a <span class="ot">-&gt;</span> <span class="dt">IO</span> a

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t ping
<span class="ot">ping ::</span> <span class="dt">RedisCtx</span> m f <span class="ot">=&gt;</span> m (f <span class="dt">Status</span>)</code></pre>
<p>If the Redis server was not started, and you tried to issue the <em>ping</em> command, the following exception will be automatically thrown by the package:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runRedis conn ping
<span class="fu">***</span> <span class="dt">Exception</span><span class="fu">:</span> connect<span class="fu">:</span> does <span class="fu">not</span> exist (<span class="dt">No</span> route to host)</code></pre>
<p>You can automate the above code snippets into Haskell code with a main function as demonstrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>
<span class="kw">import</span> <span class="dt">Database.Redis</span>

<span class="ot">main ::</span> <span class="dt">IO</span> (<span class="dt">Either</span> <span class="dt">Reply</span> <span class="dt">Status</span>)
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
  runRedis conn ping</code></pre>
<p>The <em>OverloadedStrings</em> extension allows string literals to be polymorphic for the <em>IsString</em> class. You can compile and run the above code inside GHCi, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci ping<span class="fu">.</span>hs

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( ping<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main
<span class="fu">...</span>
<span class="kw">Right</span> <span class="dt">Pong</span></code></pre>
<p>The <em>echo</em> Redis command is used to print a message that is passed as an argument to it. The equivalent <em>hedis</em> echo command expects the message to be of type <em>ByteString</em>. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>
<span class="kw">import</span> <span class="dt">Database.Redis</span>
<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.ByteString</span> <span class="kw">as</span> <span class="dt">B</span>

<span class="ot">bytes ::</span> <span class="dt">B.ByteString</span>
bytes <span class="fu">=</span> <span class="st">&quot;Hello, World&quot;</span><span class="ot"> ::</span> <span class="dt">B.ByteString</span>

<span class="ot">main ::</span> <span class="dt">IO</span> (<span class="dt">Either</span> <span class="dt">Reply</span> <span class="dt">B.ByteString</span>)
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
  runRedis conn <span class="fu">$</span> echo bytes</code></pre>
<p>Loading the above code in GHCi produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="kw">Right</span> <span class="st">&quot;Hello, World&quot;</span></code></pre>
<p>The type signature of the echo function is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">echo
<span class="ot">  ::</span> <span class="dt">RedisCtx</span> m f <span class="ot">=&gt;</span>
     <span class="dt">Data.ByteString.Internal.ByteString</span>
     <span class="ot">-&gt;</span> m (f <span class="dt">Data.ByteString.Internal.ByteString</span>)</code></pre>
<p>You can set a value to a key using the <em>set</em> function in <em>hedis</em>. An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>
<span class="kw">import</span> <span class="dt">Database.Redis</span>

<span class="ot">main ::</span> <span class="dt">IO</span> (<span class="dt">Either</span> <span class="dt">Reply</span> <span class="dt">Status</span>)
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
  runRedis conn <span class="fu">$</span> set <span class="st">&quot;a&quot;</span> <span class="st">&quot;apple&quot;</span></code></pre>
<p>Loading the above <em>set.hs</em> code in GHCi and testing the same produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>l set<span class="fu">.</span>hs
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( set<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main
<span class="kw">Right</span> <span class="dt">Ok</span></code></pre>
<p>The type signature of the <em>set</em> function is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t set
set
<span class="ot">  ::</span> <span class="dt">RedisCtx</span> m f <span class="ot">=&gt;</span>
     <span class="dt">Data.ByteString.Internal.ByteString</span>
     <span class="ot">-&gt;</span> <span class="dt">Data.ByteString.Internal.ByteString</span> <span class="ot">-&gt;</span> m (f <span class="dt">Status</span>)</code></pre>
<p>You can verify the value of the key `a’ from the <em>redis-cli</em> command, and it must return the value “apple”:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">127.0.0.1:<span class="kw">6379&gt;</span> get a
<span class="st">&quot;apple&quot;</span></code></pre>
<p>You can also retrieve the value of a key using the <em>get</em> function. For example:</p>
<pre><code>{-# LANGUAGE OverloadedStrings #-}
import Database.Redis
import Control.Monad.IO.Class

main :: IO ()
main = do
  conn &lt;- connect defaultConnectInfo
  runRedis conn $ do
         result &lt;- get &quot;a&quot;
         liftIO $ print result</code></pre>
<p>Executing the above code in GHCi gives the expected result:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>l get<span class="fu">.</span>hs
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( get<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main
<span class="kw">Right</span> (<span class="kw">Just</span> <span class="st">&quot;apple&quot;</span>)</code></pre>
<p>The <em>liftIO</em> function transforms an IO action into a <em>Monad</em>. Its type signature is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t liftIO
<span class="ot">liftIO ::</span> <span class="dt">MonadIO</span> m <span class="ot">=&gt;</span> <span class="dt">IO</span> a <span class="ot">-&gt;</span> m a</code></pre>
<p>The type signature of the <em>get</em> function is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t get
get
<span class="ot">  ::</span> <span class="dt">RedisCtx</span> m f <span class="ot">=&gt;</span>
     <span class="dt">Data.ByteString.Internal.ByteString</span>
     <span class="ot">-&gt;</span> m (f (<span class="dt">Maybe</span> <span class="dt">Data.ByteString.Internal.ByteString</span>))</code></pre>
<p>You are encouraged to read the Database.Redis documentation page that contains a comprehensive list of commands and their usage at <a href="https://hackage.haskell.org/package/hedis-0.6.5/docs/Database-Redis.html">https://hackage.haskell.org/package/hedis-0.6.5/docs/Database-Redis.html</a>.</p>
<ul>
<li>Accessing the PostgreSQL database</li>
</ul>
<p>We shall now explore accessing a PostgreSQL database using the <em>postgresql-simple</em> (0.4.10.0) package. You will need to install and configure PostgreSQL for your GNU/Linux distribution. Please follow your distribution documentation to do so. On Fedora, for example, you can install the database server using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> postgresql-server postgresql-contrib</code></pre>
<p>You can then start the database server using the following service command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> service postgresql start</code></pre>
<p>You can now install the <em>postgresql-simple</em> package using the cabal command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> postgresql-simple</code></pre>
<p>Let us first create a database and a schema using the Postgresql command-line utility <em>psql</em>:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ psql -U postgres
Password <span class="kw">for</span> user postgres: 
psql <span class="kw">(</span>9.3.5<span class="kw">)</span>
Type <span class="st">&quot;help&quot;</span> <span class="kw">for</span> help.

<span class="ot">postgres=</span># \l
                                  List of databases
   Name    <span class="kw">|</span>  Owner   <span class="kw">|</span> Encoding <span class="kw">|</span>   Collate   <span class="kw">|</span>    Ctype    <span class="kw">|</span>   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  <span class="kw">|</span> postgres <span class="kw">|</span> UTF8     <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> 
 template0 <span class="kw">|</span> postgres <span class="kw">|</span> UTF8     <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> =c/postgres          +
           <span class="kw">|</span>          <span class="kw">|</span>          <span class="kw">|</span>             <span class="kw">|</span>             <span class="kw">|</span> <span class="ot">postgres=</span>CTc/postgres
 template1 <span class="kw">|</span> postgres <span class="kw">|</span> UTF8     <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> en_US.UTF-8 <span class="kw">|</span> =c/postgres          +
           <span class="kw">|</span>          <span class="kw">|</span>          <span class="kw">|</span>             <span class="kw">|</span>             <span class="kw">|</span> <span class="ot">postgres=</span>CTc/postgres
<span class="kw">(</span>3 rows<span class="kw">)</span>

<span class="ot">postgres=</span># CREATE DATABASE test;
CREATE DATABASE

postgres-# \c <span class="kw">test</span>
You are now connected to database <span class="st">&quot;test&quot;</span> <span class="kw">as</span> user <span class="st">&quot;postgres&quot;</span>.

<span class="ot">test=</span># create schema social;
CREATE SCHEMA

<span class="ot">test=</span># \dn
 public <span class="kw">|</span> postgres
 social <span class="kw">|</span> postgres</code></pre>
<p>We can then create a users’ table with an id, first name and last name using the <em>postgresql-simple</em> package.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.PostgreSQL.Simple</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;postgres&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;postgres123&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }

  execute conn <span class="st">&quot;create table social.users (id INT, fname VARCHAR(80), lname VARCHAR(80))&quot;</span> ()

  close conn</code></pre>
<p>Loading the above code in GHCi creates the table <em>social.users</em> as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci create<span class="fu">.</span>hs 

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( create<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package text<span class="dv">-0</span><span class="fu">.</span><span class="fl">11.3</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package attoparsec<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.4</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package blaze<span class="fu">-</span>builder<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package dlist<span class="dv">-0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hashable<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.2</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mtl<span class="dv">-2</span><span class="fu">.</span><span class="fl">1.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package syb<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package pretty<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package template<span class="fu">-</span>haskell <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unordered<span class="fu">-</span>containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.3</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="kw">primitive</span><span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package vector<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package aeson<span class="dv">-0</span><span class="fu">.</span><span class="fl">6.2</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package random<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package scientific<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="kw">case</span><span class="fu">-</span>insensitive<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package blaze<span class="fu">-</span>textual<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.0</span><span class="fu">.</span><span class="dv">8</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package postgresql<span class="fu">-</span>libpq<span class="dv">-0</span><span class="fu">.</span><span class="fl">9.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package binary<span class="dv">-0</span><span class="fu">.</span><span class="fl">7.4</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package cereal<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.5</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package entropy<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.2</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package tagged<span class="dv">-0</span><span class="fu">.</span><span class="dv">6</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package crypto<span class="fu">-</span>api<span class="dv">-0</span><span class="fu">.</span><span class="dv">11</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package cryptohash<span class="dv">-0</span><span class="fu">.</span><span class="fl">9.0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package network<span class="fu">-</span>info<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package uuid<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.8</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package postgresql<span class="fu">-</span>simple<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.10</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span></code></pre>
<p>You can verify the created table from the psql prompt:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="ot">test=</span># \d social.users
 <span class="kw">id</span>     <span class="kw">|</span> integer               <span class="kw">|</span> 
 fname  <span class="kw">|</span> character varying<span class="kw">(</span>80<span class="kw">)</span> <span class="kw">|</span> 
 lname  <span class="kw">|</span> character varying<span class="kw">(</span>80<span class="kw">)</span> <span class="kw">|</span> </code></pre>
<p>You can also list the databases in the PostgreSQL server using the <em>query_</em> function as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.PostgreSQL.Simple</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;postgres&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;postgres123&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  databases <span class="ot">&lt;-</span> query_ conn <span class="st">&quot;SELECT datname FROM pg_database&quot;</span>
  <span class="fu">print</span> (<span class="ot">databases ::</span> [<span class="dt">Only</span> <span class="dt">String</span>])

  close conn</code></pre>
<p>Executing the above code in GHCi produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci <span class="fu">show.</span>hs 
<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( <span class="fu">show.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main
[<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;template1&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;template0&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;postgres&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;test&quot;</span>}]</code></pre>
<p>You can now insert a record into the databaes using the <em>execute</em> function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">execute conn <span class="st">&quot;insert into social.users (id, fname, lname) values (?, ?, ?)&quot;</span> [<span class="st">&quot;1&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Edwin&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Brady&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>]</code></pre>
<p>After executing the above code, you can verify the database entry from the <em>psql</em> prompt:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="ot">test=</span># select * from social.users;
 <span class="kw">id</span> <span class="kw">|</span> fname <span class="kw">|</span> lname 
----+-------+-------
  1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady
<span class="kw">(</span>1 row<span class="kw">)</span></code></pre>
<p>You can also do batch inserts using the <em>executeMany</em> function. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">executeMany conn <span class="st">&quot;insert into social.users (id, fname, lname) values (?, ?, ?)&quot;</span> [(<span class="st">&quot;2&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Simon&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Marlow&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>), (<span class="st">&quot;3&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Ulf&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Norell&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>)]</code></pre>
<p>After running the above code, you can check the newly added rows in the database from the <em>psql</em> command-line tool:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="ot">test=</span># select * from social.users;
 <span class="kw">id</span> <span class="kw">|</span> fname <span class="kw">|</span> lname  
----+-------+--------
  1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady
  2 <span class="kw">|</span> Simon <span class="kw">|</span> Marlow
  3 <span class="kw">|</span> Ulf   <span class="kw">|</span> Norell
<span class="kw">(</span>3 rows<span class="kw">)</span></code></pre>
<p>You can also change a record entry using the <em>UPDATE</em> statement as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">execute conn <span class="st">&quot;update social.users SET lname = 'Peyton Jones' where fname = 'Simon'&quot;</span> ()</code></pre>
<p>The corresponding entry is updated as seen from the <em>psql</em> prompt:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="ot">test=</span># select * from social.users;
 <span class="kw">id</span> <span class="kw">|</span> fname <span class="kw">|</span>    lname     
----+-------+--------------
  1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady
  3 <span class="kw">|</span> Ulf   <span class="kw">|</span> Norell
  2 <span class="kw">|</span> Simon <span class="kw">|</span> Peyton Jones
<span class="kw">(</span>3 rows<span class="kw">)</span></code></pre>
<p>It is recommended to catch exceptions when running database commands. Consider the following example, where the number of arguments passed does not match with the expected:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.PostgreSQL.Simple</span>
<span class="kw">import</span> <span class="dt">Control.Exception</span>
<span class="kw">import</span> <span class="dt">GHC.Int</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;postgres&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;postgres123&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  result <span class="ot">&lt;-</span> try (execute conn <span class="st">&quot;insert into social.users (id, fname, lname) values (?, ?, ?)&quot;</span> [<span class="st">&quot;4&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Laurel&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>])<span class="ot"> ::</span> <span class="dt">IO</span> (<span class="dt">Either</span> <span class="dt">SomeException</span> <span class="dt">Int64</span>)
  <span class="kw">case</span> result <span class="kw">of</span>
      <span class="kw">Left</span> ex  <span class="ot">-&gt;</span> <span class="fu">putStrLn</span> <span class="fu">$</span> <span class="st">&quot;Caught exception: &quot;</span> <span class="fu">++</span> <span class="fu">show</span> ex
      <span class="kw">Right</span> val <span class="ot">-&gt;</span> <span class="fu">putStrLn</span> <span class="fu">$</span> <span class="st">&quot;The answer was: &quot;</span> <span class="fu">++</span> <span class="fu">show</span> val
  close conn</code></pre>
<p>The error is observed when the <em>main</em> function is executed as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Caught</span> exception<span class="fu">:</span> <span class="dt">FormatError</span> {fmtMessage <span class="fu">=</span> <span class="st">&quot;3 '?' characters, but 2 parameters&quot;</span>, fmtQuery <span class="fu">=</span> <span class="st">&quot;insert into social.users (id, fname, lname) values (?, ?, ?)&quot;</span>, fmtParams <span class="fu">=</span> [<span class="st">&quot;4&quot;</span>,<span class="st">&quot;Laurel&quot;</span>]}</code></pre>
<p>You can also retrieve multiple records from the database and use the results using a <em>map</em> function. An example is illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.PostgreSQL.Simple</span>
<span class="kw">import</span> <span class="dt">Control.Monad</span>
<span class="kw">import</span> <span class="dt">Data.Text</span> <span class="kw">as</span> <span class="dt">Text</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;postgres&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;postgres123&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  users <span class="ot">&lt;-</span> query_ conn <span class="st">&quot;SELECT fname, lname FROM social.users&quot;</span>
  forM_ users <span class="fu">$</span> \(fname, lname) <span class="ot">-&gt;</span>
      <span class="fu">putStrLn</span> <span class="fu">$</span> Text.unpack fname <span class="fu">++</span> <span class="st">&quot; &quot;</span> <span class="fu">++</span> Text.unpack lname
  close conn</code></pre>
<p>The output after executing the above code in GHCi returns the actual data:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Edwin</span> <span class="dt">Brady</span>
<span class="dt">Ulf</span> <span class="dt">Norell</span>
<span class="dt">Simon</span> <span class="dt">Peyton</span> <span class="dt">Jones</span></code></pre>
<p>Please refer to the <em>Database.PostgreSQL.Simple</em> documentation for more examples and usage at <a href="https://hackage.haskell.org/package/postgresql-simple-0.4.10.0/docs/Database-PostgreSQL-Simple.html">https://hackage.haskell.org/package/postgresql-simple-0.4.10.0/docs/Database-PostgreSQL-Simple.html</a>.</p>]]></description>
    <pubDate>Fri, 11 Dec 2015 22:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/12/11/haskell-databases-2/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Databases</title>
    <link>http://www.shakthimaan.com/posts/2015/11/19/haskell-databases/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, March 2015 edition.]</em></p>
<p>In this ninth article on Haskell, I shall cover access to Sqlite, and MySQL databases using Haskell modules. A number of packages are available from the https://hackage.haskell.org/packages/#cat:Database website, but, I will illustrate a few of them with examples.</p>
<p>You first need to install the cabal-install tool on Fedora, for example, using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> cabal-install</code></pre>
<p>You can then install HDBC.Sqlite3 using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> HDBC-sqlite3</code></pre>
<p>This installs the latest 2.3.3.0 version from https://hackage.haskell.org/package/HDBC-sqlite3. You can also install the Sqlite3 package on Fedora for testing, as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> sqlite</code></pre>
<p>To initiate a connection to a database, you can test it out in the GHCi prompt using the <em>connectSqlite3</em> function, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">module</span> <span class="dt">Database.HDBC</span> <span class="dt">Database.HDBC.Sqlite3</span>

ghci<span class="fu">&gt;</span> conn <span class="ot">&lt;-</span> connectSqlite3 <span class="st">&quot;students.db&quot;</span>

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package text<span class="dv">-0</span><span class="fu">.</span><span class="fl">11.3</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>time<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package utf8<span class="fu">-</span>string<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.7</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mtl<span class="dv">-2</span><span class="fu">.</span><span class="fl">1.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package convertible<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">HDBC</span><span class="dv">-2</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">HDBC</span><span class="fu">-</span>sqlite3<span class="dv">-2</span><span class="fu">.</span><span class="fl">3.3</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span></code></pre>
<p>The signature of the connectSqlite3 function is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t connectSqlite3
<span class="ot">connectSqlite3 ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Connection</span></code></pre>
<p>The type of <em>conn</em> is a <em>Connection</em>.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t conn
<span class="ot">conn ::</span> <span class="dt">Connection</span></code></pre>
<p>If you already have an existing Sqlite3 database, you can give the full path to the database and connect to it, or else you can now create a table using the Sqlite <em>CREATE TABLE</em> syntax as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> run conn <span class="st">&quot;CREATE TABLE names (id INTEGER NOT NULL, fname VARCHAR(80), lname VARCHAR(80))&quot;</span> []
<span class="dv">0</span></code></pre>
<p>The type signature of <em>run</em> is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t run
run
<span class="ot">  ::</span> <span class="dt">IConnection</span> conn <span class="ot">=&gt;</span> conn <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> [<span class="dt">SqlValue</span>] <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Integer</span></code></pre>
<p>It takes three arguments as input and performs an IO computation that returns an integer indicating the status of the execution. The first argument to <em>run</em> is the connection, the second argument is the Sqlite command to be executed, and finally is the array of SqlValues that provide a mapping between Haskell values and SQL databases.</p>
<p>Both Haskell and SQL databases have types, and different databases may have different representations of the types. In order to provide a consistent mapping between the two, each HDBC driver implements the relation using SqlValue.</p>
<p>You can now insert a record into the database using the following command:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> run conn <span class="st">&quot;INSERT INTO names (id, fname, lname) VALUES(1, 'Edwin', 'Brady')&quot;</span> []
<span class="dv">1</span>

ghci<span class="fu">&gt;</span> commit conn</code></pre>
<p>The type signature of <em>commit</em> is given here:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t commit
<span class="ot">commit ::</span> <span class="dt">IConnection</span> conn <span class="ot">=&gt;</span> conn <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>It takes a connection and completes the pending IO actions. To read the result from Haskell you can use the <em>quickQuery</em> function from the GHCi prompt, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> quickQuery conn <span class="st">&quot;SELECT * from names&quot;</span> []
[[<span class="dt">SqlByteString</span> <span class="st">&quot;1&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Edwin&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Brady&quot;</span>]]</code></pre>
<p>The type signature of the <em>quickQuery</em> function is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">quickQuery
<span class="ot">  ::</span> <span class="dt">IConnection</span> conn <span class="ot">=&gt;</span>
     conn <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> [<span class="dt">SqlValue</span>] <span class="ot">-&gt;</span> <span class="dt">IO</span> [[<span class="dt">SqlValue</span>]]</code></pre>
<p>You can also verify the result of the above actions using the <em>sqlite3</em> executable in the command prompt as illustrated below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sqlite3 students.db 

SQLite version 3.8.4.3 2014-04-03 16:53:12
Enter <span class="st">&quot;.help&quot;</span> <span class="kw">for</span> usage hints.

sqlite<span class="kw">&gt;</span> .schema
CREATE TABLE names <span class="kw">(id</span> INTEGER NOT NULL, fname VARCHAR<span class="kw">(</span>80<span class="kw">)</span>, lname VARCHAR<span class="kw">(</span>80<span class="kw">))</span>;

sqlite<span class="kw">&gt;</span> <span class="kw">select</span> * from names;
1<span class="kw">|</span>Edwin<span class="kw">|</span>Brady</code></pre>
<p>You can also do batch processing for inserts by preparing the statements and executing them:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> batch <span class="ot">&lt;-</span> prepare conn <span class="st">&quot;INSERT INTO names VALUES (?, ?, ?)&quot;</span>

ghci<span class="fu">&gt;</span> execute batch [toSql (<span class="dv">2</span><span class="ot"> ::</span> <span class="dt">Int</span>), toSql <span class="st">&quot;Simon&quot;</span>, toSql <span class="st">&quot;Marlow&quot;</span>]
<span class="dv">1</span>

ghci<span class="fu">&gt;</span> execute batch [toSql (<span class="dv">3</span><span class="ot"> ::</span> <span class="dt">Int</span>), toSql <span class="st">&quot;Ulf&quot;</span>, toSql <span class="st">&quot;Norell&quot;</span>]
<span class="dv">1</span>

ghci<span class="fu">&gt;</span> commit conn</code></pre>
<p>The type signatures of the <em>prepare</em> and <em>execute</em> functions are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t prepare
<span class="ot">prepare ::</span> <span class="dt">IConnection</span> conn <span class="ot">=&gt;</span> conn <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Statement</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t execute
<span class="ot">execute ::</span> <span class="dt">Statement</span> <span class="ot">-&gt;</span> [<span class="dt">SqlValue</span>] <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Integer</span></code></pre>
<p>You can once again check the records in the database using the <em>quickQuery</em> function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> quickQuery' conn <span class="st">&quot;SELECT * from names&quot;</span> []

[[<span class="dt">SqlByteString</span> <span class="st">&quot;1&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Edwin&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Brady&quot;</span>],[<span class="dt">SqlByteString</span> <span class="st">&quot;2&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Simon&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Marlow&quot;</span>],[<span class="dt">SqlByteString</span> <span class="st">&quot;3&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Ulf&quot;</span>,<span class="dt">SqlByteString</span> <span class="st">&quot;Norell&quot;</span>]]</code></pre>
<p>You can also run an update query to the database. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> run conn <span class="st">&quot;UPDATE names set lname = 'Peyton Jones' WHERE fname = 'Simon'&quot;</span> []
<span class="dv">1</span>

ghci<span class="fu">&gt;</span> commit conn</code></pre>
<p>Verifying the output from the Sqlite3 command prompt, you get:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">sqlite<span class="kw">&gt;</span> <span class="kw">select</span> * from names;

1<span class="kw">|</span>Edwin<span class="kw">|</span>Brady
2<span class="kw">|</span>Simon<span class="kw">|</span>Peyton Jones
3<span class="kw">|</span>Ulf<span class="kw">|</span>Norell</code></pre>
<p>The HDBC driver provides many functions to retrieve information regarding the database and the drivers. A few examples are illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> hdbcDriverName conn
<span class="st">&quot;sqlite3&quot;</span>

ghci<span class="fu">&gt;</span> hdbcClientVer conn
<span class="st">&quot;3.8.4.3&quot;</span>

ghci<span class="fu">&gt;</span> dbTransactionSupport conn
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> getTables conn
[<span class="st">&quot;names&quot;</span>]

ghci<span class="fu">&gt;</span> describeTable conn <span class="st">&quot;names&quot;</span>

[(<span class="st">&quot;id&quot;</span>,<span class="dt">SqlColDesc</span> {colType <span class="fu">=</span> <span class="dt">SqlIntegerT</span>, colSize <span class="fu">=</span> <span class="kw">Nothing</span>, colOctetLength <span class="fu">=</span> <span class="kw">Nothing</span>, colDecDigits <span class="fu">=</span> <span class="kw">Nothing</span>, colNullable <span class="fu">=</span> <span class="kw">Nothing</span>}),(<span class="st">&quot;fname&quot;</span>,<span class="dt">SqlColDesc</span> {colType <span class="fu">=</span> <span class="dt">SqlUnknownT</span> <span class="st">&quot;varchar(80)&quot;</span>, colSize <span class="fu">=</span> <span class="kw">Nothing</span>, colOctetLength <span class="fu">=</span> <span class="kw">Nothing</span>, colDecDigits <span class="fu">=</span> <span class="kw">Nothing</span>, colNullable <span class="fu">=</span> <span class="kw">Nothing</span>}),(<span class="st">&quot;lname&quot;</span>,<span class="dt">SqlColDesc</span> {colType <span class="fu">=</span> <span class="dt">SqlUnknownT</span> <span class="st">&quot;varchar(80)&quot;</span>, colSize <span class="fu">=</span> <span class="kw">Nothing</span>, colOctetLength <span class="fu">=</span> <span class="kw">Nothing</span>, colDecDigits <span class="fu">=</span> <span class="kw">Nothing</span>, colNullable <span class="fu">=</span> <span class="kw">Nothing</span>})]</code></pre>
<p>It is considered good practice to use <em>handleSqlError</em> before running any HDBC commands to catch errors that may arise during the database transactions. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> handleSqlError <span class="fu">$</span> quickQuery conn <span class="st">&quot;SELECT * from namesaaa&quot;</span> []

<span class="fu">***</span> <span class="dt">Exception</span><span class="fu">:</span> user <span class="fu">error</span> (<span class="dt">SQL</span> <span class="fu">error:</span> <span class="dt">SqlError</span> {seState <span class="fu">=</span> <span class="st">&quot;&quot;</span>, seNativeError <span class="fu">=</span> <span class="dv">1</span>, seErrorMsg <span class="fu">=</span> <span class="st">&quot;prepare 23: SELECT * from namesaaa: no such table: namesaaa&quot;</span>})</code></pre>
<p>To disconnect from the database, you can use the <em>disconnect</em> function provided by HDBC as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> disconnect conn</code></pre>
<p>Let’s now look at how to access a MySQL database using the mysql-simple package. You will also need to create or grant privileges for an existing user to use the MySQL database server. Please follow your GNU/Linux distribution manual on how to install and configure a MySQL server. On Fedora, for example, you must have mysql and mysql-server installed:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> community-mysql community-mysql-server</code></pre>
<p>You can install the mysql-simple Haskell package using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal <span class="kw">install</span> mysql-simple</code></pre>
<p>Create a <em>test</em> database using the <em>mysql</em> command line tool as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ mysql -u user -p

Enter password: 
Welcome to the MySQL monitor<span class="kw">.</span>  Commands end with ; or \g.
Your MySQL connection <span class="kw">id</span> is 3
Server version: 5.5.38-log MySQL Community Server <span class="kw">(</span>GPL<span class="kw">)</span>

Copyright <span class="kw">(</span>c<span class="kw">)</span> 2000, 2014, Oracle and/or its affiliates<span class="kw">.</span> All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates<span class="kw">.</span> Other names may be trademarks of their respective
owners.

Type <span class="st">'help;'</span> or <span class="st">'\h'</span> <span class="kw">for</span> help<span class="kw">.</span> Type <span class="st">'\c'</span> to <span class="kw">clear</span> the current input statement.

mysql<span class="kw">&gt;</span> create database <span class="kw">test</span>;
Query OK, 1 row affected <span class="kw">(</span>0.03 sec<span class="kw">)</span></code></pre>
<p>Let us create a users’ table that has an id as well as first name and last name fields, using the mysql-simple package, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.MySQL.Simple</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;user&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;password&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }

  execute conn <span class="st">&quot;create table users (id INT, fname VARCHAR(80), lname VARCHAR(80))&quot;</span> ()

  close conn</code></pre>
<p>The OverloadedStrings extension allows string literals to be polymorphic for the IsString class. The defaultConnectInfo is of type ConnectInfo:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t defaultConnectInfo
<span class="ot">defaultConnectInfo ::</span> <span class="dt">ConnectInfo</span></code></pre>
<p>ConnectInfo can take many parameters to describe the connectivity to the MySQL server. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">connectInfo ::</span> <span class="dt">ConnectInfo</span>
connectInfo <span class="fu">=</span> <span class="dt">ConnectInfo</span> { connectHost <span class="fu">=</span> <span class="st">&quot;localhost&quot;</span>,
                            connectPort <span class="fu">=</span> <span class="dv">3306</span>,
                            connectUser <span class="fu">=</span> <span class="st">&quot;user&quot;</span>,
                        connectPassword <span class="fu">=</span> <span class="st">&quot;password&quot;</span>,
                        connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>,
                         connectOptions <span class="fu">=</span> [],
                            connectPath <span class="fu">=</span> <span class="st">&quot;&quot;</span>,
                             connectSSL <span class="fu">=</span> <span class="kw">Nothing</span> }</code></pre>
<p>The above code to create a table can be compiled directly in GHCi and the <em>main</em> function can be executed as given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci create<span class="fu">.</span>hs

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( create<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package text<span class="dv">-0</span><span class="fu">.</span><span class="fl">11.3</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package blaze<span class="fu">-</span>builder<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="kw">primitive</span><span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package vector<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package pcre<span class="fu">-</span>light<span class="dv">-0</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package attoparsec<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.4</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package blaze<span class="fu">-</span>textual<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.0</span><span class="fu">.</span><span class="dv">8</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base16<span class="fu">-</span>bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">6</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mysql<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">7</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package mysql<span class="fu">-</span>simple<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.2</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span></code></pre>
<p>You can check with the <em>mysql</em> command line utility for the created table:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">mysql<span class="kw">&gt;</span> use <span class="kw">test</span>;
Reading table information <span class="kw">for</span> completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql<span class="kw">&gt;</span> desc <span class="kw">users</span>;
+-------+-------------+------+-----+---------+-------+
<span class="kw">|</span> Field <span class="kw">|</span> Type        <span class="kw">|</span> Null <span class="kw">|</span> Key <span class="kw">|</span> Default <span class="kw">|</span> Extra <span class="kw">|</span>
+-------+-------------+------+-----+---------+-------+
<span class="kw">|</span> <span class="kw">id</span>    <span class="kw">|</span> int<span class="kw">(</span>11<span class="kw">)</span>     <span class="kw">|</span> YES  <span class="kw">|</span>     <span class="kw">|</span> NULL    <span class="kw">|</span>       <span class="kw">|</span>
<span class="kw">|</span> fname <span class="kw">|</span> varchar<span class="kw">(</span>80<span class="kw">)</span> <span class="kw">|</span> YES  <span class="kw">|</span>     <span class="kw">|</span> NULL    <span class="kw">|</span>       <span class="kw">|</span>
<span class="kw">|</span> lname <span class="kw">|</span> varchar<span class="kw">(</span>80<span class="kw">)</span> <span class="kw">|</span> YES  <span class="kw">|</span>     <span class="kw">|</span> NULL    <span class="kw">|</span>       <span class="kw">|</span>
+-------+-------------+------+-----+---------+-------+
3 rows <span class="kw">in</span> <span class="kw">set</span> <span class="kw">(</span>0.00 sec<span class="kw">)</span></code></pre>
<p>You can now list the databases available in the MySQL server using the <em>query_</em> function as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.MySQL.Simple</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;user&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;password&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  databases <span class="ot">&lt;-</span> query_ conn <span class="st">&quot;SHOW databases&quot;</span>
  <span class="fu">print</span> (<span class="ot">databases ::</span> [<span class="dt">Only</span> <span class="dt">String</span>])

  close conn</code></pre>
<p>You can compile the above code directly with GHCi and execute the <em>main</em> function, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"> <span class="fu">$</span> ghci <span class="fu">show-</span>databases<span class="fu">.</span>hs

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( <span class="fu">show-</span>databases<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="fu">...</span>
[<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;information_schema&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;mysql&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;performance_schema&quot;</span>},<span class="dt">Only</span> {fromOnly <span class="fu">=</span> <span class="st">&quot;test&quot;</span>}]</code></pre>
<p>You can try inserting a record into the database using the <em>execute</em> function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">execute conn <span class="st">&quot;insert into users (id, fname, lname) values (?, ?, ?)&quot;</span> [<span class="st">&quot;1&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Edwin&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Brady&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>]</code></pre>
<p>After running the code, you can check the database entry using the <em>mysql</em> client program as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">mysql<span class="kw">&gt;</span> <span class="kw">select</span> * from <span class="kw">users</span>;

+------+-------+-------+
<span class="kw">|</span> <span class="kw">id</span>   <span class="kw">|</span> fname <span class="kw">|</span> lname <span class="kw">|</span>
+------+-------+-------+
<span class="kw">|</span>    1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady <span class="kw">|</span>
+------+-------+-------+
1 row <span class="kw">in</span> <span class="kw">set</span> <span class="kw">(</span>0.00 sec<span class="kw">)</span></code></pre>
<p>You can also do batch inserts using the <em>executeMany</em> function. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">executeMany conn <span class="st">&quot;insert into users (id, fname, lname) values (?, ?, ?)&quot;</span> [(<span class="st">&quot;2&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Simon&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Marlow&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>), (<span class="st">&quot;3&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Ulf&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Norell&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>)]</code></pre>
<p>You can verify the execution of the code from the <em>mysql</em> utility:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">mysql<span class="kw">&gt;</span> <span class="kw">select</span> * from <span class="kw">users</span>;
+------+-------+--------+
<span class="kw">|</span> <span class="kw">id</span>   <span class="kw">|</span> fname <span class="kw">|</span> lname  <span class="kw">|</span>
+------+-------+--------+
<span class="kw">|</span>    1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady  <span class="kw">|</span>
<span class="kw">|</span>    2 <span class="kw">|</span> Simon <span class="kw">|</span> Marlow <span class="kw">|</span>
<span class="kw">|</span>    3 <span class="kw">|</span> Ulf   <span class="kw">|</span> Norell <span class="kw">|</span>
+------+-------+--------+
3 rows <span class="kw">in</span> <span class="kw">set</span> <span class="kw">(</span>0.01 sec<span class="kw">)</span></code></pre>
<p>You can change a record entry using the UPDATE MySQL command:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">execute conn <span class="st">&quot;update users SET lname = 'Peyton Jones' where fname = 'Simon'&quot;</span> ()</code></pre>
<p>Executing the code in GHCi, and checking the results with the <em>mysql</em> prompt gives the following changed output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">mysql<span class="kw">&gt;</span> <span class="kw">select</span> * from <span class="kw">users</span>;
+------+-------+--------------+
<span class="kw">|</span> <span class="kw">id</span>   <span class="kw">|</span> fname <span class="kw">|</span> lname        <span class="kw">|</span>
+------+-------+--------------+
<span class="kw">|</span>    1 <span class="kw">|</span> Edwin <span class="kw">|</span> Brady        <span class="kw">|</span>
<span class="kw">|</span>    2 <span class="kw">|</span> Simon <span class="kw">|</span> Peyton Jones <span class="kw">|</span>
<span class="kw">|</span>    3 <span class="kw">|</span> Ulf   <span class="kw">|</span> Norell       <span class="kw">|</span>
+------+-------+--------------+
3 rows <span class="kw">in</span> <span class="kw">set</span> <span class="kw">(</span>0.00 sec<span class="kw">)</span></code></pre>
<p>It is important to catch any exceptions that may arise on executing the database commands. Consider the following example, where the number of arguments passed does not match with the expected:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.MySQL.Simple</span>
<span class="kw">import</span> <span class="dt">Control.Exception</span>
<span class="kw">import</span> <span class="dt">GHC.Int</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;user&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;password&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  result <span class="ot">&lt;-</span> try (execute conn <span class="st">&quot;insert into users (id, fname, lname) values (?, ?, ?)&quot;</span> [<span class="st">&quot;4&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>, <span class="st">&quot;Laurel&quot;</span><span class="ot"> ::</span> <span class="dt">String</span>])<span class="ot"> ::</span> <span class="dt">IO</span> (<span class="dt">Either</span> <span class="dt">SomeException</span> <span class="dt">Int64</span>)
  <span class="kw">case</span> result <span class="kw">of</span>
      <span class="kw">Left</span> ex  <span class="ot">-&gt;</span> <span class="fu">putStrLn</span> <span class="fu">$</span> <span class="st">&quot;Caught exception: &quot;</span> <span class="fu">++</span> <span class="fu">show</span> ex
      <span class="kw">Right</span> val <span class="ot">-&gt;</span> <span class="fu">putStrLn</span> <span class="fu">$</span> <span class="st">&quot;The answer was: &quot;</span> <span class="fu">++</span> <span class="fu">show</span> val
  close conn</code></pre>
<p>The error is caught when the <em>main</em> function is executed inside GHCi:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Caught</span> exception<span class="fu">:</span> <span class="dt">FormatError</span> {fmtMessage <span class="fu">=</span> <span class="st">&quot;3 '?' characters, but 2 parameters&quot;</span>, fmtQuery <span class="fu">=</span> <span class="st">&quot;insert into users (id, fname, lname) values (?, ?, ?)&quot;</span>, fmtParams <span class="fu">=</span> [<span class="st">&quot;4&quot;</span>,<span class="st">&quot;Laurel&quot;</span>]}</code></pre>
<p>You can also map through the results returned from the database and use them for your needs. The following is an illustration of the same:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE OverloadedStrings #-}</span>

<span class="kw">import</span> <span class="dt">Database.MySQL.Simple</span>
<span class="kw">import</span> <span class="dt">Control.Monad</span>
<span class="kw">import</span> <span class="dt">Data.Text</span> <span class="kw">as</span> <span class="dt">Text</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  conn <span class="ot">&lt;-</span> connect defaultConnectInfo
    { connectUser <span class="fu">=</span> <span class="st">&quot;user&quot;</span>
    , connectPassword <span class="fu">=</span> <span class="st">&quot;password&quot;</span>
    , connectDatabase <span class="fu">=</span> <span class="st">&quot;test&quot;</span>
    }
  users <span class="ot">&lt;-</span> query_ conn <span class="st">&quot;SELECT fname, lname FROM users&quot;</span>
  forM_ users <span class="fu">$</span> \(fname, lname) <span class="ot">-&gt;</span>
      <span class="fu">putStrLn</span> <span class="fu">$</span> Text.unpack fname <span class="fu">++</span> <span class="st">&quot; &quot;</span> <span class="fu">++</span> Text.unpack lname
  close conn</code></pre>
<p>The resultant output when executing the <em>main</em> function in GHCi is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main

<span class="dt">Edwin</span> <span class="dt">Brady</span>
<span class="dt">Simon</span> <span class="dt">Peyton</span> <span class="dt">Jones</span>
<span class="dt">Ulf</span> <span class="dt">Norell</span></code></pre>
<p>You are encouraged to read Database.MySQL.Simple documentation from https://hackage.haskell.org/package/mysql-simple-0.2.2.4/docs/Database-MySQL-Simple.html for more information.</p>]]></description>
    <pubDate>Thu, 19 Nov 2015 22:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/11/19/haskell-databases/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Property-based testing and Cabal</title>
    <link>http://www.shakthimaan.com/posts/2015/11/05/property-based-testing-and-cabal/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, February 2015 edition.]</em></p>
<p>Let’s take a look at the property-based testing of Haskell programs and at the Cabal tool, which is used to build and manage Haskell packages and applications.</p>
<p>One of the main features of testing in Haskell is property-based testing. The type system allows you to infer and derive types, and also helps in auto-generating test cases. QuickCheck is a popular property-based testing library for Haskell. If your program is pure, you can write tests to ascertain the properties and invariants of your programs, and the tests can be auto-generated and executed.</p>
<p>You can install QuickCheck on Fedora, for example, by using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> ghc-QuickCheck-devel</code></pre>
<p>Consider a simple function to add two integers:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">mySum ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
mySum a b <span class="fu">=</span> a <span class="fu">+</span> b</code></pre>
<p>We can ascertain the property of the function that ‘a + b’ is the same as ‘b + a’ using the QuickCheck library. You must first define the invariant in a function as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">prop_mySum a b <span class="fu">=</span> mySum a b <span class="fu">==</span> mySum b a</code></pre>
<p>You can test the code directly in the GHCi prompt, using the following command:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci <span class="fu">sum.</span>hs 
<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( <span class="fu">sum.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> prop_mySum <span class="dv">2</span> <span class="dv">3</span>
<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package random<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package pretty<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package template<span class="fu">-</span>haskell <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">QuickCheck</span><span class="dv">-2</span><span class="fu">.</span><span class="dv">6</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="kw">True</span></code></pre>
<p>You can also invoke the <em>quickCheck</em> function in a main function, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.QuickCheck</span>

<span class="ot">mySum ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
mySum a b <span class="fu">=</span> a <span class="fu">+</span> b

<span class="ot">prop_mySum ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>
prop_mySum a b <span class="fu">=</span> mySum a b <span class="fu">==</span> mySum b a

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> quickCheck prop_mySum</code></pre>
<p>Compiling and executing the above code produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make sum.hs
[1 of 1] Compiling Main             <span class="kw">(</span> sum.hs, sum.o <span class="kw">)</span>
Linking <span class="kw">sum</span> ...

$ ./sum 
+++ OK, passed 100 tests.</code></pre>
<p>You can also dump the input that was generated for the various test cases using the <em>verboseCheck</em> function, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> verboseCheck prop_mySum</code></pre>
<p>Executing the above code with the updated main function will yield 100 input test cases that were generated in runtime.</p>
<pre class="sourceCode bash"><code class="sourceCode bash">ghci<span class="kw">&gt;</span> main
Passed:
0
0
Passed:
-1
1
Passed:
64
-44
Passed:
-2159
2134
Passed:
-927480859
61832343
...</code></pre>
<p>The <em>head</em> function in Haskell expects to receive a non-empty list. You can write a <em>headExists</em> function to check if the head exists for a list of integers, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
headExists list
    <span class="fu">|</span> <span class="fu">null</span> list    <span class="fu">=</span> <span class="kw">False</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">True</span></code></pre>
<p>You can load the above code in GHCi and test it out, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> headExists []
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> headExists [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="kw">True</span></code></pre>
<p>Let’s assume that, by mistake, you wrote an incorrect property-based test where the <em>headExists</em> function will always return ‘False’, ignoring the ‘otherwise’ case.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.QuickCheck</span>

<span class="ot">headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
headExists list
    <span class="fu">|</span> <span class="fu">null</span> list    <span class="fu">=</span> <span class="kw">False</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">True</span>

<span class="ot">prop_headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
prop_headExists emptyList <span class="fu">=</span> headExists emptyList <span class="fu">==</span> <span class="kw">False</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> quickCheck prop_headExists</code></pre>
<p>Testing the code produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make head.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> head.hs, head.o <span class="kw">)</span>
Linking <span class="kw">head</span> ...

$ ./head 
*** Failed! Falsifiable <span class="kw">(</span>after 3 tests<span class="kw">):</span>             
[0]</code></pre>
<p>The QuickCheck library generated test cases for different [Int] types and it returned a failure after the third test, for which the input was [0]. Clearly, the ‘headExists [0]’ computation will return ‘True’ and not ‘False’.</p>
<p>The way we defined the property is incorrect. We know that if the list is empty, then its length is zero. We can write a helper function <em>lengthZero</em> for the above, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">lengthZero ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
lengthZero list
    <span class="fu">|</span> <span class="fu">length</span> list <span class="fu">==</span> <span class="dv">0</span> <span class="fu">=</span> <span class="kw">True</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">False</span></code></pre>
<p>We can then use this function to assert that for any Integer list, if <em>headExists</em> returns ‘False’ then the <em>lengthZero</em> function must return ‘True’. The complete code is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.List</span>
<span class="kw">import</span> <span class="dt">Test.QuickCheck</span>

<span class="ot">headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
headExists list
    <span class="fu">|</span> <span class="fu">null</span> list    <span class="fu">=</span> <span class="kw">False</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">True</span>

<span class="ot">lengthZero ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
lengthZero list
    <span class="fu">|</span> <span class="fu">length</span> list <span class="fu">==</span> <span class="dv">0</span> <span class="fu">=</span> <span class="kw">True</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">False</span>

<span class="ot">prop_headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
prop_headExists list <span class="fu">=</span> headExists list <span class="fu">==</span> <span class="fu">not</span> (lengthZero list)

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> quickCheck prop_headExists</code></pre>
<p>Executing the code produces the required output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make head.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> head.hs, head.o <span class="kw">)</span>
Linking <span class="kw">head</span> ...

$ ./head 
+++ OK, passed 100 tests.</code></pre>
<p>We can also re-write the above code based on conditional properties. The property that the <em>headExists</em> function will return ‘True’ only for non-empty lists can be defined as a constraint. The notation syntax is <em>condition ==&gt; property</em>. In our example, if the condition that the list is non-empty is ‘True’, then the property that the <em>headExists</em> function for the list must return is ‘True’. Also, when the list is empty, the <em>headExists</em> function must return ‘False’. These two conditions can be written as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.List</span>
<span class="kw">import</span> <span class="dt">Test.QuickCheck</span>

<span class="ot">headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Bool</span>
headExists list
    <span class="fu">|</span> <span class="fu">null</span> list    <span class="fu">=</span> <span class="kw">False</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="kw">True</span>

<span class="ot">prop_headExists ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Property</span>
prop_headExists list <span class="fu">=</span> <span class="fu">length</span> list <span class="fu">&gt;</span> <span class="dv">0</span> <span class="fu">==&gt;</span> headExists list <span class="fu">==</span> <span class="kw">True</span>

<span class="ot">prop_emptyList ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Property</span>
prop_emptyList list <span class="fu">=</span> <span class="fu">length</span> list <span class="fu">==</span> <span class="dv">0</span> <span class="fu">==&gt;</span> headExists list <span class="fu">==</span> <span class="kw">False</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
     quickCheck prop_headExists
     quickCheck prop_emptyList</code></pre>
<p>Testing the code produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make cond.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> cond.hs, cond.o <span class="kw">)</span>
Linking cond ...

 $ ./cond 
+++ OK, passed 100 tests.
*** Gave up! Passed only 38 tests.</code></pre>
<p>These tests can be integrated with Hspec or HUnit for a more verbose output.</p>
<h1 id="cabal">Cabal</h1>
<p>Cabal is a software tool that is used to describe a Haskell application, list its dependencies, and provide a manifestation to distribute the source and binaries. It is not to be confused with a distribution package manager like RPM or the Debian package management system. You can install Cabal using your distribution package manager. On Fedora, for example, you can use the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> cabal-install</code></pre>
<p>Haskell software programs are available in <em>hackage.haskell.org</em>, and each project has a <em>.cabal</em> file. Let us take an example of the HSH-2.1.2 package at <em>http://hackage.haskell.org/package/HSH</em> which allows you to use shell commands and expressions within Haskell programs. You can download <em>HSH-2.1.2.tar.gz</em> and extract it using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">tar</span> xzvf HSH-2.1.2.tar.gz 

HSH-2.1.2/
HSH-2.1.2/COPYING
HSH-2.1.2/HSH.cabal
HSH-2.1.2/testsrc/
HSH-2.1.2/testsrc/runtests.hs
HSH-2.1.2/HSH.hs
HSH-2.1.2/HSH/
HSH-2.1.2/HSH/Command.hs
HSH-2.1.2/HSH/ShellEquivs.hs
HSH-2.1.2/HSH/Channel.hs
HSH-2.1.2/COPYRIGHT
HSH-2.1.2/Setup.lhs</code></pre>
<p>The <em>.cabal</em> file has various fields that describe the Haskell application. The contents of the <em>HSH.cabal</em> for version 2.1.2 are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Name</span><span class="fu">:</span> <span class="dt">HSH</span>
<span class="dt">Version</span><span class="fu">:</span> <span class="fl">2.1</span><span class="fu">.</span><span class="dv">3</span>
<span class="dt">License</span><span class="fu">:</span> <span class="dt">LGPL</span>
<span class="dt">Maintainer</span><span class="fu">:</span> <span class="dt">John</span> <span class="dt">Goerzen</span> <span class="fu">&lt;</span>jgoerzen<span class="fu">@</span>complete<span class="fu">.</span>org<span class="fu">&gt;</span>
<span class="dt">Author</span><span class="fu">:</span> <span class="dt">John</span> <span class="dt">Goerzen</span>
<span class="dt">Stability</span><span class="fu">:</span> <span class="dt">Beta</span>
<span class="dt">Copyright</span><span class="fu">:</span> <span class="dt">Copyright</span> (c) <span class="dv">2006-2014</span> <span class="dt">John</span> <span class="dt">Goerzen</span>
<span class="dt">Category</span><span class="fu">:</span> system
license<span class="fu">-</span>file<span class="fu">:</span> <span class="dt">COPYRIGHT</span>
extra<span class="fu">-</span>source<span class="fu">-</span>files<span class="fu">:</span> <span class="dt">COPYING</span>
homepage<span class="fu">:</span> http<span class="fu">://</span>software<span class="fu">.</span>complete<span class="fu">.</span>org<span class="fu">/</span>hsh
<span class="dt">Synopsis</span><span class="fu">:</span> <span class="dt">Library</span> to mix shell scripting with <span class="dt">Haskell</span> programs
<span class="dt">Description</span><span class="fu">:</span> <span class="dt">HSH</span> is designed to <span class="kw">let</span> you mix <span class="fu">and</span> match shell expressions with
 <span class="dt">Haskell</span> programs<span class="fu">.</span> <span class="dt">With</span> <span class="dt">HSH</span>, it is possible to easily run shell
 commands, capture their output <span class="fu">or</span> provide their input, <span class="fu">and</span> pipe them
 to <span class="fu">and</span> from other shell commands <span class="fu">and</span> arbitrary <span class="dt">Haskell</span> functions at will<span class="fu">.</span>
  <span class="dt">Category</span><span class="fu">:</span> <span class="dt">System</span>

<span class="dt">Cabal</span><span class="fu">-</span><span class="dt">Version</span><span class="fu">:</span> <span class="fu">&gt;=</span><span class="fl">1.2</span><span class="fu">.</span><span class="dv">3</span>
<span class="dt">Build</span><span class="fu">-</span><span class="kw">type</span><span class="fu">:</span> <span class="dt">Simple</span>

flag buildtests
  description<span class="fu">:</span> <span class="dt">Build</span> the executable to run unit tests
  default<span class="fu">:</span> <span class="kw">False</span>

library
  <span class="dt">Exposed</span><span class="fu">-</span><span class="dt">Modules</span><span class="fu">:</span> <span class="dt">HSH</span>, <span class="dt">HSH.Command</span>, <span class="dt">HSH.ShellEquivs</span>, <span class="dt">HSH.Channel</span>
  <span class="dt">Extensions</span><span class="fu">:</span> <span class="dt">ExistentialQuantification</span>, <span class="dt">OverlappingInstances</span>,
    <span class="dt">UndecidableInstances</span>, <span class="dt">FlexibleContexts</span>, <span class="dt">CPP</span>
  <span class="dt">Build</span><span class="fu">-</span><span class="dt">Depends</span><span class="fu">:</span> base <span class="fu">&gt;=</span> <span class="dv">4</span> <span class="fu">&amp;&amp;</span> <span class="fu">&lt;</span> <span class="dv">5</span>, mtl, process, regex<span class="fu">-</span>compat, <span class="dt">MissingH</span><span class="fu">&gt;=</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">0</span>,
    hslogger, filepath, regex<span class="fu">-</span>base, regex<span class="fu">-</span>posix, directory,
    bytestring
  <span class="kw">if</span> <span class="fu">!</span>os(windows)
    <span class="dt">Build</span><span class="fu">-</span><span class="dt">Depends</span><span class="fu">:</span> unix
  <span class="dt">GHC</span><span class="fu">-</span><span class="dt">Options</span><span class="fu">:</span> <span class="fu">-</span><span class="dt">O2</span> <span class="fu">-</span>threaded <span class="fu">-</span><span class="dt">Wall</span>

<span class="dt">Executable</span> runtests
  <span class="kw">if</span> flag(buildtests)
    <span class="dt">Buildable</span><span class="fu">:</span> <span class="kw">True</span>
    <span class="dt">Build</span><span class="fu">-</span><span class="dt">Depends</span><span class="fu">:</span> base <span class="fu">&gt;=</span> <span class="dv">4</span> <span class="fu">&amp;&amp;</span> <span class="fu">&lt;</span> <span class="dv">5</span>, mtl, process, regex<span class="fu">-</span>compat,
      <span class="dt">MissingH</span><span class="fu">&gt;=</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">0</span>,
      hslogger, filepath, regex<span class="fu">-</span>base, regex<span class="fu">-</span>posix, directory,
      bytestring, <span class="dt">HUnit</span>, testpack
    <span class="kw">if</span> <span class="fu">!</span>os(windows)
      <span class="dt">Build</span><span class="fu">-</span><span class="dt">Depends</span><span class="fu">:</span> unix
  <span class="kw">else</span>
    <span class="dt">Buildable</span><span class="fu">:</span> <span class="kw">False</span>
  <span class="dt">Main</span><span class="fu">-</span><span class="dt">Is</span><span class="fu">:</span> runtests<span class="fu">.</span>hs
  <span class="dt">HS</span><span class="fu">-</span><span class="dt">Source</span><span class="fu">-</span><span class="dt">Dirs</span><span class="fu">:</span> testsrc, <span class="fu">.</span>
  <span class="dt">Extensions</span><span class="fu">:</span> <span class="dt">ExistentialQuantification</span>, <span class="dt">OverlappingInstances</span>,
    <span class="dt">UndecidableInstances</span>, <span class="dt">FlexibleContexts</span>, <span class="dt">CPP</span>
  <span class="dt">GHC</span><span class="fu">-</span><span class="dt">Options</span><span class="fu">:</span> <span class="fu">-</span><span class="dt">O2</span> <span class="fu">-</span>threaded</code></pre>
<p>Enter the <em>HSH-2.1.2</em> directory and configure the project using the <em>cabal configure</em> command as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">cd</span> HSH-2.1.2

$ cabal configure
Resolving dependencies...
Configuring HSH-2.1.2...</code></pre>
<p>You can then compile the project sources using the <em>cabal build</em> step:</p>
<pre class="shell"><code>$ cabal build

Building HSH-2.1.2...
Preprocessing library HSH-2.1.2...
[1 of 4] Compiling HSH.Channel      ( HSH/Channel.hs, dist/build/HSH/Channel.o )
...
[2 of 4] Compiling HSH.Command      ( HSH/Command.hs, dist/build/HSH/Command.o )
...
[3 of 4] Compiling HSH.ShellEquivs  ( HSH/ShellEquivs.hs, dist/build/HSH/ShellEquivs.o )
...
[4 of 4] Compiling HSH              ( HSH.hs, dist/build/HSH.o )
In-place registering HSH-2.1.2...</code></pre>
<p>You can install the built library files using the <em>cabal install</em> command. By default, it installs to <em>~/.cabal</em> folder as shown below:</p>
<pre class="shell"><code>$ cabal install

Resolving dependencies...
Configuring HSH-2.1.2...
Building HSH-2.1.2...
Preprocessing library HSH-2.1.2...
In-place registering HSH-2.1.2...
Installing library in /home/guest/.cabal/lib/HSH-2.1.2/ghc-7.6.3
Registering HSH-2.1.2...
Installed HSH-2.1.2</code></pre>
<p>You can also generate HTML documentation for the source code using the <em>cabal haddock</em> option. The HTML files can also be made available at <em>hackage.haskell.org</em>.</p>
<pre class="shell"><code>$ cabal haddock

Running Haddock for HSH-2.1.2...
Preprocessing library HSH-2.1.2...
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: MissingH-1.3.0.1, rts-1.0,
hslogger-1.2.6, network-2.6.0.2
Haddock coverage:
...
Documentation created: dist/doc/html/HSH/index.html</code></pre>
<p>If you make changes to the sources and wish to generate a new release, you can update the <em>Version</em> field in the <em>HSH.cabal</em> file.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Version</span><span class="fu">:</span> <span class="fl">2.1</span><span class="fu">.</span><span class="dv">3</span></code></pre>
<p>In order to make a new tarball, use the <em>cabal sdist</em> command:</p>
<pre class="shell"><code>$ cabal sdist

Distribution quality warnings:
...
Building source dist for HSH-2.1.3...
Preprocessing library HSH-2.1.3...
Source tarball created: dist/HSH-2.1.3.tar.gz</code></pre>
<p>To test the installed application, you can run GHCi from a directory other than the HSH-2.1.2 sources directory. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci
<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">HSH</span>

ghci <span class="dt">HSH</span><span class="fu">&gt;</span> runIO <span class="st">&quot;date&quot;</span>
<span class="dt">Sun</span> <span class="dt">Jan</span>  <span class="dv">4</span> <span class="dv">14</span><span class="fu">:</span><span class="dv">22</span><span class="fu">:</span><span class="dv">37</span> <span class="dt">IST</span> <span class="dv">2015</span></code></pre>
<p>You should not run GHCi from the sources directory, since it will find the module in it and try to use it instead of the installed modules in <em>~/.cabal</em> folder.</p>
<p>You can also test the installation by writing a program:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">HSH.Command</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> <span class="kw">do</span>
  runIO <span class="st">&quot;date&quot;</span></code></pre>
<p>You can compile and execute the above as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make test.hs 
[1 of 1] Compiling Main             <span class="kw">(</span> test.hs, test.o <span class="kw">)</span>
Linking <span class="kw">test</span> ...

$ ./test 
Sun Jan  4 14:25:19 IST 2015</code></pre>
<p>You are encouraged to read the Cabal guide at <em>https://www.haskell.org/cabal/</em> for information on specific fields and their options.</p>]]></description>
    <pubDate>Thu, 05 Nov 2015 22:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/11/05/property-based-testing-and-cabal/news.html</guid>
</item>
<item>
    <title>PyCon India 2015, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2015/10/21/pycon-india-2015/news.html</link>
    <description><![CDATA[<p>I attended <a href="https://in.pycon.org/2015/">PyCon India 2015</a> at NIMHANS Convention Centre, Bengaluru, India between October 2-4, 2015.</p>
<img alt="PyCon India 2015 stage" src="http://shakthimaan.com/images/pycon-india-2015/pycon-india-2015.JPG"></img>
<p>Day 1</p>
<p>I took an early train from Chennai to reach Bengaluru, and headed straight to the venue. The workshops were scheduled on the first day. After completing the registration formalities, I went to observe the DevSprint. I met a number of <a href="http://dgplug.org/">dgplug</a> folks with whom I have been interacting online on #dgplug (irc.freenode.net).</p>
<p>After lunch, I attended <a href="https://github.com/ronojoy">Prof. Ronojoy Adhikari’s</a> workshop on <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/reasoning-under-uncertainty-with-python/">“Reasoning under uncertainity with Python”</a>. <a href="http://doraithodla.com/">Dorai Thodla</a> began the workshop with an introduction on “Data Science” and its use and applications in the industry. Prof. Ronojoy then spoke on <a href="https://speakerdeck.com/ronojoy/data-science-theory">“Data Science: Theory”</a> and <a href="https://speakerdeck.com/ronojoy/data-science-probability-theory">“Probability Theory for Data Science”</a>. We already use Boolean logic in our programming. We also have probability concepts implemented in Python. He then proceeded to demonstrate <a href="https://speakerdeck.com/ronojoy/probabilistic-programming-in-python">“Probabilistic Programming in Python”</a> using <a href="https://pypi.python.org/pypi/lea">Lea</a>. He had presented a short preview of this talk at the <a href="http://chennaipy.org/">Chennaipy</a> August 2015 meet-up. Prof. Ronojoy showed very interesting Lea one-liners with IPython Notebook. A sample is provided below:</p>
<pre class="sourceCode python"><code class="sourceCode python">In [<span class="dv">1</span>]: <span class="ch">from</span> lea <span class="ch">import</span> *

In [<span class="dv">2</span>]: faircoin = Lea.fromVals(<span class="st">'Head'</span>, <span class="st">'Tail'</span>)

In [<span class="dv">3</span>]: faircoin.random(<span class="dv">10</span>)

Out[<span class="dv">3</span>]: (<span class="st">'Tail'</span>,
         <span class="st">'Tail'</span>,
         <span class="st">'Tail'</span>,
         <span class="st">'Head'</span>,
         <span class="st">'Head'</span>,
         <span class="st">'Tail'</span>,
         <span class="st">'Tail'</span>,
         <span class="st">'Head'</span>,
         <span class="st">'Tail'</span>,
         <span class="st">'Head'</span>)

In [<span class="dv">4</span>]: die = Lea.fromVals(<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>, <span class="dv">6</span>)

In [<span class="dv">5</span>]: die1 = die.clone()
        die2 = die.clone()

In [<span class="dv">6</span>]: dice = die1 + die2

In [<span class="dv">7</span>]: dice

OUt[<span class="dv">10</span>]: <span class="dv">2</span> : <span class="dv">1</span>/<span class="dv">36</span>
         <span class="dv">3</span> : <span class="dv">2</span>/<span class="dv">36</span>
         <span class="dv">4</span> : <span class="dv">3</span>/<span class="dv">36</span>
         <span class="dv">5</span> : <span class="dv">4</span>/<span class="dv">36</span>
         <span class="dv">6</span> : <span class="dv">5</span>/<span class="dv">36</span>
         <span class="dv">7</span> : <span class="dv">6</span>/<span class="dv">36</span>
         <span class="dv">8</span> : <span class="dv">5</span>/<span class="dv">36</span>
         <span class="dv">9</span> : <span class="dv">4</span>/<span class="dv">36</span>
        <span class="dv">10</span> : <span class="dv">3</span>/<span class="dv">36</span>
        <span class="dv">11</span> : <span class="dv">2</span>/<span class="dv">36</span>
        <span class="dv">12</span> : <span class="dv">1</span>/<span class="dv">36</span></code></pre>
<p>I had installed the <a href="https://www.continuum.io/downloads">Anaconda distribution</a> and Lea for the workshop, but, couldn’t get <a href="https://github.com/jmschrei/pomegranate">Pomegranate</a> to compile. Later, I <a href="https://github.com/jmschrei/pomegranate/issues/35">worked</a> with <a href="http://homes.cs.washington.edu/~jmschr/">Jacob Schreiber</a> to get it built on Ubuntu 14.10.</p>
<p>Prof. Ronojoy then explained Bayesian networks, and how the probabilities can be fed to compute the probability for a causal-effect relationship. He demonstrated <a href="https://github.com/ValueFromData/reasoning-under-uncertainty">numerous examples</a> with live coding. His work is part of the <a href="http://valuefromdata.net/">Value from Data</a> initiative. Prof. Ronojoy and Dorai’s <a href="https://www.youtube.com/playlist?list=PLhkiT_RYTEU1mkJHBUiA2Ze56h6z1uZgj">“Bayesian Inference and Data Analytics” video lectures</a> are available in YouTube.</p>
<p>Day 2</p>
<p>After collecting my speaker kit, I attended the “KG award” presentation, which was given to <a href="http://bravegnu.org/">Vijay Kumar</a>, followed by the key note by <a href="https://expeyes.wordpress.com/people/">Dr. Ajit Kumar</a>. Vijay Kumar is doing an excellent job in organizing the monthly Chennaipy meet-ups. It was also good to meet Dr. Ajit Kumar after many years, having known his work and involvement with the Phoenix project.</p>
<p>During the tea break, I took the time to test my laptop with the projector in auditorium-1, where I was scheduled to speak. I had few demos in my talk, and I needed to set everything up before the talk. After the tea break, I attended the session by <a href="https://github.com/pratapvardhan/">Pratap Vardhan</a> on <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/consuming-government-data-with-python-and-d3/">“Consuming Government Data with Python and D3”</a>. The insights from the data and the analysis by Gramener were quite interesting.</p>
<p>I then moved to the “dgplug” 1130 IST staircase meeting, where I met more #dgplug students, and was able to connect IRC nicknames to people’s faces. My suggestion to the students was to start to identify their interests, and to specialize on them. Around noon, I moved back to auditorium-1 to setup everything that I needed for my talk - <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/pretty-printing-in-python/">“Pretty Printing in Python”</a>. There is one slot which I never wanted - the one before lunch because I know that I will be the one standing between the audience and their lunch, and that is exactly what I got. Nevertheless, the slot had to be taken by someone, and I was prepared for it. I had requested the organizers for a whiteboard and markers for my talk, and they had arranged for the same. I had lot of material to cover in 45 minutes. I did rush through, but, paused at times to explain the concepts. The audience were quite interested in 3D printing, and they asked some really interesting questions at the end of the talk. The video is available in YouTube:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/9OxWgyjlDmQ?list=PL6GW05BfqWIe6rMoFFWmllPegB2gU069m" frameborder="0" allowfullscreen></iframe>

<p>After a quick lunch, I headed for the lightning talks to present <a href="https://github.com/shakthimaan/nursery-rhymes">“Nursery Rhymes”</a>. We are all familiar with nursery rhymes, and the idea is to teach programming languages and software development using them. The audience needed something to wake them after a heavy lunch, and they thoroughly enjoyed the singing! The video link is provided below:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/KZUv5wCq6xE?list=PL6GW05BfqWIe6rMoFFWmllPegB2gU069m" frameborder="0" allowfullscreen></iframe>

<p>I then attended the <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/building-a-large-scale-production-ready-prediction-system-using-python/">“Machine learning techniques for building a large scale production ready prediction system using Python”</a> by Arthi Venkataraman. After a short tea break, I attended the talk by Pooja Salpekar on <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/test-driven-development-with-ansible/">“Test Driven Development with Ansible”</a>. She gave an overview of using <a href="http://serverspec.org/">Serverspec</a>. The subject to test is still determined by the developer, and testing with Vagrant is not the same as testing in production deployments. For the last session of the day, I attended the <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/python-and-riak-db-a-perfect-couple-for-huge-scale-distributed-computing/">“Python and Riak DB, a perfect couple for huge scale distributed computing”</a> by Naren Arya, but, it was yet another generic talk.</p>
<p>In the evening, I participated in the discussion on building and running communities organized by <a href="http://satyaakam.net/">Satyaakam Goswami</a> on how Python communities are organizing themselves in India, and the challenges faced by them. I shared my experience with the Chennaipy meet-ups, and insights from my “i want 2 do project. tell me wat 2 do” <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">presentation</a> and <a href="http://shakthimaan.com/what-to-do.html">book</a>. A video recording of the discussion is available:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/IWHH6c3wZVQ?list=PL6GW05BfqWIe6rMoFFWmllPegB2gU069m" frameborder="0" allowfullscreen></iframe>

<p>Day 3</p>
<p><a href="http://ntoll.org/">Nicholas H. Tollervey</a> began the day’s proceedings with his keynote. He shared his experience on Python and education. The <a href="https://micropython.org">Micro Python</a> and <a href="https://www.microbit.co.uk/">BBC micro:bit</a> projects are interesting initiatives. The audience did have questions on why they cannot use Android or any other mobile phone for Python development. But, I think they missed the point that Open Hardware initiatives are important and the openness is not the same with present day mobile devices. Nicholas also covered important points on how to organize Python Dojo meet-ups, and as a teacher, the experiences he shared were very useful.</p>
<p>After the tea break, I attended the session by <a href="https://www.cse.iitb.ac.in/~sumith/">Sumith Kulal</a> on <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/symengine-the-future-fast-core-of-computer-algebra-systems/">“SymEngine: The future fast core of computer algebra systems”</a>. It was an introductory session on SymEngine, and he shared the roadmap and plan that they have for the software. I was then networking with people before attending <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/design-distributed-web-applications-using-zeromq/">“How to build microservices using ZeroMQ and WSGI”</a> by Srinath G. S. It was yet another generic talk, and I headed for early lunch.</p>
<p>The previous night I prepared for another lightning talk titled “Yet Another Lightning Talk”, to once again, wake the audience after their heavy lunch. The talk went as I had planned, and the audience loved it! The video recording is available in YouTube:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/QmScfOsdxqg?list=PL6GW05BfqWIe6rMoFFWmllPegB2gU069m" frameborder="0" allowfullscreen></iframe>

<p>A number of people approached me after the lightning talk, appreciating the creativity, and I did make a lot of new friends. The last talk of the day that I attended was on <a href="https://in.pycon.org/cfp/pycon-india-2015/proposals/python-load-balancer-0-to-1-million-requests-per-second/">“Python load balancer; 0 to 1 million requests per second”</a>, and yet again it turned out to be a a very generic talk, without going into specifics. I left early to catch a flight.</p>
<p>It will be helpful if organizers can identify talks where the speaker has contributed to the project. When you hire people for free and open source software (F/OSS) work, you would like to see what their contribution to the project is, and how they have added value to the project. I am interested to hear on what the speaker has done. I can always read the project web site, and find out more information about the project. I wish all conferences add this criteria in their talk selection process.</p>
<p>The workshops have been useful. The content of the talks need to be improved though. I was able to meet fellow F/OSS developers during the conference, and also made new friends. I am pleased that I was able to deliver a talk, and two lightning talks.</p>
<p>I would like to thank <a href="http://www.systeminsights.com/">Manufacturing System Insights</a> for sponsoring my travel, and allowing me to 3D print during office hours!</p>]]></description>
    <pubDate>Wed, 21 Oct 2015 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/10/21/pycon-india-2015/news.html</guid>
</item>
<item>
    <title>Paho Python client for MQTT and G-code Visualization Talks, Chennaipy</title>
    <link>http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/news.html</link>
    <description><![CDATA[<p>I had given a couple of talks at the <a href="http://chennaipy.org/">Chennaipy</a> meetups at the <a href="https://www.imsc.res.in/">Institute of Mathematical Sciences</a>, Chennai leading up to my talk at <a href="https://in.pycon.org/2015/">PyCon India 2015</a>.</p>
<h1 id="august-2015-meetup">August 2015 meetup</h1>
<p>The first talk was titled “Paho Python client for MQTT” presented on Saturday, August 22, 2015. The slides and notes for the presentation are given below:</p>
<h2 id="mqtt-architecture">MQTT Architecture</h2>
<img alt="pub-sub-model.png" src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/pub-sub-model.png"></img>
<p><a href="http://www.embedded.com/electronics-blogs/embedded-cloud-talkers/4397229/Device-to-Cloud--">Source: Device to Cloud: MQTT and the power of topic notation</a></p>
<h2 id="topics">Topics</h2>
<pre class="shell"><code>$SYS/broker/load/connections
$SYS/broker/load/messages/received
$SYS/broker/load/messages/sent

home/living-room/temperature
home/kitchen/humidity
home/store-room/brightness</code></pre>
<h2 id="mqtt-protocol">MQTT Protocol</h2>
<img alt="connect-flow.png" src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/connect-flow.png"></img>
<p><a href="http://www.hivemq.com/mqtt-essentials-part-3-client-broker-connection-establishment/">Source: MQTT Essentials Part 3: Client, Broker and Connection Establishment</a></p>
<img alt="subscribe_flow.png" src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/subscribe_flow.png"></img>
<p><a href="http://www.hivemq.com/mqtt-essentials-part-4-mqtt-publish-subscribe-unsubscribe/">Source: MQTT Essentials Part 4: MQTT Publish, Subscribe &amp; Unsubscribe</a></p>
<h2 id="mosquitto-mqtt-installation">Mosquitto MQTT Installation</h2>
<pre class="shell"><code>$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

  You are about to add the following PPA to your system:
 
  More info: https://launchpad.net/~mosquitto-dev/+archive/ubuntu/mosquitto-ppa
  Press [ENTER] to continue or ctrl-c to cancel adding it

  gpg: keyring `/tmp/tmpd67wf6/secring.gpg' created
  gpg: keyring `/tmp/tmpd67wf6/pubring.gpg' created
  gpg: requesting key 262C4500 from hkp server keyserver.ubuntu.com
  gpg: /tmp/tmpd67wf6/trustdb.gpg: trustdb created
  gpg: key 262C4500: public key &quot;Launchpad mosquitto&quot; imported
  gpg: Total number processed: 1
  gpg:               imported: 1  (RSA: 1)
  OK

$ apt-get update
$ apt-get install python-pip mosquitto mosquitto-clients
$ pip install paho-mqtt</code></pre>
<h2 id="connectivity">Connectivity</h2>
<h3 id="start-mosquitto-server">Start mosquitto server</h3>
<pre class="shell"><code>$ sudo /etc/init.d/mosquitto status
mosquitto stop/waiting

$ sudo /etc/init.d/mosquitto start
mosquitto start/running, process 11346</code></pre>
<h3 id="verification">Verification</h3>
<pre class="shell"><code>$ netstat -na | grep :1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN     
tcp6       0      0 :::1883                 :::*                    LISTEN 

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.10
Release:	14.10
Codename:	utopic</code></pre>
<h2 id="pubsub">Pub/Sub</h2>
<h3 id="subscribe">Subscribe</h3>
<pre class="shell"><code>$ mosquitto_sub -d -t hello/world

Client mosqsub/11678-achilles sending CONNECT
Client mosqsub/11678-achilles received CONNACK
Client mosqsub/11678-achilles sending SUBSCRIBE (Mid: 1, Topic: hello/world, QoS: 0)
Client mosqsub/11678-achilles received SUBACK
Subscribed (mid: 1): 0</code></pre>
<h3 id="publish">Publish</h3>
<pre class="shell"><code>$ mosquitto_pub -d -t hello/world -m &quot;Vanakkam&quot;
Client mosqpub/11712-achilles sending CONNECT
Client mosqpub/11712-achilles received CONNACK
Client mosqpub/11712-achilles sending PUBLISH (d0, q0, r0, m1, 'hello/world', \
  ... (8 bytes))
Client mosqpub/11712-achilles sending DISCONNECT</code></pre>
<h3 id="verification-1">Verification</h3>
<pre class="shell"><code>Client mosqsub/11678-achilles received PUBLISH (d0, q0, r0, m0, 'hello/world', \
  ... (8 bytes))
Vanakkam</code></pre>
<h2 id="paho-python-connectivity">Paho Python connectivity</h2>
<pre class="sourceCode python"><code class="sourceCode python">  <span class="ch">import</span> paho.mqtt.client <span class="ch">as</span> mqtt

  <span class="kw">def</span> on_connect(client, userdata, flags, rc):
      <span class="kw">print</span>(<span class="st">&quot;Connected with result code &quot;</span>+<span class="dt">str</span>(rc))
      client.subscribe(<span class="st">&quot;hello/world&quot;</span>)

  <span class="kw">def</span> on_message(client, userdata, msg):
      <span class="kw">print</span>(msg.topic+<span class="st">&quot; &quot;</span>+<span class="dt">str</span>(msg.payload))

  client = mqtt.Client()
  client.on_connect = on_connect
  client.on_message = on_message

  client.<span class="ot">connect</span>(<span class="st">&quot;localhost&quot;</span>, <span class="dv">1883</span>, <span class="dv">60</span>)

  client.loop_forever()</code></pre>
<pre class="shell"><code>$ python client.py</code></pre>
<pre class="shell"><code>$ mosquitto_pub -d -t hello/world -m &quot;Hello, World&quot;</code></pre>
<h2 id="iot.eclipse.org">iot.eclipse.org</h2>
<pre class="sourceCode python"><code class="sourceCode python">  <span class="ch">import</span> paho.mqtt.client <span class="ch">as</span> mqtt

  <span class="kw">def</span> on_connect(client, userdata, flags, rc):
      <span class="kw">print</span>(<span class="st">&quot;Connected with result code &quot;</span>+<span class="dt">str</span>(rc))
      client.subscribe(<span class="st">&quot;$SYS/#&quot;</span>)

  <span class="kw">def</span> on_message(client, userdata, msg):
      <span class="kw">print</span>(msg.topic+<span class="st">&quot; &quot;</span>+<span class="dt">str</span>(msg.payload))

  client = mqtt.Client()
  client.on_connect = on_connect
  client.on_message = on_message

  client.<span class="ot">connect</span>(<span class="st">&quot;iot.eclipse.org&quot;</span>, <span class="dv">1883</span>, <span class="dv">60</span>)

  client.loop_forever()</code></pre>
<h2 id="source-code">Source Code</h2>
<pre class="shell"><code>  paho-mqtt-1.1:
  -rw-rw-r-- 1 shakthi shakthi  2031 Feb  1  2015 about.html
  -rw-rw-r-- 1 shakthi shakthi  3736 Feb  1  2015 CONTRIBUTING.md
  -rw-rw-r-- 1 shakthi shakthi  1569 Feb  1  2015 edl-v10
  -rw-rw-r-- 1 shakthi shakthi 11695 Feb  1  2015 epl-v10
  drwxrwxr-x 2 shakthi shakthi  4096 Feb  1  2015 examples
  -rw-rw-r-- 1 shakthi shakthi   156 Feb  1  2015 LICENSE.txt
  -rw-rw-r-- 1 shakthi shakthi  9230 Feb  1  2015 notice.html
  -rw-rw-r-- 1 shakthi shakthi   814 Feb  1  2015 PKG-INFO
  -rw-rw-r-- 1 shakthi shakthi 30871 Feb  1  2015 README.rst
  -rw-rw-r-- 1 shakthi shakthi   972 Feb  1  2015 setup.py
  drwxrwxr-x 3 shakthi shakthi  4096 Feb  1  2015 src</code></pre>
<h2 id="embedded">Embedded</h2>
<img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/raspberry-small.jpg" alt="raspberry-small.jpg"></img><img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/3g.png" alt="3g.png"></img><img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/rfid.png" alt="rfid.png"></img>
<img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/arduino.jpg" alt="arduino.jpg"></img><img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/radiation.png" alt="radiation.png"></img><img src="https://raw.githubusercontent.com/shakthimaan/paho-python-client-for-mqtt/master/bluetooth.png" alt="bluetooth.png"></img>
<p><a href="https://www.cooking-hacks.com/documentation/tutorials/raspberry-pi-to-arduino-shields-connection-bridge">Source: Raspberry Pi to Arduino</a></p>
<h2 id="references">References</h2>
<ul>
<li><a href="http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/mqtt.org">mqtt.org</a></li>
<li><a href="http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/hivemq.com">hivemq.com</a></li>
<li><a href="http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/mosquitto.org">mosquitto.org</a></li>
<li><a href="https://www.arduino.cc/">www.arduino.cc</a></li>
<li><a href="https://www.raspberrypi.org">www.raspberrypi.org</a></li>
<li><a href="http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/cooking-hacks.com">cooking-hacks.com</a></li>
<li><a href="https://pypi.python.org/pypi/paho-mqtt">pypi.python.org/pypi/paho-mqtt</a></li>
<li><a href="http://iot.eclipse.org/">iot.eclipse.org</a></li>
<li><a href="https://github.com/eschulte/epresent">github.com/eschulte/epresent</a></li>
</ul>
<h1 id="september-2015-meetup">September 2015 meetup</h1>
<p>The September 2015 talk was scheduled on Saturday, September 26, 2015 and I gave a talk on “G-code Visualization Tools”. The talk began with an introduction and history of G-codes. A Maya pyramid STL file was then used with Pronterface to generate the following G-codes:</p>
<pre class="shell"><code>G90         ; Set to Absolute Positioning
G21         ; Set Units to Millimeters
M103        ; Turn off extruder
M105        ; Get extruder temperature
M106        ; Fan (cooling) on
M140 S60.0  ; Set Bed temperature
M141 S30.0  ; Set Chamber temperature
M142 S0.0   ; Holding pressure
M113 S1.0   ; Set Extruder PWM
M108 S210.0 ; Set Extruder Speed
M104 S200.0 ; Set Extruder Temperature
G1 X-54.72 Y-53.352 Z0.72 F60.0 ; G1 Move, F Feedrate, mm/rev
M101        ; Turn extruder 1 on
G1 X-54.72 Y53.352 Z0.72 F240.0
G1 X-51.84 Y53.352 Z0.72 F240.0
...</code></pre>
<p>I then gave a demo of “Yet Another GCode Viewer” written by Jonathan Winterflood that uses the Pyglet library to render the G-code paths. You can also zoom, rotate and scale the image after it has loaded the input data. The brim that is printed for 3D objects is clearly visible in the rendition. A screenshot is shown below:</p>
<img src="http://shakthimaan.com/images/chennaipy-2015/yagv.png" alt="YAGV"></img>
<p>Blender is a free and open source software for computer graphics, 3D modelling and animations. It is written in C, C++ and Python. A Blender gcode reader plugin written by Simon Kirkby exists to visualize G-codes. This plugin generates the image from the G-codes, and converts the change in paths into arcs for a smoother image. The advantage of this plugin is that you can use all the goodies from Blender and Python. A screenshot of the pyramid using the Blender plugin is shown below:</p>
<img src="http://shakthimaan.com/images/chennaipy-2015/gcode-blender.png" alt="G-code Blender plugin"></img>
<p>The Visualization Toolkit (VTK) is yet another free and open source software for image processing and visualization. It requires its input file in a VTK file format. After using the gcode2vtk utility to convert the Maya pyramid G-code file to a VTK file format, I was able to demonstrate the G-code path simulation using ParaView - a data analysis and visualization application. An illustration of the Maya pyramid in ParaView is shown below:</p>
<img src="http://shakthimaan.com/images/chennaipy-2015/gcode-paraview.png" alt="G-code ParaView"></img>
<p>ParaView is written in C, C++, Fortran and Python. Both Blender and ParaView allow you to run simulations on the G-codes.</p>
<p>All the visualization tools discussed are free and open source software, and you can install them on your favourite *nix system.</p>]]></description>
    <pubDate>Tue, 13 Oct 2015 13:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/10/13/chennai-py-talks/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Testing</title>
    <link>http://www.shakthimaan.com/posts/2015/10/09/testing/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, January 2015 edition.]</em></p>
<p>In this article we shall cover testing of Haskell programs.</p>
<p>HUnit is a unit testing framework available for Haskell. It is similar to JUnit, which is used for the Java programming language. You can install HUnit on Fedora using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> ghc-HUnit-devel</code></pre>
<p>Consider a simple example that follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> assertEqual <span class="st">&quot;Test equality&quot;</span> <span class="dv">3</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)</code></pre>
<p>The <em>TestCase</em> is a constructor defined in the Test data type. The definition is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- Test Definition</span>
<span class="co">-- ===============</span>

<span class="co">-- | The basic structure used to create an annotated tree of test cases.</span>
<span class="kw">data</span> <span class="dt">Test</span>
    <span class="co">-- | A single, independent test case composed.</span>
    <span class="fu">=</span> <span class="dt">TestCase</span> <span class="dt">Assertion</span>
    <span class="co">-- | A set of @Test@s sharing the same level in the hierarchy. </span>
    <span class="fu">|</span> <span class="dt">TestList</span> [<span class="dt">Test</span>]
    <span class="co">-- | A name or description for a subtree of the @Test@s.</span>
    <span class="fu">|</span> <span class="dt">TestLabel</span> <span class="dt">String</span> <span class="dt">Test</span></code></pre>
<p>On executing the above code with GHCi, you get the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci test<span class="fu">.</span>hs 

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( one<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> runTestTT test1

<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">HUnit</span><span class="dv">-1</span><span class="fu">.</span><span class="fl">2.5</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">0</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">1</span>, tried <span class="fu">=</span> <span class="dv">1</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">0</span>}</code></pre>
<p>You can build a test suite of tests with <em>TestList</em> as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestList</span> [ <span class="st">&quot;Test addition&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)
                 , <span class="st">&quot;Test subtraction&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">4</span> <span class="fu">-</span> <span class="dv">1</span>)
                 ]</code></pre>
<p>The ‘~=?’ operation is shorthand to assert equality. Its definition is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- | Shorthand for a test case that asserts equality (with the expected </span>
<span class="co">--   value on the left-hand side, and the actual value on the right-hand</span>
<span class="co">--   side).</span>
<span class="ot">(~=?) ::</span> (<span class="kw">Eq</span> a, <span class="kw">Show</span> a) <span class="ot">=&gt;</span> a     <span class="co">-- ^ The expected value </span>
                        <span class="ot">-&gt;</span> a     <span class="co">-- ^ The actual value</span>
                        <span class="ot">-&gt;</span> <span class="dt">Test</span></code></pre>
<p>The ‘~:’ operation is shorthand to attach a label to a test. Its definition is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">(~:) ::</span> (<span class="dt">Testable</span> t) <span class="ot">=&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> t <span class="ot">-&gt;</span> <span class="dt">Test</span>
label <span class="fu">~:</span> t <span class="fu">=</span> <span class="dt">TestLabel</span> label (test t)</code></pre>
<p>By compiling and executing the above code with GHCi, you get the following result:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">0</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">2</span>, tried <span class="fu">=</span> <span class="dv">2</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">0</span>}</code></pre>
<p>A failure is reported when there is a mismatch between the expected result and the observed value. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestList</span> [ <span class="st">&quot;Test addition&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)
                 , <span class="st">&quot;Test subtraction&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">4</span> <span class="fu">-</span> <span class="dv">2</span>)
                 ]</code></pre>
<p>Running the above code reports the failure in the output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="fu">###</span> <span class="dt">Failure</span> <span class="kw">in</span><span class="fu">:</span> <span class="dv">1</span><span class="fu">:</span><span class="dt">Test</span> subtraction
expected<span class="fu">:</span> <span class="dv">3</span>
 but got<span class="fu">:</span> <span class="dv">2</span>
<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">1</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">2</span>, tried <span class="fu">=</span> <span class="dv">2</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">1</span>}</code></pre>
<p>If our test case definition is incorrect, the compiler will throw an error during compilation time itself! For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Char</span>
<span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestList</span> [ <span class="st">&quot;Test addition&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)
                 , <span class="st">&quot;Test case&quot;</span> <span class="fu">~:</span> <span class="st">&quot;EARTH&quot;</span> <span class="fu">~=?</span> (<span class="fu">map</span> <span class="st">&quot;earth&quot;</span>)
                 ]</code></pre>
<p>On compiling the above code, you get the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>l <span class="fu">error.</span>hs

[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( <span class="fu">error.</span>hs, interpreted )

<span class="fu">error.</span>hs<span class="fu">:</span><span class="dv">5</span><span class="fu">:</span><span class="dv">48</span><span class="fu">:</span>
    <span class="dt">Couldn't</span> match expected <span class="kw">type</span> <span class="ot">`[Char]'</span>
<span class="ot">                with actual type `</span>[a1] <span class="ot">-&gt;</span> [b0]<span class="ch">'</span>
    <span class="dt">In</span> the <span class="fu">return</span> <span class="kw">type</span> <span class="kw">of</span> a call <span class="kw">of</span> <span class="ot">`map'</span>
<span class="ot">    Probable cause: `</span>map' is applied to too few arguments
    <span class="dt">In</span> the second argument <span class="kw">of</span> <span class="ot">`(~=?)', namely `</span>(<span class="fu">map</span> <span class="st">&quot;earth&quot;</span>)<span class="ch">'</span>
    <span class="dt">In</span> the second argument <span class="kw">of</span> <span class="ot">`(~:)', namely</span>
<span class="ot">      `</span><span class="st">&quot;EARTH&quot;</span> <span class="fu">~=?</span> (<span class="fu">map</span> <span class="st">&quot;earth&quot;</span>)<span class="ch">'</span>

<span class="fu">error.</span>hs<span class="fu">:</span><span class="dv">5</span><span class="fu">:</span><span class="dv">52</span><span class="fu">:</span>
    <span class="dt">Couldn't</span> match expected <span class="kw">type</span> <span class="ot">`a1 -&gt; b0' with actual type `</span>[<span class="dt">Char</span>]<span class="ch">'</span>
    <span class="dt">In</span> the first argument <span class="kw">of</span> <span class="ot">`map', namely `</span><span class="st">&quot;earth&quot;</span><span class="ch">'</span>
    <span class="dt">In</span> the second argument <span class="kw">of</span> <span class="ot">`(~=?)', namely `</span>(<span class="fu">map</span> <span class="st">&quot;earth&quot;</span>)<span class="ch">'</span>
    <span class="dt">In</span> the second argument <span class="kw">of</span> <span class="ot">`(~:)', namely</span>
<span class="ot">      `</span><span class="st">&quot;EARTH&quot;</span> <span class="fu">~=?</span> (<span class="fu">map</span> <span class="st">&quot;earth&quot;</span>)<span class="ch">'</span>
<span class="dt">Failed</span>, modules loaded<span class="fu">:</span> none<span class="fu">.</span></code></pre>
<p>The correct version of the code and its output are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Char</span>
<span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestList</span> [ <span class="st">&quot;Test addition&quot;</span> <span class="fu">~:</span> <span class="dv">3</span> <span class="fu">~=?</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)
                 , <span class="st">&quot;Test case&quot;</span> <span class="fu">~:</span> <span class="st">&quot;EARTH&quot;</span> <span class="fu">~=?</span> (<span class="fu">map</span> <span class="fu">toUpper</span> <span class="st">&quot;earth&quot;</span>)
                 ]</code></pre>
<p>The expected test output is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">2</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">0</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">2</span>, tried <span class="fu">=</span> <span class="dv">2</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">0</span>}</code></pre>
<p>In Haskell, one needs to check for an empty list when using the <em>head</em> function, or else it will throw an error. An example test is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> assertEqual <span class="st">&quot;Head of emptylist&quot;</span> <span class="dv">1</span> (<span class="fu">head</span> [])</code></pre>
<p>Executing the above code gives:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="fu">###</span> <span class="dt">Error</span><span class="fu">:</span>
Prelude.head<span class="fu">:</span> empty list
<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">0</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">1</span>, tried <span class="fu">=</span> <span class="dv">1</span>, errors <span class="fu">=</span> <span class="dv">1</span>, failures <span class="fu">=</span> <span class="dv">0</span>}</code></pre>
<p>Other than the assertEqual function, there are conditional assertion functions like <em>assertBool</em>, <em>assertString</em> and <em>assertFailure</em> that you can use. The assertBool function takes a string that is displayed if the assertion fails and a condition to assert. A couple of examples are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> assertBool <span class="st">&quot;Does not happen&quot;</span> <span class="kw">True</span></code></pre>
<p>Executing the above code in GHCi, gives you the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">0</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">1</span>, tried <span class="fu">=</span> <span class="dv">1</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">0</span>}</code></pre>
<p>Consider the case when there is a failure:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> assertBool <span class="st">&quot;Failure!&quot;</span> (<span class="kw">False</span> <span class="fu">&amp;&amp;</span> <span class="kw">False</span>)</code></pre>
<p>The corresponding output is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="fu">###</span> <span class="dt">Failure</span><span class="fu">:</span>
<span class="dt">Failure</span><span class="fu">!</span>
<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">1</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">1</span>, tried <span class="fu">=</span> <span class="dv">1</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">1</span>}</code></pre>
<p><em>assertFailure</em> and <em>assertString</em> functions take a string as input, and return an Assertion. These are used as part of other test functions. The <em>assertFailure</em> function is used in the definition of the assertBool function as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- | Asserts that the specified condition holds.</span>
<span class="ot">assertBool ::</span> <span class="dt">String</span>    <span class="co">-- ^ The message that is displayed if the assertion fails</span>
           <span class="ot">-&gt;</span> <span class="dt">Bool</span>      <span class="co">-- ^ The condition</span>
           <span class="ot">-&gt;</span> <span class="dt">Assertion</span>
assertBool msg b <span class="fu">=</span> unless b (assertFailure msg)</code></pre>
<p>You can also use <em>assertString</em> for handling a specific case. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>

test1 <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> assertString <span class="st">&quot;Failure!&quot;</span></code></pre>
<p>Executing the above code in GHCi results in the following failure message:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runTestTT test1

<span class="fu">###</span> <span class="dt">Failure</span><span class="fu">:</span>
<span class="dt">Failure</span><span class="fu">!</span>
<span class="dt">Cases</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Tried</span><span class="fu">:</span> <span class="dv">1</span>  <span class="dt">Errors</span><span class="fu">:</span> <span class="dv">0</span>  <span class="dt">Failures</span><span class="fu">:</span> <span class="dv">1</span>
<span class="dt">Counts</span> {cases <span class="fu">=</span> <span class="dv">1</span>, tried <span class="fu">=</span> <span class="dv">1</span>, errors <span class="fu">=</span> <span class="dv">0</span>, failures <span class="fu">=</span> <span class="dv">1</span>}</code></pre>
<p>Hspec is another testing framework for Haskell, similar to Ruby’s RSpec. You can install it on any GNU/Linux distribution using the Cabal tool:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ cabal update <span class="kw">&amp;&amp;</span> cabal <span class="kw">install</span> hspec hspec-contrib</code></pre>
<p>A simple example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.Hspec</span>

<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> hspec <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;Testing equality&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;returns 3 for the sum of 2 and 1&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      <span class="dv">3</span> <span class="ot">`shouldBe`</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)</code></pre>
<p>Executing the above code with GHCi produces the following verbose output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">$</span> ghci spec<span class="fu">.</span>hs 

<span class="dt">GHCi</span>, version <span class="fl">7.6</span><span class="fu">.</span><span class="dv">3</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( spec<span class="fu">.</span>hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>

ghci<span class="fu">&gt;</span> main
<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package deepseq<span class="dv">-1</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">HUnit</span><span class="dv">-1</span><span class="fu">.</span><span class="fl">2.5</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package random<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package transformers<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package stm<span class="dv">-2</span><span class="fu">.</span><span class="fl">4.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package bytestring<span class="dv">-0</span><span class="fu">.</span><span class="fl">10.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unix<span class="dv">-2</span><span class="fu">.</span><span class="fl">6.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package containers<span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package pretty<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package template<span class="fu">-</span>haskell <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="dt">QuickCheck</span><span class="dv">-2</span><span class="fu">.</span><span class="dv">6</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package ansi<span class="fu">-</span>terminal<span class="dv">-0</span><span class="fu">.</span><span class="fl">6.2</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package async<span class="dv">-2</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">6</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hspec<span class="fu">-</span>expectations<span class="dv">-0</span><span class="fu">.</span><span class="fl">6.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package quickcheck<span class="fu">-</span>io<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package setenv<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package <span class="kw">primitive</span><span class="dv">-0</span><span class="fu">.</span><span class="fl">5.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package tf<span class="fu">-</span>random<span class="dv">-0</span><span class="fu">.</span><span class="dv">5</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hspec<span class="fu">-</span>core<span class="dv">-2</span><span class="fu">.</span><span class="fl">0.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hspec<span class="fu">-</span>discover<span class="dv">-2</span><span class="fu">.</span><span class="fl">0.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package hspec<span class="dv">-2</span><span class="fu">.</span><span class="fl">0.2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

<span class="dt">Testing</span> equality
  returns <span class="dv">3</span> for the <span class="fu">sum</span> <span class="kw">of</span> <span class="dv">2</span> <span class="fu">and</span> <span class="dv">1</span>

<span class="dt">Finished</span> <span class="kw">in</span> <span class="fl">0.0002</span> seconds
<span class="dv">1</span> example, <span class="dv">0</span> failures</code></pre>
<p>The keywords <em>describe</em> and <em>it</em> are used to specify the tests. The <em>context</em> keyword can also be used as an alias for <em>describe</em>. A particular test can be marked ‘pending’ using the <em>pending</em> and <em>pendingWith</em> keywords. The <em>pendingWith</em> function takes a string message as an argument, as illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.Hspec</span>

main <span class="fu">=</span> hspec <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;Testing equality&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;returns 3 for the sum of 2 and 1&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      <span class="dv">3</span> <span class="ot">`shouldBe`</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)

  describe <span class="st">&quot;Testing subtraction&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;returns 3 when subtracting 1 from 4&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      pendingWith <span class="st">&quot;need to add test&quot;</span></code></pre>
<p>The corresponding output for the above code snippet is provided below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main

<span class="dt">Testing</span> equality
  returns <span class="dv">3</span> for the <span class="fu">sum</span> <span class="kw">of</span> <span class="dv">2</span> <span class="fu">and</span> <span class="dv">1</span>
<span class="dt">Testing</span> subtraction
  returns <span class="dv">3</span> when subtracting <span class="dv">1</span> from <span class="dv">4</span>
     <span class="fu">#</span> <span class="dt">PENDING</span><span class="fu">:</span> need to add test

<span class="dt">Finished</span> <span class="kw">in</span> <span class="fl">0.0006</span> seconds
<span class="dv">2</span> examples, <span class="dv">0</span> failures, <span class="dv">1</span> pending</code></pre>
<p>You can use the <em>after</em> and <em>before</em> keywords to specify setup and tear down functions before running a test. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.Hspec</span>

<span class="ot">getInt ::</span> <span class="dt">IO</span> <span class="dt">Int</span>
getInt <span class="fu">=</span> <span class="kw">do</span>
  <span class="fu">putStrLn</span> <span class="st">&quot;Enter number:&quot;</span>
  number <span class="ot">&lt;-</span> <span class="fu">readLn</span>
  <span class="fu">return</span> number
 
<span class="ot">afterPrint ::</span> <span class="dt">ActionWith</span> <span class="dt">Int</span>
afterPrint <span class="dv">3</span> <span class="fu">=</span> <span class="fu">print</span> <span class="dv">3</span>
 
main <span class="fu">=</span> hspec <span class="fu">$</span> before getInt <span class="fu">$</span> after afterPrint <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;should be 3&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;should successfully return 3&quot;</span> <span class="fu">$</span> \n <span class="ot">-&gt;</span> <span class="kw">do</span>
      n <span class="ot">`shouldBe`</span> <span class="dv">3</span></code></pre>
<p>Executing the above code yields the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">ghci<span class="kw">&gt;</span> main

should be 3
Enter number:
3
3
  should successfully <span class="kw">return</span> 3

Finished <span class="kw">in</span> 0.6330 seconds
1 example, 0 failures</code></pre>
<p>The different options used with Hspec can be listed with the <em>–help</em> option, as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ runhaskell file.hs --help
Usage: spec.hs [OPTION]...

OPTIONS
                --help              display this <span class="kw">help</span> and <span class="kw">exit</span>
  -m PATTERN    --match=PATTERN     only run examples that match given PATTERN
                --color             colorize the output
                --no-color          <span class="kw">do</span> not colorize the output
  -f FORMATTER  --format=FORMATTER  use a custom formatter; this can be one of:
                                       specdoc
                                       progress
                                       failed-examples
                                       silent
  -o FILE       --out=FILE          <span class="kw">write</span> output to a <span class="kw">file</span> instead of STDOUT
                --depth=N           maximum depth of generated <span class="kw">test</span> values <span class="kw">for</span>
                                    SmallCheck properties
  -a N          --qc-max-success=N  maximum number of successful tests before a
                                    QuickCheck property succeeds
                --qc-max-size=N     <span class="kw">size</span> to use <span class="kw">for</span> the biggest <span class="kw">test</span> cases
                --qc-max-discard=N  maximum number of discarded tests per
                                    successful <span class="kw">test</span> before giving up
                --seed=N            used seed <span class="kw">for</span> QuickCheck properties
                --print-cpu-time    include used CPU <span class="kw">time</span> <span class="kw">in</span> summary
                --dry-run           pretend that everything passed; don<span class="st">'t verify</span>
<span class="st">                                    anything</span>
<span class="st">                --fail-fast         abort on first failure</span>
<span class="st">  -r            --rerun             rerun all examples that failed in the</span>
<span class="st">                                    previously test run (only works in GHCi)</span></code></pre>
<p>Other than the <em>shouldBe</em> expectation, you can also use assertions like <em>shouldReturn</em>, <em>shouldSatisfy</em>, and <em>shouldThrow</em>. Examples of each are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.Hspec</span>
<span class="kw">import</span> <span class="dt">Control.Exception</span> (evaluate)

main <span class="fu">=</span> hspec <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;shouldReturn&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;should successfully return 3&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      <span class="fu">return</span> <span class="dv">3</span> <span class="ot">`shouldReturn`</span> <span class="dv">3</span>

  describe <span class="st">&quot;shouldSatisfy&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;should satisfy the condition that 10 is greater than 5&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      <span class="dv">10</span> <span class="ot">`shouldSatisfy`</span> (<span class="fu">&gt;</span> <span class="dv">5</span>)

  describe <span class="st">&quot;shouldThrow&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;should throw an exception when taking head of an empty list&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      evaluate (<span class="dv">1</span> <span class="ot">`div`</span> <span class="dv">0</span>) <span class="ot">`shouldThrow`</span> anyException                                     </code></pre>
<p>Executing the above code provides the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main

shouldReturn
  should successfully <span class="fu">return</span> an <span class="dt">Integer</span>
shouldSatisfy
  should satisfy the condition that <span class="dv">10</span> is greater than <span class="dv">5</span>
shouldThrow
  should throw an exception when taking <span class="fu">head</span> <span class="kw">of</span> an empty list

<span class="dt">Finished</span> <span class="kw">in</span> <span class="fl">0.0015</span> seconds
<span class="dv">3</span> examples, <span class="dv">0</span> failures</code></pre>
<p>The <em>evaluate</em> function can be used to check for exceptions. Its type signature is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t evaluate
<span class="ot">evaluate ::</span> a <span class="ot">-&gt;</span> <span class="dt">IO</span> a</code></pre>
<p>You can also re-use HUnit tests and integrate them with Hspec. An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.HUnit</span>
<span class="kw">import</span> <span class="dt">Test.Hspec</span>
<span class="kw">import</span> <span class="dt">Test.Hspec.Contrib.HUnit</span> (fromHUnitTest)

test1 <span class="fu">=</span> <span class="dt">TestList</span> [ <span class="dt">TestLabel</span> <span class="st">&quot;Test subtraction&quot;</span> foo ]

<span class="ot">foo ::</span> <span class="dt">Test</span>
foo <span class="fu">=</span> <span class="dt">TestCase</span> <span class="fu">$</span> <span class="kw">do</span>
  <span class="dv">3</span> <span class="fu">@?=</span> (<span class="dv">4</span> <span class="fu">-</span> <span class="dv">1</span>)

main <span class="fu">=</span> hspec <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;Testing equality&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;returns 3 for the sum of 2 and 1&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      <span class="dv">3</span> <span class="ot">`shouldBe`</span> (<span class="dv">2</span> <span class="fu">+</span> <span class="dv">1</span>)

  describe <span class="st">&quot;Testing subtraction&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    fromHUnitTest test1</code></pre>
<p>Testing the code in GHCi produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Loading</span> package hspec<span class="fu">-</span>contrib<span class="dv">-0</span><span class="fu">.</span><span class="fl">2.0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>

<span class="dt">Testing</span> equality
  returns <span class="dv">3</span> for the <span class="fu">sum</span> <span class="kw">of</span> <span class="dv">2</span> <span class="fu">and</span> <span class="dv">1</span>
<span class="dt">Testing</span> subtraction
  <span class="dt">Test</span> subtraction

<span class="dt">Finished</span> <span class="kw">in</span> <span class="fl">0.0004</span> seconds
<span class="dv">2</span> examples, <span class="dv">0</span> failures</code></pre>
<p>The Hspec tests can also be executed in parallel. For example, computing the Fibonacci for a set of numbers, and asserting their expected values can be run in parallel as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.Hspec</span>

<span class="ot">fib ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
fib <span class="dv">0</span> <span class="fu">=</span> <span class="dv">0</span>
fib <span class="dv">1</span> <span class="fu">=</span> <span class="dv">1</span>
fib n <span class="fu">=</span> fib (n<span class="dv">-1</span>) <span class="fu">+</span> fib (n<span class="dv">-2</span>)

main <span class="fu">=</span> hspec <span class="fu">$</span> parallel <span class="fu">$</span> <span class="kw">do</span>
  describe <span class="st">&quot;Testing Fibonacci&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
    it <span class="st">&quot;must return 6765 for fib 20&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      fib <span class="dv">20</span> <span class="ot">`shouldBe`</span> <span class="dv">6765</span>

    it <span class="st">&quot;must return 75025 for fib 25&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      fib <span class="dv">25</span> <span class="ot">`shouldBe`</span> <span class="dv">75025</span>

    it <span class="st">&quot;must return 832040 for fib 30&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      fib <span class="dv">30</span> <span class="ot">`shouldBe`</span> <span class="dv">832040</span>

    it <span class="st">&quot;must return 9227465 for fib 35&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
      fib <span class="dv">35</span> <span class="ot">`shouldBe`</span> <span class="dv">9227465</span></code></pre>
<p>You can compile and execute the above code as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc -threaded parallel.hs 
Linking parallel ...

$ ./parallel +RTS -N -RTS

Testing Fibonacci
  must <span class="kw">return</span> 6765 <span class="kw">for</span> fib 20
  must <span class="kw">return</span> 75025 <span class="kw">for</span> fib 25
  must <span class="kw">return</span> 832040 <span class="kw">for</span> fib 30
  must <span class="kw">return</span> 9227465 <span class="kw">for</span> fib 35

Finished <span class="kw">in</span> 0.9338 seconds
4 examples, 0 failures</code></pre>]]></description>
    <pubDate>Fri, 09 Oct 2015 21:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/10/09/testing/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - IO</title>
    <link>http://www.shakthimaan.com/posts/2015/09/11/io/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, December 2014 edition.]</em></p>
<p>This article is a must read for anyone interested in getting a good insight into the input/output (IO) functionality of Haskell.</p>
<p>Input/output (IO) can cause side-effects and hence is implemented as a Monad. The IO Monad takes some input, does some computation and returns a value. The IO action is performed inside a <em>main</em> function. Consider a simple ‘Hello world’ example:</p>
<pre class="hs"><code>main = putStrLn &quot;Hello, World!&quot;</code></pre>
<p>Executing the above code in GHCi produces the following output:</p>
<pre class="hs"><code>$ ghci hello.hs
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( foo.hs, interpreted )
Ok, modules loaded: Main.

ghci&gt; main
Hello, World!</code></pre>
<p>The type signatures of main and putStrLn are:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">main ::</span> <span class="dt">IO</span> ()

<span class="fu">putStrLn</span><span class="ot"> ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p><em>putStrLn</em> takes a String as input and prints the String to output. It doesn’t return anything, and hence the return type is the empty tuple ().</p>
<p>The <em>getLine</em> function performs an IO to return a String.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">getLine</span>
<span class="fu">getLine</span><span class="ot"> ::</span> <span class="dt">IO</span> <span class="dt">String</span>

ghci<span class="fu">&gt;</span> name <span class="ot">&lt;-</span> <span class="fu">getLine</span>
<span class="dt">Foo</span>

ghci<span class="fu">&gt;</span> name
<span class="st">&quot;Foo&quot;</span></code></pre>
<p>The ‘&lt;-’ extracts the result of the IO String action, unwraps it to obtain the String value, and ‘name’ gets the value. So, the type of ‘name’ is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t name
<span class="ot">name ::</span> <span class="dt">String</span></code></pre>
<p>The <em>do</em> syntax is useful to chain IO together. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">main <span class="fu">=</span> <span class="kw">do</span>
  <span class="fu">putStrLn</span> <span class="st">&quot;Enter your name:&quot;</span>
  name <span class="ot">&lt;-</span> <span class="fu">getLine</span>
  <span class="fu">putStrLn</span> (<span class="st">&quot;Hello &quot;</span> <span class="fu">++</span> name)</code></pre>
<p>Executing the code in GHCi gives the following results:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Enter</span> your name<span class="fu">:</span>
<span class="dt">Shakthi</span>
<span class="dt">Hello</span> <span class="dt">Shakthi</span></code></pre>
<p>The <em>putStr</em> function is similar to the putStrLn function, except that it doesn’t emit the newline after printing the output string. Its type signature and an example are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">putStr</span>
<span class="fu">putStr</span><span class="ot"> ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> <span class="fu">putStr</span> <span class="st">&quot;Alpha &quot;</span>
<span class="dt">Alpha</span> ghci<span class="fu">&gt;</span> </code></pre>
<p>The <em>putChar</em> function takes a single character as input, and prints the same to the output. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghc<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">putChar</span>
<span class="fu">putChar</span><span class="ot"> ::</span> <span class="dt">Char</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> <span class="fu">putChar</span> <span class="ch">'s'</span>
s </code></pre>
<p>The <em>getChar</em> function is similar to the getLine function except that it takes a Char as input. Its type signature and usage are illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">getChar</span>
<span class="fu">getChar</span><span class="ot"> ::</span> <span class="dt">IO</span> <span class="dt">Char</span>

ghci<span class="fu">&gt;</span> a <span class="ot">&lt;-</span> <span class="fu">getChar</span>
d

ghci<span class="fu">&gt;</span> a
<span class="ch">'d'</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t a
<span class="ot">a ::</span> <span class="dt">Char</span></code></pre>
<p>The <em>print</em> function type signature is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">print</span>
<span class="fu">print</span><span class="ot"> ::</span> <span class="kw">Show</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>It is a parameterized function which can take input of any type that is an instance of the Show type class, and prints that to the output. Some examples are given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">print</span> <span class="dv">1</span>
<span class="dv">1</span>

ghci<span class="fu">&gt;</span> <span class="fu">print</span> <span class="ch">'c'</span>
<span class="ch">'c'</span>

ghci<span class="fu">&gt;</span> <span class="fu">print</span> <span class="st">&quot;Hello&quot;</span>
<span class="st">&quot;Hello&quot;</span>

ghci<span class="fu">&gt;</span> <span class="fu">print</span> <span class="kw">True</span>
<span class="kw">True</span></code></pre>
<p>The <em>getContents</em> function reads the input until the end-of-file (EOF) and returns a String. Its type signature is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">getContents</span>
<span class="fu">getContents</span><span class="ot"> ::</span> <span class="dt">IO</span> <span class="dt">String</span></code></pre>
<p>An example code is demonstrated below. It only outputs lines whose length is less than five characters:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">main <span class="fu">=</span> <span class="kw">do</span>
  <span class="fu">putStrLn</span> <span class="st">&quot;Enter text:&quot;</span>
  text <span class="ot">&lt;-</span> <span class="fu">getContents</span>
  <span class="fu">putStr</span> <span class="fu">.</span> <span class="fu">unlines</span> <span class="fu">.</span> <span class="fu">filter</span> (\line <span class="ot">-&gt;</span> <span class="fu">length</span> line <span class="fu">&lt;</span> <span class="dv">5</span>) <span class="fu">$</span> <span class="fu">lines</span> text </code></pre>
<p>Testing the above example gives the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="dt">Enter</span> text<span class="fu">:</span>
a
a

it
it

the
the

four
four

empty

twelve

haskell

o
o</code></pre>
<p>You can break out of this execution by pressing Ctrl-c at the GHCi prompt.</p>
<p>The <em>openFile</em>, <em>hGetContents</em>, <em>hClose</em> functions can be used to obtain a handle for a file, to retrieve the file contents, and to close the handle respectively. This is similar to file handling in C. Their type signatures are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="dt">System.IO</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t openFile
<span class="ot">openFile ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IOMode</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Handle</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t hGetContents
<span class="ot">hGetContents ::</span> <span class="dt">Handle</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">String</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t hClose
<span class="ot">hClose ::</span> <span class="dt">Handle</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>The different IOModes are ReadMode, WriteMode, AppendMode and ReadWriteMode. It is defined as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- | See 'System.IO.openFile'</span>
<span class="kw">data</span> <span class="dt">IOMode</span>      <span class="fu">=</span>  <span class="dt">ReadMode</span> <span class="fu">|</span> <span class="dt">WriteMode</span> <span class="fu">|</span> <span class="dt">AppendMode</span> <span class="fu">|</span> <span class="dt">ReadWriteMode</span>
                    <span class="kw">deriving</span> (<span class="kw">Eq</span>, <span class="kw">Ord</span>, <span class="kw">Ix</span>, <span class="kw">Enum</span>, <span class="kw">Read</span>, <span class="kw">Show</span>)</code></pre>
<p>An example code is illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.IO</span>

main <span class="fu">=</span> <span class="kw">do</span>
  f <span class="ot">&lt;-</span> openFile <span class="st">&quot;/etc/resolv.conf&quot;</span> <span class="dt">ReadMode</span>
  text <span class="ot">&lt;-</span> hGetContents f
  <span class="fu">putStr</span> text
  hClose f</code></pre>
<p>Executing the code in GHCi produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main

<span class="fu">#</span> <span class="dt">Generated</span> by <span class="dt">NetworkManager</span>
nameserver <span class="fl">192.168</span><span class="fu">.</span><span class="fl">1.1</span></code></pre>
<p>A temporary file can be created using the <em>openTempFile</em> function. It takes as input a directory location, and a pattern String for the filename. Its type signature is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t openTempFile
<span class="ot">openTempFile ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> (<span class="fu">FilePath</span>, <span class="dt">Handle</span>)</code></pre>
<p>An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.IO</span>
<span class="kw">import</span> <span class="dt">System.Directory</span>(removeFile)

main <span class="fu">=</span> <span class="kw">do</span>
  (f, handle) <span class="ot">&lt;-</span> openTempFile <span class="st">&quot;/tmp&quot;</span> <span class="st">&quot;abc&quot;</span>
  <span class="fu">putStrLn</span> f
  removeFile f
  hClose handle</code></pre>
<p>You must ensure to remove the file after using it. An example is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main
<span class="fu">/</span>tmp<span class="fu">/</span>abc2731</code></pre>
<p>The operations on opening a file to get a handle, getting the contents, and closing the handle can be abstracted to a higher level. The <em>readFile</em> and <em>writeFile</em> functions can be used for this purpose. Their type signatures are as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">readFile</span>
<span class="fu">readFile</span><span class="ot"> ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">String</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">writeFile</span>
<span class="fu">writeFile</span><span class="ot"> ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>The /etc/resolv.conf file is read and written to /tmp/resolv.conf in the following example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">main <span class="fu">=</span> <span class="kw">do</span>
  text <span class="ot">&lt;-</span> <span class="fu">readFile</span> <span class="st">&quot;/etc/resolv.conf&quot;</span>
  <span class="fu">writeFile</span> <span class="st">&quot;/tmp/resolv.conf&quot;</span> text</code></pre>
<p>You can also append to a file using the <em>appendFile</em> function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">appendFile</span>
<span class="fu">appendFile</span><span class="ot"> ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">main <span class="fu">=</span> <span class="kw">do</span>
  <span class="fu">appendFile</span> <span class="st">&quot;/tmp/log.txt&quot;</span> <span class="st">&quot;1&quot;</span>
  <span class="fu">appendFile</span> <span class="st">&quot;/tmp/log.txt&quot;</span> <span class="st">&quot;2&quot;</span>
  <span class="fu">appendFile</span> <span class="st">&quot;/tmp/log.txt&quot;</span> <span class="st">&quot;3&quot;</span></code></pre>
<p>The contents of <em>/tmp/log.txt</em> is ‘123’.</p>
<p>The actual definitions of readFile, writeFile and appendFile are in the System.IO module in the Haskell base package:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">readFile</span><span class="ot">        ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">String</span>
<span class="fu">readFile</span> name   <span class="fu">=</span>  openFile name <span class="dt">ReadMode</span> <span class="fu">&gt;&gt;=</span> hGetContents

<span class="fu">writeFile</span><span class="ot"> ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
<span class="fu">writeFile</span> f txt <span class="fu">=</span> withFile f <span class="dt">WriteMode</span> (\ hdl <span class="ot">-&gt;</span> hPutStr hdl txt)

<span class="fu">appendFile</span><span class="ot">      ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
<span class="fu">appendFile</span> f txt <span class="fu">=</span> withFile f <span class="dt">AppendMode</span> (\ hdl <span class="ot">-&gt;</span> hPutStr hdl txt)</code></pre>
<p>The System.Environment module has useful functions to read command line arguments. The <em>getArgs</em> function returns an array of arguments passed to the program. The <em>getProgName</em> provides the name of the program being executed. Their type signatures are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="dt">System.Environment</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getArgs
<span class="ot">getArgs ::</span> <span class="dt">IO</span> [<span class="dt">String</span>]

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getProgName
<span class="ot">getProgName ::</span> <span class="dt">IO</span> <span class="dt">String</span></code></pre>
<p>Here is an example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.Environment</span>

main <span class="fu">=</span> <span class="kw">do</span>
  args <span class="ot">&lt;-</span> getArgs
  program <span class="ot">&lt;-</span> getProgName
  <span class="fu">putStrLn</span> (<span class="st">&quot;Program : &quot;</span> <span class="fu">++</span> program)
  <span class="fu">putStrLn</span> <span class="st">&quot;The arguments passed are: &quot;</span>
  <span class="fu">mapM</span> <span class="fu">putStrLn</span> args</code></pre>
<p>Executing the above listed code produces the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghc --make args.hs 

[1 of 1] Compiling Main             <span class="kw">(</span> args.hs, args.o <span class="kw">)</span>
Linking args ...

$ ./args 1 2 3 4 5

Program <span class="kw">:</span> foo
The arguments passed are: 
1
2
3
4
5</code></pre>
<p>The mapM function is the map function that works for Monads. Its type signature is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">mapM</span>
<span class="fu">mapM</span><span class="ot"> ::</span> <span class="kw">Monad</span> m <span class="ot">=&gt;</span> (a <span class="ot">-&gt;</span> m b) <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> m [b]</code></pre>
<p>The System.Directory module has functions to operate on files and directories. A few examples are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t createDirectory
<span class="ot">createDirectory ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> createDirectory <span class="st">&quot;/tmp/foo&quot;</span>
ghci<span class="fu">&gt;</span></code></pre>
<p>If you try to create a directory that already exists, it will return an exception.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span>  createDirectory <span class="st">&quot;/tmp/bar&quot;</span>
<span class="fu">***</span> <span class="dt">Exception</span><span class="fu">:</span> <span class="fu">/</span>tmp<span class="fu">/</span>bar<span class="fu">:</span> createDirectory<span class="fu">:</span> already exists (<span class="dt">File</span> exists)</code></pre>
<p>You can use the <em>createDirectoryIfMissing</em> function, and pass a Boolean option to indicate whether to create the directory or not. Its type signature is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t createDirectoryIfMissing
<span class="ot">createDirectoryIfMissing ::</span> <span class="dt">Bool</span> <span class="ot">-&gt;</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>If True is passed and the directory does not exist, the function will create parent directories as well. If the option is False, it will throw up an error.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> createDirectoryIfMissing <span class="kw">False</span> <span class="st">&quot;/tmp/a/b/c&quot;</span>
<span class="fu">***</span> <span class="dt">Exception</span><span class="fu">:</span> <span class="fu">/</span>tmp<span class="fu">/</span>a<span class="fu">/</span>b<span class="fu">/</span>c<span class="fu">:</span> createDirectory<span class="fu">:</span> does <span class="fu">not</span> exist (<span class="dt">No</span> such file <span class="fu">or</span> directory)

ghci<span class="fu">&gt;</span> createDirectoryIfMissing <span class="kw">True</span> <span class="st">&quot;/tmp/a/b/c&quot;</span>
ghci<span class="fu">&gt;</span></code></pre>
<p>You can remove directories using the <em>removeDirectory</em> or <em>removeDirectoryRecursive</em> functions. Their type signatures are as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t removeDirectory
<span class="ot">removeDirectory ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t removeDirectoryRecursive
<span class="ot">removeDirectoryRecursive ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>A few examples are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> createDirectoryIfMissing <span class="kw">True</span> <span class="st">&quot;/tmp/a/b/c&quot;</span> 
ghci<span class="fu">&gt;</span>

ghci<span class="fu">&gt;</span> removeDirectory <span class="st">&quot;/tmp/a&quot;</span>
<span class="fu">***</span> <span class="dt">Exception</span><span class="fu">:</span> <span class="fu">/</span>tmp<span class="fu">/</span>a<span class="fu">:</span> removeDirectory<span class="fu">:</span> unsatisified constraints (<span class="dt">Directory</span> <span class="fu">not</span> empty)

ghci<span class="fu">&gt;</span> removeDirectoryRecursive <span class="st">&quot;/tmp/a&quot;</span>
ghci<span class="fu">&gt;</span></code></pre>
<p>The existence of a file can be tested with the <em>doesFileExist</em> function. You can check if a directory is present using the <em>doesDirectoryExist</em> function. Their type signatures are:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t doesFileExist 
<span class="ot">doesFileExist ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Bool</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t doesDirectoryExist
<span class="ot">doesDirectoryExist ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Bool</span></code></pre>
<p>Some examples of using these functions are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> doesDirectoryExist <span class="st">&quot;/abcd&quot;</span>
<span class="kw">False</span>

ghci<span class="fu">&gt;</span> doesDirectoryExist <span class="st">&quot;/tmp&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> doesFileExist <span class="st">&quot;/etc/resolv.conf&quot;</span>
<span class="kw">True</span>

ghci<span class="fu">&gt;</span> doesFileExist <span class="st">&quot;/etc/unresolv.conf&quot;</span>
<span class="kw">False</span></code></pre>
<p>To know the current directory from where you are running the command, you can use the <em>getCurrentDirectory</em> function, and to know the contents in a directory you can use the <em>getDirectoryContents</em> function. Their type signatures are:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getCurrentDirectory
<span class="ot">getCurrentDirectory ::</span> <span class="dt">IO</span> <span class="fu">FilePath</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getDirectoryContents
<span class="ot">getDirectoryContents ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> [<span class="fu">FilePath</span>]</code></pre>
<p>For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> getCurrentDirectory 
<span class="st">&quot;/tmp&quot;</span>

ghci<span class="fu">&gt;</span> getDirectoryContents <span class="st">&quot;/etc/init.d&quot;</span>
[<span class="st">&quot;livesys&quot;</span>,<span class="st">&quot;netconsole&quot;</span>,<span class="st">&quot;.&quot;</span>,<span class="st">&quot;..&quot;</span>,<span class="st">&quot;network&quot;</span>,<span class="st">&quot;README&quot;</span>,<span class="st">&quot;functions&quot;</span>,<span class="st">&quot;livesys-late&quot;</span>,<span class="st">&quot;influxdb&quot;</span>]</code></pre>
<p>The <em>copyFile</em>, <em>renameFile</em> and <em>removeFile</em> functions are used to copy, rename and delete files. Their type signatures are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t copyFile
<span class="ot">copyFile ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t renameFile
<span class="ot">renameFile ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t removeFile
<span class="ot">removeFile ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()</code></pre>
<p>Here is a very contrived example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.Directory</span>

main <span class="fu">=</span> <span class="kw">do</span>
  copyFile <span class="st">&quot;/etc/resolv.conf&quot;</span> <span class="st">&quot;/tmp/resolv.conf&quot;</span>
  renameFile <span class="st">&quot;/tmp/resolv.conf&quot;</span> <span class="st">&quot;/tmp/resolv.conf.orig&quot;</span>
  removeFile <span class="st">&quot;/tmp/resolv.conf.orig&quot;</span></code></pre>
<p>To obtain the file permissions, use the <em>getPermissions</em> function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t getPermissions
<span class="ot">getPermissions ::</span> <span class="fu">FilePath</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Permissions</span>

ghci<span class="fu">&gt;</span> getPermissions <span class="st">&quot;/etc/resolv.conf&quot;</span>
<span class="dt">Permissions</span> {readable <span class="fu">=</span> <span class="kw">True</span>, writable <span class="fu">=</span> <span class="kw">False</span>, executable <span class="fu">=</span> <span class="kw">False</span>, searchable <span class="fu">=</span> <span class="kw">False</span>}</code></pre>
<p>It is important to separate pure and impure functions in your code, and to include the type signatures for readability. An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- Pure</span>
<span class="ot">square ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
square x <span class="fu">=</span> x <span class="fu">*</span> x

<span class="co">-- Impure</span>
main <span class="fu">=</span> <span class="kw">do</span>
  <span class="fu">putStrLn</span> <span class="st">&quot;Enter number to be squared:&quot;</span>
  number <span class="ot">&lt;-</span> <span class="fu">readLn</span>
  <span class="fu">print</span> (square number)</code></pre>
<p>The readLn function is a parameterized IO action whose type signature is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">:</span>t <span class="fu">readLn</span>
<span class="fu">readLn</span><span class="ot"> ::</span> <span class="kw">Read</span> a <span class="ot">=&gt;</span> <span class="dt">IO</span> a</code></pre>
<p>Executing the code produces the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> main

<span class="dt">Enter</span> number to be squared<span class="fu">:</span>
<span class="dv">5</span>
<span class="dv">25</span></code></pre>]]></description>
    <pubDate>Fri, 11 Sep 2015 10:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/09/11/io/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - More Type Classes</title>
    <link>http://www.shakthimaan.com/posts/2015/08/20/more-type-classes/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, November 2014 edition.]</em></p>
<p>In this article, we shall explore more type classes in Haskell. Consider the Functor type class:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Functor</span> f <span class="kw">where</span>
<span class="ot">      fmap ::</span> (a <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> f a <span class="ot">-&gt;</span> f b</code></pre>
<p>It defines a function <em>fmap</em>, that accepts a function as an argument that takes input of type <em>a</em> and returns type <em>b</em>, and applies the function on every type ‘a’ to produce types ‘b’. The <em>f</em> is a type constructor. An array is an instance of the Functor class and is defined as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Functor</span> [] <span class="kw">where</span>
	 <span class="fu">fmap</span> <span class="fu">=</span> <span class="fu">map</span></code></pre>
<p>The Functor type class is used for types that can be mapped over. Examples of using the Functor type class for arrays are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> <span class="fu">length</span> [<span class="st">&quot;abc&quot;</span>, <span class="st">&quot;defg&quot;</span>]
[<span class="dv">3</span>,<span class="dv">4</span>]

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">length</span>
<span class="fu">length</span><span class="ot"> ::</span> [a] <span class="ot">-&gt;</span> <span class="dt">Int</span>

ghci<span class="fu">&gt;</span> <span class="fu">map</span> <span class="fu">length</span> [<span class="st">&quot;abc&quot;</span>, <span class="st">&quot;defg&quot;</span>]
[<span class="dv">3</span>,<span class="dv">4</span>]

ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">map</span>
<span class="fu">map</span><span class="ot"> ::</span> (a <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> [b]</code></pre>
<p>An instance of a Functor class must satisfy two laws. Firstly, it must satisfy the identity property where running the map over an id must return the id:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">fmap</span> <span class="fu">id</span> <span class="fu">=</span> <span class="fu">id</span></code></pre>
<p>For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">id</span> [<span class="st">&quot;abc&quot;</span>]
[<span class="st">&quot;abc&quot;</span>]

ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> <span class="fu">id</span> [<span class="st">&quot;abc&quot;</span>]
[<span class="st">&quot;abc&quot;</span>]</code></pre>
<p>Second, if we compose two functions and ‘fmap’ over it, then it must be the same as mapping the first function with the Functor, and then applying the second function as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">fmap</span> (f <span class="fu">.</span> g) <span class="fu">=</span> <span class="fu">fmap</span> f <span class="fu">.</span> <span class="fu">fmap</span> g</code></pre>
<p>This can also be written for a Functor ‘F’ as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">fmap</span> (f <span class="fu">.</span> g) <span class="dt">F</span> <span class="fu">=</span> <span class="fu">fmap</span> f (<span class="fu">fmap</span> g <span class="dt">F</span>)</code></pre>
<p>For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> (<span class="fu">negate</span> <span class="fu">.</span> <span class="fu">abs</span>) [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
[<span class="fu">-</span><span class="dv">1</span>,<span class="fu">-</span><span class="dv">2</span>,<span class="fu">-</span><span class="dv">3</span>,<span class="fu">-</span><span class="dv">4</span>,<span class="fu">-</span><span class="dv">5</span>]

ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> <span class="fu">negate</span> (<span class="fu">fmap</span> <span class="fu">abs</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>])
[<span class="fu">-</span><span class="dv">1</span>,<span class="fu">-</span><span class="dv">2</span>,<span class="fu">-</span><span class="dv">3</span>,<span class="fu">-</span><span class="dv">4</span>,<span class="fu">-</span><span class="dv">5</span>]</code></pre>
<p>The Maybe data type can also be an instance of the Functor class:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Maybe</span> a <span class="fu">=</span> <span class="kw">Just</span> a <span class="fu">|</span> <span class="kw">Nothing</span>
     <span class="kw">deriving</span> (<span class="kw">Eq</span>, <span class="kw">Ord</span>)

<span class="kw">instance</span> <span class="kw">Functor</span> <span class="dt">Maybe</span> <span class="kw">where</span>
    <span class="fu">fmap</span> f (<span class="kw">Just</span> x) <span class="fu">=</span> <span class="kw">Just</span> (f x)
    <span class="fu">fmap</span> f <span class="kw">Nothing</span> <span class="fu">=</span> <span class="kw">Nothing</span></code></pre>
<p>For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> (<span class="fu">+</span><span class="dv">2</span>) (<span class="kw">Nothing</span>)
<span class="kw">Nothing</span>

ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> (<span class="fu">+</span><span class="dv">2</span>) (<span class="kw">Just</span> <span class="dv">3</span>)
<span class="kw">Just</span> <span class="dv">5</span></code></pre>
<p>The two laws hold good for the Maybe data type:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">id</span> <span class="kw">Nothing</span>
<span class="kw">Nothing</span>

ghci<span class="fu">&gt;</span> <span class="fu">id</span> <span class="kw">Just</span> <span class="dv">4</span>
<span class="kw">Just</span> <span class="dv">4</span>

ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> (<span class="fu">negate</span> <span class="fu">.</span> <span class="fu">abs</span>) (<span class="kw">Just</span> <span class="dv">4</span>)
<span class="kw">Just</span> (<span class="fu">-</span><span class="dv">4</span>)

ghci<span class="fu">&gt;</span> <span class="fu">fmap</span> <span class="fu">negate</span> (<span class="fu">fmap</span> <span class="fu">abs</span> (<span class="kw">Just</span> <span class="dv">4</span>))
<span class="kw">Just</span> (<span class="fu">-</span><span class="dv">4</span>)</code></pre>
<p>The Applicative type class is defined to handle cases where a function is enclosed in a Functor, like ‘Just (*2)’:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Functor</span> f <span class="ot">=&gt;</span> <span class="kw">Applicative</span> f <span class="kw">where</span>
        <span class="co">-- | Lift a value.</span>
<span class="ot">        pure ::</span> a <span class="ot">-&gt;</span> f a

        <span class="co">-- | Sequential application.</span>
<span class="ot">        (&lt;*&gt;) ::</span> f (a <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> f a <span class="ot">-&gt;</span> f b</code></pre>
<p>The ‘&lt;$&gt;’ is defined as a synonym for ‘fmap’:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">(&lt;$&gt;) ::</span> <span class="kw">Functor</span> f <span class="ot">=&gt;</span> (a <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> f a <span class="ot">-&gt;</span> f b
f <span class="fu">&lt;$&gt;</span> a <span class="fu">=</span> <span class="fu">fmap</span> f a</code></pre>
<p>The Applicative Functor must also satisfy few mathematical laws. The Maybe data type can be an instance of the Applicative class:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"> <span class="kw">instance</span> <span class="kw">Applicative</span> <span class="dt">Maybe</span> <span class="kw">where</span>
    pure <span class="fu">=</span> <span class="kw">Just</span>
    (<span class="kw">Just</span> f) <span class="fu">&lt;*&gt;</span> (<span class="kw">Just</span> x) <span class="fu">=</span> <span class="kw">Just</span> (f x)
    _        <span class="fu">&lt;*&gt;</span> _        <span class="fu">=</span> <span class="kw">Nothing</span></code></pre>
<p>A few examples of Maybe for the Applicative type class are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Control.Applicative</span>

ghci<span class="fu">&gt;</span> <span class="kw">Just</span> (<span class="fu">+</span><span class="dv">2</span>) <span class="fu">&lt;*&gt;</span> <span class="kw">Just</span> <span class="dv">7</span>
<span class="kw">Just</span> <span class="dv">9</span>

ghci<span class="fu">&gt;</span> (<span class="fu">*</span>) <span class="fu">&lt;$&gt;</span> <span class="kw">Just</span> <span class="dv">3</span> <span class="fu">&lt;*&gt;</span> <span class="kw">Just</span> <span class="dv">4</span>
<span class="kw">Just</span> <span class="dv">12</span>

ghci<span class="fu">&gt;</span> <span class="fu">min</span> <span class="fu">&lt;$&gt;</span> <span class="kw">Just</span> <span class="dv">4</span> <span class="fu">&lt;*&gt;</span> <span class="kw">Just</span> <span class="dv">6</span>
<span class="kw">Just</span> <span class="dv">4</span>

ghci<span class="fu">&gt;</span> <span class="fu">max</span> <span class="fu">&lt;$&gt;</span> <span class="kw">Just</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">&lt;*&gt;</span> <span class="kw">Nothing</span>
<span class="kw">Nothing</span>

ghci<span class="fu">&gt;</span> <span class="fu">max</span> <span class="fu">&lt;$&gt;</span> <span class="kw">Just</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">&lt;*&gt;</span> <span class="kw">Just</span> <span class="st">&quot;World&quot;</span>
<span class="kw">Just</span> <span class="st">&quot;World&quot;</span></code></pre>
<p>The Applicative Functor unwraps the values before performing an operation.</p>
<p>For a data type to be an instance of the Monoid type class, it must satisfy two properties:</p>
<ol style="list-style-type: decimal">
<li>Identity value</li>
<li>Associative binary operator</li>
</ol>
<pre class="sourceCode haskell"><code class="sourceCode haskell">a <span class="fu">*</span> (b <span class="fu">*</span> c) <span class="fu">=</span> (a <span class="fu">*</span> b) <span class="fu">*</span> c</code></pre>
<p>These are defined in the Monoid type class:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="dt">Monoid</span> a <span class="kw">where</span>
<span class="ot">      mempty  ::</span> a           <span class="co">-- identity</span>
<span class="ot">      mappend ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> a <span class="co">-- associative binary operation</span></code></pre>
<p>Lists can be a Monoid. The identity operator is [] and the associative binary operator is (++). The instance definition of lists for a Monoid is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="dt">Monoid</span> [a] <span class="kw">where</span>
	 mempty  <span class="fu">=</span> []
	 mappend <span class="fu">=</span> (<span class="fu">++</span>)</code></pre>
<p>Some examples of lists as Monoid are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">import</span> <span class="dt">Data.Monoid</span>

ghci<span class="fu">&gt;</span> (<span class="st">&quot;a&quot;</span> <span class="ot">`mappend`</span> <span class="st">&quot;b&quot;</span>) <span class="ot">`mappend`</span> <span class="st">&quot;c&quot;</span>
<span class="st">&quot;abc&quot;</span>

ghci<span class="fu">&gt;</span> <span class="st">&quot;a&quot;</span> <span class="ot">`mappend`</span> (<span class="st">&quot;b&quot;</span> <span class="ot">`mappend`</span> <span class="st">&quot;c&quot;</span>)
<span class="st">&quot;abc&quot;</span>

ghci<span class="fu">&gt;</span> mempty <span class="ot">`mappend`</span> [<span class="dv">5</span>]
[<span class="dv">5</span>]</code></pre>
<p>The Monad type class takes a wrapped value and a function that does some computation after unwrapping the value, and returns a wrapped result. The Monad is a container type and hence a value is wrapped in it. The bind operation (&gt;&gt;=) is the important function in the Monad class that performs this operation. The ‘return’ function converts the result into a wrapped value. Monads are used for impure code where there can be side effects, for example, during a system call, performing IO etc. A data type that implements the Monad class must obey the Monad Laws. The definition of the Monad class is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Monad</span> m <span class="kw">where</span>
<span class="ot">  (&gt;&gt;=) ::</span> m a <span class="ot">-&gt;</span> (a <span class="ot">-&gt;</span> m b) <span class="ot">-&gt;</span> m b
<span class="ot">  (&gt;&gt;) ::</span> m a <span class="ot">-&gt;</span> m b <span class="ot">-&gt;</span> m b
<span class="ot">  return ::</span> a <span class="ot">-&gt;</span> m a
<span class="ot">  fail ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> m a</code></pre>
<p>The Maybe type is an instance of a Monad and is defined as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Monad</span> <span class="dt">Maybe</span> <span class="kw">where</span>
    <span class="fu">return</span> x <span class="fu">=</span> <span class="kw">Just</span> x
    <span class="kw">Nothing</span> <span class="fu">&gt;&gt;=</span> f <span class="fu">=</span> <span class="kw">Nothing</span>
    <span class="kw">Just</span> x <span class="fu">&gt;&gt;=</span> f  <span class="fu">=</span> f x
    <span class="fu">fail</span> _ <span class="fu">=</span> <span class="kw">Nothing</span></code></pre>
<p>So, when ’m’ is Maybe, and ‘a’ and ‘b’ are of type Int, the bind operation becomes:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">(&gt;&gt;=) ::</span> <span class="dt">Maybe</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> (<span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">Int</span>) <span class="ot">-&gt;</span> <span class="dt">Maybe</span> <span class="dt">Int</span></code></pre>
<p>Here’s an example of how the Maybe Monad is used:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">return</span> (<span class="kw">Just</span> <span class="dv">5</span>)
<span class="kw">Just</span> <span class="dv">5</span>

ghci<span class="fu">&gt;</span> <span class="fu">return</span> <span class="kw">Nothing</span>
<span class="kw">Nothing</span>

ghci<span class="fu">&gt;</span> <span class="kw">Just</span> <span class="dv">5</span> <span class="fu">&gt;&gt;=</span> \x <span class="ot">-&gt;</span> <span class="fu">return</span> (x <span class="fu">+</span> <span class="dv">7</span>)
<span class="kw">Just</span> <span class="dv">12</span>

ghci<span class="fu">&gt;</span> <span class="kw">Nothing</span> <span class="fu">&gt;&gt;=</span> \x <span class="ot">-&gt;</span> <span class="fu">return</span> (x <span class="fu">+</span> <span class="dv">7</span>)
<span class="kw">Nothing</span>

ghci<span class="fu">&gt;</span> <span class="kw">Just</span> <span class="dv">5</span> <span class="fu">&gt;&gt;=</span> \x <span class="ot">-&gt;</span> <span class="fu">return</span> (x <span class="fu">+</span> <span class="dv">7</span>) <span class="fu">&gt;&gt;=</span> \y <span class="ot">-&gt;</span> <span class="fu">return</span> (y <span class="fu">+</span> <span class="dv">2</span>)
<span class="kw">Just</span> <span class="dv">14</span></code></pre>
<p>The newtype keyword is used in Haskell to define a new data type that has only one constructor and only one field inside it. The Writer data type can be defined using the record syntax as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">newtype</span> <span class="dt">Writer</span> w a <span class="fu">=</span> <span class="dt">Writer</span> {<span class="ot"> runWriter ::</span> (a, w) }</code></pre>
<p>It can be an instance of a Monad as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Monoid</span>

<span class="kw">newtype</span> <span class="dt">Writer</span> w a <span class="fu">=</span> <span class="dt">Writer</span> {<span class="ot"> runWriter ::</span> (a, w) }

<span class="kw">instance</span> (<span class="dt">Monoid</span> w) <span class="ot">=&gt;</span> <span class="kw">Monad</span> (<span class="dt">Writer</span> w) <span class="kw">where</span>
    <span class="fu">return</span> x <span class="fu">=</span> <span class="dt">Writer</span> (x, mempty)
    (<span class="dt">Writer</span> (x,v)) <span class="fu">&gt;&gt;=</span> f <span class="fu">=</span> <span class="kw">let</span> (<span class="dt">Writer</span> (y, v')) <span class="fu">=</span> f x <span class="kw">in</span> <span class="dt">Writer</span> (y, v <span class="ot">`mappend`</span> v')</code></pre>
<p>To test the definition, you can write a double function as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">double ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Writer</span> <span class="dt">String</span> <span class="dt">Int</span>
double x <span class="fu">=</span> <span class="dt">Writer</span> (x <span class="fu">*</span> <span class="dv">2</span>, <span class="st">&quot; doubled &quot;</span> <span class="fu">++</span> (<span class="fu">show</span> x))</code></pre>
<p>You can execute it using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runWriter <span class="fu">$</span> double <span class="dv">3</span>
(<span class="dv">6</span>,<span class="st">&quot; doubled 3&quot;</span>)

ghci<span class="fu">&gt;</span> runWriter <span class="fu">$</span> double <span class="dv">3</span> <span class="fu">&gt;&gt;=</span> double
(<span class="dv">12</span>,<span class="st">&quot; doubled 3 doubled 6&quot;</span>)</code></pre>
<p>The evaluation for the bind operation is illustrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> runWriter <span class="fu">$</span> double <span class="dv">3</span> <span class="fu">&gt;&gt;=</span> double
(<span class="dv">12</span>,<span class="st">&quot; doubled 3 doubled 6&quot;</span>)

ghci<span class="fu">&gt;</span> runWriter <span class="fu">$</span> ((double <span class="dv">3</span>) <span class="fu">&gt;&gt;=</span> double)
(<span class="dv">12</span>,<span class="st">&quot; doubled 3 doubled 6&quot;</span>)

ghci<span class="fu">&gt;</span> runWriter <span class="fu">$</span> ((<span class="dt">Writer</span> (<span class="dv">6</span>, <span class="st">&quot;doubled 3&quot;</span>)) <span class="fu">&gt;&gt;=</span> double)
(<span class="dv">12</span>,<span class="st">&quot; doubled 3 doubled 6&quot;</span>)</code></pre>
<p>The arguments to runWriter are matched to the bind function definition in the Writer Monad. Thus, x == 6, v == ‘doubled 3’, and f == ‘double’. The function application of ‘f x’ is ‘double 6’ which yields ‘(12, “doubled 6”)’. Thus y is 12 and v’ is ‘doubled 6’. The result is wrapped into a Writer Monad with y as 12, and the string v concatenated with v’ to give ‘doubled 3 doubled 6’. This example is useful as a logger where you want a result and log messages appended together. As you can see the output differs with input, and hence this is impure code that has side effects.</p>
<p>When you have data types, classes and instance definitions, you can organize them into a module that others can reuse. To enclose the definitions inside a module, prepend them with the ‘module’ keyword. The module name must begin with a capital letter followed by a list of types and functions that are exported by the module. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">module</span> <span class="dt">Control.Monad.Writer.Class</span> (
    <span class="dt">MonadWriter</span>(<span class="fu">..</span>),
    listens,
    censor,
  ) <span class="kw">where</span>

<span class="fu">...</span></code></pre>
<p>You can import a module in your code or at the GHCi prompt, using the following command:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Control.Monad.Writer</span></code></pre>
<p>If you want to use only selected functions, you can selectively import them using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Control.Monad.Writer</span>(listens)</code></pre>
<p>If you want to import everything except a particular function, you can hide it while importing, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Control.Monad.Writer</span> <span class="kw">hiding</span> (censor)</code></pre>
<p>If two modules have the same function names, you can explicitly use the fully qualified name, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Control.Monad.Writer</span> </code></pre>
<p>You can then explicitly use the ‘listens’ functions in the module using Control.Monad.Writer.listens. You can also create an alias using the ‘as’ keyword:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Control.Monad.Writer</span> <span class="kw">as</span> <span class="dt">W</span></code></pre>
<p>You can then invoke the ‘listens’ function using W.listens.</p>
<p>Let us take an example of the iso8601-time 0.1.2 Haskell package. The module definition is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">module</span> <span class="dt">Data.Time.ISO8601</span>
  ( formatISO8601
  , formatISO8601Millis
  , formatISO8601Micros
  , formatISO8601Nanos
  , formatISO8601Picos
  , formatISO8601Javascript
  , parseISO8601
  ) <span class="kw">where</span></code></pre>
<p>It then imports few other modules:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Time.Clock</span> (<span class="dt">UTCTime</span>)
<span class="kw">import</span> <span class="dt">Data.Time.Format</span> (formatTime, parseTime)
<span class="kw">import</span> <span class="dt">System.Locale</span> (defaultTimeLocale)
<span class="kw">import</span> <span class="dt">Control.Applicative</span> ((<span class="fu">&lt;|&gt;</span>))</code></pre>
<p>This is followed by the definition of functions. Some of them are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="co">-- | Formats a time in ISO 8601, with up to 12 second decimals.</span>
<span class="fu">--</span>
<span class="co">-- This is the `formatTime` format @%FT%T%Q@ == @%%Y-%m-%dT%%H:%M:%S%Q@.</span>
<span class="ot">formatISO8601 ::</span> <span class="dt">UTCTime</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
formatISO8601 t <span class="fu">=</span> formatTime defaultTimeLocale <span class="st">&quot;%FT%T%QZ&quot;</span> t

<span class="co">-- | Pads an ISO 8601 date with trailing zeros, but lacking the trailing Z.</span>
<span class="fu">--</span>
<span class="co">-- This is needed because `formatTime` with &quot;%Q&quot; does not create trailing zeros.</span>

<span class="ot">formatPadded ::</span> <span class="dt">UTCTime</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
formatPadded t
  <span class="fu">|</span> <span class="fu">length</span> str <span class="fu">==</span> <span class="dv">19</span> <span class="fu">=</span> str <span class="fu">++</span> <span class="st">&quot;.000000000000&quot;</span>
  <span class="fu">|</span> <span class="fu">otherwise</span>        <span class="fu">=</span> str <span class="fu">++</span> <span class="st">&quot;000000000000&quot;</span>
  <span class="kw">where</span>
    str <span class="fu">=</span> formatTime defaultTimeLocale <span class="st">&quot;%FT%T%Q&quot;</span> t

<span class="co">-- | Formats a time in ISO 8601 with up to millisecond precision and trailing zeros.</span>
<span class="co">-- The format is precisely:</span>
<span class="fu">--</span>
<span class="co">-- &gt;YYYY-MM-DDTHH:mm:ss.sssZ</span>
<span class="ot">formatISO8601Millis ::</span> <span class="dt">UTCTime</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
formatISO8601Millis t <span class="fu">=</span> <span class="fu">take</span> <span class="dv">23</span> (formatPadded t) <span class="fu">++</span> <span class="st">&quot;Z&quot;</span>
<span class="fu">...</span></code></pre>
<p>The availability of free and open source software allows you to learn a lot from reading the source code, and it is a very essential practice if you want to improve your programming skills.</p>]]></description>
    <pubDate>Thu, 20 Aug 2015 10:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/08/20/more-type-classes/news.html</guid>
</item>
<item>
    <title>International edition - i want 2 do project. tell me wat 2 do</title>
    <link>http://www.shakthimaan.com/posts/2015/07/26/i-want-2-do-project-tell-me-wat-2-do-international-edition/news.html</link>
    <description><![CDATA[<p>This year, 2015, marks a decade of completion of my website shakthimaan.com! Thanks to the grace of God, the Almighty. Thanks also to my parents, friends and well-wishers for their wonderful support and encouragement over the years.</p>
<p>I am also happy to announce the launch of the international hard cover edition of my book, “i want 2 do project. tell me wat 2 do”, for worldwide distribution. You can order the book at:</p>
<ul>
<li><p>Amazon.com <a href="http://www.amazon.com/want-project-tell-wat-do/dp/9351967387">http://www.amazon.com/want-project-tell-wat-do/dp/9351967387</a></p></li>
<li><p>Dogears Etc. <a href="http://www.dogearsetc.com/books/I-Want-To-Do-A-Project.-Tell-Me-What-To-Do./38632">http://www.dogearsetc.com/books/I-Want-To-Do-A-Project.-Tell-Me-What-To-Do./38632</a></p></li>
<li><p>Infibeam <a href="http://www.infibeam.com/Books/i-want-do-project-tell-me-what-do-shakthi-kannan/9789351967835.html">http://www.infibeam.com/Books/i-want-do-project-tell-me-what-do-shakthi-kannan/9789351967835.html</a></p></li>
</ul>
<div class="figure">
<img src="http://shakthimaan.com/images/books/hard-soft-cover-books.png" title="Soft and Hard cover editions"></img><p class="caption"></p>
</div>
<p>The topics covered in the book include:</p>
<ul>
<li>Mailing List Guidelines</li>
<li>Attention to Detail</li>
<li>Project Communication</li>
<li>Project Guidelines</li>
<li>Development Guidelines</li>
<li>Methodology of Work</li>
<li>Tools</li>
<li>Reading and Writing</li>
<li>Art of Making Presentations</li>
<li>Sustenance</li>
</ul>
<p>The “Mailing List Guidelines” sample chapter is available for download from:</p>
<p><a href="http://shakthimaan.com/downloads/book/chapter1.pdf">http://shakthimaan.com/downloads/book/chapter1.pdf</a></p>
<p>The home page for the book is at:</p>
<p><a href="http://www.shakthimaan.com/what-to-do.html">http://www.shakthimaan.com/what-to-do.html</a></p>
<p>Kindly forward this information to your friends who may also benefit from the same when working with free and open source software.</p>]]></description>
    <pubDate>Sun, 26 Jul 2015 16:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/07/26/i-want-2-do-project-tell-me-wat-2-do-international-edition/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - Type Classes and User Defined Data Types</title>
    <link>http://www.shakthimaan.com/posts/2015/07/10/type-classes-and-user-defined-types/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, October 2014 edition.]</em></p>
<p>Haskell is purely a functional programming language and it enforces strictness with the use of types. In this article, we shall explore type classes and user defined data types.</p>
<p>Consider the <em>elem</em> function that takes an element of a type, a list, and returns ‘true’ if the element is a member of the list; and if not, it returns ‘false’. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="dv">2</span> <span class="ot">`elem`</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="kw">True</span>
ghci<span class="fu">&gt;</span> <span class="dv">5</span> <span class="ot">`elem`</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="kw">False</span></code></pre>
<p>It’s type signature is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">elem</span>
<span class="fu">elem</span><span class="ot"> ::</span> <span class="kw">Eq</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> <span class="dt">Bool</span></code></pre>
<p>The type signature states that the type variable ‘a’ must be an instance of class ‘Eq’. The class constraint is specified after the ’::’ symbol and before the ‘=&gt;’ symbol in the type signature. The <em>elem</em> function will thus work for all types that are instances of the Eq class.</p>
<p>The word ‘class’ has a different meaning in functional programming. A type class is a parameterised interface that defines functions. A type that is an instance of a type class needs to implement the defined functions of the type class. The <em>Eq</em> class defines functions to assert if two type values are equal or not. Its definition in Haskell is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Eq</span> a <span class="kw">where</span>
    (<span class="fu">==</span>),<span class="ot"> (/=)           ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Bool</span>

    x <span class="fu">/=</span> y               <span class="fu">=</span> <span class="fu">not</span> (x <span class="fu">==</span> y)
    x <span class="fu">==</span> y               <span class="fu">=</span> <span class="fu">not</span> (x <span class="fu">/=</span> y)</code></pre>
<p>The keyword <em>class</em> is used to define a type class. This is followed by the name of the class (starting with a capital letter). A type variable (‘a’ here) is written after the class name. Two functions are listed in this class for finding if two values of a type are equal or not. A minimal definition for the two functions is also provided. This code is available in <em>libraries/ghc-prim/GHC/Classes.hs</em> in the GHC (Glasgow Haskell Compiler) source code.</p>
<p>The example works for integers ‘2’ and ‘5’ in the example above, because they are of type <em>Int</em>, which is an instance of <em>Eq</em>. Its corresponding definition is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Int</span> <span class="kw">where</span>
    (<span class="fu">==</span>) <span class="fu">=</span> eqInt
    (<span class="fu">/=</span>) <span class="fu">=</span> neInt</code></pre>
<p>The keyword <em>instance</em> is used in the definition followed by the name of the class Eq, and a specific type <em>Int</em>. It uses two primitive functions <em>eqInt</em> and <em>neInt</em> for checking if the given integers are equal or not. The detailed definition is available in <em>libraries/ghc-prim/GHC/Classes.hs</em> in the GHC source code.</p>
<p>There are a number of pre-defined type classes available in the Haskell platform.</p>
<p>The Ord type class denotes types that can be compared. The <em>compare</em> function will need to be implemented by types that want to be instances of this class. The resultant values of ‘compare’ are GT, LT, or EQ. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="ch">'p'</span> <span class="fu">&gt;</span> <span class="ch">'q'</span>
<span class="kw">False</span>
ghci<span class="fu">&gt;</span> <span class="dv">3</span> <span class="fu">&gt;</span> <span class="dv">2</span>
<span class="kw">True</span></code></pre>
<p>Its type class definition is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> (<span class="kw">Eq</span> a) <span class="ot">=&gt;</span> <span class="kw">Ord</span> a <span class="kw">where</span>
<span class="ot">    compare              ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Ordering</span>
    (<span class="fu">&lt;</span>), (<span class="fu">&lt;=</span>), (<span class="fu">&gt;</span>),<span class="ot"> (&gt;=) ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Bool</span>
    <span class="fu">max</span>,<span class="ot"> min             ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> a

    <span class="fu">compare</span> x y <span class="fu">=</span> <span class="kw">if</span> x <span class="fu">==</span> y <span class="kw">then</span> <span class="kw">EQ</span>
                  <span class="kw">else</span> <span class="kw">if</span> x <span class="fu">&lt;=</span> y <span class="kw">then</span> <span class="kw">LT</span>
                  <span class="kw">else</span> <span class="kw">GT</span>

    x <span class="fu">&lt;</span>  y <span class="fu">=</span> <span class="kw">case</span> <span class="fu">compare</span> x y <span class="kw">of</span> { <span class="kw">LT</span> <span class="ot">-&gt;</span> <span class="kw">True</span>;  _ <span class="ot">-&gt;</span> <span class="kw">False</span> }
    x <span class="fu">&lt;=</span> y <span class="fu">=</span> <span class="kw">case</span> <span class="fu">compare</span> x y <span class="kw">of</span> { <span class="kw">GT</span> <span class="ot">-&gt;</span> <span class="kw">False</span>; _ <span class="ot">-&gt;</span> <span class="kw">True</span> }
    x <span class="fu">&gt;</span>  y <span class="fu">=</span> <span class="kw">case</span> <span class="fu">compare</span> x y <span class="kw">of</span> { <span class="kw">GT</span> <span class="ot">-&gt;</span> <span class="kw">True</span>;  _ <span class="ot">-&gt;</span> <span class="kw">False</span> }
    x <span class="fu">&gt;=</span> y <span class="fu">=</span> <span class="kw">case</span> <span class="fu">compare</span> x y <span class="kw">of</span> { <span class="kw">LT</span> <span class="ot">-&gt;</span> <span class="kw">False</span>; _ <span class="ot">-&gt;</span> <span class="kw">True</span> }

    <span class="fu">max</span> x y <span class="fu">=</span> <span class="kw">if</span> x <span class="fu">&lt;=</span> y <span class="kw">then</span> y <span class="kw">else</span> x
    <span class="fu">min</span> x y <span class="fu">=</span> <span class="kw">if</span> x <span class="fu">&lt;=</span> y <span class="kw">then</span> x <span class="kw">else</span> y</code></pre>
<p>The Ord type class needs to be a sub-class of the Eq class because we should be able to test for equality of two values if they need to be compared. This is also defined as a constraint in the class definition. Seven functions are provided and a minimal definition given in the code snippet. The instance definitions for <em>Char</em> and <em>Int</em> types are available from <em>libraries/ghc-prim/GHC/Classes.hs</em> in the GHC source code.</p>
<p>The <em>Enum</em> type class is for types whose values can be listed in an order for which you can find predecessor and successor elements. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">succ</span> <span class="ch">'a'</span>
b
ghci<span class="fu">&gt;</span> <span class="fu">pred</span> <span class="kw">EQ</span>
<span class="kw">LT</span></code></pre>
<p>The class definition for <em>Enum</em> is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Enum</span> a <span class="kw">where</span>
<span class="ot">    succ                ::</span> a <span class="ot">-&gt;</span> a
<span class="ot">    pred                ::</span> a <span class="ot">-&gt;</span> a
<span class="ot">    toEnum              ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> a
<span class="ot">    fromEnum            ::</span> a <span class="ot">-&gt;</span> <span class="dt">Int</span>

<span class="ot">    enumFrom            ::</span> a <span class="ot">-&gt;</span> [a]
<span class="ot">    enumFromThen        ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> [a]
<span class="ot">    enumFromTo          ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> [a]
<span class="ot">    enumFromThenTo      ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> [a]

    <span class="fu">succ</span>                   <span class="fu">=</span> <span class="fu">toEnum</span> <span class="fu">.</span> (<span class="fu">+</span> <span class="dv">1</span>)  <span class="fu">.</span> <span class="fu">fromEnum</span>
    <span class="fu">pred</span>                   <span class="fu">=</span> <span class="fu">toEnum</span> <span class="fu">.</span> (<span class="fu">subtract</span> <span class="dv">1</span>) <span class="fu">.</span> <span class="fu">fromEnum</span>
    <span class="fu">enumFrom</span> x             <span class="fu">=</span> <span class="fu">map</span> <span class="fu">toEnum</span> [<span class="fu">fromEnum</span> x <span class="fu">..</span>]
    <span class="fu">enumFromThen</span> x y       <span class="fu">=</span> <span class="fu">map</span> <span class="fu">toEnum</span> [<span class="fu">fromEnum</span> x, <span class="fu">fromEnum</span> y <span class="fu">..</span>]
    <span class="fu">enumFromTo</span> x y         <span class="fu">=</span> <span class="fu">map</span> <span class="fu">toEnum</span> [<span class="fu">fromEnum</span> x <span class="fu">..</span> <span class="fu">fromEnum</span> y]
    <span class="fu">enumFromThenTo</span> x1 x2 y <span class="fu">=</span> <span class="fu">map</span> <span class="fu">toEnum</span> [<span class="fu">fromEnum</span> x1, <span class="fu">fromEnum</span> x2 <span class="fu">..</span> <span class="fu">fromEnum</span> y]</code></pre>
<p>The instance for type Ordering for the <em>Enum</em> class is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Enum</span> <span class="dt">Ordering</span> <span class="kw">where</span>
  <span class="fu">succ</span> <span class="kw">LT</span> <span class="fu">=</span> <span class="kw">EQ</span>
  <span class="fu">succ</span> <span class="kw">EQ</span> <span class="fu">=</span> <span class="kw">GT</span>
  <span class="fu">succ</span> <span class="kw">GT</span> <span class="fu">=</span> <span class="fu">error</span> <span class="st">&quot;Prelude.Enum.Ordering.succ: bad argument&quot;</span>

  <span class="fu">pred</span> <span class="kw">GT</span> <span class="fu">=</span> <span class="kw">EQ</span>
  <span class="fu">pred</span> <span class="kw">EQ</span> <span class="fu">=</span> <span class="kw">LT</span>
  <span class="fu">pred</span> <span class="kw">LT</span> <span class="fu">=</span> <span class="fu">error</span> <span class="st">&quot;Prelude.Enum.Ordering.pred: bad argument&quot;</span>

  <span class="fu">toEnum</span> n <span class="fu">|</span> n <span class="fu">==</span> <span class="dv">0</span> <span class="fu">=</span> <span class="kw">LT</span>
           <span class="fu">|</span> n <span class="fu">==</span> <span class="dv">1</span> <span class="fu">=</span> <span class="kw">EQ</span>
           <span class="fu">|</span> n <span class="fu">==</span> <span class="dv">2</span> <span class="fu">=</span> <span class="kw">GT</span>
  <span class="fu">toEnum</span> _ <span class="fu">=</span> <span class="fu">error</span> <span class="st">&quot;Prelude.Enum.Ordering.toEnum: bad argument&quot;</span>

  <span class="fu">fromEnum</span> <span class="kw">LT</span> <span class="fu">=</span> <span class="dv">0</span>
  <span class="fu">fromEnum</span> <span class="kw">EQ</span> <span class="fu">=</span> <span class="dv">1</span>
  <span class="fu">fromEnum</span> <span class="kw">GT</span> <span class="fu">=</span> <span class="dv">2</span>

  <span class="co">-- Use defaults for the rest</span>
  <span class="fu">enumFrom</span>     <span class="fu">=</span> boundedEnumFrom
  <span class="fu">enumFromThen</span> <span class="fu">=</span> boundedEnumFromThen</code></pre>
<p>You can find the definition and instance definitions for <em>Char</em> and <em>Ordering</em> in <em>libraries/base/GHC/Enum.lhs</em> in the GHC source code.</p>
<p>The <em>Show</em> type class lists a <em>show</em> function to display or print data. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">show</span> <span class="fl">3.1415</span>
<span class="st">&quot;3.1415</span>
<span class="st">ghci&gt; show True</span>
<span class="st">&quot;</span><span class="dt">True</span><span class="st">&quot;</span></code></pre>
<p>The above code works for both ‘Float’ and ‘Bool’ because there are instance definitions for each in the Show type class.</p>
<p>The <em>read</em> function for the ‘Read’ type class takes as input a ‘String’ and converts it to an appropriate data type, if possible. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">read</span> <span class="st">&quot;1&quot;</span> <span class="fu">+</span> <span class="fl">2.0</span>
<span class="fl">3.0</span>
ghci<span class="fu">&gt;</span> <span class="fu">read</span> <span class="st">&quot;False&quot;</span> <span class="fu">||</span> <span class="kw">True</span>
<span class="kw">True</span></code></pre>
<p>You will find the class definitions and instances for <em>Show</em> and <em>Read</em> in <em>libraries/base/GHC/Show.lhs and libraries/base/GHC/Read.lhs</em> respectively. The .lhs file is a literate Haskell source file in which you can combine both text and code. You can also find the definition for a class, a function or type inside GHCi using ’:i’. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>i <span class="kw">Eq</span>
<span class="kw">class</span> <span class="kw">Eq</span> a <span class="kw">where</span>
<span class="ot">  (==) ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Bool</span>
<span class="ot">  (/=) ::</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Bool</span>
  	<span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Integer</span> <span class="co">-- Defined in `integer-gmp:GHC.Integer.Type'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Ordering</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Float</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Double</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Char</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Bool</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="fu">...</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>i <span class="fu">read</span>
<span class="fu">read</span><span class="ot"> ::</span> <span class="kw">Read</span> a <span class="ot">=&gt;</span> <span class="dt">String</span> <span class="ot">-&gt;</span> a 	<span class="co">-- Defined in `Text.Read'</span>

ghci<span class="fu">&gt;</span> <span class="fu">:</span>i <span class="dt">Int</span>
<span class="kw">data</span> <span class="dt">Int</span> <span class="fu">=</span> <span class="dt">GHC.Types.I</span><span class="fu">#</span> <span class="dt">GHC.Prim.Int</span><span class="fu">#</span> 	<span class="co">-- Defined in `GHC.Types'</span>
<span class="kw">instance</span> <span class="kw">Bounded</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Enum'</span>
<span class="kw">instance</span> <span class="kw">Enum</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Enum'</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Integral</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Real'</span>
<span class="kw">instance</span> <span class="kw">Num</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Num'</span>
<span class="kw">instance</span> <span class="kw">Ord</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Classes'</span>
<span class="kw">instance</span> <span class="kw">Read</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Read'</span>
<span class="kw">instance</span> <span class="kw">Real</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Real'</span>
<span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">Int</span> <span class="co">-- Defined in `GHC.Show'</span></code></pre>
<p>Let’s suppose you input the following in a GHCi prompt:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">read</span> <span class="st">&quot;3&quot;</span>

<span class="fu">&lt;</span>interactive<span class="fu">&gt;:</span><span class="dv">5</span><span class="fu">:</span><span class="dv">1</span><span class="fu">:</span>
    <span class="dt">No</span> <span class="kw">instance</span> for (<span class="kw">Read</span> a0) arising from a use <span class="kw">of</span> <span class="ot">`read'</span>
<span class="ot">    The type variable `</span>a0' is ambiguous
    <span class="dt">Possible</span> fix<span class="fu">:</span> add a <span class="kw">type</span> signature that fixes these <span class="kw">type</span> variable(s)
    <span class="dt">Note</span><span class="fu">:</span> there are several potential instances<span class="fu">:</span>
      <span class="kw">instance</span> <span class="kw">Read</span> () <span class="co">-- Defined in `GHC.Read'</span>
      <span class="kw">instance</span> (<span class="kw">Read</span> a, <span class="kw">Read</span> b) <span class="ot">=&gt;</span> <span class="kw">Read</span> (a, b) <span class="co">-- Defined in `GHC.Read'</span>
      <span class="kw">instance</span> (<span class="kw">Read</span> a, <span class="kw">Read</span> b, <span class="kw">Read</span> c) <span class="ot">=&gt;</span> <span class="kw">Read</span> (a, b, c)
        <span class="co">-- Defined in `GHC.Read'</span>
      <span class="fu">...</span>plus <span class="dv">25</span> others
    <span class="dt">In</span> the expression<span class="fu">:</span> <span class="fu">read</span> <span class="st">&quot;3&quot;</span>
    <span class="dt">In</span> an equation for <span class="ot">`it': it = read &quot;3&quot;</span></code></pre>
<p>The interpreter does not know what type to convert ‘3’ to, and hence you will need to explicitly specify the type:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">read</span> <span class="st">&quot;3&quot;</span><span class="ot"> ::</span> <span class="dt">Int</span>
<span class="dv">3</span>
ghci<span class="fu">&gt;</span> <span class="fu">read</span> <span class="st">&quot;3&quot;</span><span class="ot"> ::</span> <span class="dt">Float</span>
<span class="fl">3.0</span></code></pre>
<p>A <em>type</em> synonym is an alias that you can use for a type. ‘String’ in the Haskell platform is an array of characters defined using the <em>type</em> keyword:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">String</span> <span class="fu">=</span> [<span class="dt">Char</span>]</code></pre>
<p>You can also create a new user data type using the <em>data</em> keyword. Consider a Weekday data type that has the list of days in a week:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Weekday</span> <span class="fu">=</span> <span class="dt">Monday</span>
             <span class="fu">|</span> <span class="dt">Tuesday</span>
             <span class="fu">|</span> <span class="dt">Wednesday</span>
             <span class="fu">|</span> <span class="dt">Thursday</span>
             <span class="fu">|</span> <span class="dt">Friday</span>
             <span class="fu">|</span> <span class="dt">Saturday</span>
             <span class="fu">|</span> <span class="dt">Sunday</span></code></pre>
<p>The <em>data</em> keyword is followed by the name of the data type, starting with a capital letter. After the ‘equal to’ (‘=’) sign, the various value constructors are listed. The different constructors are separated by a pipe (‘|’) symbol.</p>
<p>If you load the above data type in GHCi, you can test the value constructors:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>t <span class="dt">Monday</span>
<span class="dt">Monday</span><span class="ot"> ::</span> <span class="dt">Weekday</span></code></pre>
<p>Each value constructor can have many type values. The user defined data type can also derive from type classes. Since the primitive data types already derive from the basic type classes, the user defined data types can also be derived. Otherwise, you will need to write instance definitions for the same. The following is an example for a user data type ‘Date’ that derives from the ‘Show’ type class for displaying the date:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Date</span> <span class="fu">=</span> <span class="dt">Int</span> <span class="dt">String</span> <span class="dt">Int</span> <span class="kw">deriving</span> (<span class="kw">Show</span>)</code></pre>
<p>Loading the above in GHCi, you get:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="dt">Date</span> <span class="dv">3</span> <span class="st">&quot;September&quot;</span> <span class="dv">2014</span> 
<span class="dt">Date</span> <span class="dv">3</span> <span class="st">&quot;September&quot;</span> <span class="dv">2014</span></code></pre>
<p>The above code will work even if we swap the year and day because the syntax is correct but the semantics are not!</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="dt">Date</span> <span class="dv">2014</span> <span class="st">&quot;September&quot;</span> <span class="dv">3</span> 
<span class="dt">Date</span> <span class="dv">2014</span> <span class="st">&quot;September&quot;</span> <span class="dv">3</span></code></pre>
<p>You can also use the record syntax that can give you helper functions:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Date</span> <span class="fu">=</span> <span class="dt">Date</span> {<span class="ot"> day ::</span> <span class="dt">Int</span>
                 ,<span class="ot"> month ::</span> <span class="dt">String</span>         
                 ,<span class="ot"> year ::</span> <span class="dt">Int</span>
                 }</code></pre>
<p>This gives you three helper functions to retrieve the day, month and year from a ‘Date’.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">let</span> d <span class="fu">=</span> <span class="dt">Date</span> {day <span class="fu">=</span> <span class="dv">14</span>, month <span class="fu">=</span> <span class="st">&quot;September&quot;</span>, year <span class="fu">=</span> <span class="dv">2014</span>}
ghci<span class="fu">&gt;</span> day d
<span class="dv">14</span>
ghci<span class="fu">&gt;</span> month d
<span class="st">&quot;September&quot;</span></code></pre>
<p>You can also make data type definition more explicit with types:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Date</span> <span class="fu">=</span> <span class="dt">Date</span> <span class="dt">Day</span> <span class="dt">Month</span> <span class="dt">Year</span> <span class="kw">deriving</span> (<span class="kw">Show</span>)

<span class="kw">type</span> <span class="dt">Year</span> <span class="fu">=</span> <span class="dt">Int</span>

<span class="kw">type</span> <span class="dt">Day</span> <span class="fu">=</span> <span class="dt">Int</span>

<span class="kw">data</span> <span class="dt">Month</span> <span class="fu">=</span> <span class="dt">January</span> 
     <span class="fu">|</span> <span class="dt">February</span>
     <span class="fu">|</span> <span class="dt">March</span>
     <span class="fu">|</span> <span class="dt">April</span>
     <span class="fu">|</span> <span class="dt">May</span>
     <span class="fu">|</span> <span class="dt">June</span>
     <span class="fu">|</span> <span class="dt">July</span>
     <span class="fu">|</span> <span class="dt">August</span>
     <span class="fu">|</span> <span class="dt">September</span>
     <span class="fu">|</span> <span class="dt">October</span>
     <span class="fu">|</span> <span class="dt">November</span>
     <span class="fu">|</span> <span class="dt">December</span>
     <span class="kw">deriving</span> (<span class="kw">Show</span>)</code></pre>
<p>Loading the above in GHCi, you can use:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="dt">Date</span> <span class="dv">3</span> <span class="dt">September</span> <span class="dv">2014</span>
<span class="dt">Date</span> <span class="dv">3</span> <span class="dt">September</span> <span class="dv">2014</span></code></pre>
<p>To support printing the date in a specific format, you can implement an instance for the ‘Show’ type class. You can also add a check to ensure that the day is within a range, and the year and day cannot be swapped:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">Date</span> <span class="kw">where</span>
    <span class="fu">show</span> (<span class="dt">Date</span> d m y)
         <span class="fu">|</span> d <span class="fu">&gt;</span> <span class="dv">0</span> <span class="fu">&amp;&amp;</span> d <span class="fu">&lt;=</span> <span class="dv">31</span> <span class="fu">=</span> (<span class="fu">show</span> d <span class="fu">++</span> <span class="st">&quot; &quot;</span> <span class="fu">++</span> <span class="fu">show</span> m <span class="fu">++</span> <span class="st">&quot; &quot;</span> <span class="fu">++</span> <span class="fu">show</span> y)
         <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="fu">error</span> <span class="st">&quot;Invalid day&quot;</span></code></pre>
<p>Loading the code in GHCi, and running the following:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">show</span> (<span class="dt">Date</span> <span class="dv">3</span> <span class="dt">September</span> <span class="dv">2014</span>)
<span class="st">&quot;3 September 2014&quot;</span>
ghci<span class="fu">&gt;</span> <span class="fu">show</span> (<span class="dt">Date</span> <span class="dv">2014</span> <span class="dt">September</span> <span class="dv">2</span>)
<span class="st">&quot;*** Exception: Invalid day</span></code></pre>
<p>Suppose, you wish to support different Gregorian date formats, you can define a data type GregorianDate as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">GregorianDate</span> <span class="fu">=</span> <span class="dt">DMY</span> <span class="dt">Day</span> <span class="dt">Month</span> <span class="dt">Year</span> <span class="fu">|</span> <span class="dt">YMD</span> <span class="dt">Year</span> <span class="dt">Month</span> <span class="dt">Day</span></code></pre>
<p>You can also define your own type classes for functions that define their own behaviour. For example, if you wish to dump the output of a date that is separated by dashes, you can write a ‘Dashed’ class with a <em>dash</em> function.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="dt">Dashed</span> a <span class="kw">where</span>
<span class="ot">    dash ::</span> a <span class="ot">-&gt;</span> <span class="dt">String</span>

<span class="kw">instance</span> <span class="dt">Dashed</span> <span class="dt">Date</span> <span class="kw">where</span>
    dash (<span class="dt">Date</span> d m y) <span class="fu">=</span> <span class="fu">show</span> d <span class="fu">++</span> <span class="st">&quot;-&quot;</span> <span class="fu">++</span> <span class="fu">show</span> m <span class="fu">++</span> <span class="st">&quot;-&quot;</span> <span class="fu">++</span> <span class="fu">show</span> y</code></pre>
<p>Testing the above in GHCi will give the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> dash (<span class="dt">Date</span> <span class="dv">14</span> <span class="dt">September</span> <span class="dv">2014</span>)
<span class="st">&quot;14-September-2014&quot;</span></code></pre>
<p>Haskell allows you to define recursive data types also. A parameterized list is defined as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">List</span> a <span class="fu">=</span> <span class="dt">Empty</span> <span class="fu">|</span> <span class="dt">Cons</span> a (<span class="dt">List</span> a) <span class="kw">deriving</span> (<span class="kw">Show</span>)</code></pre>
<p>Lists for the above definition can be created in GHCi, using the following commands:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="dt">Empty</span>
<span class="dt">Empty</span>
ghci<span class="fu">&gt;</span> (<span class="dt">Cons</span> <span class="dv">3</span> (<span class="dt">Cons</span> <span class="dv">2</span> (<span class="dt">Cons</span> <span class="dv">1</span> <span class="dt">Empty</span>)))
(<span class="dt">Cons</span> <span class="dv">3</span> (<span class="dt">Cons</span> <span class="dv">2</span> (<span class="dt">Cons</span> <span class="dv">1</span> <span class="dt">Empty</span>)))</code></pre>]]></description>
    <pubDate>Fri, 10 Jul 2015 22:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/07/10/type-classes-and-user-defined-types/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell - More Functions</title>
    <link>http://www.shakthimaan.com/posts/2015/06/22/more-haskell-functions/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, September 2014 edition.]</em></p>
<p>In the third article in the series, we will focus on more Haskell functions, conditional constructs and their usage.</p>
<p>A function in Haskell has the function name followed by arguments. An infix operator function has operands on either side of it. A simple infix <em>add</em> operation is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="dv">3</span> <span class="fu">+</span> <span class="dv">5</span>
<span class="dv">8</span></code></pre>
<p>If you wish to convert an infix function to a prefix function, it must be enclosed within parenthesis:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">3</span> <span class="dv">5</span>
<span class="dv">8</span></code></pre>
<p>Similarily, if you wish to convert a prefix function into an infix function, you must enclose the function name within <em>backquotes(`)</em>. The <em>elem</em> function takes an element and a list, and returns true if the element is a member of the list:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="dv">3</span> <span class="ot">`elem`</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="kw">True</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="dv">4</span> <span class="ot">`elem`</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="kw">False</span></code></pre>
<p>Functions can also be partially applied in Haskell. A function that subtracts <em>ten</em> from a given number can be defined as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">diffTen ::</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">Integer</span>
diffTen <span class="fu">=</span> (<span class="dv">10</span> <span class="fu">-</span>)</code></pre>
<p>Loading the file in GHCi and passing <em>three</em> as an argument yields:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> diffTen <span class="dv">3</span>
<span class="dv">7</span></code></pre>
<p>Haskell exhibits polymorphism. A type variable in a function is said to be polymorphic if it can take any type. Consider the <em>last</em> function that returns the last element in an array. Its type signature is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">last</span>
<span class="fu">last</span><span class="ot"> ::</span> [a] <span class="ot">-&gt;</span> a</code></pre>
<p>The ‘a’ in the above snippet refers to a type variable and can represent any type. Thus, the last function can operate on a list of integers or characters (string):</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">last</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
<span class="dv">5</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">last</span> <span class="st">&quot;Hello, World&quot;</span>
<span class="ch">'d'</span></code></pre>
<p>You can use a <em>where</em> clause for local definitions inside a function, as shown in the following example, to compute the area of a circle:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">areaOfCircle ::</span> <span class="dt">Float</span> <span class="ot">-&gt;</span> <span class="dt">Float</span>
areaOfCircle radius <span class="fu">=</span> <span class="fu">pi</span> <span class="fu">*</span> radius <span class="fu">*</span> radius
  <span class="kw">where</span> <span class="fu">pi</span> <span class="fu">=</span> <span class="fl">3.1415</span></code></pre>
<p>Loading it in GHCi and computing the area for radius 1 gives:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> areaOfCircle <span class="dv">1</span>
<span class="fl">3.1415</span></code></pre>
<p>You can also use the <em>let</em> expression with the <em>in</em> statement to compute the area of a circle:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">areaOfCircle ::</span> <span class="dt">Float</span> <span class="ot">-&gt;</span> <span class="dt">Float</span>
areaOfCircle radius <span class="fu">=</span> <span class="kw">let</span> <span class="fu">pi</span> <span class="fu">=</span> <span class="fl">3.1415</span> <span class="kw">in</span> <span class="fu">pi</span> <span class="fu">*</span> radius <span class="fu">*</span> radius</code></pre>
<p>Executing the above with input radius 1 gives:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> areaOfCircle <span class="dv">1</span>
<span class="fl">3.1415</span></code></pre>
<p>Indentation is very important in Haskell as it helps in code readability - the compiler will emit errors otherwise. You must make use of white spaces instead of tab when aligning code. If the <em>let</em> and <em>in</em> constructs in a function span multiple lines, they must be aligned vertically as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">compute ::</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">Integer</span>
compute x y <span class="fu">=</span>
    <span class="kw">let</span> a <span class="fu">=</span> x <span class="fu">+</span> <span class="dv">1</span>
        b <span class="fu">=</span> y <span class="fu">+</span> <span class="dv">2</span>
    <span class="kw">in</span>
      a <span class="fu">*</span> b</code></pre>
<p>Loading the example with GHCi, you get the following output:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> compute <span class="dv">1</span> <span class="dv">2</span>
<span class="dv">8</span></code></pre>
<p>Similarily, the <em>if</em> and <em>else</em> constructs must be neatly aligned. The <em>else</em> statement is mandatory in Haskell. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sign ::</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
sign x <span class="fu">=</span>
    <span class="kw">if</span> x <span class="fu">&gt;</span> <span class="dv">0</span> 
    <span class="kw">then</span> <span class="st">&quot;Positive&quot;</span>
    <span class="kw">else</span>
        <span class="kw">if</span> x <span class="fu">&lt;</span> <span class="dv">0</span>
        <span class="kw">then</span> <span class="st">&quot;Negative&quot;</span>
        <span class="kw">else</span> <span class="st">&quot;Zero&quot;</span></code></pre>
<p>Running the example with GHCi, you get:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">0</span>
<span class="st">&quot;Zero&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">1</span>
<span class="st">&quot;Positive&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign (<span class="fu">-</span><span class="dv">1</span>)
<span class="st">&quot;Negative&quot;</span></code></pre>
<p>The case construct can be used for pattern matching against possible expression values. It needs to be combined with the <em>of</em> keyword. The different values need to be aligned and the resulting action must be specified after the ’-&gt;’ symbol for every case. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sign ::</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
sign x <span class="fu">=</span>
    <span class="kw">case</span> <span class="fu">compare</span> x <span class="dv">0</span> <span class="kw">of</span>
      <span class="kw">LT</span> <span class="ot">-&gt;</span> <span class="st">&quot;Negative&quot;</span>
      <span class="kw">GT</span> <span class="ot">-&gt;</span> <span class="st">&quot;Positive&quot;</span>
      <span class="kw">EQ</span> <span class="ot">-&gt;</span> <span class="st">&quot;Zero&quot;</span></code></pre>
<p>The <em>compare</em> function compares two arguments and returns <em>LT</em> if the first argument is lesser than the second, <em>GT</em> if the first argument is greater than the second, and <em>EQ</em> if both are equal. Executing the above example, you get:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">2</span>
<span class="st">&quot;Positive&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">0</span>
<span class="st">&quot;Zero&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign (<span class="fu">-</span><span class="dv">2</span>)
<span class="st">&quot;Negative&quot;</span></code></pre>
<p>The <em>sign</em> function can also be expressed using guards (‘|’) for readability. The action for a matching case must be specified after the ‘=’ sign. You can use a default guard with the <em>otherwise</em> keyword:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sign ::</span> <span class="dt">Integer</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
sign x
    <span class="fu">|</span> x <span class="fu">&gt;</span> <span class="dv">0</span> <span class="fu">=</span> <span class="st">&quot;Positive&quot;</span>
    <span class="fu">|</span> x <span class="fu">&lt;</span> <span class="dv">0</span> <span class="fu">=</span> <span class="st">&quot;Negative&quot;</span>
    <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> <span class="st">&quot;Zero&quot;</span></code></pre>
<p>The guards have to be neatly aligned:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">0</span>
<span class="st">&quot;Zero&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign <span class="dv">3</span>
<span class="st">&quot;Positive&quot;</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> sign (<span class="fu">-</span><span class="dv">3</span>)
<span class="st">&quot;Negative&quot;</span></code></pre>
<p>There are three very important higher order functions in Haskell — <em>map</em>, <em>filter</em>, and <em>fold</em>.</p>
<p>The <em>map</em> function takes a function and a list, and applies the function to each and every element of the list. Its type signature is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">map</span>
<span class="fu">map</span><span class="ot"> ::</span> (a <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> [b]</code></pre>
<p>The first function argument accepts an element of type ‘a’ and returns an element of type ‘b’. An example on adding <em>two</em> to every element in a list can be implemented using <em>map</em>:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">map</span> (<span class="fu">+</span> <span class="dv">2</span>) [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
[<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>,<span class="dv">6</span>,<span class="dv">7</span>]</code></pre>
<p>The <em>filter</em> function accepts a predicate function for evaluation, and a list, and returns the list with those elements that satisfy the predicate. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">filter</span> (<span class="fu">&gt;</span> <span class="dv">0</span>) [<span class="fu">-</span><span class="dv">2</span>, <span class="fu">-</span><span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">2</span>]
[<span class="dv">1</span>,<span class="dv">2</span>]</code></pre>
<p>Its type signature is:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">filter</span><span class="ot"> ::</span> (a <span class="ot">-&gt;</span> <span class="dt">Bool</span>) <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> [a]</code></pre>
<p>The predicate function for <em>filter</em> takes as its first argument an element of type ‘a’ and returns <em>True</em> or <em>False</em>.</p>
<p>The <em>fold</em> function performs cumulative operation on a list. It takes as arguments a function, an accumulator (starting with an initial value) and a list. It cumulatively aggregates the computation of the function on the accumulator value as well as each member of the list. There are two types of folds — <em>left</em> and <em>right</em> fold.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldl</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
<span class="dv">15</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldr</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
<span class="dv">15</span></code></pre>
<p>Their type signatures are, respectively:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">foldl</span>
<span class="fu">foldl</span><span class="ot"> ::</span> (a <span class="ot">-&gt;</span> b <span class="ot">-&gt;</span> a) <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> [b] <span class="ot">-&gt;</span> a
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">:</span>t <span class="fu">foldr</span>
<span class="fu">foldr</span><span class="ot"> ::</span> (a <span class="ot">-&gt;</span> b <span class="ot">-&gt;</span> b) <span class="ot">-&gt;</span> b <span class="ot">-&gt;</span> [a] <span class="ot">-&gt;</span> b</code></pre>
<p>The way the fold is evaluated among the two types is different and is demonstrated below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldl</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldl</span> (<span class="fu">+</span>) <span class="dv">1</span> [<span class="dv">2</span>, <span class="dv">3</span>]
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldl</span> (<span class="fu">+</span>) <span class="dv">3</span> [<span class="dv">3</span>]
<span class="dv">6</span></code></pre>
<p>It can be represented as ‘f (f (f a b1) b2) b3’ where ‘f’ is the function, ‘a’ is the accumulator value, and ‘b1’, ‘b2’ and ‘b3’ are the elements of the list. The parenthesis is accumulated on the left for a <em>left fold</em>. The computation looks like:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) ((<span class="fu">+</span>) ((<span class="fu">+</span>) <span class="dv">0</span> <span class="dv">1</span>) <span class="dv">2</span>) <span class="dv">3</span>
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">0</span> <span class="dv">1</span>
<span class="dv">1</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) ((<span class="fu">+</span>) <span class="dv">0</span> <span class="dv">1</span>) <span class="dv">2</span>
<span class="dv">3</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) ((<span class="fu">+</span>) ((<span class="fu">+</span>) <span class="dv">0</span> <span class="dv">1</span>) <span class="dv">2</span>) <span class="dv">3</span>
<span class="dv">6</span></code></pre>
<p>With the recursion, the expression is constructed and evaluated only when the expression is finally formed. It can thus cause stack overflow or never complete when working with infinite lists. The <em>foldr</em> evaluation looks like this:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldr</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldr</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>, <span class="dv">2</span>] <span class="fu">+</span> <span class="dv">3</span>
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">foldr</span> (<span class="fu">+</span>) <span class="dv">0</span> [<span class="dv">1</span>] <span class="fu">+</span> <span class="dv">2</span> <span class="fu">+</span> <span class="dv">3</span>
<span class="dv">6</span></code></pre>
<p>It can be represented as ‘f b1 (f b2 (f b3 a))’ where ‘f’ is the function, ‘a’ is the accumulator value, and ‘b1’, ‘b2’ and ‘b3’ are the elements of the list. The computation looks like:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">1</span> ((<span class="fu">+</span>) <span class="dv">2</span> ((<span class="fu">+</span>) <span class="dv">3</span> <span class="dv">0</span>)) 
<span class="dv">6</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">3</span> <span class="dv">0</span>
<span class="dv">3</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">2</span> ((<span class="fu">+</span>) <span class="dv">3</span> <span class="dv">0</span>)
<span class="dv">5</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> (<span class="fu">+</span>) <span class="dv">1</span> ((<span class="fu">+</span>) <span class="dv">2</span> ((<span class="fu">+</span>) <span class="dv">3</span> <span class="dv">0</span>))
<span class="dv">6</span></code></pre>
<p>There are some statements like condition checking where ‘f b1’ can be computed even without requiring the subsequent arguments, and hence the foldr function can work with infinite lists. There is also a strict version of <em>foldl (foldl’)</em> that forces the computation before proceeding with the recursion.</p>
<p>If you want a reference to a matched pattern, you can use the <em>as</em> pattern syntax. The tail function accepts an input list and returns everything except the head of the list. You can write a <em>tailString</em> function that accepts a string as input and returns the string with the first character removed:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">tailString ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
tailString <span class="st">&quot;&quot;</span> <span class="fu">=</span> <span class="st">&quot;&quot;</span>
tailString input<span class="fu">@</span>(x<span class="fu">:</span>xs) <span class="fu">=</span> <span class="st">&quot;Tail of &quot;</span> <span class="fu">++</span> input <span class="fu">++</span> <span class="st">&quot; is &quot;</span> <span class="fu">++</span> xs</code></pre>
<p>The entire matched pattern is represented by <em>input</em> in the above code snippet.</p>
<p>Functions can be chained to create other functions. This is called as ‘composing’ functions. The mathematical definition is as under:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">(f o g)(x) <span class="fu">=</span> f(g(x))</code></pre>
<p>This dot (.) operator has the highest precedence and is left-associative. If you want to force an evaluation, you can use the function application operator ($) that has the second highest precedence and is right-associative. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span>  (<span class="fu">reverse</span> ((<span class="fu">++</span>) <span class="st">&quot;yrruC &quot;</span> (<span class="fu">unwords</span> [<span class="st">&quot;skoorB&quot;</span>, <span class="st">&quot;lleksaH&quot;</span>])))
<span class="st">&quot;Haskell Brooks Curry&quot;</span></code></pre>
<p>You can rewrite the above using the function application operator that is right-associative:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">reverse</span> <span class="fu">$</span> (<span class="fu">++</span>) <span class="st">&quot;yrruC &quot;</span> <span class="fu">$</span> <span class="fu">unwords</span> [<span class="st">&quot;skoorB&quot;</span>, <span class="st">&quot;lleksaH&quot;</span>]
<span class="st">&quot;Haskell Brooks Curry&quot;</span></code></pre>
<p>You can also use the dot notation to make it even more readable, but the final argument needs to be evaluated first; hence, you need to use the function application operator for it:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">reverse</span> <span class="fu">.</span> (<span class="fu">++</span>) <span class="st">&quot;yrruC &quot;</span> <span class="fu">.</span> <span class="fu">unwords</span> <span class="fu">$</span> [<span class="st">&quot;skoorB&quot;</span>, <span class="st">&quot;lleksaH&quot;</span>]
<span class="st">&quot;Haskell Brooks Curry&quot;</span></code></pre>]]></description>
    <pubDate>Mon, 22 Jun 2015 21:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/06/22/more-haskell-functions/news.html</guid>
</item>
<item>
    <title>Haskell Functions</title>
    <link>http://www.shakthimaan.com/posts/2015/05/25/haskell-functions/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, August 2014 edition.]</em></p>
<p>This second article in the series on Haskell explores a few functions.</p>
<p>Consider the function <em>sumInt</em> to compute the sum of two integers. It is defined as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sumInt ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
sumInt x y <span class="fu">=</span> x <span class="fu">+</span> y</code></pre>
<p>The first line is the type signature where the function name, arguments and return types are separated using a double colon (::). The arguments and the return types are separated by the symbol (-&gt;). Thus, the above type signature tells us that the sum function takes two arguments of type <em>Int</em> and returns an <em>Int</em>. Note that the function names must always begin with the letters of the alphabet in lower case. The names are usually written in CamelCase style.</p>
<p>You can create a Sum.hs Haskell source file using your favourite text editor, and load the file on to the Glasgow Haskell Compiler interpreter (GHCi) using the following code:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/  <span class="kw">:</span>? <span class="kw">for</span> <span class="kw">help</span>
Loading package ghc-prim ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.
Loading package integer-gmp ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.
Loading package base ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.

Prelude<span class="kw">&gt;</span> :l Sum.hs
[1 of 1] Compiling Main             <span class="kw">(</span> Sum.hs, interpreted <span class="kw">)</span>
Ok, modules loaded: Main.

*Main<span class="kw">&gt;</span> :t sumInt
sumInt :: Int -<span class="kw">&gt;</span> Int -<span class="kw">&gt;</span> Int

*Main<span class="kw">&gt;</span> sumInt 2 3
5</code></pre>
<p>If we check the type of <em>sumInt</em> with arguments, we get:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> :t sumInt 2 3
sumInt 2 3 :: Int

*Main<span class="kw">&gt;</span> :t sumInt 2
sumInt 2 :: Int -<span class="kw">&gt;</span> Int</code></pre>
<p>The value of <em>sumInt 2 3</em> is an <em>Int</em> as defined in the type signature. We can also partially apply the function <em>sumInt</em> with one argument and its return type will be <em>Int -&gt; Int</em>. In other words, <em>sumInt 2</em> takes an integer and will return an integer with 2 added to it.</p>
<p>Every function in Haskell takes only one argument. So, we can think of the <em>sumInt</em> function as one that takes an argument and returns a function that takes another argument and computes their sum. This return function can be defined as a <em>sumTwoInt</em> function that adds a 2 to an <em>Int</em> using the <em>sumInt</em> function, as shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sumTwoInt ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
sumTwoInt x <span class="fu">=</span> sumInt <span class="dv">2</span> x</code></pre>
<p>The ‘=’ sign in Haskell signifies a definition and not a variable assignment as seen in imperative programming languages. We can thus omit the ‘x’ on either side and the code becomes even more concise:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sumTwoInt ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
sumTwoInt <span class="fu">=</span> sumInt <span class="dv">2</span></code></pre>
<p>By loading <em>Sum.hs</em> again in the GHCi prompt, we get the following:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> :l Sum.hs
[1 of 1] Compiling Main             <span class="kw">(</span> Sum.hs, interpreted <span class="kw">)</span>
Ok, modules loaded: Main.

*Main<span class="kw">&gt;</span> :t sumTwoInt
sumTwoInt :: Int -<span class="kw">&gt;</span> Int

*Main<span class="kw">&gt;</span> sumTwoInt 3
5</code></pre>
<p>Let us look at some examples of functions that operate on lists. Consider list ‘a’ which is defined as <em>[1, 2, 3, 4, 5]</em> (a list of integers) in the Sum.hs file (re-load the file in GHCi before trying the list functions).</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">a ::</span> [<span class="dt">Int</span>]
a <span class="fu">=</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]</code></pre>
<p>The <em>head</em> function returns the first element of a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">head</span> a
1

*Main<span class="kw">&gt;</span> :t <span class="kw">head</span>
<span class="kw">head</span> :: [a] -<span class="kw">&gt;</span> a</code></pre>
<p>The <em>tail</em> function returns everything except the first element from a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">tail</span> a
[2,3,4,5]

*Main<span class="kw">&gt;</span> :t <span class="kw">tail</span>
<span class="kw">tail</span> :: [a] -<span class="kw">&gt;</span> [a]</code></pre>
<p>The <em>last</em> function returns the last element of a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">last</span> a
5

*Main<span class="kw">&gt;</span> :t <span class="kw">last</span>
<span class="kw">last</span> :: [a] -<span class="kw">&gt;</span> a</code></pre>
<p>The <em>init</em> function returns everything except the last element of a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> init a
[1,2,3,4]

*Main<span class="kw">&gt;</span> :t init
init :: [a] -<span class="kw">&gt;</span> [a]</code></pre>
<p>The <em>length</em> function returns the length of a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> length a
5

*Main<span class="kw">&gt;</span> :t length
length :: [a] -<span class="kw">&gt;</span> Int</code></pre>
<p>The <em>take</em> function picks the first ‘n’ elements from a list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> take 3 a
[1,2,3]

*Main<span class="kw">&gt;</span> :t take
take :: Int -<span class="kw">&gt;</span> [a] -<span class="kw">&gt;</span> [a]</code></pre>
<p>The <em>drop</em> function drops ‘n’ elements from the beginning of a list, and returns the rest:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> drop 3 a
[4,5]

*Main<span class="kw">&gt;</span> :t drop
drop :: Int -<span class="kw">&gt;</span> [a] -<span class="kw">&gt;</span> [a]</code></pre>
<p>The <em>zip</em> function takes two lists and creates a new list of tuples with the respective pairs from each list. For example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">let</span> b = [<span class="st">&quot;one&quot;</span>, <span class="st">&quot;two&quot;</span>, <span class="st">&quot;three&quot;</span>, <span class="st">&quot;four&quot;</span>, <span class="st">&quot;five&quot;</span>]

*Main<span class="kw">&gt;</span> <span class="kw">zip</span> a b
[<span class="kw">(</span>1,<span class="st">&quot;one&quot;</span><span class="kw">)</span>,<span class="kw">(</span>2,<span class="st">&quot;two&quot;</span><span class="kw">)</span>,<span class="kw">(</span>3,<span class="st">&quot;three&quot;</span><span class="kw">)</span>,<span class="kw">(</span>4,<span class="st">&quot;four&quot;</span><span class="kw">)</span>,<span class="kw">(</span>5,<span class="st">&quot;five&quot;</span><span class="kw">)</span>]

*Main<span class="kw">&gt;</span> :t <span class="kw">zip</span>
<span class="kw">zip</span> :: [a] -<span class="kw">&gt;</span> [b] -<span class="kw">&gt;</span> [<span class="kw">(</span>a, b<span class="kw">)</span>]</code></pre>
<p>The <em>let</em> expression defines the value of ‘b’ in the GHCi prompt. You can also define it in a way that’s similar to the definition of the list ‘a’ in the source file.</p>
<p>The <em>lines</em> function takes input text and splits it at newlines:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">let</span> sentence = <span class="st">&quot;First\nSecond\nThird\nFourth\nFifth&quot;</span>

*Main<span class="kw">&gt;</span> lines sentence
[<span class="st">&quot;First&quot;</span>,<span class="st">&quot;Second&quot;</span>,<span class="st">&quot;Third&quot;</span>,<span class="st">&quot;Fourth&quot;</span>,<span class="st">&quot;Fifth&quot;</span>]

*Main<span class="kw">&gt;</span> :t lines
lines :: String -<span class="kw">&gt;</span> [String]</code></pre>
<p>The <em>words</em> function takes input text and splits it on white space:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> words <span class="st">&quot;hello world&quot;</span>
[<span class="st">&quot;hello&quot;</span>,<span class="st">&quot;world&quot;</span>]

*Main<span class="kw">&gt;</span> :t words
words :: String -<span class="kw">&gt;</span> [String]</code></pre>
<p>The <em>map</em> function takes a function and a list and applies the function to every element in the list:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> map sumTwoInt a
[3,4,5,6,7]

*Main<span class="kw">&gt;</span> :t map
map :: <span class="kw">(</span>a -<span class="kw">&gt;</span> b<span class="kw">)</span> -<span class="kw">&gt;</span> [a] -<span class="kw">&gt;</span> [b]</code></pre>
<p>The first argument to map is a function which is enclosed within parenthesis in the type signature (a -&gt; b). This function takes an input of type ‘a’ and returns an element of type ‘b’. Thus, when operating over a list [a], it returns a list of type [b].</p>
<p>Recursion provides a means of looping in functional programming languages. The factorial of a number, for example, can be computed in Haskell, using the following code:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">factorial ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
factorial <span class="dv">0</span> <span class="fu">=</span> <span class="dv">1</span>
factorial n <span class="fu">=</span> n <span class="fu">*</span> factorial (n<span class="dv">-1</span>)</code></pre>
<p>The definition of factorial with different input use cases is called as pattern matching on the function. On running the above example with GHCi, you get:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> factorial 0
1
*Main<span class="kw">&gt;</span> factorial 1
1
*Main<span class="kw">&gt;</span> factorial 2
2
*Main<span class="kw">&gt;</span> factorial 3
6
*Main<span class="kw">&gt;</span> factorial 4
24
*Main<span class="kw">&gt;</span> factorial 5
120</code></pre>
<p>Functions operating on lists can also be called recursively. To compute the sum of a list of integers, you can write the <em>sumList</em> function as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sumList ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Int</span>
sumList [] <span class="fu">=</span> <span class="dv">0</span>
sumList (x<span class="fu">:</span>xs) <span class="fu">=</span> x <span class="fu">+</span> sumList xs</code></pre>
<p>The notation *(x:xs) represents a list, where ‘x’ is the first element in the list, and ‘xs’ is the rest of the list. On running <em>sumList</em> with GHCi, you get the following:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> sumList []
0
*Main<span class="kw">&gt;</span> sumList [1,2,3]
6</code></pre>
<p>Sometimes, you will need a temporary function for a computation, which you will not need to use elsewhere. You can then write an anonymous function. A function to increment an input value can be defined as:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">*Main<span class="kw">&gt;</span> <span class="kw">(</span>\x -<span class="kw">&gt;</span> x + 1<span class="kw">)</span> 3
4</code></pre>
<p>Such functions are called as Lambda functions, and the ‘\’ represents the notation for the symbol Lambda. Another example is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">map</span> (\x <span class="ot">-&gt;</span> x <span class="fu">*</span> x) [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>]
[<span class="dv">1</span>,<span class="dv">4</span>,<span class="dv">9</span>,<span class="dv">16</span>,<span class="dv">25</span>]</code></pre>
<p>It is a good practice to write the type signature of the function first when composing programs, and then write the body of the function. Haskell is a functional programming language, and understanding the use of functions is very important.</p>]]></description>
    <pubDate>Mon, 25 May 2015 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/05/25/haskell-functions/news.html</guid>
</item>
<item>
    <title>Introduction to Haskell</title>
    <link>http://www.shakthimaan.com/posts/2015/05/10/introduction-to-haskell/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, July 2014 edition.]</em></p>
<p>Haskell, a free and open source programming language, is the outcome of 20 years of research. It has all the advantages of functional programming and an intuitive syntax based on mathematical notation. This article flags off a series in which we will explore Haskell at length.</p>
<p>Haskell is a statically typed, general purpose programming language. Code written in Haskell can be compiled and also used with an interpreter. The static typing helps detect plenty of compile time bugs. The type system in Haskell is very powerful and can automatically infer types. Functions are treated as first-class citizens and you can pass them around as arguments. It is a pure functional language and employs lazy evaluation. It also supports procedural and strict evaluation similar to other programming paradigms.</p>
<p>Haskell code is known for its brevity and is very concise. The latest language standard is Haskell 2010. The language supports many extensions, and has been gaining wide-spread interest in the industry due to its capability to run algorithms on multi-core systems. It has support for concurrency because of the use of software transactional memory. Haskell allows you to quickly create prototypes with its platform and tools. Hoogle and Hayoo API search engines are available to query and browse the list of Haskell packages and libraries. The entire set of Haskell packages are available in Hackage.</p>
<p>The Haskell Platform contains all the software required to get you started on it. On GNU/Linux, you can use your distribution package manager to install the same. On Fedora, for example, you can use the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum install haskell-platform</span></code></pre>
<p>On Ubuntu, you can use the following:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># apt-get install haskell-platform</span></code></pre>
<p>On Windows, you can download and run HaskellPlatform-2013.2.0.0-setup.exe from the Haskell platform web site and follow the instructions for installation.</p>
<p>For Mac OS X, download either the 32-bit or 64-bit <em>.pkg</em> file, and click on either to proceed with the installation.</p>
<p>The most popular Haskell interpreter is the Glasgow Haskell Compiler (GHC). To use its interpreter, you can run <em>ghci</em> from the command prompt on your system:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/  <span class="kw">:</span>? <span class="kw">for</span> <span class="kw">help</span>
Loading package ghc-prim ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.
Loading package integer-gmp ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.
Loading package base ..<span class="kw">.</span> linking ..<span class="kw">.</span> <span class="kw">done</span>.
Prelude<span class="kw">&gt;</span> </code></pre>
<p>The <em>Prelude</em> prompt indicates that the basic Haskell library modules have been imported for your use.</p>
<p>To exit from GHCi, type <em>:quit</em> in the Prelude prompt:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">Prelude<span class="kw">&gt;</span> :quit
Leaving GHCi.</code></pre>
<p>The basic data types used in Haskell are discussed below.</p>
<p>A <em>Char</em> data type is for a Unicode character. You can view the type using the command <em>:type</em> at the GHCi prompt:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">type</span> <span class="ch">'s'</span>
<span class="ch">'s'</span><span class="ot"> ::</span> <span class="dt">Char</span></code></pre>
<p>The ’::’ symbol is used to separate the expression on the left with the data type on the right.</p>
<p>A <em>Bool</em> data type represents a logical value of either True or False.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">type</span> <span class="kw">True</span>
<span class="kw">True</span><span class="ot"> ::</span> <span class="dt">Bool</span></code></pre>
<p>Signed numbers with a fixed width are represented by the <em>Int</em> data type. The <em>Integer</em> type is used for signed numbers that do not have a fixed width.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="dv">5</span>
<span class="dv">5</span></code></pre>
<p>The <em>Double</em> and <em>Float</em> types are used to represent decimal values. The Double type has better precision for floating point numbers:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fl">3.0</span>
<span class="fl">3.0</span></code></pre>
<p>The basic data types can be combined to form composite types. There are two widely used composite types in Haskell, namely, lists and tuples. A list is a collection of elements of the same data type enclosed within square parenthesis. A list of characters is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">type</span> [<span class="ch">'a'</span>, <span class="ch">'b'</span>, <span class="ch">'c'</span>]
[<span class="ch">'a'</span>, <span class="ch">'b'</span>, <span class="ch">'c'</span>]<span class="ot"> ::</span> [<span class="dt">Char</span>]</code></pre>
<p>The static typing in Haskell produces errors during compile or load time (in GHCi) when you mix data types inside a list. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> [<span class="ch">'a'</span>, <span class="dv">1</span>, <span class="dv">2</span>]

<span class="fu">&lt;</span>interactive<span class="fu">&gt;:</span><span class="dv">7</span><span class="fu">:</span><span class="dv">7</span><span class="fu">:</span>
    <span class="dt">No</span> <span class="kw">instance</span> for (<span class="kw">Num</span> <span class="dt">Char</span>) arising from the literal <span class="ot">`1'</span>
<span class="ot">    Possible fix: add an instance declaration for (Num Char)</span>
<span class="ot">    In the expression: 1</span>
<span class="ot">    In the expression: ['a', 1, 2]</span>
<span class="ot">    In an equation for `</span>it'<span class="fu">:</span> it <span class="fu">=</span> [<span class="ch">'a'</span>, <span class="dv">1</span>, <span class="dv">2</span>]</code></pre>
<p>You can have a list of lists as long as they contain the same data type:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">type</span> [[<span class="ch">'a'</span>], [<span class="ch">'b'</span>, <span class="ch">'c'</span>]]
[[<span class="ch">'a'</span>], [<span class="ch">'b'</span>, <span class="ch">'c'</span>]]<span class="ot"> ::</span> [[<span class="dt">Char</span>]]</code></pre>
<p>A tuple is an ordered list of elements with a fixed size, enclosed within parenthesis, where each element can be of a different data type. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span><span class="kw">type</span> (<span class="ch">'t'</span>, <span class="kw">True</span>)
(<span class="ch">'t'</span>, <span class="kw">True</span>)<span class="ot"> ::</span> (<span class="dt">Char</span>, <span class="dt">Bool</span>)</code></pre>
<p>Note that the tuple with type (Char, Bool) is different from the tuple with type (Bool, Char).</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span>t (<span class="kw">False</span>, <span class="ch">'f'</span>)
(<span class="kw">False</span>, <span class="ch">'f'</span>)<span class="ot"> ::</span> (<span class="dt">Bool</span>, <span class="dt">Char</span>)</code></pre>
<p>Haskell originates from the theory of Lambda calculus, which was developed by Alonzo Church to formally study mathematics. In 1958, John McCarthy created Lisp, that relates programming with Lambda calculus. Robin Milner created a functional programming language called ML (meta language) for automated proofs of mathematical theorems in 1970. During the 1980s, there were a number of lazy functional programming languages scattered across the research community. Miranda was a very popular proprietary programming language released by Research Software Ltd in 1985.</p>
<p>A need arose to unify the different research developments, for which a committee was formed and the first version of the standard was released in 1990. It was called Haskell 1.0, after the mathematician and logician, Haskell Brooks Curry. Subsequently, there were four revisions made - 1.1, 1.2, 1.3 and 1.4. In 1997, the Haskell 98 report was released. In 2009, the Haskell 2010 standard was published and is the latest standard as on date. It has Foreign Function Interface (FFI) bindings to interface with other programming languages. The Hugs interpreter is useful for teaching, while the Glasgow Haskell Compiler (GHC) is very popular. The paper by John Hughes on <em>“Why Functional Programming matters?”</em> in as excellent paper to read. A number of software companies in the industry have begun to use Haskell in production systems.</p>
<p>We shall be exploring more features, constructs and use of the language in future articles.</p>
<h1 id="references">References</h1>
<p>[1] Haskell. <a href="http://haskell.org/">http://haskell.org/</a></p>
<p>[2] Haskell 2010. <a href="http://www.haskell.org/haskellwiki/Haskell_2010">http://www.haskell.org/haskellwiki/Haskell_2010</a></p>
<p>[3] Hoogle. <a href="http://www.haskell.org/hoogle/">http://www.haskell.org/hoogle/</a></p>
<p>[4] Hayoo. <a href="http://holumbus.fh-wedel.de/hayoo/hayoo.html">http://holumbus.fh-wedel.de/hayoo/hayoo.html</a></p>
<p>[5] Hackage. <a href="http://hackage.haskell.org/">http://hackage.haskell.org/</a></p>
<p>[6] Haskell Platform. <a href="http://www.haskell.org/platform/">http://www.haskell.org/platform/</a></p>
<p>[7] Glasgow Haskell Compiler. <a href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a></p>
<p>[8] Alonzo Church. <a href="http://www-groups.dcs.st-and.ac.uk/history/Mathematicians/Church.html">http://www-groups.dcs.st-and.ac.uk/history/Mathematicians/Church.html</a></p>
<p>[9] John McCarthy. <a href="http://www-formal.stanford.edu/jmc/">http://www-formal.stanford.edu/jmc/</a></p>
<p>[10] Lisp. <a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29">http://en.wikipedia.org/wiki/Lisp_%28programming_language%29</a></p>
<p>[11] Robin Milner. <a href="http://www.cl.cam.ac.uk/archive/rm135/">http://www.cl.cam.ac.uk/archive/rm135/</a></p>
<p>[12] Miranda. <a href="http://miranda.org.uk/">http://miranda.org.uk/</a></p>
<p>[13] Haskell 1.0. <a href="http://www.haskell.org/definition/haskell-report-1.0.ps.gz">http://www.haskell.org/definition/haskell-report-1.0.ps.gz</a></p>
<p>[14] Haskell Brooks Curry. <a href="http://www-history.mcs.st-andrews.ac.uk/Biographies/Curry.html">http://www-history.mcs.st-andrews.ac.uk/Biographies/Curry.html</a></p>
<p>[15] Hugs. <a href="http://www.haskell.org/hugs/">http://www.haskell.org/hugs/</a></p>
<p>[16] “Why Functional Programming matters?” <a href="http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html">http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html</a></p>
<p>[17] Why functional programming? Why Haskell?. <a href="http://book.realworldhaskell.org/read/why-functional-programming-why-haskell.html">http://book.realworldhaskell.org/read/why-functional-programming-why-haskell.html</a></p>]]></description>
    <pubDate>Sun, 10 May 2015 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/05/10/introduction-to-haskell/news.html</guid>
</item>
<item>
    <title>PostgreSQL Quick Reference</title>
    <link>http://www.shakthimaan.com/posts/2015/04/07/postgresql-quick-reference/news.html</link>
    <description><![CDATA[<table>
<col width="75%"></col>
<col width="25%"></col>
<thead>
<tr class="header">
<th align="left">Command</th>
<th align="left">Functionality</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">$ sudo /etc/init.d/postgresql start</td>
<td align="left">Start server (Ubuntu)</td>
</tr>
<tr class="even">
<td align="left">$ psql -U postgres</td>
<td align="left">Connect</td>
</tr>
<tr class="odd">
<td align="left">postgres=# \l</td>
<td align="left">Show databases</td>
</tr>
<tr class="even">
<td align="left">postgres=# \h <command></td>
<td align="left">Help</td>
</tr>
<tr class="odd">
<td align="left">postgres=# CREATE DATABASE jerry;</td>
<td align="left">Create database</td>
</tr>
<tr class="even">
<td align="left">postgres=# DROP DATABASE jerry;</td>
<td align="left">Delete database</td>
</tr>
<tr class="odd">
<td align="left">postgres=# SET search_path TO schema;</td>
<td align="left">Use schema</td>
</tr>
<tr class="even">
<td align="left">$ psql -U postgres -d <database></td>
<td align="left">Use database</td>
</tr>
<tr class="odd">
<td align="left">postgres=# \c test</td>
<td align="left">Change database</td>
</tr>
<tr class="even">
<td align="left">postgres=# \du</td>
<td align="left">List users</td>
</tr>
<tr class="odd">
<td align="left">postgres=# \d</td>
<td align="left">List tables</td>
</tr>
<tr class="even">
<td align="left">postgres=# CREATE SCHEMA sausalito;</td>
<td align="left">Create schema</td>
</tr>
<tr class="odd">
<td align="left">postgres=# \dn</td>
<td align="left">List schema</td>
</tr>
<tr class="even">
<td align="left">postgres=# DROP SCHEMA sausalito;</td>
<td align="left">Drop schema</td>
</tr>
<tr class="odd">
<td align="left">postgres=# SELECT * FROM sausalito.employees;</td>
<td align="left">Select rows</td>
</tr>
<tr class="even">
<td align="left">postgres=# CREATE TABLE sausalito.employees (id INT);</td>
<td align="left">Create table</td>
</tr>
<tr class="odd">
<td align="left">postgres=# INSERT INTO sausalito.employees VALUES (1);</td>
<td align="left">Insert record</td>
</tr>
<tr class="even">
<td align="left">postgres=# UPDATE sausalito.employees SET id = 4 WHERE id = 2;</td>
<td align="left">Update table record</td>
</tr>
<tr class="odd">
<td align="left">postgres=# DELETE FROM sausalito.employees WHERE id = 3;</td>
<td align="left">Delete record</td>
</tr>
<tr class="even">
<td align="left">postgres=# DROP TABLE sausalito.employees;</td>
<td align="left">Drop table</td>
</tr>
<tr class="odd">
<td align="left">postgres=# \q</td>
<td align="left">Quit from session</td>
</tr>
</tbody>
</table>]]></description>
    <pubDate>Tue, 07 Apr 2015 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/04/07/postgresql-quick-reference/news.html</guid>
</item>
<item>
    <title>Installation of NixOS 14.12</title>
    <link>http://www.shakthimaan.com/posts/2015/03/08/installation-of-nixos/news.html</link>
    <description><![CDATA[<p>Boot from LiveCD ( nixos-graphical-14.12.140.0dbc415-x86_64-linux.iso ), with 40 GB virtual disk, and login as root (no password required).</p>
<pre class="sourceCode bash"><code class="sourceCode bash">nixos login: root

[root@nixos:~]#</code></pre>
<p>Start the KDE environment using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">[root@nixos:~]# start display-manager</code></pre>
<p>You can then add the English Dvorak layout (optional) by selecting ‘System Settings’ -&gt; ‘Input Devices’ -&gt; ‘Keyboard settings’ -&gt; ‘Layouts’ -&gt; ‘Configure layouts’ -&gt; ‘Add’ and use the label (dvo) for the new layout. Check that networking works as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">[root@nixos:~]# ifconfig

[root@nixos:~]# <span class="kw">ping</span> -c3 www.google.com</code></pre>
<p>You can now partition the disk using ‘fdisk /dev/sda’ and create two partitions (39 GB /dev/sda1 and swap on /dev/sda2). Create the filesystems, and turn on swap using the following commands:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># mkfs.ext4 -L nixos /dev/sda1</span>

<span class="co"># mkswap -L swap /dev/sda2</span>
<span class="co"># swapon /dev/sda2</span></code></pre>
<p>Generate a basic system configuration file with nixos-generate-config:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># mount /dev/disk/by-label/nixos /mnt</span>

<span class="co"># nixos-generate-config --root /mnt</span></code></pre>
<p>Update /mnt/etc/nixos/configuration.nix with new packages that you need as illustrated below:</p>
<pre class="text"><code># Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the GRUB 2 boot loader.
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  # Define on which hard drive you want to install Grub.
  boot.loader.grub.device = &quot;/dev/sda&quot;;

  # networking.hostName = &quot;nixos&quot;; # Define your hostname.
  networking.hostId = &quot;56db3cd3&quot;;
  # networking.wireless.enable = true;  # Enables wireless.

  # Select internationalisation properties.
  # i18n = {
  #   consoleFont = &quot;lat9w-16&quot;;
  #   consoleKeyMap = &quot;us&quot;;
  #   defaultLocale = &quot;en_US.UTF-8&quot;;
  # };

  # List packages installed in system profile. To search by name, run:
  # $ nix-env -qaP | grep wget
  environment.systemPackages = with pkgs; [
    wget emacs24 git python gnuplot notmuch
    haskellPackages.pandoc

    # Installing texlive is slow and incomplete on NixOS
    # (pkgs.texLiveAggregationFun { paths = [ pkgs.texLive pkgs.texLiveExtra pkgs.texLiveBeamer ]; })    
  ];
  # texLive tetex lmodern
  
  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.layout = &quot;us&quot;;
  # services.xserver.xkbOptions = &quot;eurosign:e&quot;;

  # Enable the KDE Desktop Environment.
  services.xserver.displayManager.kdm.enable = true;
  services.xserver.desktopManager.kde4.enable = true;


  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.extraUsers.apollo = {
    home = &quot;/home/apollo&quot;;
    extraGroups = [ &quot;wheel&quot; ];
    useDefaultShell = true;
    isNormalUser = true;
    uid = 1000;
  };

}</code></pre>
<p>Install NixOS to hard disk:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># nixos-install</span>

setting root password...
Enter new UNIX password: ***
Retype new UNIX password: ***

passwd: password updated successfully
installation finished!</code></pre>
<p>You can now reboot into the system:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># reboot</span></code></pre>
<p>After you login to the console, set a password for the ‘apollo’ user. A screenshot of the desktop is shown below:</p>
<div class="figure">
<img src="http://shakthimaan.com/downloads/screenshots/nixos-14-12-screenshot.png"></img><p class="caption"></p>
</div>]]></description>
    <pubDate>Sun, 08 Mar 2015 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/03/08/installation-of-nixos/news.html</guid>
</item>
<item>
    <title>HDL Complexity Tool</title>
    <link>http://www.shakthimaan.com/posts/2015/02/07/hdl-complexity-tool/news.html</link>
    <description><![CDATA[<p><em>[Published in Electronics For You (EFY) magazine, June 2014 edition.]</em> <a href="http://electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=2063&amp;id=13454">Source</a></p>
<p><a href="http://hct.sourceforge.net/">HCT</a> stands for HDL Complexity Tool, where HDL stands for Hardware Description Language. HCT provides scores that represent the complexity of modules present in integrated circuit (IC) designs. It is written in Perl and released under the GPLv3 and LGPLv3 license. It employs <a href="http://www.literateprogramming.com/mccabe.pdf">McCabe Cyclomatic Complexity</a> that uses the control flow graph of the program source code to determine the complexity.</p>
<p>There are various factors for measuring the complexity of HDL models such as size, nesting, modularity, and timing. The measured metrics can help designers in refactoring their code, and also help managers to plan project schedules, and allocate resources, accordingly. You can run the tool from the GNU/Linux terminal for Verilog, VHDL, and CDL (Computer Design Language) files or directory sources. HCT can be installed on Fedora using the command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> hct</code></pre>
<p>After installation, consider the example project of <a href="http://opencores.org/project,uart2spi">uart2spi</a> written in Verilog, which is included in this month’s EFY DVD. It implements a simple core for a UART interface, and an internal SPI bus. The uart2spi folder contains rtl/spi under the file directory in your PC: /home/guest/uart2spi/trunk/rtl/spi. Run the HCT tool on the rtl/spi Verilog sources as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct rtl/spi</code></pre>
<p>We get the output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">Directory: /home/guest/uart2spi/trunk/rtl/spi

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> spi_ctl.v                           20     1       1          0.1724 <span class="kw">|</span>
<span class="kw">|</span>                      spi_ctl        20     1       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_core.v                          0      0       1          0.0076 <span class="kw">|</span>
<span class="kw">|</span>                      spi_core       0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_cfg.v                           0      0       1          0.0076 <span class="kw">|</span>
<span class="kw">|</span>                      spi_cfg        0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_if.v                            15     3       1          0.0994 <span class="kw">|</span>
<span class="kw">|</span>                      spi_if         15     3       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+</code></pre>
<p>The output includes various attributes that are described below:</p>
<ul>
<li><p>FILENAME is the file that is being parsed. The parser uses the file name extension to recognize the programming language.</p></li>
<li><p>MODULE refers to the specific module present in the file. A file can contain many modules.</p></li>
<li><p>IO refers to the input/output registers used in the module.</p></li>
<li><p>NET includes the network entities declared in the given module. For Verilog, it can be ‘wire’, ‘tri’, ‘supply0’ etc.</p></li>
<li><p>MCCABE provides the McCabe Cyclomatic Complexity of the module or file.</p></li>
<li><p>TIME refers to the time taken to process the file.</p></li>
</ul>
<p>A specific metric can be excluded from the output using the “–output-exclude=LIST” option. For example, type the following command on a GNU/Linux terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct --output-exclude=TIME rtl/spi </code></pre>
<p>The output will be;</p>
<pre class="sourceCode bash"><code class="sourceCode bash">Directory: /home/guest/uart2spi/trunk/rtl/spi

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>
+----------------------+----------------+--------+---------+-----------+
<span class="kw">|</span> FILENAME             <span class="kw">|</span> MODULE         <span class="kw">|</span> IO     <span class="kw">|</span> NET     <span class="kw">|</span> MCCABE    <span class="kw">|</span>
+----------------------+----------------+--------+---------+-----------+
<span class="kw">|</span> spi_ctl.v                               20       1         1         <span class="kw">|</span>
<span class="kw">|</span>                        spi_ctl          20       1         1         <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_core.v                              0        0         1         <span class="kw">|</span>
<span class="kw">|</span>                        spi_core         0        0         1         <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_cfg.v                               0        0         1         <span class="kw">|</span>
<span class="kw">|</span>                        spi_cfg          0        0         1         <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_if.v                                15       3         1         <span class="kw">|</span>
<span class="kw">|</span>                        spi_if           15       3         1         <span class="kw">|</span>
+----------------------------------------------------------------------+</code></pre>
<p>If you want only the score to be listed, you can remove the MODULE listing with the “–output-no-modules” option:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct --output-no-modules rtl/spi

Directory: /home/guest/uart2spi/trunk/rtl/spi

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>
+-----------------------+---------+----------+-------------+-----------+
<span class="kw">|</span> FILENAME              <span class="kw">|</span> IO      <span class="kw">|</span> NET      <span class="kw">|</span> MCCABE      <span class="kw">|</span> TIME      <span class="kw">|</span>
+-----------------------+---------+----------+-------------+-----------+
<span class="kw">|</span> spi_ctl.v               20        1          1             0.16803   <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_core.v              0         0          1             0.007434  <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_cfg.v               0         0          1             0.00755   <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_if.v                15        3          1             0.097721  <span class="kw">|</span>
+----------------------------------------------------------------------+</code></pre>
<p>The tool can be run on individual files, or recursively on subdirectories with the “-R” option. The output the entire uart2spi project sources is given below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct -R rtl

Directory: /home/guest/uart2spi/trunk/rtl/uart_core

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> uart_rxfsm.v                        10     0       1          0.1379 <span class="kw">|</span>
<span class="kw">|</span>                      uart_rxfsm     10     0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> clk_ctl.v                           0      0       1          0.0146 <span class="kw">|</span>
<span class="kw">|</span>                      clk_ctl        0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> uart_core.v                         18     1       1          0.1291 <span class="kw">|</span>
<span class="kw">|</span>                      uart_core      18     1       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> uart_txfsm.v                        9      0       1          0.1129 <span class="kw">|</span>
<span class="kw">|</span>                      uart_txfsm     9      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+

Directory: /home/guest/uart2spi/trunk/rtl/top

verilog, 1 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> top.v                               16     0       1          0.0827 <span class="kw">|</span>
<span class="kw">|</span>                      top            16     0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+

Directory: /home/guest/uart2spi/trunk/rtl/spi

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> spi_ctl.v                           20     1       1          0.1645 <span class="kw">|</span>
<span class="kw">|</span>                      spi_ctl        20     1       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_core.v                          0      0       1          0.0074 <span class="kw">|</span>
<span class="kw">|</span>                      spi_core       0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_cfg.v                           0      0       1          0.0073 <span class="kw">|</span>
<span class="kw">|</span>                      spi_cfg        0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> spi_if.v                            15     3       1          0.0983 <span class="kw">|</span>
<span class="kw">|</span>                      spi_if         15     3       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+

Directory: /home/guest/uart2spi/trunk/rtl/lib

verilog, 1 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> registers.v                         5      0       1          0.0382 <span class="kw">|</span>
<span class="kw">|</span>                      bit_register   5      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+

Directory: /home/guest/uart2spi/trunk/rtl/msg_hand

verilog, 1 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> uart_msg_handler.v                  0      0       1          0.0192 <span class="kw">|</span>
<span class="kw">|</span>                      uart_m~ndler   0      0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+</code></pre>
<p>The default behaviour is to dump the output to the terminal. It can be redirected to a file with the “–output-file=FILE” option. You can also specify an output file format, such as “csv” with the “–output-format=FORMAT” option:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct --output-file=/home/guest/project-metrics.csv --output-format=csv rtl/spi 

$ <span class="kw">cat</span> /home/guest/project-metrics.csv

Directory: /home/guest/uart2spi/trunk/rtl/spi

verilog, 4 <span class="kw">file(</span>s<span class="kw">)</span>

 FILENAME    , MODULE    , IO   , NET  , MCCABE  , SLOC  , COMMENT_LINES  , TIME
 spi_ctl.v   ,           , 20   , 1    , 1       , 110   , 48             , 0.1644
             , spi_ctl   , 20   , 1    , 1       , 68    , 6              ,
 spi_core.v  ,           , 0    , 0    , 1       , 46    , 43             , 0.0073
             , spi_core  , 0    , 0    , 1       , 4     , 1              ,
 spi_cfg.v   ,           , 0    , 0    , 1       , 46    , 43             , 0.0075
             , spi_cfg   , 0    , 0    , 1       , 4     , 1              ,
 spi_if.v    ,           , 15   , 3    , 1       , 80    , 44             , 0.0948
             , spi_if    , 15   , 3    , 1       , 38    , 2              ,</code></pre>
<p>There are various yyparse options that are helpful to understand the lexical parsing of the source code. They can be invoked using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ hct --yydebug=NN sources</code></pre>
<p>The NN options and their meaning is listed below:</p>
<table>
<tbody>
<tr class="odd">
<td align="left">0x01</td>
<td align="left">Lexical tokens</td>
</tr>
<tr class="even">
<td align="left">0x02</td>
<td align="left">Information on States</td>
</tr>
<tr class="odd">
<td align="left">0x04</td>
<td align="left">Shift, reduce, accept driver actions</td>
</tr>
<tr class="even">
<td align="left">0x08</td>
<td align="left">Dump of the parse stack</td>
</tr>
<tr class="odd">
<td align="left">0x16</td>
<td align="left">Tracing for error recovery</td>
</tr>
<tr class="even">
<td align="left">0x31</td>
<td align="left">Complete output for debugging</td>
</tr>
</tbody>
</table>
<p>HCT can also be used with VHDL, and <a href="http://cyclicity-cdl.sourceforge.net/">Cyclicity CDL</a> (Cycle Description Language) programs. For VHDL, the filenames must end with a .vhdl extension. You can rename .vhd files recursively in a directory (in Bash, for example) using the following script:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">for</span> <span class="kw">file</span> <span class="kw">in</span> <span class="kw">`find</span> <span class="ot">$1</span> -name <span class="st">&quot;*.vhd&quot;</span><span class="kw">`</span>
<span class="kw">do</span>
  <span class="kw">mv</span> <span class="ot">$file</span> <span class="ot">${file/</span>.vhd<span class="ot">/</span>.vhdl<span class="ot">}</span>
<span class="kw">done</span></code></pre>
<p>The “$1” refers to the project source directory that is passed as an argument to the script. Let us take the example of <a href="http://opencores.org/project,sha256core">sha256 core</a> written in VHDL, which is also included in this month’s EFY DVD. The execution of HCT on the sha256core project is as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"> $  hct rtl

Directory: /home/guest/sha256core/trunk/rtl

vhdl, 6 <span class="kw">file(</span>s<span class="kw">)</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> FILENAME           <span class="kw">|</span> MODULE       <span class="kw">|</span> IO   <span class="kw">|</span> NET   <span class="kw">|</span> MCCABE   <span class="kw">|</span> TIME   <span class="kw">|</span>
+--------------------+--------------+------+-------+----------+--------+
<span class="kw">|</span> sha_256.vhdl                        29     0       1          0.9847 <span class="kw">|</span>
<span class="kw">|</span>                      sha_256        29     0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> sha_fun.vhdl                        1      1       1          0.3422 <span class="kw">|</span>
<span class="kw">|</span>                                     1      1       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> msg_comp.vhdl                       20     0       1          0.4169 <span class="kw">|</span>
<span class="kw">|</span>                      msg_comp       20     0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> dual_mem.vhdl                       7      0       3          0.0832 <span class="kw">|</span>
<span class="kw">|</span>                      dual_mem       7      0       3                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> ff_bank.vhdl                        3      0       2          0.0260 <span class="kw">|</span>
<span class="kw">|</span>                      ff_bank        3      0       2                 <span class="kw">|</span>
+----------------------------------------------------------------------+
<span class="kw">|</span> sh_reg.vhdl                         19     0       1          0.6189 <span class="kw">|</span>
<span class="kw">|</span>                      sh_reg         19     0       1                 <span class="kw">|</span>
+----------------------------------------------------------------------+</code></pre>
<p>The “-T” option enables the use of threads to speed up computation. The <a href="http://opencores.org/project,lzrw1-compressor-core">LZRW1 (Lempel–Ziv Ross Williams) compressor core</a> project implements a lossless data compression algorithm. The output of HCT on this project, without threading and with threads enabled, is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">time</span> hct HDL

Directory: /home/guest/lzrw1-compressor-core/trunk/hw/HDL

vhdl, 8 <span class="kw">file(</span>s<span class="kw">)</span>
...
real	0m3.725s
user	0m3.612s
sys     0m0.013s

$ <span class="kw">time</span> hct HDL -T

Directory: /home/guest/lzrw1-compressor-core/trunk/hw/HDL

vhdl, 8 <span class="kw">file(</span>s<span class="kw">)</span>
...
real	0m2.301s
user	0m7.029s
sys     0m0.051s</code></pre>
<p>The supported input options for HCT can be viewed with the “-h” option.</p>
<p>The invocation of HCT can be automated, rechecked for each code check-in that happens to a project repository. The complexity measure is thus recorded periodically. The project team will then be able to monitor, analyse the complexity of each module and decide on any code refactoring strategies.</p>]]></description>
    <pubDate>Sat, 07 Feb 2015 23:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/02/07/hdl-complexity-tool/news.html</guid>
</item>
<item>
    <title>GNU Unified Parallel C</title>
    <link>http://www.shakthimaan.com/posts/2015/01/20/gnu-unified-parallel-c/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, May 2014 edition.]</em></p>
<p>This article guides readers through the installation of GNU Unified Parallel C, which is designed for high performance computing on large scale parallel machines.</p>
<p><a href="http://www.gccupc.org/">GNU Unified Parallel C</a> is an extension to the GNU C compiler (GCC), which supports execution of <a href="https://upc-lang.org/">Unified Parallel C (UPC)</a> programs. UPC uses the Partitioned Global Address Space (PGAS) model for its implementation. The current version of UPC is 1.2, and a 1.3 draft specification is available. GNU UPC is released under the GPL license, while, the UPC specification is released under the new BSD license. To install it on Fedora, you need to first install the <em>gupc</em> repository:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> http://www.gccupc.org/pub/pkg/rpms/gupc-fedora-18-1.noarch.rpm</code></pre>
<p>You can then install the <em>gupc</em> RPM using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> gupc-gcc-upc</code></pre>
<p>The installation directory is <em>/usr/local/gupc</em>. You will also require the <em>numactl</em> (library for tuning Non-Uniform Memory Access machines) development packages:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> numactl-devel numactl-libs</code></pre>
<p>To add the installation directory to your environment, install the environment-modules package:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> environment-modules</code></pre>
<p>You can then load the <em>gupc</em> module with:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># module load gupc-x86_64</span></code></pre>
<p>Consider the following simple ‘hello world’ example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;stdio.h&gt;</span>

<span class="dt">int</span> main()
{
   printf(<span class="st">&quot;Hello World</span><span class="ch">\n</span><span class="st">&quot;</span>);
   <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>You can compile it using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc hello.c -o hello</span></code></pre>
<p>Then run it with:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># ./hello -fupc-threads-5</span>

Hello World
Hello World
Hello World
Hello World
Hello World</code></pre>
<p>The argument <em>-fupc-threads-N</em> specifies the number of threads to be run. The program can also be executed using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># ./hello -n 5</span></code></pre>
<p>The gupc compiler provides a number of compile and run-time options. The ’-v’ option produces a verbose output of the compilation steps. It also gives information on GNU UPC. An example of such an output is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc hello.c -o hello -v</span>

Driving: gupc -x upc hello.c -o hello -v -fupc-link
Using built-in specs.
<span class="ot">COLLECT_GCC=</span>gupc
<span class="ot">COLLECT_LTO_WRAPPER=</span>/usr/local/gupc/libexec/gcc/x86_64-redhat-linux/4.8.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ...
Thread model: posix
<span class="kw">gcc</span> version 4.8.0 20130311 <span class="kw">(</span>GNU UPC 4.8.0-3<span class="kw">)</span> <span class="kw">(</span>GCC<span class="kw">)</span> 
<span class="ot">COLLECT_GCC_OPTIONS=</span><span class="st">'-o'</span> <span class="st">'hello'</span> <span class="st">'-v'</span> <span class="st">'-fupc-link'</span> <span class="st">'-mtune=generic'</span> <span class="st">'-march=x86-64'</span>
...
GNU UPC <span class="kw">(</span>GCC<span class="kw">)</span> version 4.8.0 20130311 <span class="kw">(</span>GNU UPC 4.8.0-3<span class="kw">)</span> <span class="kw">(</span>x86_64-redhat-linux<span class="kw">)</span>
	compiled by GNU C version 4.8.0 20130311 <span class="kw">(</span>GNU UPC 4.8.0-3<span class="kw">)</span>,
        GMP version 5.0.5, MPFR version 3.1.1, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
...
<span class="co">#include &quot;...&quot; search starts here:</span>
<span class="co">#include &lt;...&gt; search starts here:</span>
 /usr/local/gupc/lib/gcc/x86_64-redhat-linux/4.8.0/include
 /usr/local/include
 /usr/local/gupc/include
 /usr/include
End of search list.
GNU UPC <span class="kw">(</span>GCC<span class="kw">)</span> version 4.8.0 20130311 <span class="kw">(</span>GNU UPC 4.8.0-3<span class="kw">)</span> <span class="kw">(</span>x86_64-redhat-linux<span class="kw">)</span>
	compiled by GNU C version 4.8.0 20130311 <span class="kw">(</span>GNU UPC 4.8.0-3<span class="kw">)</span>, 
        GMP version 5.0.5, MPFR version 3.1.1, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9db6d080c84dee663b5eb4965bf5012f
<span class="ot">COLLECT_GCC_OPTIONS=</span><span class="st">'-o'</span> <span class="st">'hello'</span> <span class="st">'-v'</span> <span class="st">'-fupc-link'</span> <span class="st">'-mtune=generic'</span> <span class="st">'-march=x86-64'</span>
 <span class="kw">as</span> -v --64 -o /tmp/cccSYlmb.o /tmp/ccTdo4Ku.s
...
<span class="ot">COLLECT_GCC_OPTIONS=</span><span class="st">'-o'</span> <span class="st">'hello'</span> <span class="st">'-v'</span> <span class="st">'-fupc-link'</span> <span class="st">'-mtune=generic'</span> <span class="st">'-march=x86-64'</span>
...</code></pre>
<p>The <em>-g</em> option will generate debug information. To output debugging symbol information in DWARF-2 (Debugging With Attributed Record Formats), use the <em>-dwarf-2-upc</em> option. This can be used with GDB-UPC, a GNU debugger that supports UPC.</p>
<p>The <em>-fupc-debug</em> option will also generate filename and the line numbers in the output.</p>
<p>The optimization levels are similar to the ones supported by GCC: ’-O0’, ’-O1’, ’-O2’, and ’-O3’.</p>
<p>Variables that are shared among threads are declared using the ‘shared’ keyword. Examples include:</p>
<pre class="sourceCode c"><code class="sourceCode c">shared <span class="dt">int</span> i;
shared <span class="dt">int</span> a[THREADS];
shared <span class="dt">char</span> *p;</code></pre>
<p>‘THREADS’ is a reserved keyword that represents the number of threads that will get executed run-time. Consider a simple vector addition example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;upc_relaxed.h&gt;</span>
<span class="ot">#include &lt;stdio.h&gt;</span>

shared <span class="dt">int</span> a[THREADS];
shared <span class="dt">int</span> b[THREADS];
shared <span class="dt">int</span> vsum[THREADS];

<span class="dt">int</span>
main()
{
  <span class="dt">int</span> i;

  <span class="co">/* Initialization */</span>
  <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++) {
    a[i] = i + <span class="dv">1</span>;               <span class="co">/* a[] = {1, 2, 3, 4, 5}; */</span>
    b[i] = THREADS - i;         <span class="co">/* b[] = {5, 4, 3, 2, 1}; */</span>
  }

  <span class="co">/* Computation */</span>
  <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++)
    <span class="kw">if</span> (MYTHREAD == i % THREADS)
      vsum[i] = a[i] + b[i];

  upc_barrier;

  <span class="co">/* Output */</span>
  <span class="kw">if</span> (MYTHREAD == <span class="dv">0</span>) {
    <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++)
      printf(<span class="st">&quot;%d &quot;</span>, vsum[i]);
  }

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>‘MYTHREAD’ indicates the thread that is currently running. <em>upc_barrier</em> is a blocking synchronization primitive that ensures that all threads complete before proceeding further. Only one thread is required to print the output, and THREAD 0 is used for the same. The program can be compiled, and executed using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc vector_addition.c -o vector_addition</span>
<span class="co"># ./vector_addition -n 5</span>

6 6 6 6 6</code></pre>
<p>The computation loop in the above code can be simplified with the <em>upc_forall</em> statement:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;upc_relaxed.h&gt;</span>
<span class="ot">#include &lt;stdio.h&gt;</span>

shared <span class="dt">int</span> a[THREADS];
shared <span class="dt">int</span> b[THREADS];
shared <span class="dt">int</span> vsum[THREADS];

<span class="dt">int</span>
main()
{
  <span class="dt">int</span> i;

  <span class="co">/* Initialization */</span>
  <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++) {
    a[i] = i + <span class="dv">1</span>;               <span class="co">/* a[] = {1, 2, 3, 4, 5}; */</span>
    b[i] = THREADS - i;         <span class="co">/* b[] = {5, 4, 3, 2, 1}; */</span>
  }

  <span class="co">/* Computation */</span>
  upc_forall(i=<span class="dv">0</span>; i&lt;THREADS; i++; i)
      vsum[i] = a[i] + b[i];

  upc_barrier;

  <span class="kw">if</span> (MYTHREAD == <span class="dv">0</span>) {
    <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++)
      printf(<span class="st">&quot;%d &quot;</span>, vsum[i]);
  }

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>The <em>upc_forall</em> construct is similar to a for loop, except, that it accepts a fourth parameter, the affinity field. It indicates the thread on which the computation runs. It can be an integer that is internally represented as <em>integer % THREADS</em>, or it can be an address corresponding to a thread. The program can be compiled and tested with:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc upc_vector_addition.c -o upc_vector_addition</span>
<span class="co"># ./upc_vector_addition -n 5</span>

6 6 6 6 6</code></pre>
<p>The same example can also be implemented using shared pointers:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;upc_relaxed.h&gt;</span>
<span class="ot">#include &lt;stdio.h&gt;</span>

shared <span class="dt">int</span> a[THREADS];
shared <span class="dt">int</span> b[THREADS];
shared <span class="dt">int</span> vsum[THREADS];

<span class="dt">int</span>
main()
{
  <span class="dt">int</span> i;
  shared <span class="dt">int</span> *p1, *p2;

  p1 = a;
  p2 = b;

  <span class="co">/* Initialization */</span>
  <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++) {
    *(p1 + i) = i + <span class="dv">1</span>;          <span class="co">/* a[] = {1, 2, 3, 4, 5}; */</span>
    *(p2 + i) = THREADS - i;    <span class="co">/* b[] = {5, 4, 3, 2, 1}; */</span>
  }

  <span class="co">/* Computation */</span>
  upc_forall(i=<span class="dv">0</span>; i&lt;THREADS; i++, p1++, p2++; i)
      vsum[i] = *p1 + *p2;

  upc_barrier;

  <span class="kw">if</span> (MYTHREAD == <span class="dv">0</span>)
	<span class="kw">for</span> (i = <span class="dv">0</span>; i &lt; THREADS; i++)
		printf(<span class="st">&quot;%d &quot;</span>, vsum[i]);

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc pointer_vector_addition.c -o pointer_vector_addition</span>
<span class="co"># ./pointer_vector_addition -n 5</span>

6 6 6 6 6</code></pre>
<p>Memory can also be allocated dynamically. The <em>upc_all_alloc</em> function will allocate collective global memory that is shared among threads. A collective function will be invoked by every thread. The <em>upc_global_alloc</em> function will allocate non-collective global memory which will be different for all threads in the shared address space. The <em>upc_alloc</em> function will allocate local memory for a thread. Their respective declarations are as follows:</p>
<pre class="sourceCode c"><code class="sourceCode c">shared <span class="dt">void</span> *upc_all_alloc (size_t nblocks, size_t nbytes);
shared <span class="dt">void</span> *upc_global_alloc (size_t nblocks, size_t nbytes);
shared <span class="dt">void</span> *upc_alloc (size_t nbytes);</code></pre>
<p>To protect access to shared data, you can use the following synchronization locks:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">void</span> upc_lock (upc_lock_t *l)
<span class="dt">int</span> upc_lock_attempt (upc_lock_t *l)
<span class="dt">void</span> upc_unlock(upc_lock_t *l)</code></pre>
<p>There are two types of barriers for synchronizing code. The <em>upc_barrier</em> construct is blocking. The non-blocking barrier uses <em>upc_notify</em> (non-blocking), and <em>upc_wait</em> (blocking) constructs. For example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;upc_relaxed.h&gt;</span>
<span class="ot">#include &lt;stdio.h&gt;</span>

<span class="dt">int</span>
main()
{
  <span class="dt">int</span> i;

  <span class="kw">for</span> (i=<span class="dv">0</span>; i&lt;THREADS; i++) {
    upc_notify;

    <span class="kw">if</span> (i == MYTHREAD)
      printf(<span class="st">&quot;Thread: %d</span><span class="ch">\n</span><span class="st">&quot;</span>, MYTHREAD);

    upc_wait;
  }

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>The corresponding output is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># gupc count.c -o count</span>
<span class="co"># ./count -n 5</span>

Thread:  0
Thread:  1
Thread:  2
Thread:  3
Thread:  4</code></pre>
<p>You can refer the <a href="http://www.gccupc.org/documents/gupc-user-doc.html">GUPC user guide</a> for more information.</p>]]></description>
    <pubDate>Tue, 20 Jan 2015 15:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2015/01/20/gnu-unified-parallel-c/news.html</guid>
</item>
<item>
    <title>Drawtiming</title>
    <link>http://www.shakthimaan.com/posts/2014/12/26/drawtiming/news.html</link>
    <description><![CDATA[<p><em>[Published in Electronics For You (EFY) magazine, January 2014 edition.]</em> <a href="http://electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=2029&amp;id=13463">Source</a></p>
<p><a href="http://drawtiming.sourceforge.net/">Drawtiming</a> is a free/open source software tool that can be used to generate digital circuit timing diagrams. It is released under the GNU General Public License (GPL). The tool accepts text file as an input from the user and generates image output in different file formats such as PNG, JPEG, PostScript, and PDF. The input needs to adhere to a specific syntax to describe the different signals, their inter-relationships, and transitions as described in the next section with examples.</p>
<p>Before you can try the examples, you need to install the drawtiming tool in your GNU/Linux system. Installation steps may be different from system to system. To install this software in Ubuntu 12.10, just click on Ubuntu Software Centre option from desktop and search for Drawtiming to install it.</p>
<p>For a basic input command example to generate a clock for three periods, the syntax is written as:</p>
<pre class="shell"><code>CLOCK=0.
CLOCK=1.
CLOCK=0.</code></pre>
<p>A period (.) is used to mark the end of each clock cycle. The first clock period lists and sets the inital states of the signals. Save the above three-line syntax as a .txt file. Here, we name the file as ‘basic.txt’ and save it in a folder named as, say, EFYdraw. Note that the syntax is case sensitive. To generate the timing diagram, open EFYdraw from the terminal window using ‘cd’ command and enter the following command against the prompt, and you will get the output diagram as shown in Fig. 1.</p>
<pre class="shell"><code>$ drawtiming -o basic.jpg basic.txt</code></pre>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<p>The <em>tick</em> keyword can also indicate a clock cycle. The following syntax creates a single period clock as shown below:</p>
<pre class="shell"><code>CLOCK=tick.</code></pre>
<p>The output diagram is shown in Fig. 2.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/tick.jpg" title="Figure 2." alt="Figure 2."></img><p class="caption">Figure 2.</p>
</div>
<p>The order in which the signal commands are listed determines the order in which they appear in the output. Multiple signals are separated by commas as shown below:</p>
<pre class="shell"><code>CLOCK=tick, FLAG=0.</code></pre>
<p>The output diagram is shown in Fig. 3.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/order.jpg" title="Figure 3." alt="Figure 3."></img><p class="caption">Figure 3.</p>
</div>
<p>A change in one signal that triggers a change in another can be expressed using arrow notation (=&gt;). In the following example (Fig. 4), when the address latch enable (ALE) signal changes state, the read signal (RD) changes its state in the subsequent cycle. The syntax is given below:</p>
<pre class="shell"><code>ALE=tick,    RD=0.
ALE =&gt; RD=1, ALE=0.</code></pre>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/trigger.jpg" title="Figure 4." alt="Figure 4."></img><p class="caption">Figure 4.</p>
</div>
<p>If the transition is in the same clock cycle, it can be indicated in the same clock period. For instance, both CLK and CLK2 change in the second clock period:</p>
<pre class="shell"><code>CLK=0,    CLK2=0.
CLK=tick, CLK2=1.</code></pre>
<p>The output is shown in Fig. 5.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/trigger-same-clock.jpg" title="Figure 5." alt="Figure 5."></img><p class="caption">Figure 5.</p>
</div>
<p>If there are multiple signal changes, you can separate them with a comma. For example, LED is turned on when both the chip select (CS) and output enable (OE) signals change state; then the syntax is written as:</p>
<pre class="shell"><code>CS=0, OE=0, LED=Z.
CS=1, OE=1.
CS, OE =&gt; LED=ON.</code></pre>
<p>The output is as shown in Fig. 6.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/multiple.jpg" title="Figure 6." alt="Figure 6."></img><p class="caption">Figure 6.</p>
</div>
<p>A semicolon can be used to separate a list of dependency signal changes for the same clock period, which is illustrated in the third clock period (refer Fig. 7) in the following example. The syntax is as given below:</p>
<pre class="shell"><code>CS=0, OE=0, LED=Z, DATA=Z.
CS=1, OE=1.
CS, OE =&gt; LED=ON;
DATA=DATA.</code></pre>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/semicolon.jpg" title="Figure 7." alt="Figure 7."></img><p class="caption">Figure 7.</p>
</div>
<p>Drawtiming has numerous command line options which can be seen by using the <em>-h</em> option. The supported output image formats are listed in ImageMagick website. A PDF output of the basic.txt example can be created by specifying the .pdf filename extension as shown below:</p>
<pre class="shell"><code>$ drawtiming -o basic.pdf basic.txt</code></pre>
<p>Here, the output will be the same as shown in Fig. 1, only file format is changed to .pdf.</p>
<p>The output image can be scaled with the <em>-x</em> option. To generate an image that is twice the default size, you can use the command as given below:</p>
<pre class="shell"><code>$ drawtiming -x 2 -o basic-twice.jpg basic.txt</code></pre>
<p>The output is as shown in Fig. 8.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic-twice.jpg" title="Figure 8." alt="Figure 8."></img><p class="caption">Figure 8.</p>
</div>
<p>If you want to be explicit about the pixel width and height, the <em>-p</em> option followed by width ‘x’ height can be specified as given below:</p>
<pre class="shell"><code>$ drawtiming -p 250x75 -o basic-p.jpg basic.txt</code></pre>
<p>The output is as shown in Fig. 9.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic-p.jpg" title="Figure 9." alt="Figure 9."></img><p class="caption">Figure 9.</p>
</div>
<p>The default cell width and height are 64 and 48 pixels, respectively. The <em>-w</em> and <em>-c</em> options are used to modify them:</p>
<pre class="shell"><code>$ drawtiming -c 100 -o basic-c.jpg basic.txt</code></pre>
<p>The output is as shown in Fig. 10.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic-c.jpg" title="Figure 10." alt="Figure 10."></img><p class="caption">Figure 10.</p>
</div>
<p>The line width can be changed using the <em>-l</em> option. For example:</p>
<pre class="shell"><code>$ drawtiming -l 3 -o basic-l.jpg basic.txt</code></pre>
<p>The output is as shown in Fig. 11.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic-l.jpg" title="Figure 11." alt="Figure 11."></img><p class="caption">Figure 11.</p>
</div>
<p>The default font size is 25 points. You can change it with the <em>-f</em> option. You can also specify a different font using the <em>–font <name></em> option.</p>
<pre class="shell"><code>$ drawtiming -f 10 -o basic-f.jpg basic.txt</code></pre>
<p>The output is as shown in Fig. 12.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic.jpg" title="Figure 1." alt="Figure 1."></img><p class="caption">Figure 1.</p>
</div>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/basic-f.jpg" title="Figure 12." alt="Figure 12."></img><p class="caption">Figure 12.</p>
</div>
<p>Timing delays can be displayed in the output using <em>-tD&gt;</em> construct between any two signals. In a simple I/O write cycle, the minimum time between a valid address and the I/O write (IOW) strobe is shown as 92 units (minimum) as follows:</p>
<pre class="shell"><code>ADDRESS=&quot;VALID ADDRESS&quot;, DATA=&quot;&quot;, IOW=1.
DATA=&quot;&quot;, IOW=0.
ADDRESS -92min&gt; IOW;
DATA=&quot;VALID DATA&quot;.
IOW=1.
IOW -516min&gt; DATA;
ADDRESS=&quot;&quot;, DATA=&quot;&quot;.</code></pre>
<p>The output is as shown in Fig. 13.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/delay.jpg" title="Figure 13." alt="Figure 13."></img><p class="caption">Figure 13.</p>
</div>
<p>For a real-world example, let us consider the write cycle of a 68008 microprocessor. During the write cycle, the CPU first asserts the read/write (RW) signal for write operation, followed by the address and data signals. The data strobe (DS) signal is then asserted, and the CPU waits for the receiver to acknowledge the same, as indicated by the data transfer acknowledge (DTACK) signal. The syntax for this ‘write’ cycle is as given below:</p>
<pre class="shell"><code>CLK=0, ADDRESS=Z, AS=1, RW=X, DS=1, DATA=X, DTACK=1.
CLK=1, RW=1, DATA=Z.
CLK=0, ADDRESS=&quot;VALID ADDR&quot;.
CLK=1, AS=0, RW=0.
CLK=0, DATA=&quot;VALID DATA&quot;.
CLK=1, DS=0.
CLK=0, DTACK=0.
CLK=1.
CLK=0, AS=1, DS=1, DTACK=1.
CLK=1, ADDRESS=&quot;&quot;, RW=1, DATA=&quot;&quot;.
.</code></pre>
<p>The output is as shown in Fig. 14.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/68008-write.jpg" title="Figure 14." alt="Figure 14."></img><p class="caption">Figure 14.</p>
</div>
<p>The 68008 read cycle is similar to the write cycle, except that the read signal in RW is asserted, and the DS signal is asserted one clock period earlier as shown below:</p>
<pre class="shell"><code>CLK=0, ADDRESS=Z, AS=1, RW=X, DS=1, DATA=X, DTACK=1.
CLK=1, RW=1, DATA=Z.
CLK=0, ADDRESS=&quot;VALID ADDR&quot;.
CLK=1, AS=0, DS=0.
CLK=0.
CLK=1.
CLK=0, DTACK=0.
CLK=1.
CLK=0, AS=1, DS=1, DATA=&quot;DATA&quot;, DTACK=1.
CLK=1, ADDRESS=&quot;&quot;, DATA=Z.
.</code></pre>
<p>The output is as shown in Fig. 15.</p>
<div class="figure">
<img src="http://shakthimaan.com/images/drawtiming/68008-read.jpg" title="Figure 15." alt="Figure 15."></img><p class="caption">Figure 15.</p>
</div>]]></description>
    <pubDate>Fri, 26 Dec 2014 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/12/26/drawtiming/news.html</guid>
</item>
<item>
    <title>GNU Parallel</title>
    <link>http://www.shakthimaan.com/posts/2014/11/27/gnu-parallel/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, October 2013 edition.]</em></p>
<p>GNU Parallel is a tool for running jobs in parallel in a Bash environment. The job can be a single command or a script, with variable arguments. The simultaneous execution can occur on remote machines as well. Released under the GPLv3+ license, you can install it on Fedora using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> parallel</code></pre>
<p>After installation, you need to remove ’–tollef’ from the /etc/parallel/config file, if it is present. This option will be permanently removed in future releases.</p>
<p>GNU Parallel takes a command and a list of arguments for processing. The arguments are provided in the command line after the notation ’:::’, and the command is executed for each argument. For example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> ::: alpha beta gamma
alpha
beta
gamma</code></pre>
<p>You can pass multiple arguments to GNU parallel, and it will run the command for every combination of the input, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> ::: 0 1 ::: 0 1
0 0
0 1
1 0
1 1</code></pre>
<p>The order in the output may be different. The tool provides a number of replacement string options. The default string ‘{}’ represents the input:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> <span class="dt">{}</span> ::: /tmp
/tmp</code></pre>
<p>The replacement string ‘{/}’ removes everything up to and including the last forward slash:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> <span class="dt">{/}</span> ::: /tmp/stdio.h
stdio.h</code></pre>
<p>If you want to return the path only, use the ‘{//}’ string:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> <span class="dt">{//}</span> ::: /tmp/stdio.h
/tmp</code></pre>
<p>The string ‘{.}’ removes any filename extension:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">echo</span> <span class="dt">{.}</span> ::: /tmp/stdio.h
/tmp/stdio</code></pre>
<p>The output of a GNU Parallel command may not necessarily be in the order in which the input arguments are listed. For example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">sleep</span> <span class="dt">{}\;</span> <span class="kw">echo</span> <span class="dt">{}</span> ::: 5 2 1 4 3
1
2
4
3
5</code></pre>
<p>If you wish to enforce the order of execution, use the ’-k’ option, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel -k <span class="kw">sleep</span> <span class="dt">{}\;</span> <span class="kw">echo</span> <span class="dt">{}</span> ::: 5 2 1 4 3
5
2
1
4
3</code></pre>
<p>A test script, for example, may need to be run ‘N’ times for the same argument. This can be accomplished with the following code:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">seq</span> 10 <span class="kw">|</span> parallel -n0 <span class="kw">echo</span> <span class="st">&quot;Hello, World&quot;</span>
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World
Hello, World</code></pre>
<p>The ’-n’ option represents the maximum number of arguments in the command line.</p>
<p>The commands that will get executed by GNU Parallel can be observed with the ’–dry-run’ option, as illustrated below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel --dry-run -k <span class="kw">sleep</span> <span class="dt">{}\;</span> <span class="kw">echo</span> <span class="dt">{}</span> ::: 5 2 1 4 3
<span class="kw">sleep</span> 5; <span class="kw">echo</span> 5
<span class="kw">sleep</span> 2; <span class="kw">echo</span> 2
<span class="kw">sleep</span> 1; <span class="kw">echo</span> 1
<span class="kw">sleep</span> 4; <span class="kw">echo</span> 4
<span class="kw">sleep</span> 3; <span class="kw">echo</span> 3</code></pre>
<p>The ’–eta’ option will give an estimate on the time it will take to complete a job:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel --eta -k <span class="kw">sleep</span> <span class="dt">{}\;</span> <span class="kw">echo</span> <span class="dt">{}</span> ::: 5 2 1 4 3

Computers / CPU cores / Max <span class="kw">jobs</span> to run
1:local / 4 / 4

Computer:jobs running/jobs completed/%of started jobs/Average seconds to <span class="kw">complete</span>
ETA: 5s 1left 1500avg  local:1/4/100%/1.0s 
2
1
4
3
ETA: 1s 0left 1.00avg  local:0/5/100%/1.0s </code></pre>
<p>Suppose you have a large number of log files that you wish to zip and archive, you can run the gzip command in Parallel, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">gzip</span> ::: *.log</code></pre>
<p>To unzip them all, you can use the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">gunzip</span> ::: *.gz</code></pre>
<p>The ‘convert’ command is useful to transform image files. High resolution images can be scaled to a lower resolution using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ convert -resize 512x384 file.jpg file_web.jpg</code></pre>
<p>If you have a large number of files that you wish to resize, you can parallelize the task, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> <span class="kw">.</span> -name <span class="st">'*.jpg'</span> <span class="kw">|</span> parallel convert -resize 512x384 <span class="dt">{}</span> <span class="dt">{}</span>_web.jpg</code></pre>
<p>GNU Parallel with wget can help in parallel downloads of large Linux kernel releases, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel <span class="kw">wget</span> ::: www.kernel.org/pub/linux/kernel/v3.x/linux-3.11.tar.xz <span class="kw">\</span>
                    www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.10.tar.xz</code></pre>
<p>The URLs can also be stored in a text file (“input.txt”), and passed as an argument to Parallel:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel -a input.txt <span class="kw">wget</span></code></pre>
<p>The file “input.txt” contains:</p>
<pre class="txt"><code>https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.11.tar.xz
https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.10.tar.xz</code></pre>
<p>The downloaded kernel images can also be extracted in Parallel:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> <span class="kw">.</span> -name <span class="dt">\*</span>.tar.xz <span class="kw">|</span> parallel <span class="kw">tar</span> xvf</code></pre>
<p>A ‘for’ loop in a Bash script can be parallelised. In the following script, the file sizes of all the text files are printed:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co">#!/bin/sh</span>

<span class="kw">for</span> <span class="kw">file</span> <span class="kw">in</span> <span class="kw">`ls</span> *.txt<span class="kw">`</span>; <span class="kw">do</span>
  <span class="kw">ls</span> -lh <span class="st">&quot;</span><span class="ot">$file</span><span class="st">&quot;</span>
<span class="kw">done</span> <span class="kw">|</span> <span class="kw">cut</span> -d<span class="st">' '</span> -f 5</code></pre>
<p>The parallelized version is as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">ls</span> *.txt <span class="kw">|</span> parallel <span class="st">&quot;ls -lh {}&quot;</span> <span class="kw">|</span> <span class="kw">cut</span> -d<span class="st">' '</span> -f 5</code></pre>
<p>The number of CPUs and cores in your system can be listed with GNU Parallel:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel --number-of-cpus
1
$ parallel --number-of-cores
4</code></pre>
<p>The ’-j’ option specifies the number of jobs to be run in parallel. If the value 0 is given, GNU Parallel will try to start as many jobs as possible. The ‘+ N’ option with ’-j’ adds N jobs to the CPU cores. For example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">find</span> <span class="kw">.</span> -type f -print <span class="kw">|</span> parallel -j+2 <span class="kw">ls</span> -l <span class="dt">{}</span></code></pre>
<p>The input to GNU parallel can also be provided in a tabular format. Suppose you want to run ping tests for different machines, you can have a text file with the first column indicating the ping count, and the second column listing the hostname or the IP address. For example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">cat</span> hosts.txt 
1 127.0.0.1
2 localhost</code></pre>
<p>You can run the tests in parallel using the following code:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ parallel -a hosts.txt --colsep <span class="st">' '</span> <span class="kw">ping</span> -c <span class="dt">{1}</span> <span class="dt">{2}</span>

PING 127.0.0.1 <span class="kw">(</span>127.0.0.1<span class="kw">)</span> 56<span class="kw">(</span>84<span class="kw">)</span> bytes of data.
64 bytes from 127.0.0.1: <span class="ot">icmp_seq=</span>1 ttl=64 time=0.074 ms

--- 127.0.0.1 <span class="kw">ping</span> statistics ---
1 packets transmitted, 1 received, 0% packet loss, <span class="kw">time</span> 0ms
rtt min/avg/max/mdev = 0.074/0.074/0.074/0.000 ms

PING localhost.localdomain <span class="kw">(</span>127.0.0.1<span class="kw">)</span> 56<span class="kw">(</span>84<span class="kw">)</span> bytes of data.
64 bytes from localhost.localdomain <span class="kw">(</span>127.0.0.1<span class="kw">):</span> <span class="ot">icmp_seq=</span>1 ttl=64 time=0.035 ms
64 bytes from localhost.localdomain <span class="kw">(</span>127.0.0.1<span class="kw">):</span> <span class="ot">icmp_seq=</span>2 ttl=64 time=0.065 ms

--- localhost.localdomain <span class="kw">ping</span> statistics ---
2 packets transmitted, 2 received, 0% packet loss, <span class="kw">time</span> 1000ms
rtt min/avg/max/mdev = 0.035/0.050/0.065/0.015 ms</code></pre>
<p>GNU Parallel can also execute jobs on remote machines, for which you need to first test that ssh works:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="ot">SERVER1=</span>localhost
$ <span class="kw">ssh</span> <span class="ot">$SERVER1</span> <span class="kw">echo</span> <span class="st">&quot;Eureka&quot;</span>
guest@localhost<span class="st">'s password: </span>
<span class="st">Eureka</span></code></pre>
<p>You can then invoke commands or scripts to be run on SERVER1, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$  parallel -S <span class="ot">$SERVER1</span> <span class="kw">echo</span> <span class="st">&quot;Eureka from &quot;</span> ::: <span class="ot">$SERVER1</span>
guest@localhost<span class="st">'s password: </span>
<span class="st">Eureka from localhost</span></code></pre>
<p>Files can also be transferred to remote machines using the ’–transfer’ option. Rsync is used internally for the transfer. An example is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$  parallel -S <span class="ot">$SERVER1</span> --transfer <span class="kw">cat</span> ::: /tmp/host.txt 
guest@localhost<span class="st">'s password: </span>
<span class="st">1 127.0.0.1</span>
<span class="st">2 localhost</span></code></pre>
<p>Refer to the GNU Parallel tutorial and manual page for more options and examples.</p>]]></description>
    <pubDate>Thu, 27 Nov 2014 17:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/11/27/gnu-parallel/news.html</guid>
</item>
<item>
    <title>Analyse Linux Kernel Code with Sparse</title>
    <link>http://www.shakthimaan.com/posts/2014/10/30/analyse-linux-kernel-code-with-sparse/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, October 2013 edition.]</em></p>
<p>Sparse is a semantic parser written for static analysis of the Linux kernel code. Here’s how you can use it to analyse Linux kernel code.</p>
<p>Sparse implements a compiler front-end for the C programming language, and is released under the Open Software License (version 1.1). You can obtain the latest sources via git:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git </code></pre>
<p>You can also install it on Fedora using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> sparse</code></pre>
<p>The inclusion of ‘C=1’ to the <em>make</em> command in the Linux kernel will invoke Sparse on the C files to be compiled. Using ‘make C=2’ will execute Sparse on all the source files. There are a number of options supported by Sparse that provide useful warning and error messages. To disable any warning, use the ’-Wno-option’ syntax. Consider the following example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">void</span>
foo (<span class="dt">void</span>)
{
}

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  foo();

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Running sparse on the above decl.c file gives the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include decl.c

decl.c:2:1: warning: symbol <span class="st">'foo'</span> was not declared<span class="kw">.</span> Should it be static?</code></pre>
<p>The ’-Wdecl’ option is enabled by default, and detects any non-static variables or functions. You can disable it with the ’-Wno-decl’ option. To fix the warning, the function <em>foo()</em> should be declared static. A similar output was observed when Sparse was run on Linux 3.10.9 kernel sources:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">arch/x86/crypto/fpu.c:153:12: warning: symbol <span class="st">'crypto_fpu_init'</span> was not declared<span class="kw">.</span> 
Should it be static?</code></pre>
<p>While the C99 standard allows declarations after a statement, the C89 standard does not permit it. The following <em>decl-after.c</em> example includes a declaration after an assignment statement:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">int</span> x;

  x = <span class="dv">3</span>;

  <span class="dt">int</span> y;

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>When using C89 standard with the ’-ansi’ or ’-std=c89’ option, Sparse emits a warning, as shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include -ansi decl-after.c

decl-after.c:8:3: warning: mixing declarations and code</code></pre>
<p>This Sparse command line step can be automated with a Makefile:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">TARGET = decl-after

SPARSE_INCLUDE = -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
                 -I/usr/include

SPARSE_OPTIONS = -ansi

all:
	sparse <span class="ot">$(</span>SPARSE_INCLUDE<span class="ot">)</span> <span class="ot">$(</span>SPARSE_OPTIONS<span class="ot">)</span> <span class="ot">$(</span>TARGET<span class="ot">)</span>.c

clean:
	<span class="kw">rm</span> -f <span class="ot">$(</span>TARGET<span class="ot">)</span> *~ a.out</code></pre>
<p>If a void expression is returned by a function whose return type is void, Sparse issues a warning. This option needs to be explicitly specified with a ’-Wreturn-void’. For example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">static</span> <span class="dt">void</span>
foo (<span class="dt">int</span> y)
{
  <span class="dt">int</span> x = <span class="dv">1</span>;

  x = x + y;
}

<span class="dt">static</span> <span class="dt">void</span>
fd (<span class="dt">void</span>)
{
  <span class="kw">return</span> foo(<span class="dv">3</span>);
}

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  fd();

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Executing the above code with Sparse results in the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include -Wreturn-void void.c

void.c:12:3: warning: returning void-valued expression</code></pre>
<p>The ’-Wcast-truncate’ option warns about truncation of bits during casting of constants. This is enabled by default. An 8-bit character is assigned more than it can hold in the following:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">char</span> i = <span class="bn">0xFFFF</span>;
  
  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Sparse warns of truncation for the above code:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include trun.c 

trun.c:4:12: warning: cast truncates bits from constant value <span class="kw">(</span>ffff becomes ff<span class="kw">)</span></code></pre>
<p>A truncation warning from Sparse for Linux 3.10.9 kernel is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">arch/x86/kvm/svm.c:613:17: warning: cast truncates bits from 
constant value <span class="kw">(</span>100000000 becomes 0<span class="kw">)</span></code></pre>
<p>Any incorrect assignment between enums is checked with the ’-Wenum-mismatch’ option. To disable this check, use ’-Wno-enum-mismatch’. Consider the following enum.c code:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="kw">enum</span> e1 {a};
<span class="kw">enum</span> e2 {b};

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="kw">enum</span> e1 x;
  <span class="kw">enum</span> e2 y;

  x = y;

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Testing with Sparse, you get the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include enum.c

enum.c:10:7: warning: mixing different enum types
enum.c:10:7:     int enum e2  versus
enum.c:10:7:     int enum e1     </code></pre>
<p>Similar Sparse warnings can also be seen for Linux 3.10.9:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">drivers/leds/leds-lp3944.c:292:23: warning: mixing different enum types
drivers/leds/leds-lp3944.c:292:23:     int enum led_brightness  versus
drivers/leds/leds-lp3944.c:292:23:     int enum lp3944_status </code></pre>
<p>NULL is of pointer type, while, the number 0 is of integer type. Any assignment of a pointer to 0 is flagged by the ’-Wnon-pointer-null’ option. This warning is enabled by default. An integer pointer ‘p’ is set to zero in the following example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">int</span> *p = <span class="dv">0</span>;

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Sparse notifies the assignment of 0 as a NULL pointer:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include nullp.c 

nullp.c:4:12: warning: Using plain integer <span class="kw">as</span> NULL pointer</code></pre>
<p>Given below is another example of this warning in Linux 3.10.9:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">arch/x86/kvm/vmx.c:8057:48: warning: Using plain integer <span class="kw">as</span> NULL pointer</code></pre>
<p>The corresponding source code on line number 8057 contains:</p>
<pre class="sourceCode c"><code class="sourceCode c">vmx-&gt;nested.apic_access_page = <span class="dv">0</span>;</code></pre>
<p>The GNU Compiler Collection (GCC) has an old, non-standard syntax for initialisation of fields in structures or unions:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">static</span> <span class="kw">struct</span>
{
  <span class="dt">int</span> x;
} local = { x: <span class="dv">0</span> };

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Sparse issues a warning when it encounters this syntax, and recommends the use of the C99 syntax:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include old.c 

old.c:4:13: warning: obsolete struct initializer, use C99 syntax</code></pre>
<p>This option is also enabled by default. The ’-Wdo-while’ option checks if there are any missing parentheses in a <em>do-while</em> loop:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">int</span> x = <span class="dv">0</span>;

  <span class="kw">do</span>
    x = <span class="dv">3</span>;
  <span class="kw">while</span> (<span class="dv">0</span>); 

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>On running while.c with Sparse, you get:</p>
<pre><code>$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include \
         -I/usr/include -Wdo-while while.c

while.c:7:5: warning: do-while statement is not a compound statement</code></pre>
<p>This option is not enabled by default. The correct use of the the <em>do-while</em> construct is as follows:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">int</span> x = <span class="dv">0</span>;

  <span class="kw">do</span> {
    x = <span class="dv">3</span>;
  } <span class="kw">while</span> (<span class="dv">0</span>); 

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>A preprocessor conditional that is undefined can be detected with the ’-Wundef’ option. This must be specified explicitly. The preprocessor FOO is not defined in the following <em>undef.c</em> code:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#if FOO</span>
<span class="ot">#endif</span>

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Executing <em>undef.c</em> with Sparse, the following warning is shown:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include -Wundef undef.c

undef.c:1:5: warning: undefined preprocessor identifier <span class="st">'FOO</span></code></pre>
<p>The use of parenthesised strings in array initialisation is detected with the ’-Wparen-string’ option:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span>
main (<span class="dt">void</span>)
{
  <span class="dt">char</span> x1[] = { (<span class="st">&quot;hello&quot;</span>) };

  <span class="kw">return</span> <span class="dv">0</span>;
}</code></pre>
<p>Sparse warns of parenthesised string initialization for the above code:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ sparse -I/usr/include/linux -I/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include <span class="kw">\</span>
         -I/usr/include -Wparen-string paren.c

paren.c:4:18: warning: array initialized from parenthesized string constant
paren.c:4:18: warning: too long initializer-string <span class="kw">for</span> array of char</code></pre>
<p>The ’-Wsparse-all’ option enables all warnings, except those specified with ’-Wno-option’. The width of a tab can be specified with the ’-ftabstop=WIDTH’ option. It is set to 8 by default. This is useful to match the right column numbers in the errors or warnings.</p>
<p>You can refer to the following manual page for more available options:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">man</span> sparse</code></pre>]]></description>
    <pubDate>Thu, 30 Oct 2014 16:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/10/30/analyse-linux-kernel-code-with-sparse/news.html</guid>
</item>
<item>
    <title>Functional Conf 2014, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2014/10/16/functional-conf-2014/news.html</link>
    <description><![CDATA[<p>I attended <a href="http://functionalconf.com/">Functional Conf 2014</a> between October 9-11, 2014 at Hotel Chancery Pavilion, Bengaluru.</p>
<p>Day I</p>
<img alt="Stage" src="http://shakthimaan.com/images/functionalconf-2014/fc2014-stage.JPG"></img>
<p>The first day began with the keynote by Dr. Venkat Subramaniam on the <a href="http://confengine.com/functional-conf-2014/proposal/420/keynote-the-joy-of-functional-programming">“The Joy of Functional Programming”</a>. The talk was centered around what is ‘mainstream’, and why something that is mainstream is not necessarily the ideal approach. He gave examples on writing functional programs in Java, and how these code expressions are easy to read and test.</p>
<p>I then attended the talk on <a href="http://confengine.com/functional-conf-2014/proposal/329/functional-reactive-uis-with-elm">“Functional Reactive UIs with Elm”</a> by Shashi Gowda. He gave an introduction to the <a href="http://elm-lang.org/">Elm functional programming language</a> with UI reactive examples. The syntax of Elm is similar to that of Haskell. The idea is to write less code for creating interactive applications, and Elm generates HTML, CSS and Javascript. There are also <a href="https://github.com/seliopou/elm-d3">d3.js bindings for Elm</a>.</p>
<p>The talk on <a href="http://confengine.com/functional-conf-2014/proposal/354/applying-functional-programming-principles-to-large-scale-data-processing">“Applying functional programming principles to large scale data processing”</a> by Kishore Nallan from Indix introduced the “Lambda Architecture”. They scrap product details from web pages worldwide, and receive 4 TB of data every day. The architecture uses an append-only database, and has multiple readers and views for the data. You can check their <a href="http://engineering.indix.com/blog/">engineering.indix.com/blog</a> for more information on their attempts to process large data. <a href="https://github.com/twitter/scalding">Scalding</a>, <a href="http://www.cascading.org/">Cascading</a>, <a href="https://spark.apache.org/">Apache Spark</a>, and <a href="https://github.com/apache/storm">Storm</a> are tools that they are experimenting with.</p>
<p>Thomas Gazagnaire talk on <a href="http://confengine.com/functional-conf-2014/proposal/476/compile-your-own-cloud-with-mirage-os-v20">“Compile your own cloud with Mirage OS v2.0”</a> was very interesting on how they stripped down the entire OS and applications, and re-wrote them in OCaml for use in production environments. The Mirage OS is a unikernel and targets the Xen hypervisor. It is type safe, and faster to deploy and use. It uses light-weight threads. <a href="https://opam.ocaml.org/">OPAM</a> is the OCaml Package Manager. <a href="https://github.com/mirage/irmin">IRMIN</a> is an example of a distributed database implemented in OCaml. The TLS protocol was implemented in pure OCaml and deployed as a service. The demo server is available at <a href="https://tls.openmirage.org/">tls.openmirage.org</a>.</p>
<p><a href="http://confengine.com/functional-conf-2014/proposal/386/property-based-testing-for-functional-domain-models">“Property based testing for functional domain models”</a> by Debasish Ghosh introduced the concept of generative data for tests in Scala. The idea is from the QuickCheck library and property-based testing in Haskell. This allows you to focus on executable domain rules. We can get some properties for free in statically typed languages. He mentioned <a href="https://github.com/milessabin/shapeless">shapeless</a>, a type class and dependent type generic programming library for Scala, and also <a href="https://github.com/twitter/algebird">Algebird</a>, which provides Abstract Algebra for Scala.</p>
<p>Vagmi Mudumbai wrote a simple TODO MVC web application using <a href="http://clojure.org/clojurescript">ClojureScript</a> and <a href="https://github.com/swannodette/om">Om</a> in his <a href="http://confengine.com/functional-conf-2014/proposal/326/clojurescript-and-om-pragmatic-functional-programming-in-the-javascript-land">“ClojureScript and Om - Pragmatic functional programming in the Javascript Land”</a> talk. Clojure and ClojureScript can help you write concise code for the problem you want to solve. The immutability of Clojure and the DOM manipulation mutability of <a href="http://facebook.github.io/react/">React.js</a> complement each other well in implementing performance-savvy web sites.</p>
<p><a href="http://www.confengine.com/functional-conf-2014/proposal/320/learning-from-haskell-an-experience-report">“Learning (from) Haskell - An experience report”</a> by Aditya Godbole was an attempt to teach functional problem solving using <a href="http://en.wikipedia.org/wiki/Gofer_%28programming_language%29">Gofer</a> in an organization, and the lessons learnt.</p>
<p>At the end of the day, a <a href="http://en.wikipedia.org/wiki/Fishbowl_(conversation)">Fish Bowl</a> was organized where people discussed the choice of functional programming language for development, and the also shared their experiences on how they solved problems in the industry using functional programming.</p>
<p>After dinner, there was a <a href="http://en.wikipedia.org/wiki/Birds_of_a_feather_(computing)">BoF</a> session on Clojure, but, it ended with mostly discussions on different programming paradigms, and functional programming languages.</p>
<p>Day II</p>
<p>The first keynote on the second day was by Bruce Tate on <a href="http://confengine.com/functional-conf-2014/proposal/711/fear-the-role-of-fear-in-language-adoption">“Fear: The Role of Fear in Language Adoption”</a>. He classified the challenges in moving to functional programming into two categories - paralyzing fears and motivational fears. The paralyzing fears are on adoption, cost and getting developers. These can be overcome by building communities, having object-oriented languages implement functional programming features, better deployment options, and with cleaner interfaces. The motivating fears can be overcome by the need for handling code complexity, software to run for multi-core and large distributed systems, and for solving complex problems. He also mentioned that he sees three large programming language communities today - a hybrid, only functional programming, and the JavaScript land.</p>
<img alt="Morten" src="http://shakthimaan.com/images/functionalconf-2014/fc2014-morten.JPG"></img>
<p>Morten Kromberg introduced APL (A Programming Language) and Dyalog in his <a href="http://confengine.com/functional-conf-2014/proposal/436/pragmatic-functional-programming-using-dyalog">“Pragmatic Functional Programming using Dyalog”</a> talk. APL was invented by Kenneth E. Iverson, an ACM Turing award recipient. <a href="http://jsoftware.com/papers/EvalOrder.htm">Conventions Governing Order of Evaluation</a> by Kenneth explains the context and need for APL. You can try the language using the online REPL at <a href="http://tryapl.org">tryapl.org</a>. There are no reserved keywords in this language. Morten also gave a demo of MiServer which is a free and open source web server written in APL. A number of libraries are also available at <a href="http://tools.dyalog.com/library/">tools.dyalog.com/library/</a>.</p>
<p>Tejas Dinkar talked on <a href="http://confengine.com/functional-conf-2014/proposal/437/monads-you-already-use-without-knowing-it">“Monads you already use (without knowing it)”</a> where he tried to mimic the functionality of Haskell Monads in Ruby, but, there are differences in their actual implementation.</p>
<p><a href="http://confengine.com/functional-conf-2014/proposal/325/purely-functional-data-structures-demystified">“Purely functional data structures demystified”</a> by Mohit Thatte was an excellent talk that illustrates the thesis on <a href="https://www.cs.cmu.edu/~rwh/theses/okasaki.pdf">Purely Functional Data Structures</a> by Chris Okasaki. Mohit explained how data structures can be built on existing lists, and structural decomposition is an effective way to model complex data. An abstract data type (ADT) can thus be structurally decomposed using list data structures. Every abstract data type can be defined by its operations and invariants. For example, the stack has both push and pop operations, and the invariant is the property of a stack to follow Last In First Out (LIFO). Most programming languages don’t have an expressive power to specify the invariants. He explained functional data structures built with Clojure in simple words, and gave plenty of examples to illustrate the concepts.</p>
<p>I had a chance to meet Ramakrishnan Muthukrishnan, who has been a Debian contributor since 2001. Ramakrishnan’s talk was <a href="http://confengine.com/functional-conf-2014/proposal/359/-an-introduction-to-continuation-passing-style-cps">“An introduction to Continuation Passing Style (CPS)”</a> using the Scheme programming language. A continuation is what is needed to complete the rest of the computation. It provides an alternative model for the use of stacks between function calls. He gave plenty of examples on how to convert an existing piece of code into CPS. Will Byrd’s Google Hangout talk on <a href="http://www.youtube.com/watch?v=2GfFlfToBCo">Introduction to Continuations, call/cc, and CPS</a> was recommended.</p>
<p><a href="http://confengine.com/functional-conf-2014/proposal/452/elixir-today-a-round-up-on-state-of-elixir-and-its-ecosystem">“Elixir Today: a round-up on state of Elixir and it’s ecosystem”</a> talk by Akash Manohar gave an introduction to the Elixir programming language. The language is built on the Erlang VM, and the community has taken lot of goodies from the Ruby world. <a href="http://elixir-lang.org/docs/stable/mix/">Mix</a> is the tool used to create, build and test Elixir projects, and <a href="http://hex.pm/">Hex</a> is the package manager used for Erlang. Elixir code can be deployed to Heroku using a buildpack. A number of useful software are already available - <a href="https://github.com/devinus/poison">Poison</a> is a JSON parser, <a href="https://github.com/HashNuke/hound">Hound</a> for browser automation and integration tests, <a href="https://github.com/elixir-lang/ecto">Ecto</a> is a DSL for communicating with databases, <a href="https://github.com/phoenixframework/phoenix">Phoenix</a> is a web frawework for real-time, fault-tolerant applications, and <a href="https://github.com/nurugger07/calliope">Calliope</a> is an Elixir HAML parser.</p>
<p>The final keynote of the conference was a brilliant talk by Daniel Steinberg on <a href="http://confengine.com/functional-conf-2014/proposal/712/methodologies-mathematics-and-the-metalinguistic-implications-of-swift">“Methodologies, Mathematics, and the Metalinguistic Implications of Swift”</a>. He began on how people learn mathematics, and why we should reconsider the way we teach geometry. He emphasized that we always try to learn from someone in school (games, for example). Instead of presenting a programming language grammar, the rules can be presented in a playful way. Individuals and interactions are very important in problem solving. Math has a soul and it is beautiful. After providing proofs in geometry with beautiful illustrations, he goes on to say that there are things in mathematics that we can prove, and things that we cannot prove, and we have to accept that, giving examples from the Swift programming language. This was the best talk in the conference.</p>
<p>Day III</p>
<img alt="Banner" src="http://shakthimaan.com/images/functionalconf-2014/fc2014-banner.JPG"></img>
<p>I attended the “Clojure Deep-dive” workshop by Baishampayan Ghose (BG). He started with the basics of Clojure and an introduction to functional style of programming. Clojure is opinionated, and the emphasis is on simplicity and fast problem solving. It involves programming at the speed of thought, and aims to make you more productive.</p>
<p>We used the Clojure REPL to practice writing simple functions. You need to determine the data structures that you want to use first, and then work on writing functions. In Clojure, data is of greater importance than code. The <a href="https://github.com/technomancy/emacs-starter-kit">Emacs Clojure Starter Kit</a> can be used to get the required environment to work with the REPL. <a href="http://clojuredocs.org/">Clojuredocs</a> is a useful quick reference.</p>
<p>We then worked on solving a real problem of counting the most frequently used words from the ‘Alice in Wonderland’ book from <a href="http://www.gutenberg.org/">Project Gutenberg</a>. BG then explained the use and power of macros, multimethods, and concurrency capabilities in Clojure. Macros allow DSLs to be represented in the Clojure language itself. There is a <a href="https://github.com/clojure/core.typed">core.typed</a> library for static typing. <a href="https://github.com/clojure/core.async">core.async</a> can be used for asynchronous programming. <a href="https://github.com/cgrand/enlive">Enlive</a> is a selector based (CSS) templating library, and <a href="https://github.com/ring-clojure/ring">Ring</a> is a Clojure web applications library. You can find more goodies from the <a href="http://www.clojure-toolbox.com/">The Clojure Toolbox</a>.</p>
<p>A couple of online resources to get started with Clojure are <a href="http://www.braveclojure.com/">Clojure for the Brave and True</a> and <a href="http://aphyr.com/tags/Clojure-from-the-ground-up">Clojure from the Ground Up</a>.</p>
<p>The video recordings of the talks should be made available in YouTube.</p>
<p>I would like to thank <a href="http://systeminsights.com/">Manufacturing System Insights</a> for sponsoring my trip to the conference.</p>]]></description>
    <pubDate>Thu, 16 Oct 2014 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/10/16/functional-conf-2014/news.html</guid>
</item>
<item>
    <title>A peek into the CUnit testing framework</title>
    <link>http://www.shakthimaan.com/posts/2014/09/24/cunit/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, September 2013 edition.]</em></p>
<p>CUnit is a free and open source, unit testing, software framework written in C. It provides a very simple interface to write unit tests, and has a number of assertions for testing data and functions.</p>
<p>CUnit is created as a library that links with the user’s code under test. It is packaged and is available in most GNU/Linux distributions. It has been released under the LGPLv2+ license. You can install it on Fedora, for example, using the following command:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> CUnit</code></pre>
<p>The CUnit framework helps manage test cases, the test registry, and test suites. A systematic approach is to write unit tests for your code, initialize the CUnit test registry, add the test suites to the test registry, and then add the unit tests to the suites. Set-up and clean-up functions can be written for each test suite. All the test suites can be executed together or can be run selectively. The user interface method to run the tests needs to be decided before executing them. The test registry needs to be cleaned up before returning the error condition and exiting from the test run. Consider the following simple example:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;CUnit/CUnit.h&gt;</span>

<span class="dt">int</span> init_suite(<span class="dt">void</span>)  { <span class="kw">return</span> <span class="dv">0</span>; }
<span class="dt">int</span> clean_suite(<span class="dt">void</span>) { <span class="kw">return</span> <span class="dv">0</span>; }

<span class="dt">int</span>
is_even (<span class="dt">int</span> x)
{
  <span class="kw">return</span> (x % <span class="dv">2</span> == <span class="dv">0</span>);
}

<span class="dt">void</span>
test_is_even (<span class="dt">void</span>)
{
  CU_ASSERT(is_even(<span class="dv">1</span>)  == <span class="dv">0</span>);
  CU_ASSERT(is_even(<span class="dv">2</span>)  == <span class="dv">1</span>);
  CU_ASSERT(is_even(<span class="dv">3</span>)  == <span class="dv">0</span>);
}

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
   CU_pSuite pSuite = NULL;

   <span class="co">/* Initialize CUnit test registry */</span>
   <span class="kw">if</span> (CUE_SUCCESS != CU_initialize_registry())
      <span class="kw">return</span> CU_get_error();

   <span class="co">/* Add suite to registry */</span>
   pSuite = CU_add_suite(<span class="st">&quot;Basic_Test_Suite&quot;</span>, init_suite, clean_suite);
   <span class="kw">if</span> (NULL == pSuite) {
      CU_cleanup_registry();
      <span class="kw">return</span> CU_get_error();
      }

   <span class="co">/* add test to suite */</span>
   <span class="kw">if</span> ((NULL == CU_add_test(pSuite, <span class="st">&quot;test_is_even&quot;</span>, test_is_even)))
   {
      CU_cleanup_registry();
      <span class="kw">return</span> CU_get_error();
   }

   <span class="co">/* Run tests using Basic interface */</span>
   CU_basic_run_tests();

   <span class="co">/* Clean up registry and return */</span>
   CU_cleanup_registry();
   <span class="kw">return</span> CU_get_error();
}</code></pre>
<p>You can compile the above code using:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">gcc</span> basic.c -o basic -lcunit -lcurses</code></pre>
<p>The above step can also be abstracted and automated in a Makefile for subsequent compilation and testing, as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">CC = <span class="kw">gcc</span>
CUNIT_LDFLAGS = -lcunit -lcurses

objects = basic

all:
	<span class="ot">$(</span>foreach <span class="kw">file</span>,<span class="ot">$(</span>objects<span class="ot">)</span>, <span class="ot">$(</span>CC<span class="ot">)</span> <span class="ot">$(</span><span class="kw">file</span><span class="ot">)</span>.c -o <span class="ot">$(</span><span class="kw">file</span><span class="ot">)</span> <span class="ot">$(</span>CUNIT_LDFLAGS<span class="ot">)</span> ;<span class="ot">)</span>

clean:
	<span class="kw">rm</span> -f *~ *.o <span class="ot">$(</span>objects<span class="ot">)</span></code></pre>
<p>You can type ‘make’ in the terminal to compile the code, as follows:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">make</span>
<span class="kw">gcc</span> basic.c -o basic -lcunit -lcurses ;</code></pre>
<p>On execution, you get the following output:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./basic 


     CUnit - A unit testing framework <span class="kw">for</span> C - Version 2.1-2
     http://cunit.sourceforge.net/



Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      1      1    n/a      0        0
               tests      1      1      1      0        0
             asserts      3      3      3      0      n/a

Elapsed <span class="kw">time</span> =    0.000 seconds</code></pre>
<p>The above example uses the Basic interface output from CUnit. A number of assertions have been defined in CUnit/CUnit.h file. Some of them are:</p>
<table>
<col width="66%"></col>
<col width="33%"></col>
<tbody>
<tr class="odd">
<td align="left">CU_ASSERT(int expression) CU_ASSERT_FATAL(int expression)</td>
<td align="left">Check expression is non-zero</td>
</tr>
<tr class="even">
<td align="left">CU_ASSERT_TRUE(value) CU_ASSERT_TRUE_FATAL(value)</td>
<td align="left">Check value is non-zero</td>
</tr>
<tr class="odd">
<td align="left">CU_ASSERT_FALSE(value) CU_ASSERT_FALSE_FATAL(value)</td>
<td align="left">Check value is zero</td>
</tr>
<tr class="even">
<td align="left">CU_ASSERT_EQUAL(actual, expected) CU_ASSERT_EQUAL_FATAL(actual, expected)</td>
<td align="left">Check actual == expected</td>
</tr>
<tr class="odd">
<td align="left">CU_ASSERT_NOT_EQUAL(actual, expected) CU_ASSERT_NOT_EQUAL_FATAL(actual, expected)</td>
<td align="left">Check actual != expected</td>
</tr>
<tr class="even">
<td align="left">CU_ASSERT_PTR_NULL(value) CU_ASSERT_PTR_NULL_FATAL(value)</td>
<td align="left">Check pointer == NULL</td>
</tr>
<tr class="odd">
<td align="left">CU_ASSERT_PTR_NOT_NULL(value) CU_ASSERT_PTR_NOT_NULL_FATAL(value)</td>
<td align="left">Check pointer != NULL</td>
</tr>
<tr class="even">
<td align="left">CU_ASSERT_STRING_EQUAL(actual, expected) CU_ASSERT_STRING_EQUAL_FATAL(actual, expected)</td>
<td align="left">Check actual == expected</td>
</tr>
</tbody>
</table>
<p>The Automated interface dumps the output of the test results to an XML file. The following code snippet is used for the Automated interface:</p>
<pre class="sourceCode c"><code class="sourceCode c">   <span class="co">/* Run tests using the Automated interface */</span>
   CU_automated_run_tests();</code></pre>
<p>The compilation step is similar to the Basic example. The output is dumped to the CUnitAutomated-Results.xml file, which contains the following:</p>
<pre class="sourceCode xml"><code class="sourceCode xml"><span class="kw">&lt;?xml</span> version=&quot;1.0&quot; <span class="kw">?&gt;</span> 
<span class="kw">&lt;?xml-stylesheet</span> type=&quot;text/xsl&quot; href=&quot;CUnit-Run.xsl&quot; <span class="kw">?&gt;</span> 
<span class="dt">&lt;!DOCTYPE </span>CUNIT_TEST_RUN_REPORT SYSTEM &quot;CUnit-Run.dtd&quot;<span class="dt">&gt;</span> 
<span class="kw">&lt;CUNIT_TEST_RUN_REPORT&gt;</span> 
  <span class="kw">&lt;CUNIT_HEADER/&gt;</span> 
  <span class="kw">&lt;CUNIT_RESULT_LISTING&gt;</span> 
    <span class="kw">&lt;CUNIT_RUN_SUITE&gt;</span> 
      <span class="kw">&lt;CUNIT_RUN_SUITE_SUCCESS&gt;</span> 
        <span class="kw">&lt;SUITE_NAME&gt;</span> Basic_Test_Suite <span class="kw">&lt;/SUITE_NAME&gt;</span> 
        <span class="kw">&lt;CUNIT_RUN_TEST_RECORD&gt;</span> 
          <span class="kw">&lt;CUNIT_RUN_TEST_SUCCESS&gt;</span> 
            <span class="kw">&lt;TEST_NAME&gt;</span> test_is_even <span class="kw">&lt;/TEST_NAME&gt;</span> 
          <span class="kw">&lt;/CUNIT_RUN_TEST_SUCCESS&gt;</span> 
        <span class="kw">&lt;/CUNIT_RUN_TEST_RECORD&gt;</span> 
      <span class="kw">&lt;/CUNIT_RUN_SUITE_SUCCESS&gt;</span> 
    <span class="kw">&lt;/CUNIT_RUN_SUITE&gt;</span> 
  <span class="kw">&lt;/CUNIT_RESULT_LISTING&gt;</span>
  <span class="kw">&lt;CUNIT_RUN_SUMMARY&gt;</span> 
    <span class="kw">&lt;CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
      <span class="kw">&lt;TYPE&gt;</span> Suites <span class="kw">&lt;/TYPE&gt;</span> 
      <span class="kw">&lt;TOTAL&gt;</span> 1 <span class="kw">&lt;/TOTAL&gt;</span> 
      <span class="kw">&lt;RUN&gt;</span> 1 <span class="kw">&lt;/RUN&gt;</span> 
      <span class="kw">&lt;SUCCEEDED&gt;</span> - NA - <span class="kw">&lt;/SUCCEEDED&gt;</span> 
      <span class="kw">&lt;FAILED&gt;</span> 0 <span class="kw">&lt;/FAILED&gt;</span> 
      <span class="kw">&lt;INACTIVE&gt;</span> 0 <span class="kw">&lt;/INACTIVE&gt;</span> 
    <span class="kw">&lt;/CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
    <span class="kw">&lt;CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
      <span class="kw">&lt;TYPE&gt;</span> Test Cases <span class="kw">&lt;/TYPE&gt;</span> 
      <span class="kw">&lt;TOTAL&gt;</span> 1 <span class="kw">&lt;/TOTAL&gt;</span> 
      <span class="kw">&lt;RUN&gt;</span> 1 <span class="kw">&lt;/RUN&gt;</span> 
      <span class="kw">&lt;SUCCEEDED&gt;</span> 1 <span class="kw">&lt;/SUCCEEDED&gt;</span> 
      <span class="kw">&lt;FAILED&gt;</span> 0 <span class="kw">&lt;/FAILED&gt;</span> 
      <span class="kw">&lt;INACTIVE&gt;</span> 0 <span class="kw">&lt;/INACTIVE&gt;</span> 
    <span class="kw">&lt;/CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
    <span class="kw">&lt;CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
      <span class="kw">&lt;TYPE&gt;</span> Assertions <span class="kw">&lt;/TYPE&gt;</span> 
      <span class="kw">&lt;TOTAL&gt;</span> 3 <span class="kw">&lt;/TOTAL&gt;</span> 
      <span class="kw">&lt;RUN&gt;</span> 3 <span class="kw">&lt;/RUN&gt;</span> 
      <span class="kw">&lt;SUCCEEDED&gt;</span> 3 <span class="kw">&lt;/SUCCEEDED&gt;</span> 
      <span class="kw">&lt;FAILED&gt;</span> 0 <span class="kw">&lt;/FAILED&gt;</span> 
      <span class="kw">&lt;INACTIVE&gt;</span> n/a <span class="kw">&lt;/INACTIVE&gt;</span> 
    <span class="kw">&lt;/CUNIT_RUN_SUMMARY_RECORD&gt;</span> 
  <span class="kw">&lt;/CUNIT_RUN_SUMMARY&gt;</span> 
  <span class="kw">&lt;CUNIT_FOOTER&gt;</span> File Generated By CUnit v2.1-2 - Tue Jun 25 16:01:49 2013
 <span class="kw">&lt;/CUNIT_FOOTER&gt;</span> 
<span class="kw">&lt;/CUNIT_TEST_RUN_REPORT&gt;</span></code></pre>
<p>If you wish to specify the output XML filename, it can be set using the following command:</p>
<pre class="sourceCode c"><code class="sourceCode c">   CU_set_output_filename(<span class="st">&quot;Even&quot;</span>)
   CU_automated_run_tests();</code></pre>
<p>The above XML output is dumped to a ‘Even-Results.xml’ file. The Basic and Automated interfaces are non-interactive modes to run the tests. The interactive Console mode of running tests can be initiated by using the following command:</p>
<pre class="sourceCode c"><code class="sourceCode c">   <span class="co">/* Run tests in interactive Console mode */</span>
   CU_console_run_tests();</code></pre>
<p>On compilation and execution, the following menu is shown in the terminal:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"> $  ./console 


      CUnit - A Unit testing framework <span class="kw">for</span> C - Version 2.1-2
	      http://cunit.sourceforge.net/


 ***************** CUNIT CONSOLE - MAIN MENU ******************************
 <span class="kw">(</span>R<span class="kw">)</span>un  <span class="kw">(</span>S<span class="kw">)</span>elect  <span class="kw">(</span>L<span class="kw">)</span>ist  <span class="kw">(</span>A<span class="kw">)</span>ctivate  <span class="kw">(</span>F<span class="kw">)</span>ailures  <span class="kw">(</span>O<span class="kw">)</span>ptions  <span class="kw">(</span>H<span class="kw">)</span>elp  <span class="kw">(</span>Q<span class="kw">)</span>uit
 Enter command: </code></pre>
<p>This allows you to run all the test suites, or select a suite to be executed. You can list all the registered suites, and also select one to modify it. You can activate or deactivate a suite, and can view any failures from the previous test run. The other interactive ‘Curses’ mode can be invoked using:</p>
<pre class="sourceCode c"><code class="sourceCode c">    <span class="co">/* Run tests in interactive Curses mode */</span>
    CU_curses_run_tests();</code></pre>
<p>A screenshot of the Curses interface is shown below:</p>
<img alt="CUnit curses screenshot" width="512" src="http://shakthimaan.com/downloads/screenshots/cunit-curses.png"></img>
<p>Let’s suppose you have the following code snippet where the third assert fails:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="dt">void</span>
test_is_even (<span class="dt">void</span>)
{
  CU_ASSERT(is_even(<span class="dv">1</span>)  == <span class="dv">0</span>);
  CU_ASSERT(is_even(<span class="dv">2</span>)  == <span class="dv">1</span>);
  CU_ASSERT(is_even(<span class="dv">4</span>)  == <span class="dv">0</span>);
  CU_ASSERT(is_even(<span class="dv">3</span>)  == <span class="dv">0</span>);
}</code></pre>
<p>On executing the above, you will get:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ ./error 


     CUnit - A unit testing framework <span class="kw">for</span> C - Version 2.1-2
     http://cunit.sourceforge.net/


Suite Basic_Test_Suite, Test test_is_even had failures:
    1<span class="kw">.</span> error.c:17  - is_even<span class="kw">(</span>4<span class="kw">)</span> == 0

Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      1      1    n/a      0        0
               tests      1      1      0      1        0
             asserts      4      4      3      1      n/a

Elapsed <span class="kw">time</span> =    0.000 seconds</code></pre>
<p>If you wish to terminate the execution of the test when an error occurs, you can use the code shown below:</p>
<pre class="sourceCode c"><code class="sourceCode c">...
<span class="dt">void</span>
test_is_even (<span class="dt">void</span>)
{
  CU_ASSERT(is_even(<span class="dv">1</span>)  == <span class="dv">0</span>);
  CU_ASSERT(is_even(<span class="dv">2</span>)  == <span class="dv">1</span>);
  CU_ASSERT_TRUE_FATAL(is_even(<span class="dv">4</span>)  == <span class="dv">0</span>);
  CU_ASSERT(is_even(<span class="dv">3</span>)  == <span class="dv">0</span>);
}

<span class="dt">int</span>
main (<span class="dt">void</span>)
{
  ...
  CU_set_error_action(CUEA_FAIL);
  ...
}</code></pre>
<p>The corresponding output is shown below:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"> ./error-fail 


     CUnit - A unit testing framework <span class="kw">for</span> C - Version 2.1-2
     http://cunit.sourceforge.net/


Suite Basic_Test_Suite, Test test_is_even had failures:
    1<span class="kw">.</span> error-fail.c:17  - CU_ASSERT_TRUE_FATAL<span class="kw">(</span>is_even<span class="kw">(</span>4<span class="kw">)</span> == 0<span class="kw">)</span>

Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      1      1    n/a      0        0
               tests      1      1      0      1        0
             asserts      3      3      2      1      n/a

Elapsed <span class="kw">time</span> =    0.000 seconds</code></pre>
<p>The test execution stopped after the third assert failed. The different options for error actions are:</p>
<table>
<col width="25%"></col>
<col width="26%"></col>
<thead>
<tr class="header">
<th align="left">Error value</th>
<th align="left">Meaning</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">CUEA_IGNORE</td>
<td align="left">Continue on error</td>
</tr>
<tr class="even">
<td align="left">CUEA_FAIL</td>
<td align="left">Stop on error</td>
</tr>
<tr class="odd">
<td align="left">CUEA_ABORT</td>
<td align="left">Call exit() on error</td>
</tr>
</tbody>
</table>
<p>You can refer the CUnit Programmers Guide and API documentation to know more about CUnit.</p>]]></description>
    <pubDate>Wed, 24 Sep 2014 17:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/09/24/cunit/news.html</guid>
</item>
<item>
    <title>Getting Started with Haskell on Emacs</title>
    <link>http://www.shakthimaan.com/posts/2014/08/15/getting-started-with-haskell-on-emacs/news.html</link>
    <description><![CDATA[<p><em>[Published in Open Source For You (OSFY) magazine, August 2013 edition.]</em></p>
<p>Emacs is a popular text editor that can be extended and customized. Haskell is a statically typed, functional programming language. Haskell-mode is a Emacs major mode that provides support to write and use Haskell programs. This article explains interesting features and tips on using Haskell-mode with GNU Emacs.</p>
<p>You can install Haskell-mode using your distribution package manager. For example, on Fedora you can use:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum <span class="kw">install</span> emacs-haskell-mode</code></pre>
<h1 id="mode">Mode</h1>
<p>You can enter Haskell-mode when opening a Haskell source file that has an extension .hs, or it can be started within Emacs using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">M</span><span class="fu">-</span>x haskell<span class="fu">-</span>mode</code></pre>
<p>On the modeline, you will now see “(Haskell)”, indicating that the Haskell mode has been activated. You can enter the indent mode using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">M</span><span class="fu">-</span>x haskell<span class="fu">-</span>indent<span class="fu">-</span>mode</code></pre>
<p>The modeline will now show “(Haskell Ind)”.</p>
<h1 id="interpreter">Interpreter</h1>
<p>To load a Haskell source file into the interpreter, use <em>C-c C-l</em>. It will create a new buffer, load the module in the current buffer and give a prompt to work with. Consider the following <em>Square.hs</em> program:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">square ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> int
square x <span class="fu">=</span> x <span class="fu">*</span> x</code></pre>
<p>Opening a <em>Square.hs</em> file in an Emacs buffer, and running <em>C-c C-l</em> will produce the following in a new buffer:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">GHCi</span>, version <span class="fl">7.0</span><span class="fu">.</span><span class="dv">4</span><span class="fu">:</span> http<span class="fu">://</span>www<span class="fu">.</span>haskell<span class="fu">.</span>org<span class="fu">/</span>ghc<span class="fu">/</span>  <span class="fu">:?</span> for help
<span class="dt">Loading</span> package ghc<span class="fu">-</span>prim <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package integer<span class="fu">-</span>gmp <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span>load <span class="st">&quot;/home/guest/Square.hs&quot;</span>
[<span class="dv">1</span> <span class="kw">of</span> <span class="dv">1</span>] <span class="dt">Compiling</span> <span class="dt">Main</span>             ( <span class="fu">/</span>home<span class="fu">/</span>guest<span class="fu">/</span>Square.hs, interpreted )
<span class="dt">Ok</span>, modules loaded<span class="fu">:</span> <span class="dt">Main</span><span class="fu">.</span>
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> </code></pre>
<p>If you have multiple buffers opened within Emacs, you can directly switch from the (Haskell) mode buffer to the Haskell interpreter using <em>C-c C-z</em>.</p>
<h1 id="insertions">Insertions</h1>
<p>The equal to (=) sign can be inserted, and the function type can be neatly aligned with the <em>C-c C-=</em> key stroke. If you type the following function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">volume ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
volume x</code></pre>
<p>… and keep the cursor after ‘x’ and type <em>C-c C-=</em>, the equal to sign is inserted, and the code gets neatly aligned:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">volume   ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
volume x <span class="fu">=</span> </code></pre>
<p>In the following code snippet, after ‘y’, if you hit <em>Return</em> followed by <em>C-c C-|</em>, a guard symbol is inserted:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">max</span><span class="ot"> ::</span> (<span class="kw">Ord</span> a) <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> a
<span class="fu">max</span> x y
 <span class="fu">|</span></code></pre>
<p>After inserting the second guard in the above example, the ‘otherwise’ keyword can be inserted and the code is aligned using <em>C-c C-o</em>:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">max</span><span class="ot"> ::</span> (<span class="kw">Ord</span> a) <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> a <span class="ot">-&gt;</span> a
<span class="fu">max</span> x y
 <span class="fu">|</span> x <span class="fu">&gt;</span> y     <span class="fu">=</span> x
 <span class="fu">|</span> <span class="fu">otherwise</span> <span class="fu">=</span> </code></pre>
<p>The ‘where’ clause is produced using <em>C-c C-w</em>. In the following example, pressing return after ‘r’, and using <em>C-c C-w</em> inserts the ‘where’ clause:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">circleArea ::</span> <span class="dt">Float</span> <span class="ot">-&gt;</span> <span class="dt">Float</span>
circleArea r <span class="fu">=</span> <span class="fu">pi</span> <span class="fu">*</span> r <span class="fu">*</span> r
    <span class="kw">where</span> </code></pre>
<p>You can insert the type annotation for a function using <em>C-u C-c C-t</em>. Consider the sphereVolume function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">sphereVolume r <span class="fu">=</span> <span class="dv">4</span> <span class="fu">/</span> <span class="dv">3</span> <span class="fu">*</span> <span class="fu">pi</span> <span class="fu">*</span> r <span class="fu">*</span> r <span class="fu">*</span> r
    <span class="kw">where</span> <span class="fu">pi</span> <span class="fu">=</span> <span class="fl">3.1412</span></code></pre>
<p>Placing the cursor on ‘sphereVolume’ and typing <em>C-u C-c C-t</em> produces the following:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">sphereVolume ::</span> <span class="kw">Fractional</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> a
sphereVolume r <span class="fu">=</span> <span class="dv">4</span> <span class="fu">/</span> <span class="dv">3</span> <span class="fu">*</span> <span class="fu">pi</span> <span class="fu">*</span> r <span class="fu">*</span> r <span class="fu">*</span> r
    <span class="kw">where</span> <span class="fu">pi</span> <span class="fu">=</span> <span class="fl">3.1412</span></code></pre>
<h1 id="formatting">Formatting</h1>
<p>There are a number of shortcut commands that are useful for indentation. Let’s suppose you have the following function with the cursor position indicated by ‘_’:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">greeting ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
greeting x <span class="fu">=</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">++</span> x <span class="fu">++</span>
_</code></pre>
<p>Hitting <em>TAB</em> will take you through the different possible positions for inserting code. When you press <em>TAB</em> for the first time, the cursor will move under ‘Hello’; if you wish to complete the string concatenation (++), issue the following code:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">greeting ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
greeting x <span class="fu">=</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">++</span> x <span class="fu">++</span>
       	     _</code></pre>
<p>Hitting <em>TAB</em> again prepends ‘greeting’ and the cursor will be placed under ‘x’ for you to add another test condition, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">greeting ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
greeting x <span class="fu">=</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">++</span> x <span class="fu">++</span>
greeting _</code></pre>
<p>Hitting <em>TAB</em> again will move the cursor to the first column if you want to add any text:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">greeting ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
greeting x <span class="fu">=</span> <span class="st">&quot;Hello&quot;</span> <span class="fu">++</span> x <span class="fu">++</span>
_</code></pre>
<p>As you keep hitting <em>TAB</em> again and again, the above sequence will repeat. Comments in Haskell begin with ’- -’.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">one <span class="co">-- 1</span>
two <span class="co">-- 2</span>
three <span class="co">-- 3</span>
four <span class="co">-- 4</span>
five <span class="co">-- 5</span>
six <span class="co">-- 6</span>
seven <span class="co">-- 7</span></code></pre>
<p>After marking the above region, use M-x align-regexp followed by ’–’ for the regexp, and the comments will be aligned:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">one    <span class="co">-- 1</span>
two    <span class="co">-- 2</span>
three  <span class="co">-- 3</span>
four   <span class="co">-- 4</span>
five   <span class="co">-- 5</span>
six    <span class="co">-- 6</span>
seven  <span class="co">-- 7</span></code></pre>
<p><em>C-c C-.</em> helps align the code neatly. Consider the <em>Area.hs</em> program:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">area ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
area breadth height <span class="fu">=</span> breadth <span class="fu">*</span> height</code></pre>
<p>After marking the above program, and using <em>C-c C-.</em>, the code becomes:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">area                ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
area breadth height <span class="fu">=</span> breadth <span class="fu">*</span> height</code></pre>
<h1 id="query">Query</h1>
<p>To know the Haskell-mode version, use <em>M-x haskell-version</em>. As an example:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  Using haskell-mode version v2.8.0</code></pre>
<p><em>C-c C-i</em> on a symbol will prompt for getting information about the symbol. For example, ‘Show info of (default Int):’ lists the following:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Int</span> <span class="fu">=</span> <span class="dt">GHC.Types.I</span><span class="fu">#</span> <span class="dt">GHC.Prim.Int</span><span class="fu">#</span> 	<span class="co">-- Defined in GHC.Types</span>
<span class="kw">instance</span> <span class="kw">Bounded</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Enum</span>
<span class="kw">instance</span> <span class="kw">Enum</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Enum</span>
<span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Base</span>
<span class="kw">instance</span> <span class="kw">Integral</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Real</span>
<span class="kw">instance</span> <span class="kw">Num</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Num</span>
<span class="kw">instance</span> <span class="kw">Ord</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Base</span>
<span class="kw">instance</span> <span class="kw">Read</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Read</span>
<span class="kw">instance</span> <span class="kw">Real</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Real</span>
<span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">Int</span> <span class="co">-- Defined in GHC.Show</span></code></pre>
<p><em>C-c C-t</em> will obtain the type of the symbol with the prompt ‘Show type of (default pi):’. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">pi</span><span class="ot"> ::</span> <span class="kw">Floating</span> a <span class="ot">=&gt;</span> a</code></pre>
<p><em>C-c TAB</em> on a symbol returns its definition at the interpreter prompt, as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> <span class="fu">:</span>info sphereVolume
<span class="ot">sphereVolume ::</span> <span class="kw">Fractional</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> a
  	<span class="co">-- Defined at /home/guest/Sphere.hs:1:1-12</span></code></pre>
<p>To find haddock information for a symbol, you can use <em>C-c C-d</em>. Searching for ‘Float’, for example, opens up file:///usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Types.html on Fedora.</p>
<p>To use the Hayoo search engine, you can use <em>M-x haskell-hayoo</em>. It will prompt with:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">  Hayoo query:</code></pre>
<p>The query responses are shown in a browser. Similarily, the Hoogle engine can be queried using <em>M-x haskell-hoogle</em>. If you searched for ‘show’, it will open the URL <em>http://www.haskell.org/hoogle/?q=show</em> with the search results.</p>
<p>Files ending with <em>.lhs</em> are literate Haskell programs. You can use Richard Bird style to separate text and code as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Insert</span> blank line before the code
 
<span class="fu">&gt;</span><span class="ot"> quicksort ::</span> <span class="kw">Ord</span> a <span class="ot">=&gt;</span> [a] <span class="ot">-&gt;</span> [a]
<span class="fu">&gt;</span> quicksort []     <span class="fu">=</span> []
<span class="fu">&gt;</span> quicksort (p<span class="fu">:</span>xs) <span class="fu">=</span> (quicksort lesser) <span class="fu">++</span> [p] <span class="fu">++</span> (quicksort greater)
<span class="fu">&gt;</span>    <span class="kw">where</span>
<span class="fu">&gt;</span>        lesser  <span class="fu">=</span> <span class="fu">filter</span> (<span class="fu">&lt;</span> p) xs
<span class="fu">&gt;</span>        greater <span class="fu">=</span> <span class="fu">filter</span> (<span class="fu">&gt;=</span> p) xs

<span class="dt">Insert</span> blank line after the code</code></pre>
<p>The modeline will indicate that you are in the ‘(LitHaskell/bird)’ minor mode.</p>
<p>The hasktag package needs to be installed to help generate TAGS file for source files. For example:</p>
<pre class="shell"><code>$ hasktags Test.hs</code></pre>
<p>It will create both tags and TAGS files. You can use <em>M-.</em> in the Haskell buffer to search for a tag.</p>
<h1 id="checks">Checks</h1>
<p>HLint is a tool that provides suggestions to improve Haskell programs. <em>C-c C-v</em> helps to run <em>hlint</em> on a buffer. Make sure you have the tool installed on your system before using it. For example, running <em>C-c C-v</em> on the above literate quicksort Haskell program suggests:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">-*-</span> mode<span class="fu">:</span> compilation; default<span class="fu">-</span>directory<span class="fu">:</span> <span class="st">&quot;~/&quot;</span> <span class="fu">-*-</span>
<span class="dt">Compilation</span> started at <span class="dt">Thu</span> <span class="dt">Jun</span>  <span class="dv">6</span> <span class="dv">21</span><span class="fu">:</span><span class="dv">31</span><span class="fu">:</span><span class="dv">54</span>

hlint QuickSort.lhs
QuickSort.lhs<span class="fu">:</span><span class="dv">6</span><span class="fu">:</span><span class="dv">22</span><span class="fu">:</span> <span class="dt">Warning</span><span class="fu">:</span> <span class="dt">Redundant</span> bracket
<span class="dt">Found</span><span class="fu">:</span>
  (quicksort lesser) <span class="fu">++</span> [p] <span class="fu">++</span> (quicksort greater)
<span class="dt">Why</span> <span class="fu">not:</span>
  quicksort lesser <span class="fu">++</span> [p] <span class="fu">++</span> (quicksort greater)

QuickSort.lhs<span class="fu">:</span><span class="dv">6</span><span class="fu">:</span><span class="dv">44</span><span class="fu">:</span> <span class="dt">Warning</span><span class="fu">:</span> <span class="dt">Redundant</span> bracket
<span class="dt">Found</span><span class="fu">:</span>
  [p] <span class="fu">++</span> (quicksort greater)
<span class="dt">Why</span> <span class="fu">not:</span>
  [p] <span class="fu">++</span> quicksort greater

<span class="dv">2</span> suggestions

<span class="dt">Compilation</span> exited abnormally with code <span class="dv">1</span> at <span class="dt">Thu</span> <span class="dt">Jun</span>  <span class="dv">6</span> <span class="dv">21</span><span class="fu">:</span><span class="dv">31</span><span class="fu">:</span><span class="dv">54</span></code></pre>]]></description>
    <pubDate>Fri, 15 Aug 2014 15:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/08/15/getting-started-with-haskell-on-emacs/news.html</guid>
</item>
<item>
    <title>Eqntott: Truth Table Generator from Boolean Equations</title>
    <link>http://www.shakthimaan.com/posts/2014/08/08/eqntott-truth-table-generator-from-boolean-equations/news.html</link>
    <description><![CDATA[<p><em>[Published in Electronics For You (EFY) magazine, March 2013 edition.]</em> <a href="http://electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=2163&amp;id=13594">Source</a></p>
<p>This tutorial demonstrates the use of eqntott software with some code examples.</p>
<p>eqntott (short for ‘equation to truth table’) is a software tool that can generate truth tables from Boolean equations, which can be used for programmable logic array (PLA) programming. It was initially written at Berkeley, and ported to work on GNU/Linux. It is released under the new BSD license.</p>
<p>Consider a simple AND example:</p>
<pre class="shell"><code>NAME = and;
INORDER = a b;
OUTORDER = c;

c = a &amp; b;</code></pre>
<p>Here NAME refers to the name of the PLA, and is called ‘and’. INORDER lists the input order of elements, while OUTORDER has the list of outputs in the truth table. Copy this example in a text editor and save it as ‘and.eqn.’</p>
<p>To run the above example, use ‘cd’ command in order to go to the directory where the example is saved. Now run the following command:</p>
<pre class="shell"><code>$ eqntott and.eqn</code></pre>
<p>You will get the output as:</p>
<pre class="shell"><code>.i 2
.o 1
.p 1
11  1 
.e</code></pre>
<p>’.i’ in the output refers to the number of inputs defined, which refers to ‘a’ and ‘b’ in the above example. ’.o’ corresponds to the number of output variables, which is ‘c’. ’.p’ is the number of product terms. The truth table generated shows that the output is ‘1’ when bothe inputs are ‘1’.</p>
<p>You can use ’-l’ option with eqntott to output the PLA name, input, and output elements.</p>
<pre class="shell"><code>$ eqntott -l and.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 2
.o 1
.na and
.ilb  a b
.ob  c
.p 1
11  1 
.e</code></pre>
<p>The name of the PLA is mentioned next to ’.na’ in the output. The order of inputs and outputs in the truth table is also listed.</p>
<p>The following expressions are allowed in the equations for eqntott:</p>
<table>
<col width="15%"></col>
<col width="41%"></col>
<thead>
<tr class="header">
<th align="left">Expression</th>
<th align="left">Meaning</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">&amp;</td>
<td align="left">Logical AND operation</td>
</tr>
<tr class="even">
<td align="left">|</td>
<td align="left">Logical OR operation</td>
</tr>
<tr class="odd">
<td align="left">!</td>
<td align="left">Logical NOT operation</td>
</tr>
<tr class="even">
<td align="left">ZERO or 0</td>
<td align="left">False or the value zero</td>
</tr>
<tr class="odd">
<td align="left">ONE or 1</td>
<td align="left">True or the value one</td>
</tr>
<tr class="even">
<td align="left">()</td>
<td align="left">To enclose any expression</td>
</tr>
<tr class="odd">
<td align="left">?</td>
<td align="left">Don’t care condition</td>
</tr>
<tr class="even">
<td align="left"><em>name</em></td>
<td align="left">Any input/output in the expression</td>
</tr>
</tbody>
</table>
<p>The half adder circuit adds two binary digits, and produces a sum and a carry. It can be implemented as follows:</p>
<pre class="shell"><code>NAME = half_adder;
INORDER = a b;
OUTORDER = s c;
c = a &amp; b;
s = (!a &amp; b) | (a &amp; !b);</code></pre>
<p>When the above equation is run with eqntott:</p>
<pre class="shell"><code>$ eqntott -l half_adder.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 2
.o 2
.na half_adder
.ilb  a b
.ob  s c
.p 3
01  1 0 
10  1 0 
11  0 1 
.e</code></pre>
<p>The sum is represented by ’s’ and carry with ‘c.’ When either the sum or carry is ‘1’, the sum is ‘1’ and carry is ‘0’. When both the sum and carry are ‘1’, then the sum is ‘0’ and carry is ‘1’.</p>
<p>The output of eqntott can be customized using the ’-.key’ argument. The default option is the string ‘iopte’. A few key code options with their output meaning are given below:</p>
<table>
<col width="12%"></col>
<col width="36%"></col>
<thead>
<tr class="header">
<th align="left">Character</th>
<th align="left">Output</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">e</td>
<td align="left">.e</td>
</tr>
<tr class="even">
<td align="left">f</td>
<td align="left">.f output-number input-number</td>
</tr>
<tr class="odd">
<td align="left">h</td>
<td align="left">Human readable format</td>
</tr>
<tr class="even">
<td align="left">i</td>
<td align="left">.i number of inputs</td>
</tr>
<tr class="odd">
<td align="left">l</td>
<td align="left">Truth table with PLA name, inputs and outputs</td>
</tr>
<tr class="even">
<td align="left">o</td>
<td align="left">.o number of outputs</td>
</tr>
<tr class="odd">
<td align="left">p</td>
<td align="left">.p number-of-product-terms</td>
</tr>
<tr class="even">
<td align="left">v</td>
<td align="left">eqntott version number</td>
</tr>
<tr class="odd">
<td align="left">S</td>
<td align="left">PLA connectivity summary</td>
</tr>
</tbody>
</table>
<p>If the half adder example is run with the following key options:</p>
<pre class="shell"><code>$ eqntott -.lhptv half_adder.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.na half_adder
.ilb  a b
.ob  s c
2 inputs, 2 outputs, 3 product terms.
s	!a	b
s	a	!b
c	a	b
.p 3
01  1 0 
10  1 0 
11  0 1 
eqntott 9.0</code></pre>
<p>The PLA connectivity summary can be displayed using the ’-.S’ key code option. When used with ‘and.eqn’ example as:</p>
<pre class="shell"><code>$ eqntott -.S and.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>PLA Connectivity Summary
#pterms	input
1	b
1	a
#pterms	output
1	c
#out	#in	product term expression
1	2	a &amp; b</code></pre>
<p>’-s’ option allows you to use an output variable in another expression. Consider, for example:</p>
<pre class="shell"><code>NAME = s;
INORDER = a b;
OUTORDER = d;

c = a | b;
d = !c;</code></pre>
<p>When you run the above example with ’-s’ option as:</p>
<pre class="shell"><code>$ eqntott -l -s s.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 3
.o 2
.na s
.ilb  a b c
.ob  d c
.p 3
00-  1 0 
-1-  0 1 
1--  0 1 
.e</code></pre>
<p>When both the inputs ‘a’ and ‘b’ are zero, then the output ‘c’ is zero and ‘d’ is ‘1’. If either ‘a’ and ‘b’ is ‘1’, ‘c’ is ‘1’ and ‘d’ is ‘0’.</p>
<p>’-f’ option allows an input to also be present in the output, and used as though the value was observed at different times. Consider, for example:</p>
<pre class="shell"><code>NAME = f;
INORDER = a;
OUTORDER = a;

a = !a;</code></pre>
<p>When you execute the above example as:</p>
<pre class="shell"><code>$ eqntott -l -f f.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 1
.o 1
.na f
.ilb  a
.ob  a
.p 1
.f 1 1
0  1 
.e</code></pre>
<p>The truth table output is ‘1’ only when the input is ‘0’. The ’-s’ and ’-f’ options are mutually exclusive.</p>
<p>eqntott can attempt to minimize the logic terms in the equations. ’-r’ option will try to reduce the minterms in the output. Consider the example:</p>
<pre class="shell"><code>NAME = reduce;
INORDER = x y;
OUTORDER = z;

z = x &amp; y | x;</code></pre>
<p>When you use the above example with ’-l’ option as:</p>
<pre class="shell"><code>$ eqntott -l reduce.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 2
.o 1
.na reduce
.ilb  x y
.ob  z
.p 2
1-  1 
11  1 
.e</code></pre>
<p>Using ’-r’ option, eqntott will try to minimize the truth table output:</p>
<pre class="shell"><code>$ eqntott -l -r reduce.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 2
.o 1
.na reduce
.ilb  x y
.ob  z
.p 1
1-  1 
.e</code></pre>
<p>The output ‘z’ is ‘1’ whenever ‘x’ is ‘1’.</p>
<p>You can define expressions using ‘define’ keyword. The XOR logic takes two binary inputs, and returns ‘1’ only when either input is ‘1’ but not both. It can be expressed as:</p>
<pre class="shell"><code>#define xor(a,b) (a&amp;!b | !a&amp;b)

NAME = xor;
INORDER = a b;
OUTORDER = c;

c = xor (a,b);</code></pre>
<p>On running the example as:</p>
<pre class="shell"><code>$ eqntott -l xor.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 2
.o 1
.na xor
.ilb  a b
.ob  c
.p 2
01  1 
10  1 
.e</code></pre>
<p>As a final example, consider generating an odd parity bit for three inputs. The parity bit is set to ‘1’ when the number of ‘1’s’ in the input is even, so as to make the total number of ‘1’s’ odd. We can define the logic using:</p>
<pre class="shell"><code>#define xor(a,b) (a&amp;!b | !a&amp;b)

NAME = parity;
INORDER = x y z;
OUTORDER = p;

p = !( xor (xor(x,y), z) );</code></pre>
<p>When you run the above example with ’-l’ and ’-s’ option as:</p>
<pre class="shell"><code>$ eqntott -l -s parity.eqn</code></pre>
<p>The output will be:</p>
<pre class="shell"><code>.i 3
.o 1
.na parity
.ilb  x y z
.ob  p
.p 4
000  1 
011  1 
101  1 
110  1 
.e</code></pre>
<p>You can refer the manual page of eqntott for more documentation. Sources are available from the eqntott webpage.</p>]]></description>
    <pubDate>Fri, 08 Aug 2014 15:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/08/08/eqntott-truth-table-generator-from-boolean-equations/news.html</guid>
</item>
<item>
    <title>Book: i want 2 do project. tell me wat 2 do.</title>
    <link>http://www.shakthimaan.com/posts/2014/06/13/i-want-2-do-project-tell-me-wat-2-do-book/news.html</link>
    <description><![CDATA[<p>I am happy to announce my first self-published book on working with free and open source software projects, titled, “i want 2 do project. tell me wat 2 do.”</p>
<img alt="Shaks with book" src="http://www.shakthimaan.com/images/books/shaks-with-book-min.png"></img>
<p>Topics covered in the book:</p>
<ol style="list-style-type: decimal">
<li>Mailing List Guidelines</li>
<li>Attention to Detail</li>
<li>Project Communication</li>
<li>Project Guidelines</li>
<li>Development Guidelines</li>
<li>Methodology of Work</li>
<li>Tools</li>
<li>Reading and Writing</li>
<li>Art of Making Presentations</li>
<li>Sustenance</li>
</ol>
<p>The product details are as follows:</p>
<ul>
<li>Price: ₹ 399</li>
<li>Pages: 135 pages</li>
<li>Publisher: Self-published (June 2014)</li>
<li>Language: English</li>
<li>ISBN-13: 978-93-5174-187-9</li>
<li>Size: 6 x 9 inches</li>
<li>Binding: Paperback (Perfect Binding)</li>
<li>Availability: In Stock (Indian edition)</li>
</ul>
<p>You can order the book at pothi.com:</p>
<p><a href="http://pothi.com/pothi/book/shakthi-kannan-i-want-2-do-project-tell-me-wat-2-do">http://pothi.com/pothi/book/shakthi-kannan-i-want-2-do-project-tell-me-wat-2-do</a></p>
<p>The home page for the book is at:</p>
<p><a href="http://shakthimaan.com/what-to-do.html">http://shakthimaan.com/what-to-do.html</a></p>
<p>If you have any comments or queries, please feel free to write to me at author@shakthimaan.com.</p>]]></description>
    <pubDate>Fri, 13 Jun 2014 10:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/06/13/i-want-2-do-project-tell-me-wat-2-do-book/news.html</guid>
</item>
<item>
    <title>Installation of VirtualBox on Fedora 20</title>
    <link>http://www.shakthimaan.com/posts/2014/05/27/virtualbox-on-fedora/news.html</link>
    <description><![CDATA[<p>Steps to install VirtualBox 4.3.10 on Fedora 20. You need to first open a terminal and become root user:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">su</span> -
Password:
<span class="co">#</span></code></pre>
<p>Install dkms package:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum install dkms</span></code></pre>
<p>If Virtual Machine Manager is running, stop the same, and uninstall it.</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum remove virt-manager</span></code></pre>
<p>Remove the KVM modules if already loaded:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># rmmod kvm_intel</span></code></pre>
<p>Download and install rpmfusion-free repo from rpmfusion.org:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum install rpmfusion-free-release-20.noarch.rpm</span></code></pre>
<p>Install VirtualBox:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum install VirtualBox</span></code></pre>
<p>Install the required VirtualBox kernel module for your running kernel. For example, on Fedora 20 with kernel 3.11.10-301, you can run:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># yum install kmod-VirtualBox-3.11.10-301.fc20.x86_64</span></code></pre>
<p>Load the <em>vboxdrv</em> driver:</p>
<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># modprobe vboxdrv</span></code></pre>
<p>You can now start VirtualBox and use it. To convert Virt-manager images to VirtualBox, you can use:</p>
<pre class="sourceCode bash"><code class="sourceCode bash">$ VBoxManage convertdd ubuntu1204-lts.img ubuntu1204-lts.vdi</code></pre>]]></description>
    <pubDate>Tue, 27 May 2014 17:26:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2014/05/27/virtualbox-on-fedora/news.html</guid>
</item>
<item>
    <title>Westford, Massachusetts</title>
    <link>http://www.shakthimaan.com/posts/2013/08/07/westford/news.html</link>
    <description><![CDATA[<img alt="Red Hat, Westford" src="http://www.shakthimaan.com/Mambo/gallery/albums/album94/8_rh_westford_office.jpg"></img><br />
<img alt="Residence Inn" src="http://www.shakthimaan.com/Mambo/gallery/albums/album94/1_ri_entrance.jpg"></img><br />
<img alt="Boeing Lufthansa" src="http://www.shakthimaan.com/Mambo/gallery/albums/album94/27_boeing_lufthansa.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album94">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 07 Aug 2013 00:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/08/07/westford/news.html</guid>
</item>
<item>
    <title>Fedora Workshop, SJCE, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2013/06/18/fedora-workshop-mca-sjce/news.html</link>
    <description><![CDATA[<p>A Fedora workshop was organised at <a href="http://stjosephs.ac.in/">St. Joseph’s College of Engineering</a>, Chennai, Tamil Nadu, India on Friday, June 14, 2013. The participants were students from the Master of Computer Applications (MCA) department.</p>
<p>The forenoon session began with an introduction to Free/Open Source Software (F/OSS) and Fedora. I explained the various <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do
">project and communication guidelines</a> that students need to follow, and mentioned the various <a href="http://fedoraproject.org/wiki/Projects">Fedora sub-projects</a> that they can contribute to. System architecture, and compilation concepts were also discussed. The need to use free and open standards was emphasized. Copyright, and licensing were briefly addressed.</p>
<img alt="MCA lab" src="http://www.shakthimaan.com/Mambo/gallery/albums/album93/6_lab_session.jpg"></img><br />
<p>After lunch, a programming lab session was held to see how students solve problems. Their code was reviewed, and suggestions for improvement were given. <a href="http://klavaro.sourceforge.net/en/">Klavaro</a> was shown to students to learn touch typing. I also gave an overview of GCC using the <a href="http://shakthimaan.com/downloads.html#introduction-to-gcc">“Introduction to GCC”</a> presentation. The concept of using revision control systems was illustrated. A demo of Fedora 18 (x86_64) was shown, and the same was installed on the lab desktops.</p>
<p>Thanks to Prof. Parvathavarthini Mam for working with me in organizing this workshop. Thanks also to Prof. Shirley for managing the logistics.</p>
<p>Few photos taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album93">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 18 Jun 2013 11:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/06/18/fedora-workshop-mca-sjce/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day (FAD), Mysore</title>
    <link>http://www.shakthimaan.com/posts/2013/04/25/fad-mysore/news.html</link>
    <description><![CDATA[<p>A <a href="https://fedoraproject.org/wiki/FAD_Mysore_2013">Fedora Activity Day</a> was held at <a href="http://www.sjce.ac.in/">Sri Jayachamarajendra College Of Engineering</a>, Mysore, Karnataka, India on Saturday, April 20, 2013.</p>
<img alt="SJCE" src="http://www.shakthimaan.com/Mambo/gallery/albums/album92/6_sjce.jpg"></img><br />
<p>The agenda included talks in the morning, and practical sessions in the afternoon. I started the day’s proceedings on best practices to be followed when working with free/open source software projects, giving examples on <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">effective project, and communication guidelines</a>. The various <a href="http://fedoraproject.org/wiki/Projects">Fedora sub-projects</a> that students can contribute to were mentioned. This was followed by an introductory session on Python by <a href="http://aravindavk.in/">Aravinda V K</a>. The <a href="http://shakthimaan.com/downloads.html#python-introduction-for-programmers">“Python: Introduction for Programmers” presentation</a> was given to the students. <a href="https://github.com/vijaykumar-koppad">Vijaykumar Koppad</a> then gave an overview, and a demo of the <a href="http://www.gluster.org/">Gluster file system</a>.</p>
<p>After lunch, we had a Q&amp;A session with the participants. Questions on working with free/open source software projects, differences between file systems, GNU/Linux distributions, and programming languages were answered. Basic installation and troubleshooting techniques were discussed. I addressed system architecture design concepts, compilation, cross-compilation, and revision control systems, and briefed them on copyright, and licensing. Students had brought their laptops to work on Python scripting, and GlusterFS. I also worked on few bug fixes, package builds for ARM, and package updates:</p>
<ul>
<li>Bug 928059 - perl-Sys-CPU 0.54 tests fail on ARM</li>
<li>Bug 926079 - linsmith: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 925483 - gputils: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 922397 - flterm-debuginfo-1.2-1 is empty</li>
<li>Bug 925202 - csmith: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 925247 - dgc: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 925208 - CUnit: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 901632 - ghc-smallcheck-1.0.2 is available</li>
<li>Bug 926213 - nesc: Does not support aarch64 in f19 and rawhide</li>
<li>Bug 953775 - ghc-data-inttrie-0.1.0 is available</li>
</ul>
<p>Thanks to <a href="http://vbellur.wordpress.com/">Vijay Bellur</a> and Vijaykumar Koppad for working with me in organizing this workshop. Thanks also to the Fedora project for sponsoring my travel and accommodation.</p>
<p>Few photos taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album92">/gallery</a>.</p>]]></description>
    <pubDate>Thu, 25 Apr 2013 08:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/04/25/fad-mysore/news.html</guid>
</item>
<item>
    <title>Ajanta-Daulatabad-Ellora</title>
    <link>http://www.shakthimaan.com/posts/2013/04/04/ajanta-daulatabad-ellora/news.html</link>
    <description><![CDATA[<img alt="Ajanta caves" src="http://www.shakthimaan.com/Mambo/gallery/albums/album89/25_entrance_to_cave_19.jpg"></img><br />
<img alt="Daulatabad fort" src="http://www.shakthimaan.com/Mambo/gallery/albums/album90/2_daulatabad_fort.jpg"></img><br />
<img alt="Ellora caves" src="http://www.shakthimaan.com/Mambo/gallery/albums/album91/42_pillar.jpg"></img><br />
<p>More photos available in the respective albums - <a href="http://www.shakthimaan.com/Mambo/gallery/album89">Ajanta caves</a>, <a href="http://www.shakthimaan.com/Mambo/gallery/album90">Daulatabad fort</a>, and <a href="http://www.shakthimaan.com/Mambo/gallery/album91">Ellora caves</a>.</p>]]></description>
    <pubDate>Thu, 04 Apr 2013 01:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/04/04/ajanta-daulatabad-ellora/news.html</guid>
</item>
<item>
    <title>Fedora OpenStack workshop, P.E.S. College of Engineering, Aurangabad</title>
    <link>http://www.shakthimaan.com/posts/2013/03/04/fedora-openstack-pes-aurangabad/news.html</link>
    <description><![CDATA[<p>I had organized a <a href="http://fedoraproject.org/wiki/OpenStack">Fedora and OpenStack</a> workshop at <a href="http://www.pescoe.ac.in/">P.E.S. College of Engineering, Nagsen Vana, Aurangabad</a>, Maharashtra on Saturday, March 2, 2013.</p>
<img alt="P.E.S. College of Engineering" src="http://www.shakthimaan.com/Mambo/gallery/albums/album88/7_college_facade.jpg"></img>
<p>After a formal inauguration at 1000 IST, I introduced the students to communication guidelines, mailing list etiquette, and project guidelines using the <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">“i-want-2-do-project. tell-me-wat-2-do”</a> presentation. The different <a href="http://fedoraproject.org/wiki/Projects">Fedora sub-projects</a> to which they can contribute to were mentioned. I showed the various free/open source software tools available for them to learn and use. The career options with free/open source software were also discussed. I had asked them to write down any questions they had on the forenoon session, so I could answer them in the afternoon session. Few of their questions:</p>
<ul>
<li>If I do a project in Java, what are my career options?</li>
<li>What is the difference between open source and Microsoft?</li>
<li>Is Linux popular only because of security, or are there other reasons too?</li>
<li>I am interested in mainframes. How should I learn?</li>
<li>I am interested in a career in animation. What free/open source software can I use?</li>
<li>What are the steps to become a good software engineer?</li>
<li>Can I patent a software product?</li>
</ul>
<p>Post-lunch, I answered their queries in the Q&amp;A session, to the best of my knowledge. I also gave them an introduction on copyright, trademark and patents, and mentioned that IANAL. I then introduced them to the architecture of OpenStack, explaining the individual components, and their functionality. The <a href="http://fedorapeople.org/~russellb/openstack-lab-rhsummit-2012/index.html">OpenStack Lab Guide</a> was provided to them to setup their own OpenStack cloud. Some of them had brought their laptops to try it hands-on. I demonstrated the Horizon web interface after starting the required services.</p>
<img alt="Fedora Labs" src="http://www.shakthimaan.com/Mambo/gallery/albums/album88/9_fedora_lab.jpg"></img>
<p>All their computer labs have been migrated to Fedora 17. Thanks to Prof. Nitin Ujgare for working with me in organizing this workshop, and for maintaining the Fedora labs at the Institute. Aurangabad is around 230 km from Pune, and takes around 4 1/2 hours by road. There are frequent bus services between Pune and Aurangabad. You can book bus tickets at <a href="http://www.msrtc.gov.in/msrtc_live/index.html">Maharashtra State Road Transport Corporation (MSRTC)</a> web site. There are a number of historic places to visit in and around Aurangabad. Few photos taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album88">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 04 Mar 2013 16:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/03/04/fedora-openstack-pes-aurangabad/news.html</guid>
</item>
<item>
    <title>Emacs + Magit = Git Magic</title>
    <link>http://www.shakthimaan.com/posts/2013/02/25/introduction-to-magit/news.html</link>
    <description><![CDATA[<p>I had presented an introduction to <a href="https://github.com/magit/magit">Magit</a>, “Emacs + Magit = Git Magic”, at the <a href="http://www.meetup.com/the-peg">Pune Emacs Users’ group meetup</a> on Friday, February 22, 2013. Magit is an Emacs mode that interfaces with <a href="http://git-scm.com/">Git</a>. Magit doesn’t provide all the interfaces of Git, but the frequently used commands. The <a href="http://magit.github.com/magit/magit.html">user manual</a> was used as a reference. Magit is available in Fedora. You can install it using:</p>
<pre class="shell"><code>$ sudo yum install emacs-magit</code></pre>
<p>The talk was centered around the notion of writing a poem on Emacs in Emacs, and using magit to revision it. I started an Emacs session, created a directory with <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html">Dired</a> mode, and used magit (M-x magit-status) to initialize a git repo. After adding a stanza in the poem, I used the magit commands to stage (s) and commit the same (c, C-c C-c) from the magit-buffer. Another stanza and a README file were then added, and the different untracked, and tracked section visibility options (TAB, S-TAB, {1-4}, M-{1-4}) were illustrated. After adding the third stanza, and committing the same, the short (l l) and long (l L) history formatted outputs were shown. The return (RET) key on a commit in the magit-log history buffer opens a new magit-commit buffer, displaying the changes made in the commit. The sha1 can be copied using the (C-w) shortcut.</p>
<img alt="session-in-progress" src="http://photos1.meetupstatic.com/photos/event/e/1/b/6/600_207537782.jpeg"></img>
<p>The reflogs are visible with the (l h) option from the magit-buffer. The (d) command was used to show the difference between the master and a revision, and (D) for the diff between any two revisions. Annotated tags (t a) and lightweight tags (t t) can be created in magit. Resetting the working tree and discarding the current changes is possible with (X). Stashing (z z) the present changes, applying a stash (a), and killing the stash (k) were demonstrated. An org branch was then created (b n) to write a stanza on org-mode, and then merged (m m) with the master branch. An example of rebasing (R) was also illustrated. The magit-buffer can be refreshed (g) to check the current status of the git repo. Anytime, the magit buffers can be closed with the (q) command. A git command can be invoked directly using (:), and the corresponding output can be viewed with ($), which is shown in a magit-process buffer.</p>
<p>A summary of the various shortcuts are available in the <a href="http://shakthimaan.com/downloads.html#emacs-magit-git-magic">presentation</a>. The poem that I wrote on Emacs, and used in the talk:</p>
<blockquote>
Emacs is, an operating system <br />Which unlike many others, is truly, a gem <br />Its goodies can be installed, using RPM <br />Or you can use ELPA, which has already packaged them <br />
</blockquote>
<blockquote>
You can customize it, to your needs <br />You can also check EmacsWiki, for more leads <br />Your changes work, as long as reload succeeds <br />And helps you with, your daily deeds <br />
</blockquote>
<blockquote>
People say, it lacks a decent editor <br />But after using its features, they might want to differ <br />Using Magit’s shortcuts, you might infer <br />That it is something, you definitely prefer <br />
</blockquote>
<blockquote>
Plan your life, with org-mode <br />You don’t necessarily need, to write code <br />TODO lists and agenda views, can easily be showed <br />Reading the documentation, can help you come aboard <br />
</blockquote>
<blockquote>
Emacs is, a double-edged sword <br />Its powerful features, can never be ignored <br />Customization is possible, because of Free Software code <br />And this is, my simple ode. <br />
</blockquote>]]></description>
    <pubDate>Mon, 25 Feb 2013 04:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/02/25/introduction-to-magit/news.html</guid>
</item>
<item>
    <title>GCC workshop, GNUnify 2013</title>
    <link>http://www.shakthimaan.com/posts/2013/02/19/gnunify-gcc-workshop/news.html</link>
    <description><![CDATA[<p><a href="http://gnunify.in/">GNUnify 2013</a> was held at <a href="http://sicsr.ac.in/">Symbiosis Institute of Computer Studies and Research (SICSR)</a>, Pune, Maharashtra, India between February 15 to 17, 2013. I attended day one of the unconference.</p>
<img alt="poster" src="http://www.shakthimaan.com/Mambo/gallery/albums/album87/poster.jpg"></img>
<p>The first talk that I listened to was by Oyunbileg Baatar on “Screencasting Demos and HowTos”. He mentioned the various free/open source, desktop recording software available. He also gave a demo of <a href="http://recordmydesktop.sourceforge.net/about.php">recordMyDesktop</a>, and video editing using <a href="http://www.pitivi.org/">PiTiVi</a>.</p>
<p>After a short break, and a formal introduction, I began my session for the day - <a href="http://shakthimaan.com/downloads.html#introduction-to-gcc">“Introduction to GCC”</a>. Fedora 17 was installed in the labs for the participants to use. I started with a simple hello world example and the use of header files. I also explained the concepts of compilation and linking, and briefed them on the syntax of Makefiles. Examples on creating and using static and shared libraries were illustrated. We also discussed the different warning and error messages emitted by GCC. The platform-specific and optimization options were shown with examples. Students were not familiar with touch typing, and I had to demonstrate the use of <a href="http://klavaro.sourceforge.net/en/index.html">Klavaro</a> typing tutor.</p>
<img alt="GCC workshop" src="http://www.shakthimaan.com/Mambo/gallery/albums/album87/gcc_workshop.jpg"></img>
<p>The preliminary round for the programming contest was held in the afternoon. Thirty questions on C and systems programming were given to the participants to be answered in thirty minutes. I helped evaluate the answers. The practical test was to be conducted the following day. Thanks to <a href="http://neependra.net/">Neependra Khare</a> and Kiran Divarkar for organizing the programming contest.</p>
<p>I also attended the OpenStack mini-conf session in the evening where a demo of OpenStack was given by Kiran Murari. This was followed by a session on “OpenStack High Availability” by Syed Armani. Aditya Godbole’s closing session for the day on an “Introduction to Ruby” was informative. Few photos that were taken are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album87">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 19 Feb 2013 04:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/02/19/gnunify-gcc-workshop/news.html</guid>
</item>
<item>
    <title>Fedora workshop, SITRC, Nashik</title>
    <link>http://www.shakthimaan.com/posts/2013/02/06/sitrc-fedora-workshop/news.html</link>
    <description><![CDATA[<p>A Fedora workshop was organized at <a href="http://sitrc.sandipfoundation.org/">Sandip Institute of Technology and Research Center (SITRC)</a>, <a href="http://en.wikipedia.org/wiki/Nashik">Nashik</a>, Maharashtra, India from February 2 to 3, 2013.</p>
<img alt="SITRC, Nashik" src="http://www.shakthimaan.com/Mambo/gallery/albums/album86/8_amphitheatre.jpg"></img>
<p>Day I</p>
<p>I began the day’s proceedings with the <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">“i-want-2-do-project. tell-me-wat-2-do-fedora”</a> presentation in the seminar hall at SITRC. The participants were introduced to mailing list, communication and effective project guidelines when working with free/open source software. This was followed by an introduction on window managers, and demo of the Fedora desktop, GNOME, Fluxbox, and console environments.</p>
<p>After lunch, I gave an introduction on system architecture, and installation concepts. Basics of compilation and cross-compilation topics were discussed. An introduction on git was given using the <a href="http://shakthimaan.com/downloads.html#di-git-ally-managing-love-letters">“di-git-ally managing love letters”</a> presentation. After a short tea break, we moved to the labs for a hands-on session on GCC. This is a <a href="http://shakthimaan.com/downloads.html#introduction-to-gcc">presentation</a> based on the book by Brian Gough, <a href="http://www.network-theory.co.uk/gcc/intro/">“An introduction to GCC”</a>. Practical lab exercises were given to teach students compilation and linking methods using GCC. I also briefed them on the use of Makefiles. C Language standards, platform-specific and optimization options with GCC were illustrated.</p>
<img alt="GCC lab session" src="http://www.shakthimaan.com/Mambo/gallery/albums/album86/10_lab_session_in_progress.jpg"></img>
<p>Day II</p>
<p>Lab exercises from the GCC presentation were practised on the second day, along with the creation and use of static and shared libraries. The different warning options supported by GCC were elaborated. A common list of error messages that newbies face were also discussed. After the lab session, I introduced them to cloud computing and <a href="http://fedorapeople.org/~russellb/openstack-lab-rhsummit-2012/index.html">OpenStack</a>, giving them an overview of the various components, interfaces, and specifications. I also gave them a demo of the OpenStack Essex release running on Fedora 17 (x86_64) with the Horizon web interface.</p>
<p>The college was affiliated to University of Pune, and had deployed GNU/Linux labs for their coursework. Now they are autonomous, and want to explore and expand their activities. They have a local user group called <a href="http://snashlug.wordpress.com/">SnashLUG</a>. The college is 15 km away from the city of Nashik, which is around 200 km from Pune. The bus journey from Pune to Nashik takes six hours, and you can book tickets online through <a href="http://www.msrtc.gov.in/">Maharashtra State Road Transport Corporation (MSRTC)</a>. There is frequent bus service between Pune and Nashik.</p>
<p>Thanks to Rahul Mahale for working with me for the past three months in planning and organizing this workshop. Thanks also to the Management, and Faculty of SITRC for the wonderful hospitality, and their support for the workshop.</p>
<p>Few photos taken during the workshop are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album86">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 06 Feb 2013 05:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/02/06/sitrc-fedora-workshop/news.html</guid>
</item>
<item>
    <title>Dvorak keyboard layout</title>
    <link>http://www.shakthimaan.com/posts/2013/01/19/dvorak/news.html</link>
    <description><![CDATA[<blockquote>
<p>“The arrangement (QWERTY) of the letters on a typewriter is an example of the success of the least deserving method.” ~ Nassim Nicholas Taleb</p>
</blockquote>
<blockquote>
<p>“With early typewriters the mechanical arms would jam if two letters were hit in too rapid a sequence. So the classic QWERTY keyboard was designed to ‘slow down’ typing.” ~ Edward de Bono</p>
</blockquote>
<p>The continuous use of the QWERTY keyboard causes pain, and I am forced to rest my fingers. While it is good to take a break, it shouldn’t be done for the wrong reason. I started to look for alternate keyboard layouts to use, and a typing tutor to practise with. Dr. August Dvorak and Dr. William Dealey completed the Dvorak simplified keyboard layout in 1932.</p>
<img alt="Dvorak keyboard layout" src="http://upload.wikimedia.org/wikipedia/commons/2/25/KB_United_States_Dvorak.svg"></img>
<p>To add the the Dvorak keyboard layout to Gnome, select Applications -&gt; System Tools -&gt; System Settings. Choose “Region and Language”. Under the “Layout” tab, add Dvorak (English). Klavaro is a typing tutor that is available for Fedora. You can install it using:</p>
<pre class="shell"><code>$ sudo yum install klavaro</code></pre>
<p>There are five levels in Klavaro - introduction, basic course, adaptability, speed, and fluidity. After adding the Dvorak keyboard layout on Fedora, I started the exercises in Klavaro. At home I used Dvorak, while at work I used QWERTY. I was able to quickly reach 30 words per minute (wpm) with Dvorak. When I tried to go beyond 40 wpm, I was unconsciously still thinking, and using the QWERTY keyboard. To break that barrier, I switched full-time to use Dvorak, even at work. Speed was slow, initially, but after a month of practise I passed all the exercises in Klavaro.</p>
<img alt="Klavaro progress chart" src="http://shakthimaan.com/downloads/screenshots/klavaro-progress.png"></img>
<p>If you are not familiar with touch typing, it is best to start with Dvorak. I can now type continuously for hours, and my fingers don’t hurt. I also do take breaks occasionally.</p>
<p>Give it a try!</p>]]></description>
    <pubDate>Sat, 19 Jan 2013 11:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/01/19/dvorak/news.html</guid>
</item>
<item>
    <title>VLSI Design Conference, Pune, 2013</title>
    <link>http://www.shakthimaan.com/posts/2013/01/16/vlsid-2013/news.html</link>
    <description><![CDATA[<p>The <a href="http://www.vlsidesignconference.org/">26th International Conference on VLSI Design 2013 and the 12th International Conference on Embedded Systems</a> was held at the <a href="http://pune.regency.hyatt.com/">Hyatt Regency, Pune</a>, India between January 5-10, 2013. The first two days were tutorial sessions, while the main conference began on Monday, January 7, 2013.</p>
<img alt="26th VLSID 2013" src="http://shakthimaan.com/downloads/glv/2013/vlsid-2013/poster.JPG"></img>
<p>Day 1: Tutorial</p>
<p>On the first day, I attended the tutorial on “Concept to Product - Design, Verification &amp; Test: A Tutorial” by <a href="http://www.ece.wisc.edu/~saluja/">Prof. Kewal Saluja</a>, and <a href="http://www.ee.iitb.ac.in/~viren/">Prof. Virendra Singh</a>. Prof. Saluja started the tutorial with an introduction and history of VLSI. An overview of the VLSI realization process was given with an emphasis on synthesis. The theme of the conference was “green” technology, and hence the concepts of low power design were introduced. The challenges of multi-core and high performance design including cache coherence were elaborated. Prof. Singh explained the verification methodologies with an example of implementing a DVD player. Simulation and formal verification techniques were compared, with an overview on model checking. Prof. Saluja explained the basics of VLSI testing, differences between verification and testing, and the various testing techniques used. The challenges in VLSI testing were also discussed.</p>
<p>Day 2: Tutorial</p>
<p>On the second day, I attended the tutorial on “Formal Techniques for Hardware/Software Co-Verification” by <a href="http://www.kroening.com/">Prof. Daniel Kroening</a>, and <a href="http://www.cmi.ac.in/people/fac-profile.php?id=mksrivas">Prof. Mandayam Srinivas</a>. Prof. Kroening began the tutorial with the motivation for formal methods. Examples on SAT solvers, boundary model checking for hardware, and bounded program analysis for C programs were explained. Satisfiability modulo theories for bit-vectors, arrays and functions were illustrated with numerous examples. In the afternoon, Prof. Srinivas demoed formal verification for both Verilog and C. He shared the results of verification done for both a DSP and a microprocessor. The <a href"http: www.cprover.org ">CProver</a> tool has been released under a CMBC license. After discussion with Fedora Legal, and Prof. Kroening, it <a href="http://lists.fedoraproject.org/pipermail/legal/2013-January/002067.html">has been updated to a BSD license for inclusion in Fedora</a>. The <a href="http://www.cprover.org/VLSI2013/">presentation slides</a> used in the tutorial are available.</p>
<p>Day 3: Main conference</p>
<p>The first day of the main conference began with the keynote by <a href="http://www.lsi.com/about/ourstory/pages/management.aspx#Abhi">Mr. Abhi Talwalker</a>, CEO of LSI, on “Intelligent Silicon in the Data-centric Era”. He addressed the challenges in bridging the data deluge gap, latency issues in data centers, and energy efficient buildings. The second keynote of the day was given by <a href="http://en.wikipedia.org/wiki/Ruchir_Puri">Dr. Ruchir Puri</a>, IBM Fellow, on “Opportunities and Challenges for High Performance Microprocessor Designs and Design Automation”. Dr. Ruchir spoke about the various IBM multi-core processors, and the challenges facing multi-core designs - software parallelism, socket bandwidth, power, and technology complexity. He also said that more EDA innovation needs to come at the system level.</p>
<img alt="Dias" src="http://shakthimaan.com/downloads/glv/2013/vlsid-2013/dias.JPG"></img>
<p>After the keynote, I attended the “C1. Embedded Architecture” track sessions. <a href="http://www.cse.unsw.edu.au/~liangt/">Liang Tang</a> presented his paper on “Processor for Reconfigurable Baseband Modulation Mapping”. <a href"http: www.pdn.ac.lk eng pages departmentHome CE otherpages staff Dr.Swarnalatha%20Radhakrishnan.html">Dr. Swarnalatha Radhakrishnan</a> then presented her paper on “A Study on Instruction-set Selection Using Multi-application Based Application Specific Instruction-Set Processors”. She explained about ASIPs (Application Specific Instruction Set Processor), and shared test results on choosing specific instruction sets based on the application domain. The final paper for the session was presented by <a href="http://www.princeton.edu/~jha/">Prof. Niraj K. Jha</a> on “Localized Heating for Building Energy Efficiency”. He and his team at Princeton have used ultrasonic sensors to implement localized heating. A similar approach is planned for lighting as well.</p>
<p>Post-lunch, I attended the sessions for the track “B2. Test Cost Reduction and Safety”. The honourable chief minister of Maharashtra, <a href="http://en.wikipedia.org/wiki/Prithviraj_Chavan">Shri. Prithviraj Chavan</a>, arrived in the afternoon to formally inaugurate the conference. He is an engineer who graduated from the University of California, Berkeley, and said that he was committed to put Pune on the semiconductor map. The afternoon keynote was given by <a href="http://investor.marvell.com/phoenix.zhtml?c=120802&amp;p=irol-govBio&amp;ID=198477">Mr. Kishore Manghnani</a> from Marvell, on “Semiconductors in Smart Energy Products”. He primarily discussed about LEDs, and their applications. This was followed by a panel discussion on “Low power design”. There was an emphasis to create system level, software architecture techniques to increase leverage in low power design. For the last track of the day, I attended the sessions on “C3. Design and Synthesis of Reversible Logic”. The <a href="http://keccak.noekeon.org/">Keccak</a> sponge function family has been chosen to become the SHA-3 standard.</p>
<p>Day 4: Main conference</p>
<p>The second day of the main conference began with a recorded keynote by <a href="http://investor.appliedmicro.com/phoenix.zhtml?c=78121&amp;p=irol-govBio&amp;ID=192748">Dr. Paramesh Gopi</a>, AppliedMicro, on “Cloud computing needs at less power and low cost” followed by a talk by <a href="http://phx.corporate-ir.net/phoenix.zhtml?c=78121&amp;p=irol-govManage">Mr. Amal Bommireddy</a>, AppliedMicro, on “Challenges of First pass Silicon”. Mr. Bommireddy discussed the factors affecting first pass success - RTL verification, IP verification, physical design, routing strategies, package design, and validation board design. The second keynote of the day was by <a href="http://www.hhmi.org/research/fellows/scheffer_bio.html">Dr. Louis Scheffer</a> from the Howard Hughes Medical Institute, on “Deciphering the brain, cousin to the chip”. It was a brilliant talk on applying chip debugging techniques to inspect and analyse how the brain works.</p>
<p>After the keynote, I visited the exhibition hall where companies had their products displayed in their respective stalls. AppliedMicro had a demo of their <a href="http://www.apm.com/products/x-gene">X-gene</a> ARM64 platform running Ubuntu. They did mention to me that Fedora runs on their platform. Marvell had demonstrated their embedded and control solutions running on Fedora. ARM had their <a href="http://mbed.org">mbed.org</a> and <a href="http://embeddedacademic.com">embeddedacademic.com</a> kits on display for students. Post-lunch, was an excellent keynote by <a href="http://www.intel.com/jobs/virtualevent/bio/singh.htm">Dr. Vivek Singh</a>, Intel Fellow, titled “Duniyaa Maange Moore!”. He started with what people need - access, connectivity, education, and healthcare, and went to discuss the next in line for Intel’s manufacturing process. The 14nm technology is scheduled to be operational by end of 2013, while 10nm is planned for 2015. They have also started work on 7nm manufacturing processes. This was followed by a panel discussion on “Expectations of Manufacturing Sector from Semiconductor and Embedded System Companies” where the need to bridge the knowledge gap between mechanical and VLSI/embedded engineers was emphasized.</p>
<p>Day 5: Main conference</p>
<p>The final day of the main conference began with the keynote by <a href="http://www.cse.psu.edu/~vijay/">Dr. Vijaykrishnan Narayanan</a> on “Embedded Vision Systems”, where he showed the current research in intelligent cameras, augmented reality, and interactive systems. I attended the sessions for the track “C7. Advances in Functional Verification”, and “C8. Logic Synthesis and Design”. Post-lunch, <a href="http://www.linkedin.com/pub/ken-chang/4/279/2b4">Dr. Ken Chang</a> gave his keynote on “Advancing High Performance System-on-Package via Heterogeneous 3-D Integration”. He said that Intel’s 22nm Ivy Bridge which uses FinFETs took nearly 15 years to productize, but look promising for the future. Co(CoS) Chip on Chip on Substrate, and (CoW)oS Chip on Wafer on Substrate technologies were illustrated. Many hardware design houses use 15 FPGAs on a board for testing. The Xilinx Virtex-7HT FPGA has analog, memory, and ARM microprocessor integrated on a single chip giving a throughput of 2.8 Terabits/second. He also mentioned that Known Good Die (KGD) methodologies are still emerging in the market. For the last track of the conference, I attended the sessions on “C9. Advances in Circuit Simulation, Analysis and Design”.</p>
<p>Thanks to Red Hat for sponsoring me to attend the conference.</p>]]></description>
    <pubDate>Wed, 16 Jan 2013 10:50:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/01/16/vlsid-2013/news.html</guid>
</item>
<item>
    <title>Lonavla</title>
    <link>http://www.shakthimaan.com/posts/2013/01/02/lonavla/news.html</link>
    <description><![CDATA[<img alt="Pune-Mumbai expressway at Khandala" src="http://www.shakthimaan.com/Mambo/gallery/albums/album85/39_pune_mumbai_expressway_at_khandala.jpg"></img><br />
<img alt="Karla caves" src="http://www.shakthimaan.com/Mambo/gallery/albums/album85/13_karla_caves.jpg"></img><br />
<img alt="Rabindranath Tagore wax model" src="http://www.shakthimaan.com/Mambo/gallery/albums/album85/22_tagore_wax.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album85">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 02 Jan 2013 06:50:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2013/01/02/lonavla/news.html</guid>
</item>
<item>
    <title>csmith</title>
    <link>http://www.shakthimaan.com/posts/2012/12/27/csmith/news.html</link>
    <description><![CDATA[<p><a href="http://embed.cs.utah.edu/csmith/">csmith</a> is a tool for testing compilers. It can generate random C programs for the C99 standard. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install csmith</code></pre>
<p>The following simple bash script, given by the developers, demonstrates its usage:</p>
<pre class="shell"><code>set -e
while [ true ]
do
  csmith &gt; test.c;
  gcc-4.0 -I${CSMITH_PATH}/runtime -O -w test.c -o /dev/null;
done</code></pre>
<p>There are quite a number of options you can use to tell csmith to generate the programs that you want. For example, if you don’t want argc to be passed to the <em>main</em> function, you can use:</p>
<pre class="shell"><code>$ csmith --no-argc</code></pre>
<p>The <em>main</em> function in the generated C program will resemble:</p>
<pre class="sourceCode c"><code class="sourceCode c">...
<span class="dt">int</span> main (<span class="dt">void</span>)
{
...
}</code></pre>
<p>The maximum number of fields in a struct that csmith will generate is ten. You can increase it by using the –max-struct-fields option:</p>
<pre class="shell"><code>$ csmith --max-struct-fields 15</code></pre>
<p>A structure that was created with the above option is shown below:</p>
<pre class="sourceCode c"><code class="sourceCode c">...
<span class="kw">struct</span> S1 {
   <span class="dt">unsigned</span> f0 : <span class="dv">20</span>;
   <span class="dt">const</span> <span class="dt">signed</span> f1 : <span class="dv">2</span>;
   <span class="dt">volatile</span> <span class="dt">signed</span> f2 : <span class="dv">15</span>;
   <span class="dt">signed</span> f3 : <span class="dv">23</span>;
   <span class="dt">unsigned</span> f4 : <span class="dv">9</span>;
   <span class="dt">signed</span> f5 : <span class="dv">1</span>;
   <span class="dt">volatile</span> <span class="dt">uint8_t</span>  f6;
   <span class="dt">const</span> <span class="dt">volatile</span> <span class="dt">signed</span> f7 : <span class="dv">12</span>;
   <span class="dt">const</span> <span class="dt">volatile</span> <span class="dt">signed</span> f8 : <span class="dv">20</span>;
   <span class="dt">signed</span> f9 : <span class="dv">27</span>;
   <span class="dt">const</span> <span class="dt">unsigned</span> f10 : <span class="dv">11</span>;
   <span class="dt">uint16_t</span>  f11;
};
...</code></pre>
<p>csmith also produces a brief summary or statistics on the program it generates. A sample output is shown below:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="co">/************************ statistics *************************</span>
<span class="co">XXX max struct depth: 0</span>
<span class="co">breakdown:</span>
<span class="co">   depth: 0, occurrence: 278</span>
<span class="co">XXX total union variables: 13</span>

<span class="co">XXX non-zero bitfields defined in structs: 0</span>
<span class="co">XXX zero bitfields defined in structs: 0</span>
<span class="co">XXX const bitfields defined in structs: 0</span>
<span class="co">XXX volatile bitfields defined in structs: 0</span>
<span class="co">XXX structs with bitfields in the program: 0</span>
<span class="co">breakdown:</span>
<span class="co">XXX full-bitfields structs in the program: 0</span>
<span class="co">breakdown:</span>
<span class="co">XXX times a bitfields struct's address is taken: 0</span>
<span class="co">XXX times a bitfields struct on LHS: 0</span>
<span class="co">XXX times a bitfields struct on RHS: 0</span>
<span class="co">XXX times a single bitfield on LHS: 0</span>
<span class="co">XXX times a single bitfield on RHS: 0</span>

<span class="co">XXX max expression depth: 41</span>
<span class="co">breakdown:</span>
<span class="co">   depth: 1, occurrence: 81</span>
<span class="co">   depth: 2, occurrence: 19</span>
<span class="co">   depth: 3, occurrence: 2</span>
<span class="co">   depth: 4, occurrence: 3</span>
<span class="co">   depth: 5, occurrence: 1</span>
<span class="co">   depth: 10, occurrence: 1</span>
<span class="co">   depth: 11, occurrence: 1</span>
<span class="co">   depth: 12, occurrence: 1</span>
<span class="co">   depth: 13, occurrence: 3</span>
<span class="co">   depth: 14, occurrence: 1</span>
<span class="co">   depth: 15, occurrence: 1</span>
<span class="co">   depth: 16, occurrence: 1</span>
<span class="co">   depth: 18, occurrence: 2</span>
<span class="co">   depth: 21, occurrence: 2</span>
<span class="co">   depth: 28, occurrence: 1</span>
<span class="co">   depth: 32, occurrence: 1</span>
<span class="co">   depth: 40, occurrence: 1</span>
<span class="co">   depth: 41, occurrence: 1</span>

<span class="co">XXX total number of pointers: 191</span>

<span class="co">XXX times a variable address is taken: 88</span>
<span class="co">XXX times a pointer is dereferenced on RHS: 93</span>
<span class="co">breakdown:</span>
<span class="co">   depth: 1, occurrence: 85</span>
<span class="co">   depth: 2, occurrence: 5</span>
<span class="co">   depth: 3, occurrence: 3</span>
<span class="co">XXX times a pointer is dereferenced on LHS: 137</span>
<span class="co">breakdown:</span>
<span class="co">   depth: 1, occurrence: 129</span>
<span class="co">   depth: 2, occurrence: 5</span>
<span class="co">   depth: 3, occurrence: 2</span>
<span class="co">   depth: 4, occurrence: 1</span>
<span class="co">XXX times a pointer is compared with null: 16</span>
<span class="co">XXX times a pointer is compared with address of another variable: 2</span>
<span class="co">XXX times a pointer is compared with another pointer: 5</span>
<span class="co">XXX times a pointer is qualified to be dereferenced: 4443</span>

<span class="co">XXX max dereference level: 5</span>
<span class="co">breakdown:</span>
<span class="co">   level: 0, occurrence: 0</span>
<span class="co">   level: 1, occurrence: 501</span>
<span class="co">   level: 2, occurrence: 29</span>
<span class="co">   level: 3, occurrence: 13</span>
<span class="co">   level: 4, occurrence: 2</span>
<span class="co">   level: 5, occurrence: 1</span>
<span class="co">XXX number of pointers point to pointers: 57</span>
<span class="co">XXX number of pointers point to scalars: 132</span>
<span class="co">XXX number of pointers point to structs: 0</span>
<span class="co">XXX percent of pointers has null in alias set: 42.4</span>
<span class="co">XXX average alias set size: 1.73</span>

<span class="co">XXX times a non-volatile is read: 668</span>
<span class="co">XXX times a non-volatile is write: 407</span>
<span class="co">XXX times a volatile is read: 6</span>
<span class="co">XXX    times read thru a pointer: 2</span>
<span class="co">XXX times a volatile is write: 1</span>
<span class="co">XXX    times written thru a pointer: 0</span>
<span class="co">XXX times a volatile is available for access: 73</span>
<span class="co">XXX percentage of non-volatile access: 99.4</span>

<span class="co">XXX forward jumps: 0</span>
<span class="co">XXX backward jumps: 1</span>

<span class="co">XXX stmts: 81</span>
<span class="co">XXX max block depth: 5</span>
<span class="co">breakdown:</span>
<span class="co">   depth: 0, occurrence: 27</span>
<span class="co">   depth: 1, occurrence: 18</span>
<span class="co">   depth: 2, occurrence: 17</span>
<span class="co">   depth: 3, occurrence: 10</span>
<span class="co">   depth: 4, occurrence: 5</span>
<span class="co">   depth: 5, occurrence: 4</span>

<span class="co">XXX percentage a fresh-made variable is used: 16.2</span>
<span class="co">XXX percentage an existing variable is used: 83.8</span>
<span class="co">********************* end of statistics **********************/</span></code></pre>
<p>If you don’t want the statistics, and would like a brief output, you can use the –concise option with csmith:</p>
<pre class="shell"><code>$ csmith --concise</code></pre>
<p>You are encouraged to read the <a href="http://embed.cs.utah.edu/csmith/using.html">usage guide</a> for more information on using the tool.</p>]]></description>
    <pubDate>Thu, 27 Dec 2012 09:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/12/27/csmith/news.html</guid>
</item>
<item>
    <title>ghc-data-memocombinators</title>
    <link>http://www.shakthimaan.com/posts/2012/12/15/ghc-data-memocombinators/news.html</link>
    <description><![CDATA[<p>The <a href="http://hackage.haskell.org/package/data-memocombinators">data-memocombinators</a> package provides combinators for creating memo tables. It can build up data similar to a lookup table. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-data-memocombinators-devel</code></pre>
<p>The time and memory consumption for a command execution can be viewed in ghci by setting the following:</p>
<pre class="shell"><code>ghci&gt; :set +s</code></pre>
<p>Suppose we wish to apply memoization to the Fibonacci function:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.MemoCombinators</span> <span class="kw">as</span> <span class="dt">Memo</span>

fib <span class="fu">=</span> Memo.integral fib'
    <span class="kw">where</span>
    fib' <span class="dv">0</span> <span class="fu">=</span> <span class="dv">0</span>
    fib' <span class="dv">1</span> <span class="fu">=</span> <span class="dv">1</span>
    fib' x <span class="fu">=</span> fib (x<span class="dv">-1</span>) <span class="fu">+</span> fib (x<span class="dv">-2</span>)</code></pre>
<p>The 10,000th Fibonacci number using the fib function is returned in a much shorter time in the second attempt:</p>
<pre class="shell"><code>ghci&gt; fib 10000
...
(0.15 secs, 87703888 bytes)

ghci&gt; fib 10000
...
(0.03 secs, 9652144 bytes)</code></pre>
<p>We can also specify a range for which the memoization is to be applied. In the following example, it is applied only for the numbers between 1 and 1000:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.MemoCombinators</span> <span class="kw">as</span> <span class="dt">Memo</span>

fib2 <span class="fu">=</span> Memo.arrayRange (<span class="dv">1</span>, <span class="dv">1000</span>) fib'
    <span class="kw">where</span>
    fib' <span class="dv">0</span> <span class="fu">=</span> <span class="dv">0</span>
    fib' <span class="dv">1</span> <span class="fu">=</span> <span class="dv">1</span>
    fib' x <span class="fu">=</span> fib2 (x<span class="dv">-1</span>) <span class="fu">+</span> fib2 (x<span class="dv">-2</span>)</code></pre>
<p>Using fib2 to return the 1000th Fibonacci number, we observe the following:</p>
<pre class="shell"><code>ghci&gt; fib2 1000
...
(0.04 secs, 10804024 bytes)

ghci&gt; fib2 1000
...
(0.02 secs, 7384584 bytes)</code></pre>
<p>The mulHundred function takes an integer list as an argument and muliplies each element in the list with 100. We want to tabulate the values for faster lookup using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.MemoCombinators</span> <span class="kw">as</span> <span class="dt">Memo</span>

mulHundred <span class="fu">=</span> (Memo.list Memo.integral) b
  <span class="kw">where</span>
  b [] <span class="fu">=</span> []
  b (x<span class="fu">:</span>xs) <span class="fu">=</span> [<span class="dv">100</span> <span class="fu">*</span> x]  <span class="fu">++</span> mulHundred xs </code></pre>
<p>Running the mulHundred function in ghci:</p>
<pre class="shell"><code>ghci&gt; mulHundred [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[100,200,300,400,500,600,700,800,900,1000]
(0.03 secs, 9592680 bytes)

ghci&gt; mulHundred [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[100,200,300,400,500,600,700,800,900,1000]
(0.02 secs, 8426040 bytes)</code></pre>
<p>We can also apply memoization for quicksort. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.MemoCombinators</span> <span class="kw">as</span> <span class="dt">Memo</span>

quicksort <span class="fu">=</span> (Memo.list Memo.integral) quicksort' <span class="kw">where</span>
          quicksort' [] <span class="fu">=</span> []
          quicksort' (p<span class="fu">:</span>xs) <span class="fu">=</span> (quicksort lesser) <span class="fu">++</span> [p] <span class="fu">++</span> (quicksort greater)
                            <span class="kw">where</span>
                            lesser <span class="fu">=</span> <span class="fu">filter</span> (<span class="fu">&lt;</span> p) xs
                            greater <span class="fu">=</span> <span class="fu">filter</span> (<span class="fu">&gt;=</span> p) xs</code></pre>
<p>Subsequent sorting of the input is faster:</p>
<pre class="shell"><code>ghci&gt; let input = [x | x &lt;- [100, 99..1]]
(0.02 secs, 7895376 bytes)

ghci&gt; quicksort input
[1,2,..100]
(0.04 secs, 19918312 bytes)

ghci&gt; quicksort input
[1,2,..100]
(0.01 secs, 7925856 bytes)</code></pre>
<p>If we would like to create a table of results for the AND operation, we could use Memo.bool:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.MemoCombinators</span> <span class="kw">as</span> <span class="dt">Memo</span>

andGate <span class="fu">=</span> Memo.bool new
  <span class="kw">where</span>
  new x y <span class="fu">=</span> x <span class="fu">&amp;&amp;</span> y</code></pre>
<p>For example:</p>
<pre class="shell"><code>ghci&gt; False &amp;&amp; True
False
(0.02 secs, 8537120 bytes)

ghci&gt; andGate False True
False
(0.02 secs, 8442648 bytes)

ghci&gt; andGate False True
False
(0.01 secs, 7376560 bytes)</code></pre>]]></description>
    <pubDate>Sat, 15 Dec 2012 08:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/12/15/ghc-data-memocombinators/news.html</guid>
</item>
<item>
    <title>OpenStack workshop, Symbiosis, Pune, December 1, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/12/03/openstack-symbiosis-pune-december-2012/news.html</link>
    <description><![CDATA[<p>A workshop on <a href="http://www.openstack.org/">OpenStack</a> was conducted on Saturday, December 1, 2012 at the <a href="http://sicsr.ac.in/">Symbiosis Institute of Computer Studies and Research (SICSR)</a>, Pune, India. Both theory and lab sessions were organized for the students. I started the proceedings using Perry Myers’s presentation on “Introduction and Overview of OpenStack for IaaS (Infrastructure as a Service) Clouds” for the Essex release. The various building blocks of OpenStack with their functionality was explained. An overall big picture of the architecture was presented to them with illustrations.</p>
<img src="http://www.shakthimaan.com/downloads/glv/2012/openstack-symbiosis-2012/openstack-workshop-lab.JPG" alt="OpenStack hands-on session"></img>
<p>The <a href="http://fedorapeople.org/~russellb/openstack-lab-rhsummit-2012/">OpenStack Lab Guide</a> was then given to the participants to setup their own OpenStack private cloud. Some of them had brought their own laptops, while others used the Fedora machines in the labs. We started by setting up the Keystone service, and adding users for authentication. The Glance service was then installed, and configured. A <a href="http://docs.openstack.org/trunk/openstack-compute/admin/content/starting-images.html">Fedora 17 and cirros image</a> were then imported into Glance. The Nova service was then setup, and a SSH keypair was created for testing.</p>
<p>The Horizon dashboard user interface was used to start a virtual machine instance. Using ssh and the created keypair, we were able to login to the virtual machine and use it. curl was used to test the different REST API on the running stack. I also showed them simple Python examples to demonstrate the OpenStack APIs. As a final presentation for the day, I gave an introduction on libvirtd, and KVM.</p>
<p>Thanks to Manoj Aswani for working with me in organizing this workshop. Thanks also to Perry Myers and Mark McLoughlin for permission to use their presentation.</p>]]></description>
    <pubDate>Mon, 03 Dec 2012 16:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/12/03/openstack-symbiosis-pune-december-2012/news.html</guid>
</item>
<item>
    <title>ghc-arrows</title>
    <link>http://www.shakthimaan.com/posts/2012/12/01/ghc-arrows/news.html</link>
    <description><![CDATA[<p>Arrows provide a generalization for monads, which was introduced by John Hughes. The <a href="http://hackage.haskell.org/package/arrows">arrows</a> package provides classes that extend the Arrows class. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-arrows-devel</code></pre>
<p>Consider the identity function defined using the arrows notation:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE Arrows #-}</span>
 
<span class="kw">import</span> <span class="dt">Control.Arrow</span> (returnA)
 
<span class="ot">idA ::</span> a <span class="ot">-&gt;</span> a
idA <span class="fu">=</span> proc a <span class="ot">-&gt;</span> returnA <span class="fu">-&lt;</span> a</code></pre>
<p>The idA function returns the given input as shown below:</p>
<pre class="shell"><code>*Main&gt; idA 6
6
*Main&gt; idA True
True
*Main&gt; idA &quot;Eureka!&quot;
&quot;Eureka!&quot;</code></pre>
<p>A mulTwo function that multiplies an integer by two can be written as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE Arrows #-}</span>
 
<span class="kw">import</span> <span class="dt">Control.Arrow</span> (returnA)

<span class="ot">mulTwo ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
mulTwo <span class="fu">=</span> proc a <span class="ot">-&gt;</span> returnA <span class="fu">-&lt;</span> (a <span class="fu">*</span> <span class="dv">2</span>)</code></pre>
<p>Testing mulTwo with ghci:</p>
<pre class="shell"><code>*Main&gt; mulTwo 4
8
*Main&gt; mulTwo 5
10</code></pre>
<p>We can also use the do notation with arrows. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE Arrows #-}</span>
 
<span class="kw">import</span> <span class="dt">Control.Arrow</span> (returnA)

<span class="ot">mulFour ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
mulFour <span class="fu">=</span> proc a <span class="ot">-&gt;</span> <span class="kw">do</span> b <span class="ot">&lt;-</span> mulTwo <span class="fu">-&lt;</span> a
                       mulTwo <span class="fu">-&lt;</span> b</code></pre>
<p>Loading mulFour in ghci:</p>
<pre class="shell"><code>*Main&gt; mulFour 2
8
*Main&gt; mulFour 3
12</code></pre>
<p>Arrows also supports the use of conditional statements. An example when used with the if … then … else construct is as follows:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE Arrows #-}</span>
 
<span class="kw">import</span> <span class="dt">Control.Arrow</span> (returnA)

<span class="ot">condMul ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span>
condMul <span class="fu">=</span> proc a <span class="ot">-&gt;</span>
               <span class="kw">if</span> a <span class="fu">&lt;</span> <span class="dv">5</span>
               <span class="kw">then</span> returnA <span class="fu">-&lt;</span> (a <span class="fu">*</span> <span class="dv">2</span>)
               <span class="kw">else</span> returnA <span class="fu">-&lt;</span> (a <span class="fu">*</span> <span class="dv">3</span>)                      </code></pre>
<p>The condMul function multiplies the input integer by two if it is less than five, and with three when greater than five:</p>
<pre class="shell"><code>*Main&gt; condMul 2
4
*Main&gt; condMul 6
18</code></pre>]]></description>
    <pubDate>Sat, 01 Dec 2012 16:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/12/01/ghc-arrows/news.html</guid>
</item>
<item>
    <title>SuperLU</title>
    <link>http://www.shakthimaan.com/posts/2012/11/10/SuperLU/news.html</link>
    <description><![CDATA[<p><a href="http://crd-legacy.lbl.gov/~xiaoye/SuperLU/">SuperLU</a> is a library for solving sparse linear system of equations AX = B. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install SuperLU-devel</code></pre>
<p>The superlu.c 5x5 example in the sources demonstrates the use of the SuperLU library:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &quot;slu_ddefs.h&quot;</span>

main(<span class="dt">int</span> argc, <span class="dt">char</span> *argv[])
{
    SuperMatrix A, L, U, B;
    <span class="dt">double</span>   *a, *rhs;
    <span class="dt">double</span>   s, u, p, e, r, l;
    <span class="dt">int</span>      *asub, *xa;
    <span class="dt">int</span>      *perm_r; <span class="co">/* row permutations from partial pivoting */</span>
    <span class="dt">int</span>      *perm_c; <span class="co">/* column permutation vector */</span>
    <span class="dt">int</span>      nrhs, info, i, m, n, nnz, permc_spec;
    superlu_options_t options;
    SuperLUStat_t stat;

    <span class="co">/* Initialize matrix A. */</span>
    m = n = <span class="dv">5</span>;
    nnz = <span class="dv">12</span>;
    <span class="kw">if</span> ( !(a = doubleMalloc(nnz)) ) ABORT(<span class="st">&quot;Malloc fails for a[].&quot;</span>);
    <span class="kw">if</span> ( !(asub = intMalloc(nnz)) ) ABORT(<span class="st">&quot;Malloc fails for asub[].&quot;</span>);
    <span class="kw">if</span> ( !(xa = intMalloc(n<span class="dv">+1</span>)) ) ABORT(<span class="st">&quot;Malloc fails for xa[].&quot;</span>);
    s = <span class="fl">19.0</span>; u = <span class="fl">21.0</span>; p = <span class="fl">16.0</span>; e = <span class="fl">5.0</span>; r = <span class="fl">18.0</span>; l = <span class="fl">12.0</span>;
    a[<span class="dv">0</span>] = s; a[<span class="dv">1</span>] = l; a[<span class="dv">2</span>] = l; a[<span class="dv">3</span>] = u; a[<span class="dv">4</span>] = l; a[<span class="dv">5</span>] = l;
    a[<span class="dv">6</span>] = u; a[<span class="dv">7</span>] = p; a[<span class="dv">8</span>] = u; a[<span class="dv">9</span>] = e; a[<span class="dv">10</span>]= u; a[<span class="dv">11</span>]= r;
    asub[<span class="dv">0</span>] = <span class="dv">0</span>; asub[<span class="dv">1</span>] = <span class="dv">1</span>; asub[<span class="dv">2</span>] = <span class="dv">4</span>; asub[<span class="dv">3</span>] = <span class="dv">1</span>;
    asub[<span class="dv">4</span>] = <span class="dv">2</span>; asub[<span class="dv">5</span>] = <span class="dv">4</span>; asub[<span class="dv">6</span>] = <span class="dv">0</span>; asub[<span class="dv">7</span>] = <span class="dv">2</span>;
    asub[<span class="dv">8</span>] = <span class="dv">0</span>; asub[<span class="dv">9</span>] = <span class="dv">3</span>; asub[<span class="dv">10</span>]= <span class="dv">3</span>; asub[<span class="dv">11</span>]= <span class="dv">4</span>;
    xa[<span class="dv">0</span>] = <span class="dv">0</span>; xa[<span class="dv">1</span>] = <span class="dv">3</span>; xa[<span class="dv">2</span>] = <span class="dv">6</span>; xa[<span class="dv">3</span>] = <span class="dv">8</span>; xa[<span class="dv">4</span>] = <span class="dv">10</span>; xa[<span class="dv">5</span>] = <span class="dv">12</span>;

    <span class="co">/* Create matrix A in the format expected by SuperLU. */</span>
    dCreate_CompCol_Matrix(&amp;A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE);
    
    <span class="co">/* Create right-hand side matrix B. */</span>
    nrhs = <span class="dv">1</span>;
    <span class="kw">if</span> ( !(rhs = doubleMalloc(m * nrhs)) ) ABORT(<span class="st">&quot;Malloc fails for rhs[].&quot;</span>);
    <span class="kw">for</span> (i = <span class="dv">0</span>; i &lt; m; ++i) rhs[i] = <span class="fl">1.0</span>;
    dCreate_Dense_Matrix(&amp;B, m, nrhs, rhs, m, SLU_DN, SLU_D, SLU_GE);

    <span class="kw">if</span> ( !(perm_r = intMalloc(m)) ) ABORT(<span class="st">&quot;Malloc fails for perm_r[].&quot;</span>);
    <span class="kw">if</span> ( !(perm_c = intMalloc(n)) ) ABORT(<span class="st">&quot;Malloc fails for perm_c[].&quot;</span>);

    <span class="co">/* Set the default input options. */</span>
    set_default_options(&amp;options);
    options.ColPerm = NATURAL;

    <span class="co">/* Initialize the statistics variables. */</span>
    StatInit(&amp;stat);

    <span class="co">/* Solve the linear system. */</span>
    dgssv(&amp;options, &amp;A, perm_c, perm_r, &amp;L, &amp;U, &amp;B, &amp;stat, &amp;info);
    
    dPrint_CompCol_Matrix(<span class="st">&quot;A&quot;</span>, &amp;A);
    dPrint_CompCol_Matrix(<span class="st">&quot;U&quot;</span>, &amp;U);
    dPrint_SuperNode_Matrix(<span class="st">&quot;L&quot;</span>, &amp;L);
    print_int_vec(<span class="st">&quot;</span><span class="ch">\n</span><span class="st">perm_r&quot;</span>, m, perm_r);

    <span class="co">/* De-allocate storage */</span>
    SUPERLU_FREE (rhs);
    SUPERLU_FREE (perm_r);
    SUPERLU_FREE (perm_c);
    Destroy_CompCol_Matrix(&amp;A);
    Destroy_SuperMatrix_Store(&amp;B);
    Destroy_SuperNode_Matrix(&amp;L);
    Destroy_CompCol_Matrix(&amp;U);
    StatFree(&amp;stat);
}</code></pre>
<p>Running the program produces the following output:</p>
<pre class="shell"><code>$ ./superlu

CompCol matrix A:
Stype 0, Dtype 1, Mtype 0
nrow 5, ncol 5, nnz 12
nzval: 19.000000  12.000000  12.000000  21.000000  12.000000  12.000000  21.000000  16.000000  21.000000  5.000000  21.000000  18.000000  
rowind: 0  1  4  1  2  4  0  2  0  3  3  4  
colptr: 0  3  6  8  10  12  

CompCol matrix U:
Stype 0, Dtype 1, Mtype 4
nrow 5, ncol 5, nnz 11
nzval: 21.000000  -13.263158  7.578947  21.000000  
rowind: 0  1  2  0  
colptr: 0  0  0  1  4  4  

SuperNode matrix L:
Stype 3, Dtype 1, Mtype 1
nrow 5, ncol 5, nnz 11, nsuper 2
nzval:
0	0	1.900000e+01
1	0	6.315789e-01
4	0	6.315789e-01
1	1	2.100000e+01
2	1	5.714286e-01
4	1	5.714286e-01
1	2	-1.326316e+01
2	2	2.357895e+01
4	2	-2.410714e-01
3	3	5.000000e+00
4	3	-7.714286e-01
3	4	2.100000e+01
4	4	3.420000e+01

nzval_colptr: 0  3  6  9  11  13  
rowind: 0  1  4  1  2  4  3  4  
rowind_colptr: 0  3  6  6  8  8  
col_to_sup: 0  1  1  2  2  
sup_to_col: 0  1  3  5  

perm_r
0	0
1	1
2	2
3	3
4	4</code></pre>
<p>The <a href="http://crd-legacy.lbl.gov/~xiaoye/SuperLU/superlu_ug.pdf">SuperLU User’s Guide</a> provides detailed documentation on the algorithms and usage of three libraries used to solve sparse linear systems.</p>]]></description>
    <pubDate>Sat, 10 Nov 2012 04:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/11/10/SuperLU/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day, RVCE, Bengaluru, October 7, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/10/08/fad-rvce-bengaluru-october-2012/news.html</link>
    <description><![CDATA[<p>A <a href="https://fedoraproject.org/wiki/FAD_Bengaluru_2012">Fedora Activity Day</a> was organized at <a href="http://www.rvce.edu.in/">R. V. College of Engineering</a>, Bengaluru on Sunday, October 7, 2012. The participants were students from the Master of Computer Applications (MCA) department.</p>
<p>I started the day’s proceedings on best <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">communication practices, project guidelines</a> that need to be followed, and introduced the audience to the various Fedora sub-projects that they can get started with. The next session was on version control systems, and their importance with an <a href="http://shakthimaan.com/downloads.html#di-git-ally-managing-love-letters">introduction to Git</a>. We had a hands-on session where the participants practised simple Git commands.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album84/4_git_session.jpg" alt="Git hands-on session"></img>
<p><a href="https://fedoraproject.org/wiki/User:Kumarpraveen">Praveen Kumar</a> (HP) then spoke about Bugzilla, and how one can file bugs for Fedora. He also explained how to write meaningful bug reports.</p>
<p>Post-lunch, I introduced them to packaging concepts and terminology. Using the <a href="http://shakthimaan.com/downloads.html#packaging-red-hot-paneer-butter-masala">RPM packaging presentation</a>, we taught them how to build, and test RPMs. Praveen Kumar explained the Fedora package review process, and the various tools and infrastructure that we use for the same.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album84/6_pk_bugzilla.jpg" alt="Praveen Kumar on Bugzilla"></img>
<p>The final session of the day was from <a href="https://fedoraproject.org/wiki/User:Charlesrose">Charles Rose</a> (Dell) who introduced the participants to virtualization with KVM on Fedora. He also addressed the basic concepts involved in virtualization with numerous examples. The department lab is planning to move all their backend services to Virtual Machines.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album84/8_qemu_cmd_line.jpg" alt="Charles Rose on Virtualization"></img>
<p>Thanks to Prof. Renuka Prasad for working with us in organizing this workshop.</p>
<p>More photos are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album84">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 08 Oct 2012 10:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/10/08/fad-rvce-bengaluru-october-2012/news.html</guid>
</item>
<item>
    <title>ghc-blaze-textual</title>
    <link>http://www.shakthimaan.com/posts/2012/10/02/ghc-blaze-textual/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/blaze-textual">blaze-textual</a> is a library for rendering Haskell data types to bytestrings. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-blaze-textual-devel</code></pre>
<p>You can import the Text module (for example) using:</p>
<pre class="shell"><code>ghci&gt; :m + Blaze.Text</code></pre>
<p>A simple example of using <strong>digit</strong>, <strong>integral</strong>, and <strong>float</strong> functions is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.ByteString.Lazy</span> <span class="kw">as</span> <span class="dt">L</span>
<span class="kw">import</span> <span class="dt">Blaze.ByteString.Builder</span>

<span class="kw">import</span> <span class="dt">Blaze.Text</span>
<span class="kw">import</span> <span class="dt">Blaze.Text.Int</span>

main <span class="fu">=</span> <span class="kw">do</span>
     <span class="kw">let</span> a <span class="fu">=</span> toLazyByteString <span class="fu">$</span> digit <span class="dv">3</span>
         b <span class="fu">=</span> toLazyByteString <span class="fu">$</span> integral <span class="dv">3</span>
         c <span class="fu">=</span> toLazyByteString <span class="fu">$</span> float <span class="dv">3</span>
     L.putStrLn a
     L.putStrLn b
     L.putStrLn c</code></pre>
<p>You can compile it using:</p>
<pre class="shell"><code>$ ghc --make test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...</code></pre>
<p>Running <em>test</em> gives:</p>
<pre class="shell"><code>$ ./test
3
3
3.0</code></pre>]]></description>
    <pubDate>Tue, 02 Oct 2012 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/10/02/ghc-blaze-textual/news.html</guid>
</item>
<item>
    <title>ghc-HSH</title>
    <link>http://www.shakthimaan.com/posts/2012/09/30/ghc-HSH/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/HSH">HSH</a> package allows you to use shell commands and expressions with Haskell programs. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-HSH-devel</code></pre>
<p>You can import the HSH module using:</p>
<pre class="shell"><code>ghci&gt; :m + HSH</code></pre>
<p>The <strong>runIO</strong> function can execute a shell command:</p>
<pre class="shell"><code>Prelude HSH&gt; runIO &quot;date&quot;
Sun Sep 30 21:29:50 IST 2012</code></pre>
<p>You can use pipes with multiple commands by separating them with “-|-”:</p>
<pre class="shell"><code>Prelude HSH&gt; runIO $ &quot;date&quot; -|- &quot;wc&quot;
      1       6      29</code></pre>
<p>The <strong>runSL</strong> function takes a command as an argument and returns the first line of the output:</p>
<pre class="shell"><code>Prelude HSH&gt; runSL &quot;cal&quot;
&quot;   September 2012&quot;</code></pre>
<p>The <strong>setenv</strong> function can set an environment variable:</p>
<pre class="shell"><code>Prelude HSH&gt; runIO &quot;echo $TERM&quot;
xterm

Prelude HSH&gt; runIO $ setenv [(&quot;TERM&quot;, &quot;gnome-terminal&quot;)] $ &quot;echo $TERM&quot;
gnome-terminal</code></pre>
<p>The HSH package also provides shell equivalent commands. Few examples are shown below:</p>
<pre class="shell"><code>Prelude HSH&gt; basename &quot;/tmp/tmp/doc&quot;
&quot;doc&quot;

Prelude HSH&gt; dirname &quot;/tmp/tmp/doc&quot;
&quot;/tmp/tmp&quot;

Prelude HSH&gt; pwd
&quot;/tmp&quot;

Prelude HSH&gt; cut 2 ' ' &quot;alpha bravo charlie delta echo&quot;
&quot;charlie&quot;</code></pre>
<p>The <strong>wcL</strong> and <strong>wcW</strong> functions count the lines and words respectively:</p>
<pre class="shell"><code>Prelude HSH&gt; wcL [&quot;hello&quot;, &quot;world&quot;]
[&quot;2&quot;]

Prelude HSH&gt; wcW [&quot;first&quot;, &quot;second&quot;, &quot;third fourth&quot;]
[&quot;4&quot;]</code></pre>]]></description>
    <pubDate>Sun, 30 Sep 2012 18:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/30/ghc-HSH/news.html</guid>
</item>
<item>
    <title>ghc-MonadRandom</title>
    <link>http://www.shakthimaan.com/posts/2012/09/23/ghc-MonadRandom/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/MonadRandom">MonadRandom</a> package is a random number generation monad. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-MonadRandom-devel</code></pre>
<p>The example of simulating a die is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Control.Monad.Random</span>

<span class="ot">die ::</span> (<span class="dt">RandomGen</span> g) <span class="ot">=&gt;</span> <span class="dt">Rand</span> g <span class="dt">Int</span>
die <span class="fu">=</span> getRandomR (<span class="dv">1</span>,<span class="dv">6</span>)

<span class="ot">dice ::</span> (<span class="dt">RandomGen</span> g) <span class="ot">=&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Rand</span> g [<span class="dt">Int</span>]
dice n <span class="fu">=</span> <span class="fu">sequence</span> (<span class="fu">replicate</span> n die)

main <span class="fu">=</span> <span class="kw">do</span>
  values <span class="ot">&lt;-</span> evalRandIO (dice <span class="dv">1</span>)
  <span class="fu">putStrLn</span> (<span class="fu">show</span> values)</code></pre>
<p>Compile it using:</p>
<pre class="shell"><code>$ ghc --make die.hs 
[1 of 1] Compiling Main             ( die.hs, die.o )
Linking die ...</code></pre>
<p>You can run it using:</p>
<pre class="shell"><code>$ ./die 
[3]
$ ./die 
[5]
$ ./die 
[1]
$ ./die 
[1]
$ ./die 
[6]</code></pre>
<p>The fromList function produces a random value from a weighted list:</p>
<pre class="shell"><code>Prelude&gt; :m + Control.Monad.Random
Prelude Control.Monad.Random&gt; fromList [(1,2), (3,4), (5,6)]
5
Prelude Control.Monad.Random&gt; fromList [(1,2), (3,4), (5,6)]
1
Prelude Control.Monad.Random&gt; fromList [(1,2), (3,4), (5,6)]
5
Prelude Control.Monad.Random&gt; fromList [(1,2), (3,4), (5,6)]
3
Prelude Control.Monad.Random&gt; fromList [(1,2), (3,4), (5,6)]
1</code></pre>]]></description>
    <pubDate>Sun, 23 Sep 2012 16:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/23/ghc-MonadRandom/news.html</guid>
</item>
<item>
    <title>ghc-show</title>
    <link>http://www.shakthimaan.com/posts/2012/09/21/ghc-show/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/show">show</a> package provides ShowQ, ShowFun and SimpleReflect modules. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-show-devel</code></pre>
<p>To import the ShowQ module (for example), you can use:</p>
<pre class="shell"><code>Prelude&gt; :m + ShowQ</code></pre>
<p>The ShowFun module provides Typeable instances for IO expressions. The ShowQ module includes SmallCheck and QuickCheck support. Example uses of mysmallcheck, myquickcheck and tests functions in ShowQ are shown below:</p>
<pre class="shell"><code>Prelude ShowQ&gt; mysmallcheck (\s -&gt; length (&quot;Hello&quot;) == 5)
Depth 0:
  Completed 1 test(s) without failure.
Depth 1:
  Completed 1 test(s) without failure.
Depth 2:
  Completed 1 test(s) without failure.
Depth 3:
  Completed 1 test(s) without failure.
Depth 4:
  Completed 1 test(s) without failure.
Depth 5:
  Completed 1 test(s) without failure.
Depth 6:
  Completed 1 test(s) without failure.
()

Prelude ShowQ&gt; myquickcheck (\s -&gt; length (&quot;Hello&quot;) == 5)
&quot;+++ OK, passed 100 tests.
OK, passed 100 tests.&quot;

Prelude ShowQ&gt; tests (\s -&gt; length(&quot;Hello&quot;) == 5) 5 [[&quot;a&quot;], [&quot;b&quot;]]
+++ OK, passed 100 tests.
&quot;OK, passed 100 tests.1%b.\n1%a.\n&quot;</code></pre>
<p>The SimpleReflect module expands functions literally, and provides simple reflection of Haskell expressions containing variables. Few examples:</p>
<pre class="shell"><code>Prelude SimpleReflect&gt; foldr f x [1..5]
f 1 (f 2 (f 3 (f 4 (f 5 x))))

Prelude SimpleReflect&gt; sum [1..5] :: Expr
0 + 1 + 2 + 3 + 4 + 5

Prelude SimpleReflect&gt; sum $ map (*x) [1..5]
0 + 1 * x + 2 * x + 3 * x + 4 * x + 5 * x</code></pre>]]></description>
    <pubDate>Fri, 21 Sep 2012 13:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/21/ghc-show/news.html</guid>
</item>
<item>
    <title>ghc-IOSpec</title>
    <link>http://www.shakthimaan.com/posts/2012/09/20/ghc-IOSpec/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/IOSpec">IOSpec</a> package provides several modules that give a pure specification of functions in the IO monad. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-IOSpec-devel</code></pre>
<p>To import a specific Fork module (for example), you can use:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Test.IOSpec.Fork</span></code></pre>
<p>Test.IOSpec.Teletype provides a pure specification of the getChar and putChar functions. A simple example of echo is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE NPlusKPatterns #-}</span>

<span class="kw">import</span> <span class="dt">Prelude</span> <span class="kw">hiding</span> (<span class="fu">getChar</span>, <span class="fu">putChar</span>)
<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Prelude</span> (<span class="fu">putStrLn</span>)
<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.Stream</span> <span class="kw">as</span> <span class="dt">Stream</span>
<span class="kw">import</span> <span class="dt">Test.IOSpec</span> <span class="kw">hiding</span> (<span class="fu">putStrLn</span>)
<span class="kw">import</span> <span class="dt">Test.QuickCheck</span>
<span class="kw">import</span> <span class="dt">Data.Char</span> (<span class="fu">ord</span>)

<span class="ot">echo ::</span> <span class="dt">IOSpec</span> <span class="dt">Teletype</span> ()
echo <span class="fu">=</span> <span class="fu">getChar</span> <span class="fu">&gt;&gt;=</span> <span class="fu">putChar</span> <span class="fu">&gt;&gt;</span> echo

<span class="ot">copy ::</span> <span class="dt">Effect</span> ()
copy <span class="fu">=</span> <span class="dt">ReadChar</span> (\x <span class="ot">-&gt;</span> <span class="dt">Print</span> x copy)

<span class="ot">takeOutput ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Effect</span> () <span class="ot">-&gt;</span> <span class="dt">String</span>
takeOutput <span class="dv">0</span> _ <span class="fu">=</span> <span class="st">&quot;&quot;</span>
takeOutput (n <span class="fu">+</span> <span class="dv">1</span>) (<span class="dt">Print</span> c xs) <span class="fu">=</span> c <span class="fu">:</span> takeOutput n xs
takeOutput _ _ <span class="fu">=</span> <span class="fu">error</span> <span class="st">&quot;Echo.takeOutput&quot;</span>

<span class="ot">withInput ::</span> <span class="dt">Stream.Stream</span> <span class="dt">Char</span> <span class="ot">-&gt;</span> <span class="dt">Effect</span> a <span class="ot">-&gt;</span> <span class="dt">Effect</span> a
withInput stdin (<span class="dt">Done</span> x)     <span class="fu">=</span> <span class="dt">Done</span> x
withInput stdin (<span class="dt">Print</span> c e)  <span class="fu">=</span> <span class="dt">Print</span> c (withInput stdin e)
withInput stdin (<span class="dt">ReadChar</span> f) <span class="fu">=</span> withInput (Stream.tail stdin)
                                 (f (Stream.head stdin))

<span class="ot">echoProp ::</span> <span class="dt">Stream.Stream</span> <span class="dt">Char</span> <span class="ot">-&gt;</span> <span class="dt">Property</span>
echoProp input <span class="fu">=</span>
    forAll (choose (<span class="dv">1</span>,<span class="dv">10000</span>)) <span class="fu">$</span> \n <span class="ot">-&gt;</span>
    takeOutput n (withInput input (evalIOSpec echo singleThreaded))
    <span class="fu">==</span> takeOutput n (withInput input copy)

main <span class="fu">=</span> <span class="kw">do</span>
  Prelude.putStrLn <span class="st">&quot;Testing echo...&quot;</span>
  quickCheck echoProp</code></pre>
<p>You can compile it using:</p>
<pre class="shell"><code>$ ghc --make Echo.hs
[1 of 1] Compiling Main             ( Echo.hs, Echo.o )
Linking Echo ...</code></pre>
<p>Test it using:</p>
<pre class="shell"><code>$ ./Echo 
Testing echo...
+++ OK, passed 100 tests.</code></pre>
<p>The Test.IOSpec.IORef provides a pure specification of mutable variables. An example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.IOSpec</span>
<span class="kw">import</span> <span class="dt">Test.QuickCheck</span>

<span class="ot">readOnce ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">IOSpec</span> <span class="dt">IORefS</span> <span class="dt">Int</span>
readOnce x <span class="fu">=</span> <span class="kw">do</span> ref <span class="ot">&lt;-</span> newIORef x
                readIORef ref

<span class="ot">readTwice ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">IOSpec</span> <span class="dt">IORefS</span> <span class="dt">Int</span>
readTwice x <span class="fu">=</span> <span class="kw">do</span> ref <span class="ot">&lt;-</span> newIORef x
                 readIORef ref
                 readIORef ref

<span class="ot">readIORefProp ::</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Bool</span>
readIORefProp x <span class="fu">=</span>
  <span class="kw">let</span> once  <span class="fu">=</span> evalIOSpec (readOnce x) singleThreaded
      twice <span class="fu">=</span> evalIOSpec (readTwice x) singleThreaded
  <span class="kw">in</span> once <span class="fu">==</span> twice

main <span class="fu">=</span> quickCheck readIORefProp</code></pre>
<p>You can compile it using:</p>
<pre class="shell"><code>$ ghc --make Refs.hs 
[1 of 1] Compiling Main             ( Refs.hs, Refs.o )
Linking Refs ...</code></pre>
<p>Test it using:</p>
<pre class="shell"><code>$ ./Refs 
+++ OK, passed 100 tests.</code></pre>]]></description>
    <pubDate>Thu, 20 Sep 2012 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/20/ghc-IOSpec/news.html</guid>
</item>
<item>
    <title>ghc-data-inttrie</title>
    <link>http://www.shakthimaan.com/posts/2012/09/19/ghc-data-inttrie/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/data-inttrie">data-inttrie</a> package is a simple lazy, infinite trie for integers. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-data-inttrie-devel</code></pre>
<p>To import the data-inttrie module, use:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Data.IntTrie</span></code></pre>
<p>The Bits class in Data.Bits module defines bitwise operations on integral types, and is defined using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Num</span> a <span class="ot">=&gt;</span> <span class="dt">Bits</span> a <span class="kw">where</span></code></pre>
<p>The complement function, for example, reverses the bits in the argument:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> Data.bits
<span class="dt">Prelude</span> <span class="dt">Data.Bits</span><span class="fu">&gt;</span> complement <span class="dv">3</span>
<span class="fu">-</span><span class="dv">4</span></code></pre>
<p>The apply function in Data.IntTrie applies a trie to an argument:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">apply ::</span> (<span class="kw">Ord</span> b, <span class="dt">Bits</span> b) <span class="ot">=&gt;</span> <span class="dt">IntTrie</span> a <span class="ot">-&gt;</span> b <span class="ot">-&gt;</span> a</code></pre>
<p>For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Data.IntTrie</span><span class="fu">&gt;</span> <span class="kw">let</span> bits f <span class="fu">=</span> apply (<span class="fu">fmap</span> f identity)
<span class="dt">Prelude</span> <span class="dt">Data.IntTrie</span><span class="fu">&gt;</span> bits (<span class="fu">*</span><span class="dv">3</span>) <span class="dv">4</span><span class="ot"> ::</span> <span class="dt">Int</span>
<span class="dv">12</span></code></pre>]]></description>
    <pubDate>Wed, 19 Sep 2012 05:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/19/ghc-data-inttrie/news.html</guid>
</item>
<item>
    <title>emacs-identica-mode</title>
    <link>http://www.shakthimaan.com/posts/2012/09/14/emacs-identica-mode/news.html</link>
    <description><![CDATA[<p><a href="https://savannah.nongnu.org/projects/identica-mode/">identica-mode</a> is an Emacs mode to receive and submit updates to laconica microblogging site. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install emacs-identica-mode</code></pre>
<p>To enter into identica-mode in GNU Emacs, you can use:</p>
<pre class="lisp"><code>M-x identica-mode</code></pre>
<p>Or, you can also add the following in your ~/.emacs:</p>
<pre class="lisp"><code>(require 'identica-mode)
(setq identica-username &quot;yourusername&quot;)</code></pre>
<p>To send an update, use C-c C-s within GNU Emacs, or use:</p>
<pre class="lisp"><code>M-x identica-update-status-interactive</code></pre>
<p>To view the public timeline, you can use:</p>
<pre class="lisp"><code>C-c C-a</code></pre>
<p>To view a user’s timeline, you can use:</p>
<pre class="lisp"><code>C-c C-u</code></pre>
<p>To send a direct message to a user, you can use:</p>
<pre class="lisp"><code>C-c C-d</code></pre>
<p>You can press ‘G’ anytime to refresh the timeline in the *identica* buffer. The Identica mode manual has more examples and shortcuts to interact with identi.ca.</p>]]></description>
    <pubDate>Fri, 14 Sep 2012 15:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/14/emacs-identica-mode/news.html</guid>
</item>
<item>
    <title>ghc-oeis</title>
    <link>http://www.shakthimaan.com/posts/2012/09/12/ghc-oeis/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/oeis">oeis</a> package provides an interface to the Online Encyclopaedia of Integer Sequences - <a href="http://oeis.org">http://oeis.org</a>. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-oeis-devel</code></pre>
<p>To import the OEIS module, use:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="fu">:</span>m <span class="fu">+</span> <span class="dt">Math.OEIS</span></code></pre>
<p>Few examples are shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Math.OEIS</span><span class="fu">&gt;</span> getSequenceByID <span class="st">&quot;A000040&quot;</span>
<span class="kw">Just</span> [<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">5</span>,<span class="dv">7</span>,<span class="dv">11</span>,<span class="dv">13</span>,<span class="dv">17</span>,<span class="dv">19</span>,<span class="dv">23</span>,<span class="dv">29</span>,<span class="dv">31</span>,<span class="dv">37</span>,<span class="dv">41</span>,<span class="dv">43</span>,<span class="dv">47</span>,<span class="dv">53</span>,<span class="dv">59</span>,<span class="dv">61</span>,<span class="dv">67</span>,<span class="dv">71</span>,<span class="dv">73</span>,<span class="dv">79</span>,<span class="dv">83</span>,<span class="dv">89</span>,
<span class="dv">97</span>,<span class="dv">101</span>,<span class="dv">103</span>,<span class="dv">107</span>,<span class="dv">109</span>,<span class="dv">113</span>,<span class="dv">127</span>,<span class="dv">131</span>,<span class="dv">137</span>,<span class="dv">139</span>,<span class="dv">149</span>,<span class="dv">151</span>,<span class="dv">157</span>,<span class="dv">163</span>,<span class="dv">167</span>,<span class="dv">173</span>,<span class="dv">179</span>,<span class="dv">181</span>,<span class="dv">191</span>,
<span class="dv">193</span>,<span class="dv">197</span>,<span class="dv">199</span>,<span class="dv">211</span>,<span class="dv">223</span>,<span class="dv">227</span>,<span class="dv">229</span>,<span class="dv">233</span>,<span class="dv">239</span>,<span class="dv">241</span>,<span class="dv">251</span>,<span class="dv">257</span>,<span class="dv">263</span>,<span class="dv">269</span>,<span class="dv">271</span>]</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Math.OEIS</span><span class="fu">&gt;</span> description <span class="ot">`fmap`</span> lookupSequenceByID <span class="st">&quot;A000040&quot;</span>
<span class="kw">Just</span> <span class="st">&quot;The prime numbers.&quot;</span></code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Math.OEIS</span><span class="fu">&gt;</span> lookupOEIS <span class="st">&quot;2,3,5,7&quot;</span>
[<span class="st">&quot;The prime numbers.&quot;</span>,<span class="st">&quot;[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,</span>
<span class="st">67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,</span>
<span class="st">167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,</span>
<span class="st">269,271]&quot;</span>]</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Math.OEIS</span><span class="fu">&gt;</span> extendSequence [<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">5</span>]
[<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">5</span>,<span class="dv">7</span>,<span class="dv">11</span>,<span class="dv">13</span>,<span class="dv">17</span>,<span class="dv">19</span>,<span class="dv">23</span>,<span class="dv">29</span>,<span class="dv">31</span>,<span class="dv">37</span>,<span class="dv">41</span>,<span class="dv">43</span>,<span class="dv">47</span>,<span class="dv">53</span>,<span class="dv">59</span>,<span class="dv">61</span>,<span class="dv">67</span>,<span class="dv">71</span>,<span class="dv">73</span>,<span class="dv">79</span>,<span class="dv">83</span>,<span class="dv">89</span>,<span class="dv">97</span>,
<span class="dv">101</span>,<span class="dv">103</span>,<span class="dv">107</span>,<span class="dv">109</span>,<span class="dv">113</span>,<span class="dv">127</span>,<span class="dv">131</span>,<span class="dv">137</span>,<span class="dv">139</span>,<span class="dv">149</span>,<span class="dv">151</span>,<span class="dv">157</span>,<span class="dv">163</span>,<span class="dv">167</span>,<span class="dv">173</span>,<span class="dv">179</span>,<span class="dv">181</span>,<span class="dv">191</span>,
<span class="dv">193</span>,<span class="dv">197</span>,<span class="dv">199</span>,<span class="dv">211</span>,<span class="dv">223</span>,<span class="dv">227</span>,<span class="dv">229</span>,<span class="dv">233</span>,<span class="dv">239</span>,<span class="dv">241</span>,<span class="dv">251</span>,<span class="dv">257</span>,<span class="dv">263</span>,<span class="dv">269</span>,<span class="dv">271</span>]</code></pre>]]></description>
    <pubDate>Wed, 12 Sep 2012 18:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/09/12/ghc-oeis/news.html</guid>
</item>
<item>
    <title>ghc-numbers</title>
    <link>http://www.shakthimaan.com/posts/2012/08/10/ghc-numbers/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/numbers">numbers</a> package provides instances of numerical classes for different types of numbers - (computable) real numbers, precison fixed numbers, floating point numbers, differentiable numbers, symbolic numbers, and interval arithmetic. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-numbers-devel</code></pre>
<p>For interval arithmentic, Interval is defined as a type constructor:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Interval</span> a <span class="fu">=</span> <span class="dt">I</span> a a</code></pre>
<p>The ival function two arguments of the same type and returns an Interval a, while, the getIval function takes an interval and returns a pair.</p>
<pre class="shell"><code>ghci&gt; :m + Data.Number.Interval

ghci&gt; ival 1 2
1..2

ghci&gt; getIval (ival 3 4)
(3,4)</code></pre>
<p>The CReal type implements (constructive) real numbers. The showCReal function takes a number of decimals, a real number, and returns a string.</p>
<pre class="shell"><code>ghci&gt; :m + Data.Number.CReal

ghci&gt; showCReal 5 pi
&quot;3.14159&quot;</code></pre>
<p>The Dif type is a type defined for differentiable numbers. The dCon function takes a number and constructs a Dif number with the same value, while the val function does the opposite.</p>
<pre class="shell"><code>ghci&gt; :m + Data.Number.Dif

ghci&gt; dCon 3
3~~

ghci&gt; val (dCon 5)
5</code></pre>
<p>The mkDif function takes a value and a Dif value and makes a Dif number as its derivative.</p>
<pre class="shell"><code>ghci&gt; mkDif 4 (dCon 2)
4~~</code></pre>
<p>The deriv function takes a derivative of a function. For example, if we have an equation f(x)=x<sup>2</sup>, then the first derivative, f’(x)=2x. This can be defined as:</p>
<pre class="shell"><code>ghci&gt; let f x = x * x
ghci&gt; let f' = deriv f

ghci&gt; f 3
9

ghci&gt; f' 3
6</code></pre>]]></description>
    <pubDate>Fri, 10 Aug 2012 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/08/10/ghc-numbers/news.html</guid>
</item>
<item>
    <title>ghc-readline</title>
    <link>http://www.shakthimaan.com/posts/2012/08/02/ghc-readline/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/readline">readline</a> is a Haskell binding to the <a href="http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html">GNU Readline</a> library. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-readline-devel</code></pre>
<p>The Readline library provides functions to for line editing, and managing history of commands entered interactively through the command-line. It is Free Software. A simple example of using ghc-readline is demonstrated:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.Console.Readline</span>

<span class="ot">readEvalPrintLoop ::</span> <span class="dt">IO</span> ()
readEvalPrintLoop <span class="fu">=</span> <span class="kw">do</span>
   maybeLine <span class="ot">&lt;-</span> readline <span class="st">&quot;% &quot;</span>
   <span class="kw">case</span> maybeLine <span class="kw">of</span> 
    <span class="kw">Nothing</span>     <span class="ot">-&gt;</span> <span class="fu">return</span> () 
    <span class="kw">Just</span> <span class="st">&quot;exit&quot;</span> <span class="ot">-&gt;</span> <span class="fu">return</span> ()
    <span class="kw">Just</span> line <span class="ot">-&gt;</span> <span class="kw">do</span> addHistory line
                    <span class="fu">putStrLn</span> <span class="fu">$</span> <span class="st">&quot;The user input: &quot;</span> <span class="fu">++</span> (<span class="fu">show</span> line)
                    readEvalPrintLoop

main <span class="fu">=</span> <span class="kw">do</span>
     readEvalPrintLoop</code></pre>
<p>Compile it using:</p>
<pre class="shell"><code> $ ghc --make read.hs
Linking read ...</code></pre>
<p>Run it and test it:</p>
<pre class="shell"><code> $ ./read
% 
The user input: &quot;&quot;
% Lorem ipsum
The user input: &quot;Lorem ipsum&quot;
% exit
 $</code></pre>]]></description>
    <pubDate>Thu, 02 Aug 2012 17:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/08/02/ghc-readline/news.html</guid>
</item>
<item>
    <title>unlambda</title>
    <link>http://www.shakthimaan.com/posts/2012/07/27/unlambda/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/unlambda">unlambda</a> package contains an interpreter written in Haskell for the <a href="http://en.wikipedia.org/wiki/Unlambda">Unlambda</a> language. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install unlambda</code></pre>
<p>Unlambda is a “nearly pure” functional programming language. There are no named functions in Unlambda. The s and k primitive functions are part of the core language, and are sufficient to make Unlambda Turing complete. The backquote(`) is used for function application. There are no variables in Unlambda. r prints a newline, and i is the identity function.</p>
<pre class="shell"><code> $ unlambda
`ri

 $</code></pre>
<p>The k combinator takes two arguments (by currying), say X and Y, and is expressed as ``kXY, which evaluates to X (Y is also evaluated). The s combinator takes three arguments and is applied as ``FXYZ, which evaluates to ``XZ`YZ. The .x functions prints the character x to the output. So, the r function is an instance of .x function where x represents the newline character.</p>
<pre class="shell"><code> $ unlambda
```k.Hii

H $</code></pre>
<p>The classic hello world program:</p>
<pre class="shell"><code>$ unlambda
`r```````````.H.e.l.l.o. .w.o.r.l.di
Hello world</code></pre>
<p>The following hello.unl program prints “Hello world!” followed by asterisk symbol, in incremental fashion.</p>
<pre class="shell"><code>```s``sii`ki
 ``s``s`ks	
     ``s``s`ks``s`k`s`kr
               ``s`k`si``s`k`s`k
                               `d````````````.H.e.l.l.o.,. .w.o.r.l.d.!
                        k
	k
  `k``s``s`ksk`k.*</code></pre>
<pre class="shell"><code>$ unlambda &lt; hello.unl

Hello, world!
Hello, world!*
Hello, world!**
Hello, world!***
Hello, world!****
Hello, world!*****
Hello, world!******
Hello, world!*******
Hello, world!********
Hello, world!*********
Hello, world!**********
...</code></pre>]]></description>
    <pubDate>Fri, 27 Jul 2012 12:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/07/27/unlambda/news.html</guid>
</item>
<item>
    <title>ghc-Stream</title>
    <link>http://www.shakthimaan.com/posts/2012/07/20/ghc-Stream/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/Stream">Stream</a> provides functions to create and manipulate infinite lists. It is defined as:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Stream</span> a <span class="fu">=</span> <span class="dt">Cons</span> a (<span class="dt">Stream</span> a)</code></pre>
<p>It is now available on Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-Stream-devel</code></pre>
<p>The fromList function converts an infinite list to a stream. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span><span class="fu">&gt;</span> <span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">Data.Stream</span> <span class="kw">as</span> <span class="dt">S</span>
<span class="dt">Prelude</span> <span class="dt">Data.Stream</span><span class="fu">&gt;</span> <span class="kw">let</span> numbers <span class="fu">=</span> S.fromList [<span class="dv">1</span><span class="fu">..</span>]
<span class="dt">Prelude</span> <span class="dt">Data.Stream</span><span class="fu">&gt;</span> S.head numbers
<span class="dv">1</span></code></pre>
<p>There are numerous functions available for building, transforming, extracting, sublisting, indexing streams. Most of them are analogous to the functions in Data.List. Few examples:</p>
<p>The map function applies a function uniformly over all the elements of a stream.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Data.Stream</span><span class="fu">&gt;</span> S.take <span class="dv">5</span> <span class="fu">$</span> S.map (<span class="fu">*</span><span class="dv">3</span>) numbers
[<span class="dv">3</span>,<span class="dv">6</span>,<span class="dv">9</span>,<span class="dv">12</span>,<span class="dv">15</span>]</code></pre>
<p>The cycle function can return an infinite repetition of a given list.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Data.Stream</span><span class="fu">&gt;</span> S.take <span class="dv">10</span> <span class="fu">$</span> S.cycle [<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]
[<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">1</span>]</code></pre>
<p>The take function extracts a sublist of n elements from the stream.</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Prelude</span> <span class="dt">Data.Stream</span><span class="fu">&gt;</span> S.take <span class="dv">10</span> numbers
[<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>,<span class="dv">6</span>,<span class="dv">7</span>,<span class="dv">8</span>,<span class="dv">9</span>,<span class="dv">10</span>]</code></pre>
<p>We can use the (!!) function to return an element at an index n in the stream.</p>
~~~~ {.haskell} Prelude Data.Stream&gt; numbers S.!! 5 6 ~~~~]]></description>
    <pubDate>Fri, 20 Jul 2012 11:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/07/20/ghc-Stream/news.html</guid>
</item>
<item>
    <title>ghc-logict</title>
    <link>http://www.shakthimaan.com/posts/2012/07/09/ghc-logict/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/logict">logict</a> is a “continuation-based, backtracking, logic programming monad”. It is a library that provides backtracking computations to a Haskell monad. It is now available on Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-logict-devel</code></pre>
<p>The observeAll function, for example, obtains all the results from a Logic computation:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Control.Applicative</span> ((<span class="fu">&lt;|&gt;</span>))
<span class="kw">import</span> <span class="dt">Control.Monad.Logic</span> (observeAll)
<span class="kw">import</span> <span class="dt">Control.Monad</span> (filterM)

<span class="ot">powerset ::</span> [a] <span class="ot">-&gt;</span> [[a]]
powerset <span class="fu">=</span> observeAll <span class="fu">.</span> filterM (<span class="fu">const</span> (<span class="fu">return</span> <span class="kw">False</span> <span class="fu">&lt;|&gt;</span> <span class="fu">return</span> <span class="kw">True</span>))</code></pre>
<p>You can compile and run the above example using:</p>
<p>~~~~ {.shell} $ ghci Powerset.hs GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim … linking … done. Loading package integer-gmp … linking … done. Loading package base … linking … done. [1 of 1] Compiling Main ( Powerset.hs, interpreted ) Ok, modules loaded: Main.</p>
*Main&gt; powerset [1,2] Loading package transformers-0.2.2.0 … linking … done. Loading package mtl-2.0.1.0 … linking … done. Loading package logict-0.5.0.1 … linking … done. [[],[2],[1],[1,2]] ~~~~]]></description>
    <pubDate>Mon, 09 Jul 2012 11:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/07/09/ghc-logict/news.html</guid>
</item>
<item>
    <title>Fedora workshop, ICCS, June 30, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/07/02/fedora-workshop-iccs/news.html</link>
    <description><![CDATA[<p>I had organized a one-day Fedora workshop at <a href="http://iccs.ac.in/">Indira College of Commerce and Science</a>, Pune, Maharashtra, India on Saturday, June 30, 2012. The college is affiliated to the <a href="http://www.unipune.ac.in/">University of Pune</a>.</p>
<p>The participants were post-graduate students in computer applications. They were familiar with basic programming in C, C++, Java and PHP. Their syllabus now mandates the use of *nix. Fedora was installed on all their lab machines for students to use and learn.</p>
<p>The forenoon session was lecture-based, where I began with an overview of the system architecture. Installation concepts were discussed, along with common newbie mistakes that are made during installation. I then demoed the Fedora desktop, and showed the various software, and window managers that they can use. The need to use a version control system was emphasized, and also introduced them to the use of git, with few examples.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album83/5_lab_session.jpg" alt="Lab session in progress"></img>
<p>Post-lunch was a lab session, where students worked on shell scripts and C programming exercises. I gave them numerous examples on how they can improve their programs by composing functions that do one thing and do it well. The students were also advised to follow coding guidelines, and learn and improve by reading code from free/open source software projects. I have also given them the latest Fedora .iso images (32-bit and 64-bit).</p>
<p>Thanks to Antriksh Shah for his help in organizing this workshop. Few photos taken during the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album83">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 02 Jul 2012 08:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/07/02/fedora-workshop-iccs/news.html</guid>
</item>
<item>
    <title>ghc-lazysmallcheck</title>
    <link>http://www.shakthimaan.com/posts/2012/07/01/ghc-lazysmallcheck/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/lazysmallcheck">lazysmallcheck</a> is a demand-driven testing library for Haskell programs. It requires fewer test cases to verify properties for inputs for a depth. It is now available on Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-lazysmallcheck-devel</code></pre>
<p>The depthCheck function lists the number of fewer tests required at a given depth. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.LazySmallCheck</span>
<span class="kw">import</span> <span class="dt">System</span>

<span class="kw">type</span> <span class="dt">Set</span> a <span class="fu">=</span> [a]

<span class="ot">empty ::</span> <span class="dt">Set</span> a
empty <span class="fu">=</span> []

<span class="ot">insert ::</span> <span class="kw">Ord</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> <span class="dt">Set</span> a <span class="ot">-&gt;</span> <span class="dt">Set</span> a
insert a [] <span class="fu">=</span> [a]
insert a (x<span class="fu">:</span>xs)
  <span class="fu">|</span> a <span class="fu">&lt;</span> x <span class="fu">=</span> a<span class="fu">:</span>x<span class="fu">:</span>xs
  <span class="fu">|</span> a <span class="fu">&gt;</span> x <span class="fu">=</span> x<span class="fu">:</span>insert a xs
  <span class="fu">|</span> a <span class="fu">==</span> x <span class="fu">=</span> x<span class="fu">:</span>xs

<span class="ot">set ::</span> <span class="kw">Ord</span> a <span class="ot">=&gt;</span> [a] <span class="ot">-&gt;</span> <span class="dt">Set</span> a
set <span class="fu">=</span> <span class="fu">foldr</span> insert Main.empty

ordered [] <span class="fu">=</span> <span class="kw">True</span>
ordered [x] <span class="fu">=</span> <span class="kw">True</span>
ordered (x<span class="fu">:</span>y<span class="fu">:</span>zs) <span class="fu">=</span> x <span class="fu">&lt;=</span> y <span class="fu">&amp;&amp;</span> ordered (y<span class="fu">:</span>zs)

allDiff [] <span class="fu">=</span> <span class="kw">True</span>
allDiff (x<span class="fu">:</span>xs) <span class="fu">=</span> x <span class="ot">`notElem`</span> xs <span class="fu">&amp;&amp;</span> allDiff xs

isSet s <span class="fu">=</span> ordered s <span class="fu">&amp;&amp;</span> allDiff s

<span class="co">-- Properties</span>

<span class="kw">infixr</span> <span class="dv">0</span> <span class="fu">--&gt;</span>
<span class="kw">False</span> <span class="fu">--&gt;</span> _ <span class="fu">=</span> <span class="kw">True</span>
<span class="kw">True</span> <span class="fu">--&gt;</span> x <span class="fu">=</span> x

<span class="ot">prop_insertSet ::</span> (<span class="dt">Char</span>, <span class="dt">Set</span> <span class="dt">Char</span>) <span class="ot">-&gt;</span> <span class="dt">Bool</span>
prop_insertSet (c, s) <span class="fu">=</span> ordered s <span class="fu">--&gt;</span> ordered (insert c s)

main <span class="fu">=</span> <span class="kw">do</span>
        [d] <span class="ot">&lt;-</span> getArgs
        depthCheck (<span class="fu">read</span> d) prop_insertSet</code></pre>
<p>You can compile and run it using:</p>
<p>~~~~ {.shell} $ ghc –make ListSet.hs [1 of 1] Compiling Main ( ListSet.hs, ListSet.o ) Linking ListSet …</p>
$ ./ListSet 2 OK, required 23 tests at depth 2 ~~~~]]></description>
    <pubDate>Sun, 01 Jul 2012 04:50:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/07/01/ghc-lazysmallcheck/news.html</guid>
</item>
<item>
    <title>ghc-smallcheck</title>
    <link>http://www.shakthimaan.com/posts/2012/06/29/ghc-smallcheck/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/smallcheck">smallcheck</a> is a testing library to verify properties for test cases to a certain depth. The depth for data values refers to the depth of nested constructors, while for functional values, it refers to the depth of nested case analysis and results. The test cases will be generated by smallcheck. It is now available on Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-smallcheck-devel</code></pre>
<p>The following BitAdd.hs example demonstrates the use of smallcheck:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Test.SmallCheck</span>

and2 (a,b)       <span class="fu">=</span> a <span class="fu">&amp;&amp;</span> b

xor2 (a,b)       <span class="fu">=</span> a <span class="fu">/=</span> b

halfAdd (a,b)    <span class="fu">=</span> (<span class="fu">sum</span>,carry)
  <span class="kw">where</span> <span class="fu">sum</span>      <span class="fu">=</span> xor2 (a,b)
        carry    <span class="fu">=</span> and2 (a,b)

bit <span class="kw">False</span>        <span class="fu">=</span> <span class="dv">0</span>
bit <span class="kw">True</span>         <span class="fu">=</span> <span class="dv">1</span>

num []           <span class="fu">=</span> <span class="dv">0</span>
num (a<span class="fu">:</span><span class="kw">as</span>)       <span class="fu">=</span> bit a <span class="fu">+</span> <span class="dv">2</span> <span class="fu">*</span> num <span class="kw">as</span>

bitAdd a []      <span class="fu">=</span> [a]
bitAdd a (b<span class="fu">:</span>bs)  <span class="fu">=</span> s <span class="fu">:</span> bitAdd c bs
  <span class="kw">where</span> (s,c)    <span class="fu">=</span> halfAdd (a,b)

prop_bitAdd a <span class="kw">as</span> <span class="fu">=</span> num (bitAdd a <span class="kw">as</span>) <span class="fu">==</span> bit a <span class="fu">+</span> num <span class="kw">as</span>

main             <span class="fu">=</span> smallCheck <span class="dv">3</span> prop_bitAdd</code></pre>
<p>We ask smallcheck to run tests to a depth of 3. You can compile and run it using:</p>
<p>~~~~ {.shell} $ ghc –make BitAdd.hs [1 of 1] Compiling Main ( BitAdd.hs, BitAdd.o ) Linking BitAdd …</p>
$ ./BitAdd Depth 0: Completed 2 test(s) without failure. Depth 1: Completed 6 test(s) without failure. Depth 2: Completed 14 test(s) without failure. Depth 3: Completed 30 test(s) without failure. ~~~~]]></description>
    <pubDate>Fri, 29 Jun 2012 13:25:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/29/ghc-smallcheck/news.html</guid>
</item>
<item>
    <title>ghc-netlist-to-vhdl</title>
    <link>http://www.shakthimaan.com/posts/2012/06/24/ghc-netlist-to-vhdl/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/netlist-to-vhdl">netlist-to-vhdl</a> converts a Netlist AST (Abstract Syntax Tree) to VHDL (VHSIC Hardware Description Language). It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-netlist-to-vhdl-devel</code></pre>
<p>The genVHDL function accepts a Netlist.AST module and emits VHDL. For example:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE ParallelListComp #-}</span>

<span class="kw">import</span> <span class="dt">Language.Netlist.AST</span>
<span class="kw">import</span> <span class="dt">Language.Netlist.Util</span>
<span class="kw">import</span> <span class="dt">Language.Netlist.GenVHDL</span>

<span class="ot">t ::</span> <span class="dt">Module</span>
t <span class="fu">=</span> <span class="dt">Module</span> <span class="st">&quot;foo&quot;</span> (f ins) (f outs) [] ds
  <span class="kw">where</span>
    f xs <span class="fu">=</span> [ (x, makeRange <span class="dt">Down</span> sz) <span class="fu">|</span> (x, sz) <span class="ot">&lt;-</span> xs ]
    ins <span class="fu">=</span> [(<span class="st">&quot;clk&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;reset&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;enable&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;x&quot;</span>, <span class="dv">16</span>)]
    outs <span class="fu">=</span> [(<span class="st">&quot;z&quot;</span>, <span class="dv">16</span>)]

<span class="ot">ds ::</span> [<span class="dt">Decl</span>]
ds <span class="fu">=</span> [ <span class="dt">NetDecl</span> <span class="st">&quot;a&quot;</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) (<span class="kw">Just</span> (<span class="dt">ExprVar</span> <span class="st">&quot;x&quot;</span>))
     , <span class="dt">NetDecl</span> <span class="st">&quot;b&quot;</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) (<span class="kw">Just</span> (sizedInteger <span class="dv">16</span> <span class="dv">10</span>))
     , <span class="dt">MemDecl</span> <span class="st">&quot;c&quot;</span> <span class="kw">Nothing</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) <span class="kw">Nothing</span>
     , <span class="dt">ProcessDecl</span> (<span class="dt">Event</span> (<span class="dt">ExprVar</span> <span class="st">&quot;clk&quot;</span>) <span class="dt">PosEdge</span>)
                   (<span class="kw">Just</span> (<span class="dt">Event</span> (<span class="dt">ExprVar</span> <span class="st">&quot;reset&quot;</span>) <span class="dt">PosEdge</span>, 
		   	(<span class="dt">Assign</span> (<span class="dt">ExprVar</span> <span class="st">&quot;c&quot;</span>) (sizedInteger <span class="dv">16</span> <span class="dv">0</span>))))
                   (<span class="dt">If</span> (<span class="dt">ExprVar</span> <span class="st">&quot;enable&quot;</span>)
                         (<span class="dt">Assign</span> (<span class="dt">ExprVar</span> <span class="st">&quot;c&quot;</span>) (<span class="dt">ExprVar</span> <span class="st">&quot;x&quot;</span>))
                         <span class="kw">Nothing</span>)
     ]

main <span class="fu">=</span> <span class="kw">do</span>
        <span class="fu">putStrLn</span> <span class="fu">$</span> genVHDL t [<span class="st">&quot;work.all&quot;</span>]</code></pre>
<p>The above code can be compiled and run using:</p>
<pre class="shell"><code>$ ghc --make Example.hs

$ ./Example</code></pre>
<p>When executed it will generate the following VHDL:</p>
<pre class="shell"><code>library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.all;
entity foo is
  port(clk : in std_logic;
       reset : in std_logic;
       enable : in std_logic;
       x : in std_logic_vector(15 downto 0);
       z : out std_logic_vector(15 downto 0));
end entity foo;
architecture str of foo is
  signal a : std_logic_vector(15 downto 0) := x;
  signal b : std_logic_vector(15 downto 0) := &quot;0000000000001010&quot;;
  signal c : std_logic_vector(15 downto 0);
begin
  proc3 : process(clk,reset) is
  begin
    if reset = '1' then
      c &lt;= &quot;0000000000000000&quot;;
    elsif rising_edge(clk) then
      if enable then
        c &lt;= x;
      end if;
    end if;
  end process proc3;
end architecture str;</code></pre>]]></description>
    <pubDate>Sun, 24 Jun 2012 11:05:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/24/ghc-netlist-to-vhdl/news.html</guid>
</item>
<item>
    <title>ghc-sized-types</title>
    <link>http://www.shakthimaan.com/posts/2012/06/23/ghc-sized-types/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/sized-types">sized-types</a> provides indices, matrices, signed and unsigned bit vectors. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-sized-types-devel</code></pre>
<p>An n-bit sized type is represented by X<sub>n</sub>. For example, a 4-bit unsigned number can be represented by Unsigned X4. Few examples:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> [<span class="fu">minBound</span> <span class="fu">..</span> <span class="fu">maxBound</span>]<span class="ot"> ::</span> [<span class="dt">X4</span>]
[<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]

ghci<span class="fu">&gt;</span> <span class="dv">100</span><span class="ot"> ::</span> <span class="dt">Unsigned</span> <span class="dt">X4</span>
<span class="dv">4</span>

ghci<span class="fu">&gt;</span> <span class="dv">100</span> <span class="fu">+</span> <span class="dv">100</span><span class="ot"> ::</span> <span class="dt">Signed</span> <span class="dt">X8</span>
<span class="fu">-</span><span class="dv">56</span></code></pre>
<p>The signed and unsigned types can also be used in matrix operations:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">ghci<span class="fu">&gt;</span> <span class="kw">let</span> n <span class="fu">=</span> matrix [<span class="dv">1</span><span class="fu">..</span><span class="dv">12</span>]<span class="ot"> ::</span> <span class="dt">Matrix</span> (<span class="dt">X3</span>,<span class="dt">X4</span>) <span class="dt">Int</span>
ghci<span class="fu">&gt;</span> n
[ <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>, <span class="dv">6</span>, <span class="dv">7</span>, <span class="dv">8</span>, <span class="dv">9</span>, <span class="dv">10</span>, <span class="dv">11</span>, <span class="dv">12</span> ]

ghci<span class="fu">&gt;</span> <span class="fu">print</span> <span class="fu">$</span> tranpose n
[ <span class="dv">1</span>, <span class="dv">5</span>, <span class="dv">9</span>, <span class="dv">2</span>, <span class="dv">6</span>, <span class="dv">10</span>, <span class="dv">3</span>, <span class="dv">7</span>, <span class="dv">11</span>, <span class="dv">4</span>, <span class="dv">8</span>, <span class="dv">12</span> ]

ghci<span class="fu">&gt;</span> <span class="kw">let</span> m <span class="fu">=</span> matrix [<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>,<span class="dv">6</span>]<span class="ot"> ::</span> <span class="dt">Matrix</span> <span class="dt">X4</span> <span class="dt">Int</span>
ghci<span class="fu">&gt;</span> m
[ <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>, <span class="dv">6</span>]
ghci<span class="fu">&gt;</span> m <span class="fu">!</span> <span class="dv">2</span>
<span class="dv">5</span></code></pre>
<p>These general purpose types are very useful in specifying hardware descriptions, especially when you need fixed-width, irregular size, signed and unsigned numbers.</p>]]></description>
    <pubDate>Sat, 23 Jun 2012 15:55:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/23/ghc-sized-types/news.html</guid>
</item>
<item>
    <title>Barcamp Mumbai 9, June 17, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/06/19/barcamp-mumbai-9-2012/news.html</link>
    <description><![CDATA[<p>I attended <a href="http://barcampmumbai.org/index.php/BCM9">Barcamp Mumbai 9</a> at <a href="http://www.vjti.ac.in/">Veermata Jijabai Technological Institute (VJTI)</a>, Mumbai, Maharashtra, India on Sunday, June 17, 2012. After an informal introduction, four parallel tracks were scheduled. Each session was 20 minutes long, and 10 minutes between talks for people to move between the halls. Although most of the talks were non-technical, there were quite a few interesting sessions.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album82/4_vjti_sign_board.jpg" alt="VJTI sign board"></img>
<p>Raj Desai presented on “The Math of Music”. He explained how the rhythms or beats used in music formed a pattern, and how they often use prime numbers. For example, a 5-beat sequence is made from a combination of a 2-3 beat sequence, or, a 7-beat sequence is made from a 2-2-3 or a 3-2-2 beat sequence. He also played the different beats, giving numerous examples.</p>
<p>Krishna Patel played the short movie <a href="http://www.pixar.com/shorts/gg/index.html">“Geri’s Game”</a> in his session on “How To Watch a Movie”, and explained the different aspects in a movie like composition, props, sound, colour etc. He mentioned that one might have to watch a movie several times focusing on just one aspect at a time to observe and learn how they have been used.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album82/6_list_of_talks.jpg" alt="List of talks"></img>
<p>The session on “How to memorise a pack of 52 playing cards in under 2 minutes” by Aniceto Pereira taught how to use two simple mnemonic systems to memorise a pack of cards. For the four suites, we used the letters C (clubs), S (spades), H (hearts), D (diamonds). For each card in a suite, a consonant is assigned. For example, Ace was assigned the letter ’t’ or ‘d’, because there is one vertical line in it, referring to one. The number ‘2’ was assigned the letter ‘n’ because there were two downward strokes in it. So, if we had an Ace (’t’) of clubs (‘c’), we would combine the letter and the consonant to form an image, say “cat”, and associate it with our environment to remember it. For each card that we have, we build a series of images to remember them.</p>
<p><a href="http://web.gnuer.org/blog/index.php">Anurag Patel’s</a> session on “Sh*t people say to a chat bot” was hilarious! He had created <a href="http://rickfare.com">http://rickfare.com</a> to compute Mumbai’s autorickshaw fare calculation, and later added support for other cities as well. There were times when people started to chat with the bot, and he shared quite a few entertaining, priceless conversations from the server logs.</p>
<p>The talk on “Negotiating with VCs - An Entrepreneur’s Legal Guide” by Abhyudaya Agarwal was very informative, and detailed. I had presented <a href="http://shakthimaan.com/downloads.html#qucs-a-qt-love-story">“Quite Universal Circuit Simulator - A Qt Love Story”</a>, an introduction to electrical circuit theory using <a href="http://qucs.sourceforge.net/">Qucs</a>. You can install Qucs on Fedora using:</p>
<pre class="shell"><code>  $ sudo yum install qucs</code></pre>
<p>I also had a chance to stay at <a href="http://en.wikipedia.org/wiki/Anushakti_Nagar">Anu Shakti Nagar</a>, a quiet, serene, beautiful residential township in Mumbai in this visit. Few pictures taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album82">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 19 Jun 2012 08:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/19/barcamp-mumbai-9-2012/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day, June 2, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/06/04/fad-pune-june-2012/news.html</link>
    <description><![CDATA[<p>A <a href="https://fedoraproject.org/wiki/FAD_Pune_2012_June_02">Fedora Activity Day</a> (FAD) was organized on Saturday, June 2, 2012 at the Red Hat office premises in Pune, India.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album81/5_discussion.jpg" alt="Discussion in progress"></img>
<p>This was an activity based event, where there were no talks. The various topics suggested during the FAD included development, packaging, and documentation work.</p>
<p>The newbies worked on <a href="https://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package">GNU Hello RPM packaging</a>, while others worked on pushing updates to existing packages, and packaging new software.</p>
<p>I had submitted a new <a href="http://embed.cs.utah.edu/csmith/">Csmith</a> package release for review, and packaged and submitted <a href="http://hackage.haskell.org/package/sized-types-0.3.4.0">sized-types</a>, and <a href="http://hackage.haskell.org/package/netlist-to-vhdl-0.3.1">netlist-to-vhdl</a> Haskell packages for review. Lakshmi Narasimhan completed the package review for sized-types.</p>
<p>I had requested Fedora Infrastructure to make <a href="http://www.agilofortrac.com/">Agilo for Trac</a> (Apache license) available. It was made available for testing during the FAD, and I tested the same with the <a href="https://fedorahosted.org/fedora-electronic-lab/">Fedora Electronic Lab</a> trac instance. All the Agilo plugins are now enabled in the trac for use.</p>
<p>We also had an F17 release party during the event, where Rahul Sundaram cut a beautiful, tasty, F17 cake.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album81/1_cake.jpg" alt="F17 cake"></img>
<p>Thanks to Red Hat for hosting the event, sponsoring lunch, and providing the facilities for the FAD.</p>
<p>More photos are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album81">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 04 Jun 2012 12:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/04/fad-pune-june-2012/news.html</guid>
</item>
<item>
    <title>I Know What You Are Going To Do This Summer 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/06/02/dgplug-summer-training-2012/news.html</link>
    <description><![CDATA[<p>We are happy to announce <a href="http://wiki.dgplug.org/index.php/SummerTraining12">“I know what You Are Going To Do This Summer 2012”</a>, a free (as in freedom), online (<a href="http://fedoraproject.org/wiki/Communicate/IRCHowTo">IRC-based</a>) training program in Free/Libre/Open Source Software at #dgplug on irc.freenode.net.</p>
<p>If you are a prospective candidate, or a mentor, who would like to participate in this year’s sessions, please go through the <a href="http://www.dgplug.org/irclogs/">previous year’s IRC logs</a>.</p>
<p>We will have review, and Q&amp;A sessions, on topics addressed in the previous years before proceeding with new topics for this year.</p>
<p>The session timings are usually after 1900 IST, every day.</p>
<p>To participate, you will need a reliable Internet connection, and any latest distribution installed (Fedora 16/17 preferable).</p>
<p>The program is open to all. If you are interested in participating, please confirm the same by sending an e-mail to kushaldas AT gmail DOT com, or shakthimaan at fedoraproject dot org.</p>
<p>References:</p>
<p>URL: <a href="http://dgplug.org">http://dgplug.org</a></p>
<p>Planet: <a href="http://planet.dgplug.org">http://planet.dgplug.org</a></p>
<p>Wiki: <a href="http://wiki.dgplug.org/">http://wiki.dgplug.org</a></p>
<p>Mailing list group (for queries, discussions): <a href="http://lists.dgplug.org/listinfo.cgi/users-dgplug.org">http://lists.dgplug.org/listinfo.cgi/users-dgplug.org</a></p>]]></description>
    <pubDate>Sat, 02 Jun 2012 15:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/06/02/dgplug-summer-training-2012/news.html</guid>
</item>
<item>
    <title>Fort Jadhav Ghad</title>
    <link>http://www.shakthimaan.com/posts/2012/05/27/fort-jadhav-ghad/news.html</link>
    <description><![CDATA[<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album80/3_fort_jadhav_ghad.jpg" alt="Fort Jadhav Ghad"></img><br />
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album80/7_welcome_note.jpg" alt="Welcome note"></img><br />
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album80/13_museum_side.jpg" alt="Museum side"></img><br />
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album80/23_fort_rear_side.jpg" alt="Fort rear, side"></img><br />
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album80/34_swimming_pool.jpg" alt="swimming pool"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album80">/gallery</a>.</p>]]></description>
    <pubDate>Sun, 27 May 2012 11:45:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/05/27/fort-jadhav-ghad/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day, Red Hat, Pune, June 2, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/05/25/fad-announcement-june-2-2012/news.html</link>
    <description><![CDATA[<p>A <a href="http://fedoraproject.org/wiki/Fedora_Activity_Day_-_FAD">Fedora Activity Day</a> event is scheduled for Saturday, June 2, 2012 at the Red Hat, Pune, India office premises.</p>
<p>Venue:</p>
<pre class="shell"><code>  Red Hat Software Services Pvt Ltd 
  Tower X, Level-1,
  Cybercity, Magarpatta City,
  Hadapsar, Pune 411 013
  Maharashtra
  India</code></pre>
<p>Date : Saturday, June 2, 2012.</p>
<p>Time : 1000 IST onwards.</p>
<p>Entry is free, but, we have limited seats (50). Online registration closes on Tuesday, May 29, 2012, 2359 IST. If you are interested in attending, please add your name to <a href="https://fedoraproject.org/wiki/FAD_Pune_2012_June_02">https://fedoraproject.org/wiki/FAD_Pune_2012_June_02</a>.</p>
<p>There will be no registration on the day of the event.</p>
<p>This is purely an activity based event where you are required to work on Fedora related sub-projects. There will be no talks.</p>
<p>Lunch will be sponsored by Red Hat. We will also have an F17 release party!</p>
<p>Please make sure to bring a valid photo identity card (driving license/voter’s id etc.) to enter the premises.</p>
<p>If you would like to suggest projects/task to work on during the FAD, please feel free to update the wiki page.</p>
<p>You are encouraged to bring your laptop. Please do ensure that you have all the necessary software installed for your work, or atleast:</p>
<pre class="shell"><code>  # yum install @development-tools fedora-packager</code></pre>
<p>There will be Internet access available at the facility.</p>]]></description>
    <pubDate>Fri, 25 May 2012 13:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/05/25/fad-announcement-june-2-2012/news.html</guid>
</item>
<item>
    <title>Blog using Hakyll</title>
    <link>http://www.shakthimaan.com/posts/2012/05/22/blog-using-hakyll/news.html</link>
    <description><![CDATA[<p>I wanted to migrate my blog to a static site generator, and chose <a href="http://jaspervdj.be/hakyll/">Hakyll</a>, since it is written in Haskell. You can install it on Fedora using:</p>
<pre class="shell"><code>$ sudo yum install ghc-hakyll-devel</code></pre>
<p>I started looking at existing sites generated using Hakyll, and chose <a href="http://www.skybluetrades.net/">Ian Ross’s blog</a> as a reference. I began customizing the same during the <a href="http://www.hackfest.in">Hackfest</a> organized by <a href="http://changer.in/">Changer</a> in Pune, India on Saturday, May 5, 2012.</p>
<p>The 2012 posts now have permanent URLs. Posts are tagged. I have retained the CSS, current <a href="http://www.shakthimaan.com/news.xml">RSS feed</a> and <a href="http://www.shakthimaan.com/news.html">blog URL</a> during this migration. You can get the sources from gitorious.org:</p>
<pre class="shell"><code>$ git clone git://gitorious.org/shakthimaan-blog/mainline.git</code></pre>]]></description>
    <pubDate>Tue, 22 May 2012 11:50:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/05/22/blog-using-hakyll/news.html</guid>
</item>
<item>
    <title>Disassembly of HP Pavilion dv6000</title>
    <link>http://www.shakthimaan.com/posts/2012/04/28/Disassembly-of-HP-Pavilion-dv6000/news.html</link>
    <description><![CDATA[<p>Some pictures of a used HP Pavilion dv6000 which had a fried motherboard:</p>
<img alt="Keyboard removed" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/2-without-keyboard.JPG"></img>
<img alt="Keyboard" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/3-keyboard.JPG"></img>
<img alt="Metal casing" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/4-metal-casing.JPG"></img>
<img alt="TFT" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/6-TFT.JPG"></img>
<img alt="Without the TFT" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/5-without-TFT.JPG"></img>
<img alt="Motherboard" src="http://shakthimaan.com/downloads/hardware/hp-dv6000/7-motherboard.JPG"></img>]]></description>
    <pubDate>Sat, 28 Apr 2012 15:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/04/28/Disassembly-of-HP-Pavilion-dv6000/news.html</guid>
</item>
<item>
    <title>ghc-data-reify</title>
    <link>http://www.shakthimaan.com/posts/2012/04/25/ghc-data-reify/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/data-reify">data-reify</a> provides a way to turn recursive data structures into graphs. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-data-reify-devel</code></pre>
<p>A list [1,2,3] can be written using Cons, Nil, and In for recursion using:</p>
<pre><code>In (Cons 1 (In (Cons 2 (In (Cons 3 (In Nil))))))</code></pre>
<p>An example when using data-reify for the above is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE TypeFamilies #-}</span>
<span class="kw">module</span> <span class="dt">Main</span> <span class="kw">where</span>

<span class="kw">import</span> <span class="dt">Control.Applicative</span> <span class="kw">hiding</span> (<span class="dt">Const</span>)

<span class="kw">import</span> <span class="dt">Data.Reify</span>
<span class="kw">import</span> <span class="dt">Control.Monad</span>

<span class="kw">data</span> <span class="dt">List</span> a b <span class="fu">=</span> <span class="dt">Nil</span> <span class="fu">|</span> <span class="dt">Cons</span> a b
  <span class="kw">deriving</span> <span class="kw">Show</span>

<span class="kw">instance</span> <span class="dt">MuRef</span> [a] <span class="kw">where</span>
  <span class="kw">type</span> <span class="dt">DeRef</span> [a] <span class="fu">=</span> <span class="dt">List</span> a 

  mapDeRef f (x<span class="fu">:</span>xs) <span class="fu">=</span> <span class="dt">Cons</span> x <span class="fu">&lt;$&gt;</span> f xs
  mapDeRef f []     <span class="fu">=</span> pure <span class="dt">Nil</span>

main <span class="fu">=</span> <span class="kw">do</span>
        <span class="kw">let</span> g1 <span class="fu">=</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>]
        reifyGraph g1 <span class="fu">&gt;&gt;=</span> <span class="fu">print</span></code></pre>
<p>Compile it using:</p>
<pre class="shell"><code>$ ghc --make Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...</code></pre>
<p>Run it using:</p>
<pre class="shell"><code>$ ./Test
let [(1,Cons 1 2),(2,Cons 2 3),(3,Cons 3 4),(4,Nil)] in 1</code></pre>]]></description>
    <pubDate>Wed, 25 Apr 2012 10:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/04/25/ghc-data-reify/news.html</guid>
</item>
<item>
    <title>ghc-dotgen</title>
    <link>http://www.shakthimaan.com/posts/2012/04/24/ghc-dotgen/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/dotgen">dotgen</a> provides a a simple interface for generating .dot graph files. It is now available in Fedora. Install it along with graphviz using:</p>
<pre class="shell"><code> $ sudo yum install ghc-dotgen-devel graphviz</code></pre>
<p>A binary search tree example is shown below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">module</span> <span class="dt">Main</span> <span class="kw">where</span>

<span class="kw">import</span> <span class="dt">Text.Dot</span>

box label <span class="fu">=</span> node <span class="fu">$</span> [ (<span class="st">&quot;shape&quot;</span>,<span class="st">&quot;record&quot;</span>),(<span class="st">&quot;height&quot;</span>,<span class="st">&quot;.1&quot;</span>),(<span class="st">&quot;label&quot;</span>,label) ]

main <span class="fu">=</span> <span class="fu">putStrLn</span> <span class="fu">$</span> showDot <span class="fu">$</span> <span class="kw">do</span>
     c0 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; G|&amp;lt;f2&amp;gt; &quot;</span>
     c1 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; E|&amp;lt;f2&amp;gt; &quot;</span>
     c2 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; B|&amp;lt;f2&amp;gt; &quot;</span>
     c3 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; F|&amp;lt;f2&amp;gt; &quot;</span>
     c4 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; R|&amp;lt;f2&amp;gt; &quot;</span>
     c5 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; H|&amp;lt;f2&amp;gt; &quot;</span>
     c6 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; Y|&amp;lt;f2&amp;gt; &quot;</span>
     c7 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; A|&amp;lt;f2&amp;gt; &quot;</span>
     c8 <span class="fu">&amp;</span>lt;<span class="fu">-</span> box <span class="st">&quot;&amp;lt;f0&amp;gt; |&amp;lt;f1&amp;gt; C|&amp;lt;f2&amp;gt; &quot;</span>

     c0 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c4
     c0 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c1
     c1 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c2
     c1 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c3
     c2 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c8
     c2 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c7
     c4 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c6
     c4 <span class="fu">.-&amp;</span>gt;<span class="fu">.</span> c5

     <span class="fu">return</span> ()</code></pre>
<p>Compile, and run it using:</p>
<pre class="shell"><code>$ ghc --make Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...

$ ./Test &gt; test.dot</code></pre>
<p>You can convert the generated .dot graph file into .png using:</p>
<pre class="shell"><code>$ dot -Tpng test.dot -o test.png</code></pre>
<p>A screenshot of the generated png:</p>
<a href="http://www.shakthimaan.com/downloads/screenshots/binary-search-tree.png"><img alt="binary search tree screenshot" src="http://www.shakthimaan.com/downloads/screenshots/binary-search-tree.png"></img></a>]]></description>
    <pubDate>Tue, 24 Apr 2012 07:40:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/04/24/ghc-dotgen/news.html</guid>
</item>
<item>
    <title>xmonad-gnome</title>
    <link>http://www.shakthimaan.com/posts/2012/04/05/xmonad-gnome/news.html</link>
    <description><![CDATA[<p>I was looking for a tiling window manager to use, and found <a href="http://xmonad.org/">xmonad</a>. It is written in Haskell, and is quite extensible. You can install it on Fedora using:</p>
<pre class="shell"><code>$ sudo yum install xmonad-gnome</code></pre>
<p>Here is a screenshot of the same (click image):</p>
<a href="http://www.shakthimaan.com/downloads/screenshots/xmonad-screenshot.png"><img width="676" height="263" alt="xmonad screenshot" src="http://www.shakthimaan.com/downloads/screenshots/xmonad-screenshot-thumbnail.png"></img></a>
<p>The left ALT key is used by default as the “mod” key in xmonad. Since I use it with GNU Emacs, the Windows key has been reconfigured now to be used as the “mod” key. I also use xmonad with GNOME 3 in fallback mode, which actually looks like GNOME 2. The configuration file ~/.xmonad/xmonad.hs:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">XMonad</span>
<span class="kw">import</span> <span class="dt">XMonad.Config.Gnome</span>
<span class="kw">import</span> <span class="kw">qualified</span> <span class="dt">XMonad.StackSet</span> <span class="kw">as</span> <span class="dt">W</span>
<span class="kw">import</span> <span class="dt">XMonad.Util.EZConfig</span>

main <span class="fu">=</span> <span class="kw">do</span>
     xmonad <span class="fu">$</span> gnomeConfig {
            workspaces <span class="fu">=</span> myWorkspaces
            , modMask <span class="fu">=</span> mod4Mask
     } <span class="ot">`additionalKeysP`</span> myKeys

myWorkspaces <span class="fu">=</span> [<span class="st">&quot;1&quot;</span>, <span class="st">&quot;2&quot;</span>, <span class="st">&quot;3&quot;</span>, <span class="st">&quot;4&quot;</span>, <span class="st">&quot;5&quot;</span>, <span class="st">&quot;6&quot;</span>, <span class="st">&quot;7&quot;</span>, <span class="st">&quot;8&quot;</span>, <span class="st">&quot;9&quot;</span>]

myKeys <span class="fu">=</span> [
 
    <span class="co">-- other additional keys</span>
 
    ] <span class="fu">++</span> <span class="co">-- (++) is needed here because the following list comprehension</span>
         <span class="co">-- is a list, not a single key binding. Simply adding it to the</span>
         <span class="co">-- list of key bindings would result in something like [ b1, b2,</span>
         <span class="co">-- [ b3, b4, b5 ] ] resulting in a type error. (Lists must</span>
         <span class="co">-- contain items all of the same type.)</span>
 
    [ (otherModMasks <span class="fu">++</span> <span class="st">&quot;M-&quot;</span> <span class="fu">++</span> [key], action tag)
      <span class="fu">|</span> (tag, key)  <span class="fu">&amp;</span>lt;<span class="fu">-</span> <span class="fu">zip</span> myWorkspaces <span class="st">&quot;123456789&quot;</span>
      , (otherModMasks, action) <span class="fu">&amp;</span>lt;<span class="fu">-</span> [ (<span class="st">&quot;&quot;</span>, windows <span class="fu">.</span> W.view) <span class="co">-- was W.greedyView</span>
                                      , (<span class="st">&quot;S-&quot;</span>, windows <span class="fu">.</span> W.shift)]
    ]</code></pre>]]></description>
    <pubDate>Thu, 05 Apr 2012 12:30:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/04/05/xmonad-gnome/news.html</guid>
</item>
<item>
    <title>Publican, Document Freedom Day workshop, ISI, Kolkata</title>
    <link>http://www.shakthimaan.com/posts/2012/03/30/publican-dfd-isical-workshop/news.html</link>
    <description><![CDATA[<p>I presented <a href="https://fedorahosted.org/publican/">Publican</a> at the <a href="http://www.ilug-cal.info/index.php?option=com_content&amp;task&amp;=view&amp;id=185">Document Freedom Workshop 2012</a> at the <a href="http://www.isical.ac.in/~cssc/">Computer and Statistical Service Centre (CSSC)</a>, S N Bose Bhavan, <a href="http://www.isical.ac.in/">Indian Statistical Institute, Kolkata</a>, West Bengal, India held between March 28-29, 2012.</p>
<img alt="Poster at registration desk" src="http://www.shakthimaan.com/Mambo/gallery/albums/album79/3_poster_at_registration_desk.jpg"></img>
<p>Day I</p>
<p><a href="http://fedoraproject.org/wiki/User:Amani">A Mani</a> started the day’s proceedings with an introduction to Free/Libre/Open Source Software, and basic shell commands. We had a computer lab with Fedora installed where the participants used the terminal to try out the hands-on exercises.</p>
<p>I then introduced Publican to the audience comprising mostly of students and faculty. <a href="http://fedoraproject.org/wiki/User:Jsmith">Jared Smith</a> had presented Publican during <a href="http://fudcon.in/">FUDCon Pune 2011</a>, and, with his permission, I added more content and a lab section. The participants were able to use Publican to create and build documents with Bengali content!</p>
<img alt="Lab session" src="http://www.shakthimaan.com/Mambo/gallery/albums/album79/11_latex_lab_session.jpg"></img>
<p>After lunch, <a href="http://souravsengupta.com/">Sourav Sen Gupta</a> gave an introduction to <a href="http://www.latex-project.org/">LaTeX</a> and <a href="http://en.wikipedia.org/wiki/Beamer_%28LaTeX%29">Beamer</a> with his “‘Golden Ratio’ for Typesetting - A quick and random introduction to LaTeX and Beamer” presentation. He used the <a href="http://kile.sourceforge.net/">Kile</a> editor to demonstrate LaTeX markups and for generating PDF files. I helped the students with the lab session in writing, and troubleshooting warnings and errors when using Kile with pdflatex.</p>
<p>I also met and spoke with two physicists, <a href="http://en.wikipedia.org/wiki/John_A._Smolin">John Smolin</a> and <a href="http://www.infres.enst.fr/~markham/">Damian Markham</a>, who had come to present at another workshop on <a href="http://www.isical.ac.in/~coec/workshop/quant2012.html">“Information and Security in Quantum World”</a>. John Smolin is an avid Fedora user!</p>
<p>Day II</p>
<p>The first session on the second day was by <a href="http://www.jitrc.com/">Jit Ray Chowdhury</a> on <a href="http://moodle.org/">Moodle</a> CMS. He started with the basics of installing Apache, MySQL and PHP on Fedora, followed by creating a simple HTML, and PHP page. Participants then learnt how to install Drupal, Moodle and configure the same.</p>
<p><a href="http://www.hbcse.tifr.res.in/people/academic/nagarjuna-g">Prof. Nagarjuna</a> then started his session on why document freedom is essential, and gave an introduction to <a href="http://orgmode.org/">Emacs org-mode</a>, with examples. I also met Krishnakant Mane but couldn’t attend his (post-lunch) session on “LibreOffice and Screen Readers” as I had to leave early to catch a flight.</p>
<p>Thanks to the organizing committee: <a href="http://www.isical.ac.in/~mandar/">Prof. Mandar Mitra</a>, A Mani, Partha Pratim Kundu, <a href="http://www.isical.ac.in/~malay_r/">Malay Bhattacharya</a>, and Tanmay Basu for the wonderful hospitality, and to Red Hat for sponsoring my travel.</p>
<p>The <a href="http://shakthimaan.com/downloads.html#publican">publican presentation</a> is available. Few photos taken during the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album79">/gallery</a>.</p>]]></description>
    <pubDate>Fri, 30 Mar 2012 19:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/03/30/publican-dfd-isical-workshop/news.html</guid>
</item>
<item>
    <title>RubyConf, India, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/03/26/rubyconf-india-2012/news.html</link>
    <description><![CDATA[<p>I attended and also gave a lightning talk at <a href="http://rubyconfindia.org/">RubyConf India 2012</a> at the <a href="http://pune.regency.hyatt.com/hyatt/hotels/index.jsp?null">Hyatt Regency</a>, Pune, Maharashtra, India between March 24-25, 2012.</p>
<img alt="RubyConf India 2012" src="http://www.shakthimaan.com/Mambo/gallery/albums/album78/1_banner.jpg"></img>
<p>Day I</p>
<p>The keynote was delivered by <a href="http://blog.headius.com/">Charles Oliver Nutter</a> on JRuby, and Ruby virtual machines. This was followed by the recorded video keynote by <a href="http://en.wikipedia.org/wiki/Yukihiro_Matsumoto">Yukihiro Matsumoto</a> on Ruby, its history, and his focus on Ruby for embedded and scientific computing for the next couple of years. mruby for embedded systems will be an interesting project to look forward to this summer.</p>
<p>I then attended the talk on “Using Ruby to Craft and Test Beautiful Command Line Applications” by Nikhil Mungel and Shishir Das, who gave useful examples on how to construct meaningful and helpful command line tools. <a href="http://parolkar.com/">Abhishek Parolkar</a>, founder of <a href="http://www.bigdata.sg">BigData.sg</a>, spoke on available Ruby tools, and architectures for processing large volumes of data in the “Ruby for the soul of Big Data nerds” talk.</p>
<p>Post lunch, I attended the session on “Responsive Design: now 90% easier with SASS!” by Arpan CJ, who also designed the RubyConf India 2012 website. He explained how <a href="http://sass-lang.com/">Sass</a> is useful in creating websites that can be quickly made to fit different display dimensions and resolutions across phones, tablets, and PCs.</p>
<p><a href="http://blog.deobald.ca/">Steven Deobald</a> presented on “Clojure is my favourite ruby”. He gave wonderful programming construct examples for Ruby and Clojure, and why he enjoyed Clojure more than Ruby. For the last talk of the day, I attended Sandip Ransing and Shailesh Patil’s talk on “VoIP on Rails in India” where they had developed a call centre Rails front-end application that uses <a href="http://adhearsion.com/">Adhearsion</a>. They have an internal LAN setup for call centres: Rails application -&gt; Adhearsion -&gt; Asterisk -&gt; PRI (Primary Rate Interface) -&gt; PSTN (Public Switched Telephone Network).</p>
<p>There were quite a number of lightning talks at the end of the day. One from <a href="http://www.flipkart.com">flipkart.com</a>, where they mentioned that they use a service oriented architecture with JSON over HTTP, along with RabbitMQ, Padrino and JRuby.</p>
<p>Day II</p>
<p>The second day began with a keynote by <a href="http://lindsaar.net/">Mikel Lindsaar</a> on “How to win”, where he emphasized on defining a purpose/reason to do anything and everything. <a href="http://blog.saush.com/">Chang Sau Sheong</a> presented on using Ruby and R tools for doing population simulation in his “Sex, Money and Evolution - Simulation and Data Analysis with Ruby and R” talk. Niranjan Prabhakar Sarade gave an overview of the internal data structures present in the Ruby MRI virtual machine source code in the “What lies beneath the beautiful code?” talk.</p>
<p>After lunch, I attended the “Smells and patterns in test/spec code” talk by Sidu Ponnappa and Aninda Kundu where they discussed the different patterns and smells of test driven code, and their implications. Karunakar presented on “Large scale Ruby project, challenges and Pitfalls”, sharing his experience on managing and maintaining large scale Ruby projects. For the last talk of the day, I attended <a href="http://matthewkirk.com/">Matthew Kirk’s</a> talk on “‘method_missing’ Should be Missing” where he talked about the overuse of method_missing, “monkey patching”, and eval from his experience.</p>
<p>Lightning talks were scheduled for the second day as well, and I was happy to present <a href="http://shakthimaan.com/downloads.html#nursery-rhymes-rb">nursery_rhymes.rb</a>. Few photos taken during the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album78">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 26 Mar 2012 17:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/03/26/rubyconf-india-2012/news.html</guid>
</item>
<item>
    <title>Pragyan, NIT, Trichy, India, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/02/27/pragyan-nit-trichy-2012/news.html</link>
    <description><![CDATA[<p>I had presented the (in)famous <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">“i-want-2-do-project.tell-me-wat-2-do-fedora”</a> presentation as a guest lecturer at <a href="http://www.pragyan.org">“Pragyan 2012”</a>, <a href="http://www.nitt.edu/home/">NIT, Trichy</a>, Tamil Nadu, India on Sunday, February 26, 2012.</p>
<img alt="NIT Trichy" src="http://www.shakthimaan.com/Mambo/gallery/albums/album77/6_nit_trichy.jpg"></img>
<p>Most of the student participants were familiar with the the *nix desktop. I explained to them the various project, communication guidelines, and best practices that they need to follow when working on free/open source software projects. I had also introduced them to the various Fedora sub-projects that they can participate and learn from.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album77/8_audience.jpg"></img>
<p>Four years ago, I was invited by the <a href="http://www.pragyan.org/12/home/pengufest/">Pengufest</a> team of Pragyan, but, I couldn’t make it then. Apparently, my presentation has been circulating among them for quite some time, and they now got to hear it from the horse’s mouth.</p>
<p>On Saturday, as part of the Pengufest track there were sessions held by <a href="http://www.bell-labs.com/user/poosala/">Dr. Viswanath Poosala</a> on “Engineering Innovation - A recipe for coming up with disruptive ideas”, and sessions on “How to be a Hacker?”, “Functional Programming and why it matters”, and “Lisp - God’s own programming language” by <a href="http://www.linuxforu.com/author/vivek-shangari/">Vivek Shangari</a>.</p>
<p>I also attended <a href="http://sunson.livejournal.com/">Suraj Kumar’s</a> talk on “GNU/Linux in large scale Internet based businesses”, where he addressed the different concepts, terminologies and F/OSS tools that people use for large scale web deployments.</p>
<p>I would like to thank Red Hat for sponsoring my travel, and the organizing team of Pragyan 2012 for the wonderful hospitality.</p>
<img alt="Twilight" src="http://www.shakthimaan.com/Mambo/gallery/albums/album77/4_twilight.jpg"></img>
<p>More photos taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album77">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 27 Feb 2012 12:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/02/27/pragyan-nit-trichy-2012/news.html</guid>
</item>
<item>
    <title>Karaikudi trip photos</title>
    <link>http://www.shakthimaan.com/posts/2012/02/19/karaikudi-trip-2012/news.html</link>
    <description><![CDATA[<p>Few photos taken on a trip to <a href="http://en.wikipedia.org/wiki/Karaikudi">Karaikudi</a>, Tamil Nadu, India. More photos in my <a href="http://www.shakthimaan.com/Mambo/gallery/album76">/gallery</a>.</p>
<img alt="Street view" src="http://www.shakthimaan.com/Mambo/gallery/albums/album76/1_street_view.jpg"></img>
<img alt="Inside courtyard" src="http://www.shakthimaan.com/Mambo/gallery/albums/album76/4_inside_courtyard.jpg"></img>
<img alt="Chettinad palace" src="http://www.shakthimaan.com/Mambo/gallery/albums/album76/10_chettinad_palace.jpg"></img>]]></description>
    <pubDate>Sun, 19 Feb 2012 14:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/02/19/karaikudi-trip-2012/news.html</guid>
</item>
<item>
    <title>ghc-netlist</title>
    <link>http://www.shakthimaan.com/posts/2012/02/19/ghc-netlist/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/netlist">Netlist</a> is a simplified and generic netlist designed to be compatible with Hardware Description Languages (HDLs) like Verilog and VHDL. It is now available in Fedora. Install it using:</p>
<pre class="shell"><code> $ sudo yum install ghc-netlist-devel</code></pre>
<p>An example usage from the sources is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Language.Netlist.AST</span>
<span class="kw">import</span> <span class="dt">Language.Netlist.Util</span>

<span class="ot">t ::</span> <span class="dt">Module</span>
t <span class="fu">=</span> <span class="dt">Module</span> <span class="st">&quot;foo&quot;</span> (f ins) (f outs) [] ds
  <span class="kw">where</span>
    f xs <span class="fu">=</span> [ (x, makeRange <span class="dt">Down</span> sz) <span class="fu">|</span> (x, sz) <span class="fu">&amp;</span>lt;<span class="fu">-</span> xs ]
    ins <span class="fu">=</span> [(<span class="st">&quot;clk&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;reset&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;enable&quot;</span>, <span class="dv">1</span>), (<span class="st">&quot;x&quot;</span>, <span class="dv">16</span>)]
    outs <span class="fu">=</span> [(<span class="st">&quot;z&quot;</span>, <span class="dv">16</span>)]

<span class="ot">ds ::</span> [<span class="dt">Decl</span>]
ds <span class="fu">=</span> [ <span class="dt">NetDecl</span> <span class="st">&quot;a&quot;</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) (<span class="kw">Just</span> (<span class="dt">ExprVar</span> <span class="st">&quot;x&quot;</span>))
     , <span class="dt">NetDecl</span> <span class="st">&quot;b&quot;</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) (<span class="kw">Just</span> (sizedInteger <span class="dv">16</span> <span class="dv">10</span>))
     , <span class="dt">MemDecl</span> <span class="st">&quot;c&quot;</span> <span class="kw">Nothing</span> (makeRange <span class="dt">Down</span> <span class="dv">16</span>) <span class="kw">Nothing</span>
     , <span class="dt">ProcessDecl</span> (<span class="dt">Event</span> (<span class="dt">ExprVar</span> <span class="st">&quot;clk&quot;</span>) <span class="dt">PosEdge</span>)
                   (<span class="kw">Just</span> (<span class="dt">Event</span> (<span class="dt">ExprVar</span> <span class="st">&quot;reset&quot;</span>) <span class="dt">PosEdge</span>, (<span class="dt">Assign</span> (<span class="dt">ExprVar</span> <span class="st">&quot;c&quot;</span>) (sizedInteger <span class="dv">16</span> <span class="dv">0</span>))))
                   (<span class="dt">If</span> (<span class="dt">ExprVar</span> <span class="st">&quot;enable&quot;</span>)
                         (<span class="dt">Assign</span> (<span class="dt">ExprVar</span> <span class="st">&quot;c&quot;</span>) (<span class="dt">ExprVar</span> <span class="st">&quot;x&quot;</span>))
                         <span class="kw">Nothing</span>)
     ]</code></pre>
<p>Load it using ghci version 7.0.2 gives:</p>
<pre class="shell"><code>$ ghci Test.hs 
GHCi, version 7.0.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Test.hs, interpreted )
Ok, modules loaded: Main.</code></pre>
<p>You can check the value of ‘ds’ using:</p>
~~~~ {.haskell} <em>Main&gt; ds Loading package array-0.3.0.2 … linking … done. Loading package bytestring-0.9.1.10 … linking … done. Loading package containers-0.4.0.0 … linking … done. Loading package binary-0.5.0.2 … linking … done. Loading package syb-0.3 … linking … done. Loading package netlist-0.3.1 … linking … done. [NetDecl “a” (Just (Range (ExprLit Nothing (ExprNum 15)) (ExprLit Nothing (ExprNum 0)))) (Just (ExprVar “x”)),NetDecl “b” (Just (Range (ExprLit Nothing (ExprNum 15)) (ExprLit Nothing (ExprNum 0)))) (Just (ExprLit (Just 16) (ExprNum 10))),MemDecl “c” Nothing (Just (Range (ExprLit Nothing (ExprNum 15)) (ExprLit Nothing (ExprNum 0)))) Nothing,ProcessDecl (Event (ExprVar “clk”) PosEdge) (Just (Event (ExprVar “reset”) PosEdge,Assign (ExprVar “c”) (ExprLit (Just 16) (ExprNum 0)))) (If (ExprVar “enable”) (Assign (ExprVar “c”) (ExprVar “x”)) Nothing)]</em>Main&gt; ~~~~]]></description>
    <pubDate>Sun, 19 Feb 2012 02:05:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/02/19/ghc-netlist/news.html</guid>
</item>
<item>
    <title>GNUnify, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/02/13/gnunify-pune-2012/news.html</link>
    <description><![CDATA[<p>I attended <a href="http://gnunify.in/">GNUnify 2012</a> on February 10-11, 2012 at <a href="http://sicsr.ac.in/">Symbiosis Institute of Computer Studies and Research</a>, Pune, India.</p>
<p>Day I</p>
<p>The first day first session that I attended was on <a href="http://gnunify.in/2012/KYS/ArunKhan#talk1">“Build your own cloud computing infrastructure”</a> by <a href="http://www.gnunify.in/2012/KYS/ArunKhan">Arun Khan</a>. He addressed the different concepts and tools available for setting up a private computing infrastructure. After the first session, I moved to listen to <a href="http://fedoraproject.org/wiki/User:Tuxdna">Saleem Ansari’s</a> talk on <a href="http://gnunify.in/2012/KYS/SaleemAnsari#talk1">“Torque Box - Ruby App Server”</a>. TorqueBox is small adaptation layer on top of JBoss’s Java application server. I then attended <a href="http://gnunify.in/2012/KYS/SrikantPatnaik">Srikant Patnaik’s</a> talk on <a href="http://gnunify.in/2012/KYS/SrikantPatnaik#talk1">“Web based embedded project design”</a>. He demonstrated a simple example of using an LED with Arduino and controlling it with a Python CGI webserver. He also demonstrated the use of Fritzing to build the demoed circuit. All the tools are available on Fedora:</p>
<pre class="shell"><code> $ sudo yum install fritzing arduino</code></pre>
<p>After lunch, I attended the talk on “Btrfs - The next Generation Filesystem on Linux” by <a href="http://wiki.embeddednirvana.org/User:Neependra">Neependra Khare</a>. He addressed the different problems in the current filesystems, and how Btrfs tries to solve them. For the last talk of the day I attended Dr. Abhijat Vichare’s (from <a href="http://www.crlindia.com/">Computational Research Laboratories</a> Pune) session on “Portability concepts in GCC”. It was a detailed session on the internals of <a href="http://gcc.gnu.org/">GCC</a>.</p>
<p>Day II</p>
<p>I attended <a href="http://fedoraproject.org/wiki/User:Suchakra">Suchakra Sharma’s</a> session on <a href="http://gnunify.in/2012/KYS/SuchakrapaniDattSharma#talk1">“Developing QT Apps on Android”</a>. I then went to assist with the system programming contest organized by Neependra Khare. The participants were given a written test on the first day, and based on the results, few were selected to compete in the programming contest (sponsored by <a href="http://stec-inc.com/">STEC</a>). For the contest, few programming problems were given to the participants to be solved in C within couple of hours time. The first, second and third prices were worth INR 5000, 3000 and 2000 respectively. Kiran Divekar (from <a href="http://www.marvell.com/">Marvell</a>) joined us, and we reviewed the code and chose the winners. After lunch, we announced the winners and the organizers and <a href="http://plug.org.in">PLUG</a> members helped with the prize distribution.</p>
<img alt="Programming contest" src="http://www.shakthimaan.com/Mambo/gallery/albums/album75/5_programming_contest.jpg"></img>
<p>I then went to attend Arun Khan’s session on <a href="http://gnunify.in/2012/KYS/arunkhan#talk2">“Convert your old laptop to an useful network device”</a>. He had illustrated with numerous examples on how he had used old hardware into functional, useful network devices. It is extremely useful for beginners who are interested in getting started in working with inexpensive hardware. I then had a chance to meet and talk with <a href="http://blog.mozilla.com/gen/">Gen Kanai</a> and <a href="http://playingwithsid.blogspot.in/">Rakesh “Arky” Ambati</a> from Mozilla. It was also good to catch up with lot of Wikimedia folks, with whom I went for dinner at the <a href="http://www.vaishalihotel.in/main.html">Vaishali restaurant</a>. Few pictures taken during the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album75">/gallery</a>.</p>
<img alt="Wikimedia dinner at Vaishali" src="http://www.shakthimaan.com/Mambo/gallery/albums/album75/7_vaishali_dinner.jpg"></img>]]></description>
    <pubDate>Mon, 13 Feb 2012 16:10:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/02/13/gnunify-pune-2012/news.html</guid>
</item>
<item>
    <title>VLSI Conference, Hyderabad, 2012</title>
    <link>http://www.shakthimaan.com/posts/2012/01/15/vlsi-conference-hyderabad-2012/news.html</link>
    <description><![CDATA[<p>I attended the <a href="http://vlsiconference.com/vlsi2012/">25th International Conference on VLSI Design and 11th International Conference on Embedded Systems</a> between January 7-11, 2012 at the <a href="http://www.hicc.com/">Hyderabad International Convention Centre</a>, Hyderabad, India. The first two days consisted of tutorial sessions, and the next three days had the <a href="http://vlsiconference.com/vlsi2012/conf_schedule.htm">conference presentations</a>. There were also exhibit stalls from different companies.</p>
<img alt="25th VLSID 2012" src="http://shakthimaan.com/downloads/glv/2012/vlsid-jan/vlsid-jan-2012.png"></img>
<p>On the first day I attended the tutorial session on <a href="http://www.systemc-ams.org/">SystemC AMS extensions</a> by <a href="https://www.fp7-smartcode.eu/ecws2/biosketch/damm">Markus Damm</a>, <a href="https://www.ict.tuwien.ac.at/mitarbeiter/adhikari">Sumit Adhikari</a>, and <a href="http://www.lip6.fr/actualite/personnes-fiche.php?ident=P102">François Pecheux</a>. <a href="http://fedoraproject.org/wiki/User:Chitlesh">Chitlesh Goorah</a> had earlier tried to get <a href="http://www.spinics.net/linux/fedora/fedora-electronic-lab/msg00117.html">SystemC into Fedora</a> and <a href="http://spins.fedoraproject.org/fel/">Fedora Electronic Lab</a>, but, due to licensing issues it could not be included. SystemC-AMS is now released under Apache license. Open SystemC Initiative and Accellera Unite have now integrated to become <a href="http://www.accellera.org/home/">Accellera Systems Initiative</a>. We hope to work with them to get their sources under a single free/open source software license. François Pecheux is from <a href="http://www.lip6.fr/index.php?LANG=en">Laboratoire d’Informatique de Paris 6</a>, <a href="http://www.upmc.fr/en/index.html">Pierre &amp; Marie Curie University (UPMC)</a>, Paris, France, and we already ship their free/open source EDA tools in Fedora.</p>
<p>On day two, I attended the tutorial session by <a href="http://people.epfl.ch/arvind.sridhar">Sridhar Arvind</a> on <a href="http://esl.epfl.ch/3d-ice.html">3D-ICE</a>, a free/open source interlayer cooling emulator from <a href="http://esl.epfl.ch">Embedded System Laboratory</a>, <a href="http://www.epfl.ch/index.en.html">Ecole polytechnique fédérale de Lausanne</a>, Switzerland. I have already been working with Sridhar, <a href="http://people.epfl.ch/david.atienza">Prof. David Atienza</a> and <a href="http://people.epfl.ch/alessandro.vincenzi">Alessandro Vincenzi</a> on testing 3D-ICE on Fedora. I had built and tested the dependency <a href="http://crd-legacy.lbl.gov/~xiaoye/SuperLU/">SuperLU</a> library and the 3D-ICE package before the tutorial session. Their software has already been downloaded by over 70 research labs around the world. I will push our tested changes to them. On the later half of the day, I attended a session on verification constraint complexity. <a href="http://www.trusster.com/products/teal/">Teal</a> is a useful verification utility and connection library that has support for constraints and parameter control. The authors of the tool had agreed to release it as free/open source software, and we also ship it in Fedora.</p>
<p>On the following three days of the conference, I attended various paper presentations from different tracks from reconfigurable architectures to methods in AMS optimization. I met <a href="http://www.isical.ac.in/~ssk/">Prof. Susmita Sur-Kolay</a> from the <a href="http://www.isical.ac.in/">Indian Statistical Institute</a>, Kolkata, India where they run Fedora in their labs. They also wished to use the 3D-ICE tool and GPU tools in their labs. I also visited the exhibit stalls meeting different people from the industry and academia. There are quite a few interesting free/open source tools that users can benefit from, and we will work in making them available in Fedora. In 2013, the conference will be held in Pune. Thanks to Red Hat for sponsoring my travel and participation at the conference.</p>]]></description>
    <pubDate>Sun, 15 Jan 2012 13:20:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2012/01/15/vlsi-conference-hyderabad-2012/news.html</guid>
</item>
<item>
    <title>Tux workshop, COEP</title>
    <link>http://www.shakthimaan.com/posts/2011/12/28/tux-workshop-coep/news.html</link>
    <description><![CDATA[<p>I had conducted an introductory session on Fedora as part of the <a href="http://mind-spark.org/tux.php">Tux workshop</a>, MindSpark 2011 at <a href="http://www.coep.org.in/">College of Engineering, Pune</a>, Maharashtra, India on Tuesday, December 27, 2011.</p>
<img alt="Tux workshop" src="http://www.shakthimaan.com/Mambo/gallery/albums/album74/2_poster.jpg"></img>
<p>There were hundred participants distributed between the morning and repeat sessions in the afternoon. I explained about hardware architecture, system boot sequence, and discussed basic installation concepts to the participants. I then gave a demo of installing Fedora using Virtual Machine Manager. I showed them the plethora of F/OSS software that they can use, and also discussed about Fedora sub-projects, and basic project/communication guidelines. I have given them F16 ISO DVD images.</p>
<p>Thanks to Sanket Mehta for working with me for a month in organizing this workshop. Few photos taken at the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album74">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 28 Dec 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/12/28/tux-workshop-coep/news.html</guid>
</item>
<item>
    <title>Wai, Mahabaleshwar trip</title>
    <link>http://www.shakthimaan.com/posts/2011/12/13/wai-mahabaleshwar-trip/news.html</link>
    <description><![CDATA[<p>I had been on a weekend trip to <a href="http://en.wikipedia.org/wiki/Wai,_Maharashtra">Wai</a> and <a href="http://en.wikipedia.org/wiki/Mahabaleshwar">Mahabaleshwar</a>, Maharashtra, India. More photos in my <a href="http://www.shakthimaan.com/Mambo/gallery/album73">/gallery</a>.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album73/DSC03186_2.jpg" alt="highway"></img>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album73/DSC03186_40.jpg" alt="Sahyadri hills"></img>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album73/DSC03186_64.jpg" alt="Dhom Dam"></img>]]></description>
    <pubDate>Tue, 13 Dec 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/12/13/wai-mahabaleshwar-trip/news.html</guid>
</item>
<item>
    <title>Fedora workshop, Foresight Institute</title>
    <link>http://www.shakthimaan.com/posts/2011/12/04/fedora-workshop-foresight/news.html</link>
    <description><![CDATA[<p>I had conducted a one-day introductory workshop on Fedora at <a href="http://www.foresightedu.com">Foresight Institute of Management and Research</a>, affiliated to University of Pune, Maharashtra, India on Saturday, December 3, 2011.</p>
<img alt="Foresight Institute" src="http://shakthimaan.com/downloads/glv/2011/foresight-2011/2-foresight.JPG"></img>
<p>I started the day’s proceedings with an introduction to free/open source software. Most of the students who participated were studying towards their bachelor’s programme in computer applications (BCA), and were familiar with C, C++ and Java development. I gave a demo of the Fedora desktop, and also showed them the plethora of software that they can use.</p>
<p>I also introduced them to revision control with examples on using git. I also addressed the various communication tools that we use, the basic communication guidelines, and the Fedora sub-projects that they can participate in.</p>
<img alt="Audience" src="http://shakthimaan.com/downloads/glv/2011/foresight-2011/1-audience.JPG"></img>
<p>During the post-lunch session, I explained to them about copyright, trademarks, and licensing, and how to use them. I explained the basic concepts in installation, and gave them a demo of installation of Fedora. I have given them CD/DVD images of both Fedora 15 and 16.</p>
<p>Thanks to Antriksh Shah for working with me for a month in organizing this workshop.</p>]]></description>
    <pubDate>Sun, 04 Dec 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/12/04/fedora-workshop-foresight/news.html</guid>
</item>
<item>
    <title>Shakthimaan's tweets</title>
    <link>http://www.shakthimaan.com/posts/2011/11/14/shakthimaan-tweets/news.html</link>
    <description><![CDATA[<a href="http://identi.ca/shakthimaan"><img src="http://shakthimaan.com/downloads/companylogos/identi_ca.jpg" alt="identica logo"></img></a>
<a href="http://twitter.com/shakthimaan"><img src="http://shakthimaan.com/downloads/companylogos/twitter.png" alt="twitter logo"></img></a>
<p>Shakthimaan’s tweets are now available for reference at <a href="http://www.shakthimaan.com/links/tweets.html">http://www.shakthimaan.com/links/tweets.html</a>. I use identi.ca and twitter for documentation links, book references, and useful tips. I am now making it available for others as well. You can also get the sources at:</p>
~~~~ {.shell} $ git clone git://gitorious.org/shakthimaan-tweets/mainline.git<br />~~~~]]></description>
    <pubDate>Mon, 14 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/14/shakthimaan-tweets/news.html</guid>
</item>
<item>
    <title>GNU Emacs erc notify</title>
    <link>http://www.shakthimaan.com/posts/2011/11/13/emacs-erc-notify/news.html</link>
    <description><![CDATA[<p>I use the following code in .emacs with Emacs <a href="http://www.emacswiki.org/emacs/ERC">ERC</a> to get notified using notify-send whenever anyone pings me on IRC:</p>
~~~~ {.lisp} (defun erc-global-notify (matched-type nick msg) (interactive) (when (eq matched-type ’current-nick) (shell-command (concat “notify-send -t 8000 -c &quot;im.received&quot; &quot;” (car (split-string nick “!”)) &quot; mentioned your nick&quot; &quot;&quot; msg “&quot;”)))) (add-hook ’erc-text-matched-hook ’erc-global-notify) ~~~~]]></description>
    <pubDate>Sun, 13 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/13/emacs-erc-notify/news.html</guid>
</item>
<item>
    <title>FUDCon Pune badges</title>
    <link>http://www.shakthimaan.com/posts/2011/11/12/fudcon-pune-badges/news.html</link>
    <description><![CDATA[<img alt="FUDCon Pune" src="https://fedoraproject.org/w/uploads/c/cf/Button.png"></img>
<p>As part of the <a href="http://fudcon.in/">FUDCon Pune 2011</a> organizing team, I had volunteered to help with design work. After attending few training sessions on <a href="http://inkscape.org/">Inkscape</a> by <a href="http://fedoraproject.org/wiki/User:Duffy">Máirín Duffy</a>, I decided to give it a try. <a href="http://fedoraproject.org/wiki/User:Ianweller">Ian Weller</a> had written a Python script to create name badges with Inkscape. It would read list of names from a comma separated file (csv) file, and would generate pdfs from the design provided in the svg file. I had customized the script with help from <a href="http://fedoraproject.org/wiki/DaveMalcolm">Dave Malcolm</a>, created csv files for speakers, volunteers and registered delegates, and generated over 400 named badges for the FUDCon event.</p>
<img alt="FUDCon coupons" src="http://shakthimaan.com/downloads/glv/2011/fudcon-2011/registration-desk-name-badges.jpg"></img>
<p>Thanks to <a href="http://fedoraproject.org/wiki/User:Kushal">Kushal Das</a> for the <a href="http://www.flickr.com/photos/kushaldas/sets/72157628097141150">photograph</a>.</p>
<p>Badges printed on green paper would be for volunteers and organizers, while those printed on blue paper were for speakers. Everyone else got their names printed on white paper. We had also printed badges with just the FUDCon Pune logo for people who register at the venue to write their names on it. We decided not to use QR codes. If we had data on the delegates such as t-shirt size, food preference, identi.ca/twitter feed, IRC nick names, we could have printed them on the badge as well. I did leave enough white space, so people could write whatever they want. The scripts, the Inkscape svg design, an example csv and sample pdf generated are available at <a href="http://shakthimaan.fedorapeople.org/docs/fudcon/">http://shakthimaan.fedorapeople.org/docs/fudcon</a>. I had also designed the coupons for lunch, day I and II, and for the FUDPub:</p>
<img alt="FUDCon coupons" src="http://shakthimaan.com/downloads/glv/2011/fudcon-2011/fudcon-coupons.png"></img>]]></description>
    <pubDate>Sat, 12 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/12/fudcon-pune-badges/news.html</guid>
</item>
<item>
    <title>FUDCon Pune QUCS</title>
    <link>http://www.shakthimaan.com/posts/2011/11/08/fudcon-pune-qucs/news.html</link>
    <description><![CDATA[<img alt="FUDCon Pune" src="https://fedoraproject.org/w/uploads/c/cf/Button.png"></img>
<p>As a follow-up to my talk on <a href="http://qucs.sourceforge.net/">QUCS</a> on day II of FUDCon Pune 2011, I wanted to create circuit examples on the final day from a text book that was being followed for basic electrical engineering course work. This would be a supplement that a student can use when learning circuit theory. Anuj More and Payas Awadhutkar joined in, and we worked on schematics from chapter I of <a href="http://www.amazon.ca/Fundamentals-Electrical-Engineering-Leonard-Bobrow/dp/0195105095">‘Fundamentals of Electrical Engineering’</a> by Leonard S. Boborow, a.k.a “Babu Rao” in India. The schematics were created in qucs-0.0.16, and are available from Payas Awadhutkar gitorious repo:</p>
<pre class="shell"><code>$ git clone git://gitorious.org/qucs-baburao/qucs-baburao.git</code></pre>
<p>As a finale to the event, Jared Smith cut the Fedora cake!</p>
<img alt="Jared cutting the cake" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/39_jared_smith_cake_cutting.jpg"></img>
<p>I would like to thank all the volunteers from <a href="http://www.coep.org.in/">College of Engineering, Pune</a> and <a href="http://www.coep.org.in/index.php?profile=abhijit.comp">Prof. Abhijit A M</a> who coordinated with us in organizing this conference. Thanks also goes to the Fedora contributors who helped in getting things done. Special thanks to <a href="http://www.redhat.com/">Red Hat</a> for sponsoring the event, and for their wonderful support. The COEP volunteers:</p>
<img alt="COEP volunteers" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/32_coep_volunteers.jpg"></img>
<p>We trained many students over the years as part of the Fedora project. I was very happy to see them as speakers and present on the things that they have been working on, and also help others when required during the conference. This is the best outcome that I take from the event.</p>
<p>All the photos taken at FUDCon Pune 2011 are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album72">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 08 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/08/fudcon-pune-qucs/news.html</guid>
</item>
<item>
    <title>FUDCon Pune Day II</title>
    <link>http://www.shakthimaan.com/posts/2011/11/07/fudcon-pune-day-2/news.html</link>
    <description><![CDATA[<img alt="FUDCon Pune" src="https://fedoraproject.org/w/uploads/c/cf/Button.png"></img>
<p>I arrived early again on day II of <a href="http://fudcon.in/">FUDCon Pune 2011</a>. The day’s proceedings started with a keynote by <a href="http://fedoraproject.org/wiki/User:HarishPillay">Harish Pillay</a> on his thoughts on community work, and on his new role as the lead of <a href="http://fedoraproject.org/wiki/Category:Community_Architecture">Community Architecture</a>. I then attended the <a href="http://fudcon.in/sessions/security-open-source-world">‘Security in the Open Source world!’</a> talk by <a href="http://fedoraproject.org/wiki/User:Eteo">Eugene Teo</a> and <a href="http://fedoraproject.org/wiki/User:Huzaifas">Huzaifa Sidhpurwala</a>. Their talk covered quite a bit on the various security threats, and on how they are handled.</p>
<img alt="Eugene Teo" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/11_eugene_teo.jpg"></img>
<p>Since I attended the GlusterFS overview talk on the first day, I wanted to follow it up with the <a href="http://fudcon.in/sessions/glusterfs-hacking-howto">‘GlusterFS: Hacking HOWTO’</a> talk by <a href="https://github.com/amarts">Amar Tumballi</a>. He suggested newbies to read on translators as a starting point to work with Gluster, along with few ideas that they could start with. Lunch was again served at 12 noon. After lunch, I headed to Seminar Hall 2 for my talk on <a href="http://fudcon.in/sessions/qucs-qt-love-story">‘Quite Universal Circuit Simulator - A Qt Love Story’</a> (<a href="http://qucs.sourceforge.net/">QUCS</a>). It is an introduction to electrical circuit theory using circuit components as “fictional” men and women. The example circuits were created using qucs-0.0.15. The examples are available at the <a href="https://gitorious.org/qucs-a-qt-love-story/qucs-a-qt-love-story_prj">gitorious repo</a>:</p>
<pre class="shell"><code>$ git clone git://gitorious.org/qucs-a-qt-love-story/qucs-a-qt-love-story_prj.git</code></pre>
<p>After my talk, I went to the auditorium to attend the talk by <a href="http://fedoraproject.org/wiki/User:Amitshah">Amit Shah</a> on <a href="http://fudcon.in/sites/default/files/slides/Virtualization-with-libvirt.pdf">‘Linux Virtualization’</a> followed by <a href="http://fedoraproject.org/wiki/User:Kashyapc">Kashyap Chamarthy’s</a> talk on <a href="http://fudcon.in/sessions/virtualization-libvirt">‘Virtualization with Libvirt’</a>. They had given a good overview of virtualization in the Linux kernel, and available tools that one could use. I do use <a href="https://fedorahosted.org/publican/">Publican</a>, and thus attended Jared Smith’s talk on the same. Publican does insert blank pages to ensure that new chapters start on the right-hand side if the content were to be printed as a book. For the final talk of the day, I attended <a href="http://fedoraproject.org/wiki/User:Sundaram">Rahul Sundaram’s</a> session on <a href="http://fudcon.in/sessions/ask-fedora-community-support-and-knowledge-base">Askbot for Fedora</a>, and the roadmap and features that he is interested in. We then travelled to <a href="http://www.parcestique.com/pune.htm">Hotel Parc Estique</a> for the FUDPub!</p>
<img alt="FUDPub" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/24_dance_floor.jpg"></img>]]></description>
    <pubDate>Mon, 07 Nov 2011 00:00:10 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/07/fudcon-pune-day-2/news.html</guid>
</item>
<item>
    <title>FUDCon Pune Day I</title>
    <link>http://www.shakthimaan.com/posts/2011/11/07/fudcon-pune-day-1/news.html</link>
    <description><![CDATA[<img alt="FUDCon Pune" src="https://fedoraproject.org/w/uploads/c/cf/Button.png"></img>
<p>I arrived early on day I of <a href="http://fudcon.in/">FUDCon Pune 2011</a> to help with the registration desk. We had different counters for speakers and volunteers, and for delegates. A printer was available for us to print badges, directions, or posters as required.</p>
<img alt="Registration desk" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/3_volunteer_speaker_registration_desk.jpg"></img>
<p>I attended the keynote by <a href="http://fedoraproject.org/wiki/User:Jsmith">Jared Smith</a>, the Fedora Project Leader. The illustrations used in his presentation, <a href="http://fudcon.in/sessions/fedora-state-union-address">‘Fedora “State of the Union” Address’</a> were really good. I then proceeded to the classrooms to attend Ramakrishna Reddy’s talk on <a href="http://fudcon.in/sessions/developer-survival-manual-impatient-developer-guide-groking-source">‘Developer Survivor Manual’</a>. He addressed essential things that newbie developers need to know, and demoed various revision control systems. Fedora banners were placed at various seminar locations on campus to indicate where the talks and sessions were being held.</p>
<img alt="Registration desk" src="http://www.shakthimaan.com/Mambo/gallery/albums/album72/6_banner.jpg"></img>
<p>Lunch was served at 12 noon, and then I moved on to attend the <a href="http://fudcon.in/sessions/fedora-remix-and-community">‘Fedora Remix and the Community’</a> talk by <a href="http://fedoraproject.org/wiki/User:Snavin">Danishka Navin</a>. He shared his experience with the <a href="http://www.hanthana.org/">Hanthana</a> project, which is a Fedora remix that has support for Sinhalese, and Tamil and has been deployed at various schools in Sri Lanka. Fedora is one of the first and largest user of <a href="https://github.com/sitaramc/gitolite">gitolite</a>, and I was happy to meet its author, Sitaram Chamarthy, from TCS Innovation Labs, Hyderabad, India. <a href="http://fudcon.in/sites/default/files/slides/gitolite-at-fudcon-india-2011.pdf">His talk</a> was filled with numerous examples from people using gitolite. The other large users of gitolite are <a href="http://kde.org/">KDE</a> and <a href="http://www.kernel.org">kernel.org</a>. I then attended the <a href="http://fudcon.in/sessions/glusterfs-red-hat-storage-storage-red-hat">‘GlusterFS’</a> talk by Krishna Srinivas from Red Hat, who gave an overview of the Gluster file system, its architecture, and uses.</p>]]></description>
    <pubDate>Mon, 07 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/07/fudcon-pune-day-1/news.html</guid>
</item>
<item>
    <title>FUDCon Pune</title>
    <link>http://www.shakthimaan.com/posts/2011/11/04/fudcon-pune/news.html</link>
    <description><![CDATA[<p>I had filed a ticket year-end of 2009 to <a href="https://fedorahosted.org/fedora-india/">Fedora India</a> to organize a <a href="http://fedoraproject.org/wiki/FUDCon">FUDCon</a> in India. We couldn’t make it in 2010, but it is happening this year!</p>
<img alt="FUDCon Pune" src="https://fedoraproject.org/w/uploads/4/40/Button3-going.png"></img>]]></description>
    <pubDate>Fri, 04 Nov 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/11/04/fudcon-pune/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day II, COEP</title>
    <link>http://www.shakthimaan.com/posts/2011/10/10/fad-2-coep/news.html</link>
    <description><![CDATA[<p>In preparation to <a href="http://fedoraproject.org/wiki/FUDCon:India_2011">FUDCon, Pune 2011</a>, we had organized our <a href="http://fedoraproject.org/wiki/FAD_Pune_2011">second Fedora Activity Day (FAD)</a> at the FOSS Lab, <a href="http://www.coep.org.in/">College of Engineering, Pune, India</a> on Saturday, October 8, 2011. Thanks to COEP for hosting the FAD, and to <a href="http://www.coep.org.in/index.php?profile=abhijit.comp">Prof. Abhijit</a> for working with us in organizing the same. <a href="http://fedoraproject.org/wiki/User:Tuxdna">Saleem Ansari</a> had setup <a href="http://fudcon.in">http://fudcon.in</a> using <a href="http://usecod.com/">Conference Organization Distribution</a>, which we used it for registration at the venue.</p>
<img alt="FOSS Lab audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album71/1_foss_lab_audience.jpg"></img>
<p><a href="http://fedoraproject.org/wiki/User:Pjp">Prasad Pandit</a> started the day’s proceedings with an <a href="http://pjp.dgplug.org/tools/introduction-python.pdf">introduction to Python</a>. Basic syntax, semantics of Python were covered, and we helped the participants in getting started in writing simple scripts. I then presented an overview of contributing to Fedora using the <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">i-want-2-do-project. tell-me-wat-2-do-fedora</a> presentation, and the various communication channels that they need to be familiar with to work with the larger Fedora community.</p>
<img alt="communication channels" src="http://www.shakthimaan.com/Mambo/gallery/albums/album71/2a_fedora_contribution.jpg"></img>
<p>We had lunch at the <a href="http://coepboatclub.com/">COEP Boat Club</a> canteen. After lunch, <a href="http://fedoraproject.org/wiki/User:Kashyapc">Kashyap Chamarthy</a> presented <a href="http://kashyapc.fedorapeople.org/Presentations/virtualization-in-fedora.pdf">KVM virtualization</a> in Fedora illustrating examples using libvirt and virt tools. <a href="http://fedoraproject.org/wiki/User:Amitshah">Amit Shah</a> and Kashyap answered queries regarding virtualization. Saleem Ansari then presented an <a href="https://github.com/tuxdna/conf_jmilug">introduction to web development and Django</a>, illustrating the use of model, view and template design. I concluded the day’s sessions with an introduction to git using the <a href="http://shakthimaan.com/downloads.html#di-git-ally-managing-love-letters">di-git-ally managing love letters</a> presentation.</p>
<p>Few photos taken at the event are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album71">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 10 Oct 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/10/10/fad-2-coep/news.html</guid>
</item>
<item>
    <title>Shaastra, IIT Madras</title>
    <link>http://www.shakthimaan.com/posts/2011/10/03/shaastra-iit-madras/news.html</link>
    <description><![CDATA[<p>The Shaastra team has been trying to get me to speak at their event for many years. This year I wanted to make it, and as part of the <a href="http://www.shaastra.org/2011/main/events/Hackfest/">Hackfest at Shaastra 2011</a>, September 28 to October 2, 2011 at <a href="http://www.iitm.ac.in/">IIT-Madras</a>, Chennai, India I had presented the talk on <a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">i-want-2-do-project. tell-me-wat-2-do</a>.</p>
<img alt="Audience" src="http://shakthimaan.com/downloads/glv/2011/shaastra-2011/1-audience.JPG"></img>
<p>Most of the students were interested in participating in the Google Summer of Code program. I was also able to meet and talk with past Google Summer of Code students, who had already been introduced to this presentation.</p>
<p>I visited the IITM Research Expo at the K V grounds on campus where students had presented their research work. There were quite a few interesting <a href="http://www.ee.iitm.ac.in/mems/">papers on MEMS</a>. I also attended the Paper and Poster presentation by students at the <a href="http://respark.iitm.ac.in/">IITM Research Park</a>. A small memento that I received:</p>
<img alt="momento" src="http://shakthimaan.com/downloads/glv/2011/shaastra-2011/3-momento.JPG"></img>]]></description>
    <pubDate>Mon, 03 Oct 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/10/03/shaastra-iit-madras/news.html</guid>
</item>
<item>
    <title>Fedora Activity Day I, Red Hat, Pune</title>
    <link>http://www.shakthimaan.com/posts/2011/09/25/fad-1-redhat-pune/news.html</link>
    <description><![CDATA[<p>In preparation to <a href="http://fedoraproject.org/wiki/FUDCon:India_2011">FUDCon, Pune 2011</a>, we had organized a <a href="https://fedoraproject.org/wiki/FAD_Pune_2011_Sep_24">Fedora Activity Day (FAD) I</a> at Red Hat, Pune, India on Saturday, September 24, 2011.</p>
<img alt="Introductions" src="http://shakthimaan.com/downloads/glv/2011/fad-1-rh-pune-2011/2-introductions.JPG"></img>
<p><a href="https://fedoraproject.org/wiki/User:Sundaram">Rahul Sundaram</a> started the proceedings with a session on how to <a href="http://sundaram.fedorapeople.org/presentations/fedora-how-to-contribute.pdf">contribute to Fedora</a>, and how people can get involved with the community. I showed the various communication channels that people need to use to connect with the large Fedora community.</p>
<img alt="Understanding Fedora" src="http://shakthimaan.com/downloads/glv/2011/fad-1-rh-pune-2011/1-fedora-contribute.JPG"></img>
<p>We then proceeded to do a hands-on session on RPM packaging. We used the <a href="http://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package">GNU Hello RPM packaging</a> example from the fedoraproject.org wiki. Rahul and I explained each section of the .spec file, and showed them how to use rpmbuild. The participants learnt to write the .spec file, and also built, installed, and tested the hello package.</p>
<p>We then took a break for lunch following which I presented a hands-on session on git using the <a href="file:///tmp/news/downloads.html#di-git-ally-managing-love-letters">di-git-ally managing love letters</a> presentation. <a href="http://fedoraproject.org/wiki/User:Siddhesh">Siddhesh Poyarekar</a> then took an introductory hands-on <a href="http://meetbot.fedoraproject.org/fedora-classroom/2010-05-03/autotools_workshop.2010-05-03-13.29.log.html">session on autotools</a>.</p>
<img alt="Autotools session" src="http://shakthimaan.com/downloads/glv/2011/fad-1-rh-pune-2011/3-autotools-siddhesh.JPG"></img>
<p>All the presentations are available in the <a href="https://fedoraproject.org/wiki/FAD_Pune_2011_Sep_24#Agenda">FAD wiki</a> page. Thanks to Red Hat for letting us use their facility, and for sponsoring the pizza! They were able to arrange for ten laptops with Fedora 15 installed for participants who didn’t have laptops.</p>
<p>Thanks also to <a href="http://fedoraproject.org/wiki/User:Kashyapc">Kashyap Chamarthy</a>, <a href="http://fedoraproject.org/wiki/User:Kushal">Kushal Das</a>, <a href="http://fedoraproject.org/wiki/User:Siddhesh">Siddhesh Poyarekar</a> for their help to the participants during the workshop sessions.</p>]]></description>
    <pubDate>Sun, 25 Sep 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/09/25/fad-1-redhat-pune/news.html</guid>
</item>
<item>
    <title>PyCon India</title>
    <link>http://www.shakthimaan.com/posts/2011/09/20/pycon-india/news.html</link>
    <description><![CDATA[<p>I had presented <a href="http://www.shakthimaan.com/downloads.html#from-python-to-silicon">From Python to Silicon: python-myhdl</a> talk at <a href="http://in.pycon.org/2011/">PyCon India 2011</a>, September 16-18, 2011 at Symbiosis, Pune, India.</p>
<img alt="PyCon India sponsors" src="http://www.shakthimaan.com/Mambo/gallery/albums/album70/3_sponsors.jpg"></img>
<p>The first day of the (un)conference was filled with tutorials. I attended the <a href="http://in.pycon.org/2011/talks/4-functional-programming-with-python">Functional Programming with Python</a> talk by Anand Chitipothu. He had illustrated list comprehensions, recursions, higher-order functions, iterators and generators in Python with numerous examples.</p>
<p>On the second day, I attended the keynote by Raymond Hettinger on <a href="http://urtalk.kpoint.in/kapsule/gcc-e7c717db-f77e-43dc-9dc0-255eb47e9dd3">What Makes Python Awesome</a>. It was a very informative talk illustrating the key characteristics of Python, and the community that surrounds it.</p>
<p>I also attended the <a href="http://in.pycon.org/2011/talks/13-python-on-android">Python on Android</a> talk by Sajjad Anwar, who gave simple examples using android-scripting. The <a href="http://in.pycon.org/2011/talks/7-emacs-as-a-python-ide">Emacs as a Python IDE</a> talk by Noufal Ibrahim had useful tips and tricks on using Emacs for development work, and issue tracking using <a href="http://orgmode.org/">org-mode</a>. I also attended the <a href="http://in.pycon.org/2011/talks/43-decorators-as-composable-abstractions">Decorators as Composable Abstractions</a> by Sidhant Godiwala which was an introduction to using decorators in Python.</p>
<p>On the final day of the event, I attended <a href="http://in.pycon.org/2011/talks/35-network-programming-with-umit-project">Network Programming with Umit Project</a> by Narendran Thangaranjan who gave demos on network protocol implementation, and testing in Python using the <a href="http://www.umitproject.org/">Umit project</a>. Jivitesh Singh Dhaliwal gave a demo of using PySerial to control robots in the <a href="http://in.pycon.org/2011/talks/30-python-in-the-real-world-from-everyday-applications-to-advanced-robotics">Python in the Real World: From Blinking LEDs to Advanced Robotics</a> talk.</p>
<p>My presentation slides are <a href="http://www.shakthimaan.com/downloads.html#from-python-to-silicon">available</a>. Thanks to Christopher Felton for his valuable feedback.</p>
<p>Few photos taken during the event are available at my <a href="http://www.shakthimaan.com/Mambo/gallery/album70">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 20 Sep 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/09/20/pycon-india/news.html</guid>
</item>
<item>
    <title>Packaging RPM presentation</title>
    <link>http://www.shakthimaan.com/posts/2011/09/10/packaging-rpm-presentation/news.html</link>
    <description><![CDATA[<p>Released <a href="http://shakthimaan.com/downloads.html#packaging-red-hot-paneer-butter-masala">Packaging RPM</a> (Packaging Red hot, Paneer (butter) Masala) presentation 1.7. The LaTeX sources are available at <a href="https://gitorious.org/packaging-red-hot-paneer-butter-masala">gitorious.org</a>.</p>
~~~~ {.shell} $ git clone git://gitorious.org/packaging-red-hot-paneer-butter-masala/mainline.git ~~~~]]></description>
    <pubDate>Sat, 10 Sep 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/09/10/packaging-rpm-presentation/news.html</guid>
</item>
<item>
    <title>FISAT, GNU Make</title>
    <link>http://www.shakthimaan.com/posts/2011/08/29/fisat-gnu-make/news.html</link>
    <description><![CDATA[<p>I had presented GNU Make, <a href="http://shakthimaan.com/downloads.html#dum-ka-biryani-make-for-each-other">Dum Ka Biryani, Make for each other</a> at <a href="http://icefoss.fisat.ac.in/">ICE-FOSS 2011</a>, August 26-27, 2011 at <a href="http://www.fisat.ac.in/">Federal Institute of Science and Technology</a>, Angamaly, Kerala.</p>
<img alt="FISAT" src="http://www.shakthimaan.com/Mambo/gallery/albums/album69/5_fisat.jpg"></img>
<p>The conference had talks, hands-on workshops, and project demos. There were interesting projects displayed at the stalls by the students varying from Arduino-based hardware projects, to Python mobile application development to games, and applications developed using opencv. Pamphlets were made for each project, and given to the visitors at the stall. I reviewed the projects that were demoed and gave them feedback. The Institute is in the process of migrating their servers, so we should (hopefully) see the sources made available online.</p>
<p>I also had a chance to meet Anvar K Sadath, Executive Director at the <a href="https://www.itschool.gov.in/index.php">IT@School</a> project. They have trained nearly 2 lakh teachers on F/OSS over the years. Their new initiative is <a href="https://www.itschool.gov.in/animation/">animation training</a> using free/open source software.</p>
<p>The Institute does have a cluster setup called “Dakshina” which is used by students, and the faculty. They also do allow other nearby colleges to use the facility on request.</p>
<img alt="Dakshina cluster" width="320" height="427" src="http://www.shakthimaan.com/Mambo/gallery/albums/album69/17_dakshina_cluster.sized.jpg"></img>
<p>Thanks to the Management of FISAT, for sponsoring my travel and for the wonderful hospitality. Photos taken during the trip are available at my <a href="http://www.shakthimaan.com/Mambo/gallery/album69">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 29 Aug 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/08/29/fisat-gnu-make/news.html</guid>
</item>
<item>
    <title>PICT Ruby Rails workshop</title>
    <link>http://www.shakthimaan.com/posts/2011/08/22/pict-ruby-rails/news.html</link>
    <description><![CDATA[<p>I had conducted a session on test driven, behaviour driven development on Saturday, August 20, 2011 at <a href="http://www.pict.edu/">Pune Institute of Computer Technology</a>, Pune, Maharashtra, India using Ruby, Cucumber, and Rails with examples from <a href="https://joindiaspora.com/">Diaspora</a>.</p>
<p>Thanks to <a href="http://www.j4v4m4n.in/">Praveen Arimbrathodiyil</a> for initiating this workshop and <a href="http://fedoraproject.org/wiki/User:Shreyankg">Shreyank Gupta</a> for helping the students during the hands-on session.</p>
<p>Participants were new to Ruby, and we started off with <a href="http://www.ruby-lang.org/en/documentation/quickstart/">Ruby in Twenty Minutes</a>. Using interactive ruby (irb) students were able to understand the language syntax and its usage. We then moved on to writing tests in Ruby, and writing them first before writing code.</p>
<img alt="irc session" src="http://shakthimaan.com/downloads/glv/2011/pict-aug-20-2011/pict-irb-aug-20-2011.JPG"></img>
<p>User stories were introduced with explanation on understanding how features, and step definitions are written. <a href="http://cukes.info">Cucumber</a> was used to run through the features with simple examples. We then moved on to using cucumber with Rails illustrating an <a href="http://asciicasts.com/episodes/155-beginning-with-cucumber">example of a Rails blog application</a>. I had setup Diaspora on my laptop, and had then given them a visual demo of how cucumber runs feature tests with selenium webdriver. <a href="http://www.flickr.com/photos/shreyankg/sets/72157627481625374/">Photos</a> taken from Shreyank’s camera are available.</p>]]></description>
    <pubDate>Mon, 22 Aug 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/08/22/pict-ruby-rails/news.html</guid>
</item>
<item>
    <title>GNU Emacs ERC</title>
    <link>http://www.shakthimaan.com/posts/2011/08/13/gnu-emacs-erc/news.html</link>
    <description><![CDATA[<p><a title="ERC" href="http://www.emacswiki.org/emacs/ERC/">ERC</a> is a modular, extensible Emacs Internet relay chat client. It is available as part of GNU Emacs. You can use it to connect to irc.freenode.net (for example) chat server using:</p>
<pre class="lisp"><code>;; .emacs
(load &quot;/path/to/secrets.el&quot;)

;; erc
(defun erc-freenode-connect ()
  (interactive)
  (erc :server &quot;irc.freenode.net&quot; :port 6667 :full-name &quot;&lt;Firstname Lastname&gt;&quot; 
   :nick &quot;&lt;your-nickname-here&gt;&quot;)
  (require 'erc)
  (require 'erc-match)
  (setq erc-keywords '(&quot;&lt;your-nickname-here&gt;&quot;))
  (setq erc-current-nick-highlight-type 'nick)
  (setq erc-track-exclude-types '(&quot;JOIN&quot; &quot;PART&quot; &quot;QUIT&quot; &quot;NICK&quot; &quot;MODE&quot;))
  (setq erc-track-use-faces t)
  (setq erc-track-faces-priority-list
	'(erc-current-nick-face erc-keyword-face))
  (setq erc-track-priority-faces-only 'all)
  (setq erc-input-line-position -2)
  (setq erc-echo-notices-in-minibuffer-flag t)
  (setq erc-autojoin-channels-alist 
	'((&quot;freenode.net&quot; &quot;#fedora-india&quot; &quot;#fedora-devel&quot; &quot;##linux-india&quot; 
            &quot;#edev&quot; &quot;#fedora-arm&quot; &quot;#fedora-haskell&quot; &quot;#fudcon-planning&quot; &quot;#gcc&quot;
  	    ))))

(defun nickname-freenode-after-connect (server nick)
  (when (and (string-match &quot;freenode\\.net&quot; server)
	     (boundp 'irc-freenode-nick-passwd))
    (erc-message &quot;PRIVMSG&quot; (concat &quot;NickServ identify &quot; irc-freenode-nick-passwd))))
(add-hook 'erc-after-connect 'nickname-freenode-after-connect)</code></pre>
<p>The secrets.el file loads your encrypted files that contain passwords:</p>
<pre class="lisp"><code>;; secrets.el
(load-library &quot;~/pass.el.gpg&quot;)</code></pre>
<p>A sample pass.el.gpg file:</p>
<pre class="lisp"><code>;; pass.el.gpg
(set 'irc-freenode-nick-passwd &quot;your-password&quot;)</code></pre>
<p>The first time you load the above, you will be prompted to create a password for the encryption. Remember it. Whenever you start Emacs thereafter, or when you try to modify the .gpg files, you will be prompted for the password. To initiate connection to irc.freenode.net within Emacs, you can use:</p>
<pre class="lisp"><code>M-x erc-freenode-connect</code></pre>
<p>It should connect to the server, join you to the channels, and identify yourself to NickServ! Each channel is a buffer, and thus Emacs buffer commands work. Whenever someone sends you a message using your nick, you will get a notification in the Emacs status bar. For more ERC commands and options, please refer the <a href="http://mwolson.org/static/doc/erc.html">ERC user manual</a>.</p>]]></description>
    <pubDate>Sat, 13 Aug 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/08/13/gnu-emacs-erc/news.html</guid>
</item>
<item>
    <title>Python workshop, MIT, Pune</title>
    <link>http://www.shakthimaan.com/posts/2011/08/08/python-workshop-mit/news.html</link>
    <description><![CDATA[<p>I had conducted a one-day hands-on “Introduction to Python” programming workshop at <a href="http://mitcoe.edu.in/">Maharashtra Institute of Technology, College of Engineering</a>, Kothrud, Pune, India on Saturday, August 6, 2011.</p>
<p>The participants were engineering students who had some programming experience but were new to Python. I wanted to do a hands-on session so I could help them along the way. I decided to use the presentation <a href="http://www-uxsup.csx.cam.ac.uk/courses/PythonProgIntro/">Python: Introduction for Programmers</a> by Bruce Beckles and Bob Dowling from the University Computing Service, University of Cambridge. I had requested permission to re-use the slides giving credit to the authors, for which they agreed.</p>
<p>Two software labs (I and II) were made available at the venue. Remote desktop was setup so the slides were visible on both the lab projectors. A speaker system was arranged so people could hear me from either lab. Gedit was used to write simple programs.</p>
<img alt="Software Lab I" src="http://www.shakthimaan.com/Mambo/gallery/albums/album68/4_lab_one.jpg"></img>
<p>Thanks to Prof. Reena D. Pagare (MIT, College of Engineering) for working with me during the last few weeks in organizing this workshop.</p>
<p>More photos taken at the venue and during the workshop are available at my <a href="http://www.shakthimaan.com/Mambo/gallery/album68">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 08 Aug 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/08/08/python-workshop-mit/news.html</guid>
</item>
<item>
    <title>GNU Emacs EasyPG</title>
    <link>http://www.shakthimaan.com/posts/2011/08/05/emacs-easypg/news.html</link>
    <description><![CDATA[<p><a title="EasyPG" href="http://epg.sourceforge.jp/">EasyPG</a>, a GnuPG interface is available from Emacs 23 which provides automatic encryption of .gpg files. You can list all the required encrypted .gpg files to be used by Emacs in a secrets.el file (for example):</p>
<pre class="lisp"><code>;; secrets.el
(load-library &quot;~/pass.el.gpg&quot;)</code></pre>
<p>You can then load this file in your Emacs initialization file:</p>
<pre class="lisp"><code>;; .emacs
(load &quot;/path/to/secrets.el&quot;)</code></pre>
<p>The first time you load the above, you will be prompted to create a password for the encryption. Remember it. Whenever you start Emacs thereafter, or when you try to modify the .gpg files, you will be prompted for the password.</p>]]></description>
    <pubDate>Fri, 05 Aug 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/08/05/emacs-easypg/news.html</guid>
</item>
<item>
    <title>GNU Emacs reference card</title>
    <link>http://www.shakthimaan.com/posts/2011/07/18/emacs-reference-card/news.html</link>
    <description><![CDATA[<p><a href="http://www.shakthimaan.com/downloads.html#emacs-a-day-keeps-the-vizing-away">Emacs-a-day-keeps-the-vi-zing-away</a>, a <a href="http://shakthimaan.com/downloads/glv/presentations/emacs-a-day-keeps-the-vi-zing-away.pdf">GNU Emacs reference card</a> is now available under the GNU General Public License. You can get the LaTeX sources from:</p>
~~~~ {.shell} $ git clone git://gitorious.org/emacs-a-day-keeps-the-vi-zing-away/mainline.git ~~~~]]></description>
    <pubDate>Mon, 18 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/07/18/emacs-reference-card/news.html</guid>
</item>
<item>
    <title>freeDiameter</title>
    <link>http://www.shakthimaan.com/posts/2011/07/07/freediameter/news.html</link>
    <description><![CDATA[<p><a href="http://www.freediameter.net/trac/">freeDiameter</a>, a free/open source <a href="http://en.wikipedia.org/wiki/Diameter_%28protocol%29">Diameter</a> protocol implementation is now available for Fedora/RHEL. Install it using:</p>
<pre class="shell"><code>$ sudo yum install freeDiameter freeDiameter-devel</code></pre>
<p>It fully supports the Diameter Base Protocol as specified in <a href="http://tools.ietf.org/html/rfc3588">RFC 3588</a>, Diameter Extensible Authentication Protocol (EAP) application server from <a href="http://tools.ietf.org/html/rfc4072">RFC 4072</a>, and Diameter Session Initiation Protocol (SIP) application from <a href="http://tools.ietf.org/html/rfc4740">RFC 4740</a>. Thanks to Sebastien Decugis for accepting the upstream patches.</p>]]></description>
    <pubDate>Thu, 07 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/07/07/freediameter/news.html</guid>
</item>
<item>
    <title>MyHDL</title>
    <link>http://www.shakthimaan.com/posts/2011/07/06/myhdl/news.html</link>
    <description><![CDATA[<p><a href="http://www.myhdl.org/doku.php">MyHDL</a>, a Python hardware description and verification language is now available for Fedora/RHEL. Install it using:</p>
<pre class="shell"><code>$ sudo yum install python-myhdl</code></pre>
<p>A simple example of a D flip-flop is given below:</p>
<pre class="sourceCode python"><code class="sourceCode python"><span class="co">#!/usr/bin/python</span>

<span class="ch">from</span> myhdl <span class="ch">import</span> *
<span class="ch">from</span> random <span class="ch">import</span> randrange
 
<span class="kw">def</span> dff(q, d, clk):
    <span class="ot">@always</span>(clk.posedge)
    <span class="kw">def</span> logic():
        q.<span class="dt">next</span> = d
 
    <span class="kw">return</span> logic
 
<span class="kw">def</span> test_dff():
    q, d, clk = [Signal(<span class="dt">bool</span>(<span class="dv">0</span>)) <span class="kw">for</span> i in <span class="dt">range</span>(<span class="dv">3</span>)]
 
    dff_inst = dff(q, d, clk)
 
    <span class="ot">@always</span>(delay(<span class="dv">10</span>))
    <span class="kw">def</span> clkgen():
        clk.<span class="dt">next</span> = not clk
 
    <span class="ot">@always</span>(clk.negedge)
    <span class="kw">def</span> stimulus():
        d.<span class="dt">next</span> = randrange(<span class="dv">2</span>)
 
    <span class="kw">return</span> dff_inst, clkgen, stimulus
 
<span class="kw">def</span> simulate(timesteps):
    tb = traceSignals(test_dff)
    sim = Simulation(tb)
    sim.run(timesteps)
 
simulate(<span class="dv">2000</span>)</code></pre>
<p>You can run it using:</p>
<pre class="shell"><code>$ python test.py</code></pre>
<p>The generated test_dff.vcd can be viewed in GTKWave:</p>
<img alt="python-myhdl generated .vcd file for d flip-flop" src="http://www.shakthimaan.com/downloads/screenshots/gtkwave-python-myhdl.png"></img>
<p>You can also generate Verilog code using the toVerilog() function. For example:</p>
<pre class="sourceCode python"><code class="sourceCode python"><span class="kw">def</span> convert():
    q, d, clk = [Signal(<span class="dt">bool</span>(<span class="dv">0</span>)) <span class="kw">for</span> i in <span class="dt">range</span>(<span class="dv">3</span>)]
    toVerilog(dff, q, d, clk)
 
convert()</code></pre>
<p>The generated Verilog code looks like:</p>
<pre class="sourceCode verilog"><code class="sourceCode verilog"><span class="ot">`timescale 1ns/10ps</span>

<span class="kw">module</span> dff (
    q,
    d,
    clk
);

<span class="dt">output</span> q;
<span class="dt">reg</span> q;
<span class="dt">input</span> d;
<span class="dt">input</span> clk;

<span class="kw">always</span> @(<span class="kw">posedge</span> clk) <span class="kw">begin:</span><span class="dt"> DFF</span>_LOGIC
    q &amp;lt;= d;
<span class="kw">end</span>

<span class="kw">endmodule</span></code></pre>
<p>Refer their <a href="http://www.myhdl.org/doku.php/start">wiki</a> for more documentation.</p>]]></description>
    <pubDate>Wed, 06 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/07/06/myhdl/news.html</guid>
</item>
<item>
    <title>Essential Abstractions in GCC</title>
    <link>http://www.shakthimaan.com/posts/2011/07/04/essential-abstractions-in-gcc/news.html</link>
    <description><![CDATA[<p>I have been wanting to attend the <a href="http://www.cse.iitb.ac.in/grc/gcc-workshop-11/index.php">‘Essential Abstractions in GCC’</a> workshop at <a href="http://www.iitb.ac.in/">IIT Bombay</a>, Powai, Mumbai for many years, and I was finally able to make it this year (their fourth), June 30-July 3, 2011. Thanks to <a href="http://www.redhat.com">Red Hat</a> for sponsoring me.</p>
<p>The first day started off with an introduction to the <a href="http://www.cse.iitb.ac.in/grc/">GCC Resource Center</a> at IIT, Bombay, and their primary research interests in program analysis and optimization, translation validation, retargetable compilation, and parallelization and vectorization. They proceeded to give an overview of compiling GCC, and probing techniques used in understanding the functionality of the <a href="http://gcc.gnu.org/">GNU C compiler</a>. Lab sessions were held in the afternoon, and assignments were given to illustrate the concepts discussed. In general, lectures were scheduled in the morning, and lab sessions in the afternoon.</p>
<p>The second day focussed on introducing the control flow in gcc, adding passes to gcc, and manipulating <a href="http://gcc.gnu.org/wiki/GIMPLE">GIMPLE</a> for adding interprocedural and intraprocedural passes. Using simple GIMPLE API in gcc-4.6.0 were illustrated, along with adding static/dynamic plugin passes. The lab sessions were held in the afternoon. Teaching Assistants (students) were present to assist the participants during the lab sessions. There were regular tea breaks provided between breakfast, lunch, and dinner.</p>
<p>The third day began with an introduction to machine descriptions. Examples of retargetability mechanisms in gcc using <a href="http://spimsimulator.sourceforge.net">spim</a>, a MIPS processor simulator were illustrated with examples. The instructions sets were added incrementally at different machine description levels, beginning from assignment operations to arithmetic to pointers and function calls. The issues of retargetability mechanisms in gcc were also discussed.</p>
<p>The final day started with an introduction on parallelization and vectorization, theory, and concepts. Their implementation in gcc-4.6.0 was illustrated, specifically for the case of loops with data dependency diagrams. The use of <a href="http://gcc.gnu.org/wiki/Graphite">graphite</a>, and <a href="http://www.cse.ohio-state.edu/~pouchet/software/pocc/">polyhedral compilation</a> in gcc-4.6.0 were also discussed. We had lab assignments in the afternoon, and the session concluded with a summary of the essential concepts required in understanding the internals of GCC.</p>
<p>The workshop is useful if you have worked with compiler internals. I only wish they would release the sources of their work under a Free/Open Source license for everyone to benefit from.</p>
<p>Few photos taken during the trip are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album67">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 04 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/07/04/essential-abstractions-in-gcc/news.html</guid>
</item>
<item>
    <title>ghc-MonadCatchIO-mtl</title>
    <link>http://www.shakthimaan.com/posts/2011/06/29/ghc-MonadCatchIO-mtl/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/MonadCatchIO-mtl">MonadCatchIO-mtl</a>, a monad-transformer version of the Control.Exception.catch function is now available for Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-MonadCatchIO-mtl ghc-MonadCatchIO-mtl-devel</code></pre>
<p>A simple example to throw or catch an exception that is an instance of the Exception class:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE DeriveDataTypeable #-}</span>

<span class="kw">import</span> <span class="dt">Control.Monad.CatchIO</span>
<span class="kw">import</span> <span class="dt">Data.Typeable</span>
<span class="kw">import</span> <span class="dt">Prelude</span> <span class="kw">hiding</span> (<span class="fu">catch</span>)

<span class="kw">data</span> <span class="dt">MyException</span> <span class="fu">=</span> <span class="dt">ThisException</span> <span class="fu">|</span> <span class="dt">ThatException</span>
     <span class="kw">deriving</span> (<span class="kw">Show</span>, <span class="dt">Typeable</span>)

<span class="kw">instance</span> <span class="dt">Exception</span> <span class="dt">MyException</span>

main <span class="fu">=</span> <span class="kw">do</span>
     throw <span class="dt">ThisException</span> <span class="ot">`catch`</span> \e <span class="ot">-&gt;</span> <span class="fu">putStrLn</span> (<span class="st">&quot;Caught &quot;</span> <span class="fu">++</span> <span class="fu">show</span> (<span class="ot">e ::</span> <span class="dt">MyException</span>))</code></pre>
<p>Thanks to Daniel Gorín for the upstream changes.</p>]]></description>
    <pubDate>Wed, 29 Jun 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/06/29/ghc-MonadCatchIO-mtl/news.html</guid>
</item>
<item>
    <title>hiredis</title>
    <link>http://www.shakthimaan.com/posts/2011/05/27/hiredis/news.html</link>
    <description><![CDATA[<p><a href="https://github.com/antirez/hiredis">Hiredis</a>, a minimalistic C client library for the <a href="http://redis.io/">Redis</a> database is now available for Fedora/RHEL. Install it using:</p>
<pre class="shell"><code>  $ sudo yum install hiredis hiredis-devel</code></pre>]]></description>
    <pubDate>Fri, 27 May 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/05/27/hiredis/news.html</guid>
</item>
<item>
    <title>ghc-ForSyDe</title>
    <link>http://www.shakthimaan.com/posts/2011/05/25/ghc-ForSyDe/news.html</link>
    <description><![CDATA[<p><a href="http://www.ict.kth.se/forsyde/">Formal System Design</a> (ForSyDe) from <a href="http://www.kth.se/ict?l=en_UK">KTH Royal Institute of Technology</a>, Sweden is now available for Fedora. It is a methodology with the objective to move system design (System on Chip, Hardware and Software systems) to a higher level of abstraction, and to bridge the abstraction gap by transformational design refinement. You can install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-ForSyDe</code></pre>
<p>It is the 100th Haskell package in Fedora.</p>]]></description>
    <pubDate>Wed, 25 May 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/05/25/ghc-ForSyDe/news.html</guid>
</item>
<item>
    <title>Electronics For You Expo, New Delhi</title>
    <link>http://www.shakthimaan.com/posts/2011/02/22/efy-new-delhi/news.html</link>
    <description><![CDATA[<p>I had participated in the panel discussion on “Free/Open Source Hardware - What it means to Design Engineers” at the <a href="http://www.efyexpo.com/">Electronics For You Expo</a> 2011, <a href="http://en.wikipedia.org/wiki/Pragati_Maidan">Pragati Maidan</a>, New Delhi on Saturday, February 19, 2011 representing <a href="http://fedoraproject.org">Fedora</a>, and <a href="http://spins.fedoraproject.org/fel/">Fedora Electronic Lab</a>. <a href="http://www.massimobanzi.com/about/">Massimo Banzi</a> (Arduino) chaired the session.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album66/4_ajith_kumar.jpg" alt="panel discussion"></img>
<p>The <a href="http://shakthimaan.com/downloads.html#free-open-source-hardware-what-it-means-to-design-engineers">presentation</a> and <a href="http://www.shakthimaan.com/Mambo/gallery/album66">photos</a> are available. It was good to meet up with Massimo Banzi, <a href="http://opencores.org/acc,view,marcus.erlandsson">Marcus Erlandsson</a> (<a href="http://www.opencores.org">OpenCores.org</a>) and <a href="http://www.ifixit.com/User/Contributions/2/Kyle+Wiens">Kyle Wiens</a> (<a href="http://www.ifixit.com">iFixit</a>). Marcus Erlandsson gave a demo of the <a href="http://www.orsoc.se/">ORSoC</a> development board:</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album66/2_orsoc_board.jpg" alt="orsoc board"></img>
<p>I was also able to catch up with few Arduino hackers from Delhi. We had a good discussion about open hardware, licensing, community development, hardware hacking, and of course Fedora Electronic Lab. Special thanks to Electronics For You for sponsoring the travel.</p>]]></description>
    <pubDate>Tue, 22 Feb 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/02/22/efy-new-delhi/news.html</guid>
</item>
<item>
    <title>ghc-parameterized-data</title>
    <link>http://www.shakthimaan.com/posts/2011/02/21/ghc-parameterized-data/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/parameterized-data">parameterized-data</a> is now available for Fedora. Install it using:</p>
<pre class="shell"><code>$ sudo yum install ghc-parameterized-data</code></pre>
<p>A <a href="http://www.ict.kth.se/forsyde/files/tutorial/tutorial.html#FSVec">tutorial</a> illustrating vectors parameterized in size using the above is written by Alfonso Acosta.</p>]]></description>
    <pubDate>Mon, 21 Feb 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/02/21/ghc-parameterized-data/news.html</guid>
</item>
<item>
    <title>GNUnify, GNU Make, Pune</title>
    <link>http://www.shakthimaan.com/posts/2011/02/12/gnunify-gnu-make/news.html</link>
    <description><![CDATA[<p>Presented <a href="http://shakthimaan.com/downloads.html#dum-ka-biryani-make-for-each-other">Dum Ka Biryani, Make for each other</a> at <a href="http://gnunify.in">GNUnify 2011</a>, Symbiosis Institute of Computer Studies and Research, Pune. The presentation is an illustrative, introduction on <a href="http://www.gnu.org/software/make/">GNU Make</a>.</p>
<img src="http://shakthimaan.com/downloads/glv/2011/gnunify/1-dum-biryani-presentation.jpg" alt="make presentation picture"></img>
<p>The <a href="http://shakthimaan.com/downloads/glv/presentations/dum-ka-biryani-make-for-each-other.pdf">pdf</a> and the LaTeX beamer sources are available under the GNU Free Documentation License. You can clone the sources using:</p>
<pre class="shell"><code>$ git clone git://gitorious.org/dum-ka-biryani-make-for-each-other/mainline.git</code></pre>
<p>I had also conducted an introductory workshop on gcc, Makefiles, static, shared libraries for newbies at the (un)conference.</p>
<img src="http://shakthimaan.com/downloads/glv/2011/gnunify/2-c-workshop.jpg" alt="C workshop picture"></img>]]></description>
    <pubDate>Sat, 12 Feb 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/02/12/gnunify-gnu-make/news.html</guid>
</item>
<item>
    <title>CUnit</title>
    <link>http://www.shakthimaan.com/posts/2011/02/09/CUnit/news.html</link>
    <description><![CDATA[<p><a href="http://cunit.sourceforge.net/">CUnit</a>, a lightweight system for writing, administering, and running unit test cases in C is now available for Fedora.</p>
<pre class="shell"><code>  $ sudo yum install cunit</code></pre>
<p>An example code, is given below:</p>
<pre class="sourceCode c"><code class="sourceCode c"><span class="ot">#include &lt;stdio.h&gt;</span>
<span class="ot">#include &lt;string.h&gt;</span>
<span class="ot">#include &quot;CUnit/Basic.h&quot;</span>

<span class="dt">static</span> FILE* temp_file = NULL;

<span class="dt">int</span> init_suite1(<span class="dt">void</span>)
{
   <span class="kw">if</span> (NULL == (temp_file = fopen(<span class="st">&quot;temp.txt&quot;</span>, <span class="st">&quot;w+&quot;</span>))) {
      <span class="kw">return</span> -<span class="dv">1</span>;
   }
   <span class="kw">else</span> {
      <span class="kw">return</span> <span class="dv">0</span>;
   }
}

<span class="dt">int</span> clean_suite1(<span class="dt">void</span>)
{
   <span class="kw">if</span> (<span class="dv">0</span> != fclose(temp_file)) {
      <span class="kw">return</span> -<span class="dv">1</span>;
   }
   <span class="kw">else</span> {
      temp_file = NULL;
      <span class="kw">return</span> <span class="dv">0</span>;
   }
}

<span class="dt">void</span> testFPRINTF(<span class="dt">void</span>)
{
   <span class="dt">int</span> i1 = <span class="dv">10</span>;

   <span class="kw">if</span> (NULL != temp_file) {
      CU_ASSERT(<span class="dv">0</span> == fprintf(temp_file, <span class="st">&quot;&quot;</span>));
      CU_ASSERT(<span class="dv">2</span> == fprintf(temp_file, <span class="st">&quot;Q</span><span class="ch">\n</span><span class="st">&quot;</span>));
      CU_ASSERT(<span class="dv">7</span> == fprintf(temp_file, <span class="st">&quot;i1 = %d&quot;</span>, i1));
   }
}

<span class="dt">void</span> testFREAD(<span class="dt">void</span>)
{
   <span class="dt">unsigned</span> <span class="dt">char</span> buffer[<span class="dv">20</span>];

   <span class="kw">if</span> (NULL != temp_file) {
      rewind(temp_file);
      CU_ASSERT(<span class="dv">9</span> == fread(buffer, <span class="kw">sizeof</span>(<span class="dt">unsigned</span> <span class="dt">char</span>), <span class="dv">20</span>, temp_file));
      CU_ASSERT(<span class="dv">0</span> == strncmp(buffer, <span class="st">&quot;Q</span><span class="ch">\n</span><span class="st">i1 = 10&quot;</span>, <span class="dv">9</span>));
   }
}

<span class="dt">int</span> main()
{
   CU_pSuite pSuite = NULL;

   <span class="co">/* initialize the CUnit test registry */</span>
   <span class="kw">if</span> (CUE_SUCCESS != CU_initialize_registry())
      <span class="kw">return</span> CU_get_error();

   <span class="co">/* add a suite to the registry */</span>
   pSuite = CU_add_suite(<span class="st">&quot;Suite_1&quot;</span>, init_suite1, clean_suite1);
   <span class="kw">if</span> (NULL == pSuite) {
      CU_cleanup_registry();
      <span class="kw">return</span> CU_get_error();
   }

   <span class="co">/* add the tests to the suite */</span>
   <span class="co">/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */</span>
   <span class="kw">if</span> ((NULL == CU_add_test(pSuite, <span class="st">&quot;test of fprintf()&quot;</span>, testFPRINTF)) ||
       (NULL == CU_add_test(pSuite, <span class="st">&quot;test of fread()&quot;</span>, testFREAD)))
   {
      CU_cleanup_registry();
      <span class="kw">return</span> CU_get_error();
   }

   <span class="co">/* Run all tests using the CUnit Basic interface */</span>
   CU_basic_set_mode(CU_BRM_VERBOSE);
   CU_basic_run_tests();
   CU_cleanup_registry();
   <span class="kw">return</span> CU_get_error();
}</code></pre>
<p>Compile it using:</p>
<pre class="shell"><code>$ gcc test.c -o test -lcunit</code></pre>
<p>Output is given below:</p>
<p>~~~~ {.shell} $ ./test</p>
<pre><code> CUnit - A unit testing framework for C - Version 2.1-2
 http://cunit.sourceforge.net/</code></pre>
<p>Suite: Suite_1 Test: test of fprintf() …passed Test: test of fread() …passed</p>
<p>Run Summary: Type Total Ran Passed Failed Inactive suites 1 1 n/a 0 0 tests 2 2 2 0 0 asserts 5 5 5 0 n/a</p>
Elapsed time = 0.000 seconds ~~~~]]></description>
    <pubDate>Wed, 09 Feb 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/02/09/CUnit/news.html</guid>
</item>
<item>
    <title>ghc-ansi-terminal</title>
    <link>http://www.shakthimaan.com/posts/2011/02/04/ghc-ansi-terminal/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/ansi-terminal-0.5.5">ghc-ansi-terminal</a>, ANSI terminal support for Haskell is now available for Fedora. It allows cursor movement, clearing the screen, coloured output, showing or hiding the cursor, and setting the title.</p>
<pre class="shell"><code>$ sudo yum install ghc-ansi-terminal ghc-ansi-terminal-devel</code></pre>
<p>An example code, ansi.hs is given below:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">System.Console.ANSI</span>

main <span class="fu">=</span> <span class="kw">do</span>
    setCursorPosition <span class="dv">5</span> <span class="dv">0</span>
    setTitle <span class="st">&quot;ANSI Terminal Short Example&quot;</span>

    setSGR [ <span class="dt">SetConsoleIntensity</span> <span class="dt">BoldIntensity</span>
           , <span class="dt">SetColor</span> <span class="dt">Foreground</span> <span class="dt">Vivid</span> <span class="dt">Red</span>
           ]
    <span class="fu">putStr</span> <span class="st">&quot;Hello&quot;</span>
    
    setSGR [ <span class="dt">SetConsoleIntensity</span> <span class="dt">NormalIntensity</span>
           , <span class="dt">SetColor</span> <span class="dt">Foreground</span> <span class="dt">Vivid</span> <span class="dt">White</span>
           , <span class="dt">SetColor</span> <span class="dt">Background</span> <span class="dt">Dull</span> <span class="dt">Blue</span>
           ]
    <span class="fu">putStrLn</span> <span class="st">&quot;World!&quot;</span></code></pre>
<p>A screenshot of the output when the above code is executed:</p>
<img src="http://shakthimaan.com/downloads/screenshots/ghc-ansi-terminal-screenshot.png" alt="ghc-ansi-terminal output screenshot"></img>]]></description>
    <pubDate>Fri, 04 Feb 2011 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2011/02/04/ghc-ansi-terminal/news.html</guid>
</item>
<item>
    <title>flterm</title>
    <link>http://www.shakthimaan.com/posts/2010/11/18/flterm/news.html</link>
    <description><![CDATA[<p>flterm, a serial terminal and firmware download program, part of the <a href="http://www.milkymist.org/">Milkymist VJ SoC</a> is now available on Fedora.</p>
<pre class="shell"><code>  $ sudo yum install flterm</code></pre>
<p>You can run it using:</p>
<p>~~~~ {.shell} $ flterm Serial boot program for the Milkymist VJ SoC - v. 1.1 Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq</p>
<p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.</p>
Usage: flterm –port <port> [–double-rate] –kernel <kernel_image> [–kernel-adr
<address>
] [–cmdline <cmdline> [–cmdline-adr
<address>
]] [–initrd <initrd_image> [–initrd-adr
<address>
<p>]]</p>
Default load addresses: kernel: 0x40000000 cmdline: 0x41000000 initrd: 0x41002000 ~~~~]]></description>
    <pubDate>Thu, 18 Nov 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/11/18/flterm/news.html</guid>
</item>
<item>
    <title>Lavasa</title>
    <link>http://www.shakthimaan.com/posts/2010/11/09/Lavasa/news.html</link>
    <description><![CDATA[<p>Visited <a href="http://www.lavasa.com/high/visiting_lavasa.aspx">Lavasa</a>, Pune, Maharashtra, India for the <a href="http://en.wikipedia.org/wiki/Diwali">Deepavali</a> weekend. More photos are available at my <a href="http://www.shakthimaan.com/Mambo/gallery/album65">/gallery</a>.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album65/13_lavasa_city.jpg" alt="Lavasa view from the top"></img>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album65/22_baji_pasalkar_reservoir.jpg" alt="Baji Pasalkar reservoir"></img>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album65/25_dasve_boulevard.jpg" alt="Dasve boulevard"></img>]]></description>
    <pubDate>Tue, 09 Nov 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/11/09/Lavasa/news.html</guid>
</item>
<item>
    <title>OLPC at Sreenidhi International School</title>
    <link>http://www.shakthimaan.com/posts/2010/10/11/Sreenidhi-school/news.html</link>
    <description><![CDATA[<p>I had visited <a href="http://www.sreenidhiinternational.com/">Sreenidhi International School</a>, Aziznagar, Moinabad, Andhra Pradesh, India to help them with the <a href="http://kmrfoundation.org/">KMR Foundation’s</a> <a href="http://wiki.laptop.org/go/The_OLPC_Wiki">OLPC</a> project. They will soon start using an instance of <a href="http://wordpress.org/">WordPress</a> for their blogs, where you can get to know updates on their OLPC deployment. They already have a blog for their <a href="http://sis.edu.in/blog/">Primary Years Programme (PYP)</a>. I helped them with few software, hardware problems that they were facing with their OLPCs (XO-1).</p>
<img src="http://shakthimaan.com/downloads/glv/hyd/olpc/kmrf-olpc-512.JPG" alt="Dismantling the OLPC"></img>]]></description>
    <pubDate>Mon, 11 Oct 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/10/11/Sreenidhi-school/news.html</guid>
</item>
<item>
    <title>Mepco Schlenk IRC training</title>
    <link>http://www.shakthimaan.com/posts/2010/10/05/Mepco-Schlenk-IRC-training/news.html</link>
    <description><![CDATA[<p>I had scheduled to conduct a one-day Fedora, Free Software workshop at <a href="http://www.mepcoeng.ac.in/">Mepco Schlenk Engineering College, Sivaskasi, Tamil Nadu, India</a> on Saturday, October 2, 2010, but due to the <a href="http://www.thehindu.com/news/national/article800650.ece">Ayodhya verdict</a>, I had to cancel it in the last moment.</p>
<p>I then tried to get <a href="http://fedoraproject.org/wiki/Communicate/IRCHowTo">Internet Relay Chat</a> (IRC) up and running on their college computer labs that were running Fedora. They were using squid proxy, and I had requested the system administrator to <a href="http://fedorasolved.org/Members/realz/squid_IM">configure</a> it to allow IRC connections. He got it working, and we decided to go ahead with online IRC training for the following sessions:</p>
<ul>
<li><a href="http://shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">i-want-2-do-project. tell-me-wat-2-do-fedora</a></li>
<li><a href="http://shakthimaan.com/downloads.html#di-git-ally-managing-love-letters">di-git-ally managing love letters</a></li>
<li>Q/A session</li>
<li><a href="http://shakthimaan.com/downloads.html#packaging-red-hot-paneer-butter-masala">Packaging RPM</a></li>
</ul>
<p>The <a href="http://shakthimaan.com/downloads/glv/2010/logs/mepco-schlenk-foss-oct-2-2010.log.html">IRC log</a> of the session is available. They were kind enough to take some <a href="http://www.shakthimaan.com/Mambo/gallery/album64">pictures</a> during the sessions and send it across to me.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album64/3_lab.jpg" alt="IRC session in progress"></img>
<p>Thanks to Prof. Shenbagaraj for working with me for the past two months in organizing this workshop. Hopefully, someday, I will meet them in person.</p>]]></description>
    <pubDate>Tue, 05 Oct 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/10/05/Mepco-Schlenk-IRC-training/news.html</guid>
</item>
<item>
    <title>OSI Tech Days 2010</title>
    <link>http://www.shakthimaan.com/posts/2010/09/22/OSI-Tech-Days/news.html</link>
    <description><![CDATA[<p>Attended <a href="http://www.osidays.com">OSI Tech Days</a>, September 19-21, 2010, Chennai to listen to <a href="http://emoglen.law.columbia.edu/">Prof. Eben Moglens’</a> talk on <a href="http://www.softwarefreedom.org/events/2010/freedom-and-web-equality-21st-century/">Freedom and the Web: Equality in the 21st Century</a>. I also manned the <a href="http://www.ilugc.in">ILUGC</a> stall for some time. It was good to catch up with lot of old-timers.</p>
<p>Later in the evening, I was asked to join the panel discussion on “Building a FOSS Ecosystem in India; the role of different players”, and had a chance to meet <a href="http://thelittlesasi.wikidot.com/">Dr. M. Sasikumar</a> (Director, CDAC, Mumbai), <a href="http://www.cse.iitb.ac.in/~siva/">Prof. G. Sivakumar</a> (IIT, Mumbai), V S Raghunathan (Technical Director, <a href="http://www.tn.nic.in/">National Informatics Centre, Tamil Nadu State Centre, Chennai</a>), <a href="http://www.au-kbc.org/cnkpage.htm">Prof. C N Krishnan</a> et. al. A picture of the panel discussion:</p>
<img src="http://shakthimaan.com/downloads/glv/2010/osi-days-2010/osi-days-2010.jpg" alt="FOSS ecosystem panel discussion"></img>]]></description>
    <pubDate>Wed, 22 Sep 2010 00:00:05 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/09/22/OSI-Tech-Days/news.html</guid>
</item>
<item>
    <title>Software Freedom Day, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2010/09/22/SFD-Chennai/news.html</link>
    <description><![CDATA[<p>Attended Software Freedom Day, 2010, at Chennai, on Saturday, September 18, 2010 at Birla Planetarium, organized by <a href="http://www.ilugc.in">ILUGC</a>. <a href="http://www.facebook.com/album.php?aid=38346&amp;id=133359730009404">Photos</a>, courtesy of <a href="http://goinggnu.wordpress.com/">T. Shrinivasan</a>. Two important observations:</p>
<ul>
<li>The number of colleges/universities that participated in the Free/Open Source Software (F/OSS) stalls has increased.</li>
<li>F/OSS awareness programmes are essential, and have their own signficance.</li>
</ul>]]></description>
    <pubDate>Wed, 22 Sep 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/09/22/SFD-Chennai/news.html</guid>
</item>
<item>
    <title>ghc-type-level</title>
    <link>http://www.shakthimaan.com/posts/2010/09/06/ghc-type-level/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/type-level">Type-level</a> programming library is now available on Fedora testing repository. Type-level functions are implemented using functional dependencies of multi parameter type classes. A tutorial on type-level numerals and their usage to implement numerically-parameterized vectors is available at <a href="http://www.ict.kth.se/forsyde/files/tutorial/tutorial.html#FSVec">http://www.ict.kth.se/forsyde/files/tutorial/tutorial.html#FSVec</a>. You can install it on Fedora using:</p>
~~~~ {.shell} $ sudo yum –enablerepo=updates-testing update ghc-type-level ~~~~]]></description>
    <pubDate>Mon, 06 Sep 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/09/06/ghc-type-level/news.html</guid>
</item>
<item>
    <title>Clojure workshop</title>
    <link>http://www.shakthimaan.com/posts/2010/08/30/clojure-workshop/news.html</link>
    <description><![CDATA[<p>A hands-on workshop on <a href="http://clojure.org/">Clojure</a> was organized in <a href="http://www.shakthimaan.com/posts/2010/08/30/clojure-workshop/www.ilughyd.org.in">TwinCLinGs’</a> August months’ meet at <a href="http://www.rhythm.com/india/overview.html">Rhythm &amp; Hues Studios Pvt. Ltd</a>, Hitech City, Hyderabad, India by <a href="http://freegeek.in/blog/">Bhaishampayan Ghose</a>, co-founder and chief geek at <a href="http://infinitelybeta.com/">Infinitely Beta</a>. A picture of the attendees:</p>
<img src="http://shakthimaan.com/downloads/glv/hyd/images/clojure-hyderabad-workshop-aug-29-2010.jpg" alt="clojure meet attendees"></img>
<p>The <a href="http://www.slideshare.net/zaph0d/pune-clojure-course-outline">slides</a> are available. You can install clojure on Fedora using:</p>
<pre class="shell"><code>$ sudo yum install clojure</code></pre>
<p>A clojure programming book is also available at <a href="http://en.wikibooks.org/wiki/Clojure">http://en.wikibooks.org/wiki/Clojure</a> to get started! Thanks to volunteers who sponsored for Bhaishampayan Ghoses’ travel, to and from Pune, India.</p>]]></description>
    <pubDate>Mon, 30 Aug 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/08/30/clojure-workshop/news.html</guid>
</item>
<item>
    <title>KMRF OLPC visit</title>
    <link>http://www.shakthimaan.com/posts/2010/08/22/KMRF-visit/news.html</link>
    <description><![CDATA[<p>Visited <a href="http://www.kmrfoundation.org/">KMRF</a> who needed assistance in installation, troubleshooting, and use of the <a href="http://wiki.laptop.org/go/Home">XO</a> laptops. I had a chance to visit the Government school in Aziznagar, Ranga Reddy district, Andhra Pradesh, India, where they have their XO laptop deployment. Most of the students can speak only in Telugu. They have a chart in the classroom for English-Telugu reference.</p>
<p><img src="http://shakthimaan.com/downloads/glv/hyd/olpc/2-text-reference.jpg" alt="olpc text chart"></img>.</p>
<p><a href="http://www.geekcomix.com/dm/tuxmath/gallery/">Tuxmath</a> was installed, and they enjoy using it a lot:</p>
<img src="http://shakthimaan.com/downloads/glv/hyd/olpc/1-tuxmath.jpg" alt="olpc text chart"></img>]]></description>
    <pubDate>Sun, 22 Aug 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/08/22/KMRF-visit/news.html</guid>
</item>
<item>
    <title>nesC</title>
    <link>http://www.shakthimaan.com/posts/2010/08/17/nesC/news.html</link>
    <description><![CDATA[<p><a href="http://nescc.sourceforge.net/">nesC</a> is now available for Fedora. It is an extension to the C programming language designed for use with <a href="http://www.tinyos.net/">TinyOS</a>, which is used in wireless sensor networks. Install it using:</p>
<pre class="shell"><code>$ sudo yum --enablerepo=updates-testing update nesc</code></pre>
<p>It could not be shipped with Fedora earlier because it used the now deprecated <a href="http://www.opensource.org/licenses/intel-open-source-license.php">Intel Open Source license</a>. Thanks to <a href="http://www.barnowl.org/">David Gay</a> and <a href="http://csl.stanford.edu/~pal/">Philip Levis</a>, it has now been updated with dual BSD/GPL license. There is also support for GNU Emacs with the emacs-nesc package.</p>
<pre class="shell"><code>$ sudo yum --enablerepo=updates-testing update emacs-nesc</code></pre>
<p>Here is a screenshot of GNU Emacs with syntax highlighting in nesc-mode: <img src="http://www.shakthimaan.com/downloads/screenshots/emacs-nesc-screenshot.png" alt="Emacs nesc screenshot"></img></p>]]></description>
    <pubDate>Tue, 17 Aug 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/08/17/nesC/news.html</guid>
</item>
<item>
    <title>Teal</title>
    <link>http://www.shakthimaan.com/posts/2010/08/02/Teal/news.html</link>
    <description><![CDATA[<p><a href="http://www.trusster.com/products/teal/">Teal</a>, the popular verification utility and connection library is now available for Fedora:</p>
<pre class="shell"><code>$ sudo yum install teal</code></pre>
<p>It is a C++ multithreaded library to verify verilog designs. It deals with simulation logging, error reporting, threading, memory model management. It basically provides all the low level building blocks needed to start a verification environment. A simple example:</p>
<pre class="sourceCode cpp"><code class="sourceCode cpp"><span class="ot">#include &lt;teal.h&gt;</span>
<span class="kw">using</span> <span class="kw">namespace</span> teal;
<span class="dt">int</span> verification_top ()
{
  vreg clock (“testbench.clk”);
  vout log (“Chapter <span class="dv">4</span>- Example <span class="dv">1</span>”);
  dictionary::start (“simple_clock_test.txt”);
  <span class="dt">uint</span> number_of_periods (dictionary::find (“number_of_clocks”,<span class="dv">20</span>));
  <span class="kw">for</span> (<span class="dt">int</span> i(<span class="dv">0</span>); i &lt; number_of_periods; ++i)  {
    log &lt;&lt; note &lt;&lt; “i is “ &lt;&lt; i &lt;&lt; clock is &lt;&lt; clock &lt;&lt; endm;
  }
  dictionary::stop ();
  vlog::get (expected) &lt;&lt; “test completed” &lt;&lt; endl;
}</code></pre>
<p>It is released under the Trusster open source license, but, that is incompatible with the GPL. But, thanks to the founders of Trusster.com, <a href="http://www.trusster.com/welcome/about/">Mike Mintz and Robert Ekendahl</a>, who agreed to release the same under the LGPLv2+ and GPLv2+ license for Fedora!</p>]]></description>
    <pubDate>Mon, 02 Aug 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/08/02/Teal/news.html</guid>
</item>
<item>
    <title>Computational Fluid Dynamics General Notation System</title>
    <link>http://www.shakthimaan.com/posts/2010/07/20/CGNS/news.html</link>
    <description><![CDATA[<p>The <a href="http://cgns.sourceforge.net/">Computational Fluid Dynamics General Notation System</a> (CGNS) library is now available in Fedora under the zlib license. Install it using:</p>
<pre class="shell"><code>$ yum install cgnslib</code></pre>
<p>It provides a general, portable, and extensible standard for the storage and retrieval of computational fluid dynamics (CFD) analysis data. It consists of a collection of conventions, and free and open software implementing those conventions. It is self-descriptive, machine-independent, <a href="http://www.grc.nasa.gov/WWW/cgns/user/index.html">well-documented</a>, and administered by an international <a href="http://cgns.sourceforge.net/steering.html">Steering Committee</a>.</p>]]></description>
    <pubDate>Tue, 20 Jul 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/07/20/CGNS/news.html</guid>
</item>
<item>
    <title>Chalmers Lava2000</title>
    <link>http://www.shakthimaan.com/posts/2010/06/30/ghc-chalmers-lava2000/news.html</link>
    <description><![CDATA[<p><a href="http://hackage.haskell.org/package/chalmers-lava2000">Chalmers Lava2000</a>, a hardware description library in Haskell is now available for Fedora. Thanks to <a href="http://www.cse.chalmers.se/~emax/index.html">Emil Axelsson</a> and <a href="http://fedoraproject.org/wiki/JensPetersen">Jens Peterson</a> for their feedback, and package review. You can install the same using:</p>
<pre class="shell"><code>$ sudo yum install ghc-chalmers-lava2000 ghc-chalmers-lava2000-devel ghc-chalmers-lava2000-doc</code></pre>
<p>To illustrate a half adder example with the use of the Lava library, create a Test.hs file:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Lava</span>

halfAdd (a, b) <span class="fu">=</span> (<span class="fu">sum</span>, carry)
  <span class="kw">where</span>
    <span class="fu">sum</span>   <span class="fu">=</span> xor2 (a, b)
    carry <span class="fu">=</span> and2 (a, b)</code></pre>
<p>Load it with ghci (Glasgow Haskell Compiler):</p>
<pre class="shell"><code>$ ghci Test.hs

GHCi, version 6.12.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling Main             ( Test.hs, interpreted )
Ok, modules loaded: Main.</code></pre>
<p>Test half adder with low, high inputs using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> simulate halfAdd(low, high)
<span class="dt">Loading</span> package syb<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base<span class="dv">-3</span><span class="fu">.</span><span class="fl">0.3</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package filepath<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">3</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>time<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">3</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unix<span class="dv">-2</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package directory<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package process<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package random<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package haskell98 <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package chalmers<span class="fu">-</span>lava2000<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
(high,low)
<span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> </code></pre>
<p>Testing half adder with high, high inputs gives:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> simulate halfAdd(high, high)
(low,high)</code></pre>
<p>You can also generate vhdl file using:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">*</span><span class="dt">Main</span><span class="fu">&gt;</span> writeVhdl <span class="st">&quot;halfAdd&quot;</span> halfAdd

<span class="dt">Loading</span> package syb<span class="dv">-0</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package base<span class="dv">-3</span><span class="fu">.</span><span class="fl">0.3</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package array<span class="dv">-0</span><span class="fu">.</span><span class="fl">3.0</span><span class="fu">.</span><span class="dv">0</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package filepath<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.0</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>locale<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package old<span class="fu">-</span>time<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package unix<span class="dv">-2</span><span class="fu">.</span><span class="fl">4.0</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package directory<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package process<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.1</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package time<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.4</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package random<span class="dv">-1</span><span class="fu">.</span><span class="fl">0.0</span><span class="fu">.</span><span class="dv">2</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package haskell98 <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Loading</span> package chalmers<span class="fu">-</span>lava2000<span class="dv">-1</span><span class="fu">.</span><span class="fl">1.1</span> <span class="fu">...</span> linking <span class="fu">...</span> done<span class="fu">.</span>
<span class="dt">Writing</span> to file <span class="st">&quot;halfAdd.vhd&quot;</span> <span class="fu">...</span> <span class="dt">Done</span><span class="fu">.</span></code></pre>
<p>Copy /usr/share/chalmers-lava2000-1.1.1/Vhdl/lava.vhd to your project directory, and you can verify the generated halfAdd.vhd with it using <a href="http://ghdl.free.fr/">ghdl</a>:</p>
<pre class="shell"><code>$ ghdl -a lava.vhd
$ ghdl -a halfAdd.vhd 
$</code></pre>
<p>You are encouraged to read the <a href="http://www.cse.chalmers.se/edu/course/TDA956/Papers/lava-tutorial.ps">“Slightly Revised Tutorial on Lava”</a> by <a href="http://www.chalmers.se/cse/EN/people/claessen-koen">Koen Claessen</a>, and <a href="http://www.cse.chalmers.se/~ms/">Mary Sheeran</a> for more detailed documentation on using the library.</p>]]></description>
    <pubDate>Wed, 30 Jun 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/06/30/ghc-chalmers-lava2000/news.html</guid>
</item>
<item>
    <title>Hardware Complexity Tool</title>
    <link>http://www.shakthimaan.com/posts/2010/06/18/hct/news.html</link>
    <description><![CDATA[<p><a href="http://hct.sourceforge.net/index.html">Hardware Complexity Tool</a> (hct) is now available for Fedora. It generates scores that represent the complexity of the modules of integrated circuit design projects. It uses <a href="http://www.literateprogramming.com/mccabe.pdf">McCabes’ cyclomatic complexity</a> for understanding branch complexity. You can run hct on verilog, vhdl, cdl (computer design language) files or directories that contain these files. For example:</p>
<p>~~~~ {.shell} $ hct verilog Directory: /tmp/verilog</p>
verilog, 18 file(s) +——————–+————–+——+——-+———-+——–+ | FILENAME | MODULE | IO | NET | MCCABE | TIME | +——————–+————–+——+——-+———-+——–+ | Case.v 0 0 18 0.1504 | | case 0 0 18 | +———————————————————————-+ | modules.v 1 0 2 0.0137 | | m1 1 0 1 | | m2 0 0 1 | +———————————————————————-+ | RAM.v 7 0 4 0.1653 | | RAM 7 0 4 | +———————————————————————-+ | hello_world.v 0 0 1 0.0113 | | hello_world 0 0 1 | +———————————————————————-+ | one_day2.v 0 0 2 0.0423 | | one_day2 0 0 2 | +———————————————————————-+ | S430.v 13 4 1 0.2438 | | S430 13 4 1 | +———————————————————————-+ | one_day3.v 0 0 4 0.0305 | | one_day3 0 0 4 | +———————————————————————-+ | first_counter.v 4 3 3 0.0765 | | first<em>~unter 4 3 3 | +———————————————————————-+ | Multiplier.v 7 4 1 0.1646 | | Multiplier 7 4 1 | +———————————————————————-+ | Sys430.v 10 12 9 0.5017 | | Sys430 3 12 5 | | LEDTest 7 0 4 | +———————————————————————-+ | first_counter_tb.v 0 1 1 0.0279 | | first</em>~er_tb 0 1 1 | +———————————————————————-+ | longtest.v 9 5 12 2.1130 | | RAMB16_S9 9 5 12 | +———————————————————————-+ | GPR.v 8 0 3 0.1039 | | GPR 8 0 3 | +———————————————————————-+ | encoder_u~g_case.v 3 0 16 0.1384 | | encode~_case 3 0 16 | +———————————————————————-+ | RAMB16_S9.v 9 5 12 2.0922 | | RAMB16_S9 9 5 12 | +———————————————————————-+ | comment.v 0 0 1 0.0264 | | comment 0 0 1 | +———————————————————————-+ | encoder_using_if.v 3 0 17 0.1941 | | encode~ng_if 3 0 17 | +———————————————————————-+ | MUX2.v 0 0 1 0.0035 | | INV 0 0 1 | +———————————————————————-+ ~~~~]]></description>
    <pubDate>Fri, 18 Jun 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/06/18/hct/news.html</guid>
</item>
<item>
    <title>Dell Vostro 1310 rawhide</title>
    <link>http://www.shakthimaan.com/posts/2010/06/16/dell-vostro-rawhide/news.html</link>
    <description><![CDATA[<p>Have updated my Dell Vostro 1310 to Fedora rawhide. The relevant <a href="http://www.shakthimaan.com/installs/dell-vostro-1310.html">configuration outputs</a> are now made available:</p>
<ul>
<li><a href="http://www.shakthimaan.com/downloads/laptop/dell-vostro-1310/f13/lspci.txt">/sbin/lspci</a></li>
<li><a href="http://www.shakthimaan.com/downloads/laptop/dell-vostro-1310/f13/lsmod.txt">/sbin/lsmod</a></li>
<li><a href="http://www.shakthimaan.com/downloads/laptop/dell-vostro-1310/f13/menu.lst.txt">/boot/grub/menu.lst</a></li>
<li><a href="http://www.shakthimaan.com/downloads/laptop/dell-vostro-1310/f13/dmesg.txt">dmesg</a></li>
</ul>
<p>Updating tcl to tcl-8.5.8-2.fc14 solves <a href="https://bugzilla.redhat.com/show_bug.cgi?id=540296">540296</a>. One can now do:</p>
<pre class="shell"><code>$ tclsh
% package require Tk</code></pre>
<p>Running “mcu8051ide –check-libraries” should now be clean on Fedora:</p>
<pre class="shell"><code>Checking libraries...
	1/9 Checking for library BWidget
		Library present	... YES
		Version 1.7	... YES
	2/9 Checking for library Itcl
		Library present	... YES
		Version 3.4	... YES
	3/9 Checking for library Tcl
		Library present	... YES
		Version 8.2	... YES
	4/9 Checking for library md5
		Library present	... YES
		Version 2.0	... YES
	5/9 Checking for library crc16
		Library present	... YES
		Version 1.1	... YES
	6/9 Checking for library Tk
		Library present	... YES
		Version 8.5	... YES
	7/9 Checking for library img::png
		Library present	... YES
		Version 1.3	... YES
	8/9 Checking for library tdom
		Library present	... YES
		Version 0.8	... YES
	9/9 Checking for library Tclx
		Library present	... YES
		Version 8.0	... YES
RESULTS:
	Number of fails: 0
	Everything seems ok</code></pre>
<p>Pushed recent <a href="http://mcu8051ide.sf.net">mcu8051ide</a> 1.3.7 and <a href="http://vrq.sf.net">vrq</a> 1.0.76 to Fedora repository.</p>]]></description>
    <pubDate>Wed, 16 Jun 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/06/16/dell-vostro-rawhide/news.html</guid>
</item>
<item>
    <title>Blender workshop</title>
    <link>http://www.shakthimaan.com/posts/2010/05/17/blender-workshop/news.html</link>
    <description><![CDATA[<p>Attended May months’ <a href="http://ilughyd.org.in/">Hyderabad user group</a> meeting on Sunday, May 16, 2010 at:</p>
<pre class="shell"><code>Rhythm &amp; Hues Studios India Pvt. Ltd.
The V, Vega Block, 11th Floor,
Left Wing, Plot No - 17, Software Units layout
HITEC City, Madhapur, 
Hyderabad 500 081
India</code></pre>
<p>Satish “iloveblender” Goda gave a very informative talk about the history of the <a href="http://www.blender.org/">Blender</a> project, <a href="http://www.blender.org/features-gallery/blender-open-projects/">animation movies created</a> using the Blender software, pipelines involved in animation movie production, and on how the blender community functions in producing open animation movies with the guidance of <a href="http://www.blender.org/blenderorg/blender-foundation/history/">Ton Roosendaal</a>.</p>
<p>Their open animation movie projects are code named after names of fruits. One interesting aspect is that before starting on a new movie project, one can pay and pre-order the DVD, and your name is added to the credits when the movie is released. This funding also helps the team in producing the movie!</p>
<p>Thanks to the Management of Rhythm &amp; Hues Studios India Pvt. Ltd. for hosting our user group meet at their auditorium. Special thanks to “cheedhu” and “iloveblender” for initiating the effort. We hope to have more sessions of blender and other F/OSS sessions at this venue.</p>
<p>A photo taken at the end of the session:</p>
<img src="http://shakthimaan.com/downloads/glv/hyd/blender-hyderabad-meet-may-16-2010.png" alt></img>]]></description>
    <pubDate>Mon, 17 May 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/05/17/blender-workshop/news.html</guid>
</item>
<item>
    <title>Sreenidhi-KMRF OLPC visit</title>
    <link>http://www.shakthimaan.com/posts/2010/05/08/Sreenidhi-KMRF/news.html</link>
    <description><![CDATA[<p>Visited <a href="http://www.sreenidhiinternational.com/">Sreenidhi International School</a> and members of the <a href="http://www.kmrfoundation.org/">KMR Foundation</a> today, Saturday, May 8, 2010 in Hyderabad. They have <a href="http://laptop.org/en/">OLPC</a> XOs that they are using for class(grade) IV students in a school near their premises at Aziznagar, Ranga Reddy district, Andhra Pradesh, India. They require support for Telugu language and use of XO software for the school students. Here is a screenshot of one of the XOs:</p>
<img alt="olpc xo" src="http://shakthimaan.com/downloads/glv/hyd/olpc/olpc-xo.png"></img>]]></description>
    <pubDate>Sat, 08 May 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/05/08/Sreenidhi-KMRF/news.html</guid>
</item>
<item>
    <title>perl-Sys-CPU</title>
    <link>http://www.shakthimaan.com/posts/2010/05/07/perl-Sys-CPU/news.html</link>
    <description><![CDATA[<p>Pushed <a href="http://search.cpan.org/~mkoderer/Sys-CPU/CPU.pm/">perl-Sys-CPU</a> to Fedora repository. You can use it like:</p>
<p>~~~~ {.perl} use Sys::CPU;</p>
<p>$number_of_cpus = Sys::CPU::cpu_count(); printf(“I have %d CPU’s”, $number_of_cpus);</p>
print &quot; Speed : “, Sys::CPU::cpu_clock(),”“; print” Type : “, Sys::CPU::cpu_type(),”&quot;; ~~~~]]></description>
    <pubDate>Fri, 07 May 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/05/07/perl-Sys-CPU/news.html</guid>
</item>
<item>
    <title>LaTeX \newcommand</title>
    <link>http://www.shakthimaan.com/posts/2010/04/21/latex-newcommand/news.html</link>
    <description><![CDATA[<p>Used \newcommand to abstract the four actor names in <a href="http://shakthimaan.com/downloads.html#di-git-ally-managing-love-letters">di-git-ally managing love letters</a> presentation:</p>
<pre class="sourceCode latex"><code class="sourceCode latex">\newcommand{\oneactor}{pretty-zinta}
\newcommand{\twoactor}{raaani-mukerji}
\newcommand{\threeactor}{nayantaaara}
\newcommand{\fouractor}{aishvarya-ray}</code></pre>
<p>You can now get the <a href="http://gitorious.org/di-git-ally-managing-love-letters">sources from gitorious</a>, and replace the above names to your liking, and rebuild the presentation by invoking <em>make</em> from the sources directory.</p>
<pre class="shell"><code>$ git clone git://gitorious.org/di-git-ally-managing-love-letters/mainline.git</code></pre>]]></description>
    <pubDate>Wed, 21 Apr 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/04/21/latex-newcommand/news.html</guid>
</item>
<item>
    <title>Jyväskylä, Finland</title>
    <link>http://www.shakthimaan.com/posts/2010/02/20/Jyvaskyla-Finland/news.html</link>
    <description><![CDATA[<img alt="Office building" src="http://www.shakthimaan.com/Mambo/gallery/albums/album61/4_jyvaskyla_office_building.jpg"></img><br />
<img alt="Dinner with colleagues" src="http://www.shakthimaan.com/Mambo/gallery/albums/album61/34_work_colleagues_at_restaurant.jpg"></img><br />
<img alt="At ski resort" src="http://www.shakthimaan.com/Mambo/gallery/albums/album61/44_high_speed_blind_ski_turn.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album61">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 20 Feb 2010 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/02/20/Jyvaskyla-Finland/news.html</guid>
</item>
<item>
    <title>KMRF OLPC</title>
    <link>http://www.shakthimaan.com/posts/2010/01/22/KMRF/news.html</link>
    <description><![CDATA[<p>We will be initiating olpc, Hyderabad for content creation (Telugu) and to support the students, faculty and staff at <a href="http://www.kmrfoundation.org/">KMRF</a> who need assistance. Thanks to my good friend, <a href="http://verma.sfsu.edu/index.php">Dr. Sameer Verma</a> for coordinating with me last few months in this regard. <a href="http://cob.sfsu.edu/cob/directory/faculty_profile.cfm?facid=416">Prof. Humaira Mahi</a> will be having a field deployment through <a href="http://www.kmrfoundation.org/">KMR Foundation</a>. Please do write to me if you are interested in helping them in Hyderabad.</p>]]></description>
    <pubDate>Fri, 22 Jan 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/01/22/KMRF/news.html</guid>
</item>
<item>
    <title>Sandwitch?</title>
    <link>http://www.shakthimaan.com/posts/2010/01/20/sandwitch/news.html</link>
    <description><![CDATA[<p>Witch one did you ask for? at Chennai domestic airport.</p>
<img alt="MAA airport witch" src="http://shakthimaan.com/downloads/clips/maa-airport-witch.jpg"></img>]]></description>
    <pubDate>Wed, 20 Jan 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/01/20/sandwitch/news.html</guid>
</item>
<item>
    <title>Digital Gate Compiler</title>
    <link>http://www.shakthimaan.com/posts/2010/01/12/dgc/news.html</link>
    <description><![CDATA[<p><a href="http://sourceforge.net/projects/dgc/">Digital Gate Compiler (DGC)</a> was written by Oliver Kraus in 2003, who is not with <a href="http://www.uni-erlangen.de/">Universität Erlangen-Nürnberg</a> anymore. The current maintainer of the project is <a href="http://www.lzs.eei.uni-erlangen.de/Mitarbeiter/Dichtl">Tobias Dichtl</a>. His line of scientific research is not the same as that of DGC, but, he said he will be adding “extended burst mode synthesis support” this year. Meanwhile, I had updated the sources with autotools build changes, and released 0.98 for Fedora. The updated changes are available at <a href="http://git.fedorahosted.org/git/dgc.git">dgc.git Fedora Hosted repository</a>.</p>]]></description>
    <pubDate>Tue, 12 Jan 2010 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2010/01/12/dgc/news.html</guid>
</item>
<item>
    <title>LXDE on Asus EEE PC</title>
    <link>http://www.shakthimaan.com/posts/2009/12/29/lxde-on-asue-eee-pc/news.html</link>
    <description><![CDATA[<p>Installed livecd-tools, used livecd-iso-to-disk to write F12 LXDE spin to a USB disk, and used it to boot a Asus EEE PC:</p>
<pre class="shell"><code># yum install livecd-tools</code></pre>
<p><img src="http://shakthimaan.com/downloads/clips/asus_eee_pc_f12_lxde.jpg" alt="Fedora 12 LXDE from USB disk"></img>.</p>]]></description>
    <pubDate>Tue, 29 Dec 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/12/29/lxde-on-asue-eee-pc/news.html</guid>
</item>
<item>
    <title>Fedora workshop, Maharaja Sayajirao University of Baroda</title>
    <link>http://www.shakthimaan.com/posts/2009/12/28/fedora-workshop-msu-baroda/news.html</link>
    <description><![CDATA[<p>I had conducted a one-day Fedora, Free Software workshop at the Bachelor of Computer Applications department, Maharaja Sayajirao University of Baroda (Vadodara), Gujarat, India on Saturday, December 26, 2009.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album60/3a_telescope_dome.jpg" alt="MSU, Baroda"></img>
<p>Thanks to <a href="http://www.vglug.info">VGLUG</a> for coordinating with me for the past few months in organizing this event. I would like to thank the Fedora project for sponsoring the travel.</p>
<p>The BCA department lab systems were equipped to run on Fedora 12, and we used it for couple of the hands-on sessions:</p>
<ul>
<li>Use of git: <a href="http://shakthimaan.com/downloads/glv/presentations/di-git-ally-managing-love-letters.pdf">di-git-ally managing love letters</a>.</li>
<li><a href="http://shakthimaan.com/downloads/glv/presentations/packaging-red-hot-paneer-butter-masala.pdf">Packaging Fedora RPM</a>.</li>
</ul>
<p>I had also addressed the following topics:</p>
<ul>
<li><a href="http://www.shakthimaan.com/downloads/glv/presentations/i-want-2-do-project-tell-me-wat-2-do-fedora.pdf">i-want-2-do-project. tell-me-wat-2-do-fedora</a>.</li>
<li><a href="http://www.shakthimaan.com/downloads/glv/presentations/badam.halwa.of.embedded.systems.pdf">Badam Halwa of Embedded Systems</a>.</li>
</ul>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album60/9_git_session_in_progress.jpg" alt="Git session"></img>
<p>Participants were from the BCA department, and had also come from <a href="http://wikitravel.org/en/Ahmedabad">Ahmedabad</a>. Vadodara (Baroda) connects to Ahmedabad via 95 km <a href="http://en.wikipedia.org/wiki/Indian_National_Expressway_1">National Expressway 1</a>.</p>
<p>Free/Open Source Software is officially included in the Gujarat state school syllabus for higher secondary (XI and XII). In the coming years it is expected to be even introduced from standard VIII.</p>
<p>The Department coordinator and Professor V A Kalamkar is happy to facilitate work between VGLUG, and the students for Free/Open Source Software projects. We hope to have more interaction with them in the future.</p>
<p>VGLUG members are also keen on participating in the Fedora project at various sub-projects of their interests.</p>
<p>Due to the <a href="http://beta.thehindu.com/news/national/article69789.ece">political crisis</a> in Hyderabad, I was uncertain about reaching the Hyderabad airport, and thus making it to the workshop. The bandh was withdrawn for December 25th, and when I made it the airport on the 25th, the scheduled flight was cancelled. So, I had to re-schedule a different flight, but, the airline officials said they couldn’t guarantee if I will make it to my connecting flight in Mumbai. This re-scheduled flight got delayed even further. Luckily, my connecting flight also got delayed, and I finally managed to make it to Vadodara.</p>
<p>As customary, here are some <a href="http://www.shakthimaan.com/Mambo/gallery/album60">photos</a> taken during the trip.</p>]]></description>
    <pubDate>Mon, 28 Dec 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/12/28/fedora-workshop-msu-baroda/news.html</guid>
</item>
<item>
    <title>Poky scripts</title>
    <link>http://www.shakthimaan.com/posts/2009/12/22/poky-scripts/news.html</link>
    <description><![CDATA[<p>Pushed poky-scripts to Fedora repository. <a href="http://pokylinux.org/">Poky</a> is a platform builder tool written in Python that allows you to build toolchains, kernels, rootfs images for different target hardware. Use:</p>
<pre class="shell"><code># yum install poky-scripts</code></pre>
<p>You can test run <a href="http://pokylinux.org/releases/pinky-3.1/">pre-built images</a>, for example from Pinky (3.1.x) releases:</p>
<pre class="shell"><code>$ poky-qemu zImage-2.6.23-pinky-3.1-qemuarm.bin poky-image-sdk-qemuarm-pinky-3.1.rootfs.ext2</code></pre>
<img src="http://shakthimaan.com/downloads/clips/poky-pinky-qemu-arm-screenshot.png" alt="Poky QEMU ARM screenshot"></img>
<p>If you want to build your complete environment, you need to download the latest Poky stable release 3.2.x ‘Purple’ (latest) and extract it to ~/devel. Make sure you have a broadband connection and atleast 3G of disk space as the scripts will fetch, build everything from toolchains, kernels, user space applications. Follow the <a href="http://pokylinux.org/support/">Poky handbook</a> which is very well documented. Supported reference platforms include (to mention a few):</p>
<ul>
<li>Intel Atom devices</li>
<li>Compulab cm-x270 and em-x270</li>
<li>Freescale MX31</li>
<li>ST Nomadik</li>
<li>Marvell Zylonite</li>
<li>QEMU ARM and x86</li>
</ul>]]></description>
    <pubDate>Tue, 22 Dec 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/12/22/poky-scripts/news.html</guid>
</item>
<item>
    <title>FedX</title>
    <link>http://www.shakthimaan.com/posts/2009/12/12/FedX/news.html</link>
    <description><![CDATA[<p>Downloaded Fedora 12 (i386) mirror using <a href="http://gitorious.org/fedx">FedX</a>, written by <a href="http://ratnadeepdebnath.wordpress.com/">Ratnadeep Debnath</a> and myself. I have updated it to rsync from a mirror to a local copy as well as from an external disk to a local directory.</p>
<pre class="shell"><code>  $ git clone git://gitorious.org/fedx/mainline.git</code></pre>
<ul>
<li>Fedora 11 (i386) with rpmfusion repository = 29 GB</li>
<li>Fedora 12 (i386) with rpmfusion repository = 23 GB</li>
</ul>
<p>I assume that this drastic size reduction is due to the switch from gzip compression to XZ (LZMA format). Please refer <a href="https://fedoraproject.org/wiki/Features/XZRpmPayloads">XZRpmPayloads</a> (when the site is back up and running). This Fedora offline repository is very handy when working offline, or when it is required to install packages when using slow Internet connectivity speeds.</p>]]></description>
    <pubDate>Sat, 12 Dec 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/12/12/FedX/news.html</guid>
</item>
<item>
    <title>Sparcy</title>
    <link>http://www.shakthimaan.com/posts/2009/12/06/sparcy/news.html</link>
    <description><![CDATA[<p>Bought the GDL3204 GPS data logger from Sparc Systems Ltd, Mumbai, India for INR 7500 (taxes and shipping charges additional). They use <a href="http://www.gpleda.org/">gEDA (GPL Electronic Design Automation)</a> and <a href="http://pcb.gpleda.org/index.html">Printed Circuit Board (PCB)</a> for their work, and I thought I should support them by buying a unit.</p>
<img src="http://shakthimaan.com/downloads/hardware/GDL3204.jpg" alt="GLD3204 GPS data logger"></img>
<p>It has a serial interface to connect to a computer, and can store 74000 track points on a 4MB non-volatile memory. It can be used for <a href="http://www.openstreetmap.org/">openstreetmap</a> work. You can use the sparcy (command line tool) with it from Fedora.</p>
~~~~ {.shell} # yum install sparcy ~~~~]]></description>
    <pubDate>Sun, 06 Dec 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/12/06/sparcy/news.html</guid>
</item>
<item>
    <title>The Lost Chronicles</title>
    <link>http://www.shakthimaan.com/posts/2009/11/03/the-lost-chronicles/news.html</link>
    <description><![CDATA[<p>We approach technical advisor X and assistant professor Y for a F/OSS unconference at a premier International Institute, and they never respond for weeks. Apparently, we knew the Head of the Institute, who whole-heartedly agrees, having been a user group member during his college years, and asks X and Y to take things further.</p>
<p>Now, X and Y are upset, because we approached the Head of the Institute, and permission was granted. Then X and Y show off their ego, presence, and reciprocate by not communicating at all our requests. Weeks go by, and we still don’t get any prompt response. And we decide to finally call it off with them because it was not helping us progress any further.</p>
<p>End result is that the students/faculty of the Institute are at a big loss for not having the event at their venue for no fault of theirs!</p>
<p>While, I have seen such extreme <em>ego</em> cases in India in most of my attempts to organize Free Software unconferences, I have never shared it with others. Maybe I should write a book – The Adventures of Shakthimaan: The “Lost” Chronicles :)</p>]]></description>
    <pubDate>Tue, 03 Nov 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/11/03/the-lost-chronicles/news.html</guid>
</item>
<item>
    <title>Beam Telecom uses Joomla</title>
    <link>http://www.shakthimaan.com/posts/2009/10/03/beam-telecom-joomla/news.html</link>
    <description><![CDATA[<p><a href="http://beamcablesystem.in/">Beam Telecom</a> (formerly Beam Cable), a popular ISP in Madhapur, Hi-tech area at Hyderabad is <a href="http://shakthimaan.com/downloads/clips/beam-cable-using-joomla.png">using Joomla</a> for their portal. This screenshot was taken before they fixed their database migration :)</p>
<img src="http://shakthimaan.com/downloads/clips/beam-cable-using-joomla.png" alt="Beam Telecom using Joomla"></img>]]></description>
    <pubDate>Sat, 03 Oct 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/10/03/beam-telecom-joomla/news.html</guid>
</item>
<item>
    <title>Software Freedom Day, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2009/09/19/SFD-Hyderabad/news.html</link>
    <description><![CDATA[<p>On September 19, 2009, Software Freedom Day at Hyderabad, I visited Devnar Foundation for the Blind, a follow-up to last weekends’ installation.</p>
<p>Most of their systems have been donated. So, there are different motherboards, and brands. Apparently, the local AMC support guy who had come today didn’t have drivers for different proprietary OSes, and for different motherboards. I then migrated their office computers to Fedora 11 :)</p>
<p>Now, they have HCL, Wipro computers running Fedora. I have disabled many start-up services, to boot the systems faster. I also adjusted Orca pitch, rate settings for clarity. It should take them some time to get accustomed to the American accent.</p>
<p>Thanks to Prof. Haasan, Department of Astronomy, Osmania University, I have deployed Fedora 11 repository (29 GB) at one of their department systems.</p>
<p>They are interested in creating a Fedora Spin for Astronomy, and release it, as this is the <a href="http://www.astronomy2009.org">International Year of Astronomy</a>. I have provided Rahul Sundarams’ e-mail contact to them.</p>]]></description>
    <pubDate>Sat, 19 Sep 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/09/19/SFD-Hyderabad/news.html</guid>
</item>
<item>
    <title>Devnar Foundation for the Blind</title>
    <link>http://www.shakthimaan.com/posts/2009/09/13/Devnar-Foundation-for-the-Blind/news.html</link>
    <description><![CDATA[<p>Today, Sunday, September 13, 2009, I deployed Fedora 11, and Fedora 11 offline repository at Devnar Foundation for the Blind, Mayurmarg, Begumpet, Hyderabad, India.</p>
<p>They have been using a proprietary software on a proprietary system, and wanted to explore better alternatives in this regard.</p>
<p>I was given a 256 MB RAM system, with 40 GB hard-disk. This system did not have Internet connectivity. The offline repository really helped. Most of the systems are donated by companies for the school to use. The school follows the Andhra Pradesh State syllabus, and this year they have introduced Intermediate (after Board X). They write their exams on slate or on Braille paper (which I believe, is very expensive). Some students stay in the school hostel, while others’ are day scholars.</p>
<p>They do have one <a href="http://mountbattenbrailler.com/">MountBatten Brailler</a> (costing around 1,00,000 INR) which can produce output to a computer or a printer. It also spells out the input. I didn’t have time to test it with Fedora (serial, parallel ports).</p>
<p>A junior teacher, Miss. Shashi, did try out <a href="http://live.gnome.org/Orca">Orca</a> with the Gnome shortcut keys, listening to Orcas’ audio output. She was able to navigate through the Gnome menus, and use Openoffice.org Writer. They did want spoken American English, which is default in Gnome. It will be good to have those Orca audio recorded in Telugu or other regional languages in India.</p>
<p>There were some very interesting questions like:</p>
<ul>
<li><p>Orca loads only after logging in – which spells out menus, the frame window that is selected, keys pressed etc. So, grub which loads prior to all these doesn’t announce the choice of kernel. So, how does one choose the right kernel?</p></li>
<li><p>A sound can be played after gdm loads? Otherwise, they wouldn’t know if the system booted to gdm or not. If there are multiple user accounts, some application need to spell-out the login names?</p></li>
<li><p>By default there is no shutdown sound in Fedora 11? How to set one?</p></li>
<li><p>Some applications pop-up menus didn’t support tab feature, so one had to remember to use shortcuts like Alt+S to Save, or Alt+C to Cancel.</p></li>
</ul>
<p>I shall check these requests with the Orca project team, and any other queries that they might have as follow-ups.</p>
<p>I would like to thank Padma Shri Dr. A. Saibaba Goud for giving me an opportunity to deploy the solution at their school. Thanks to Rakesh (“arky”) Ambati for introducing me to them, who also works for <a href="http://www.braillewithoutborders.org/ENGLISH/index.html">Braille Without Borders</a>. Eric Ofori from South Africa will be following it up with support for the school staff (about 40 in number). If anyone who is coming to Hyderabad and who would like to help them, please do contact me offline.</p>
<p>With all due respect to the physically challenged, I did not take any photos.</p>]]></description>
    <pubDate>Sun, 13 Sep 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/09/13/Devnar-Foundation-for-the-Blind/news.html</guid>
</item>
<item>
    <title>Fedora workshop, ACE College</title>
    <link>http://www.shakthimaan.com/posts/2009/08/22/Fedora-workshop-ACE-College/news.html</link>
    <description><![CDATA[<p>Today, Saturday, August 22, 2009, I conducted a Fedora workshop at <a href="http://aceec.ac.in/">ACE College of Engineering</a>, Ankushapur, <a href="http://en.wikipedia.org/wiki/Ghatkesar">Ghatkesar</a> Mandal, Ranga Reddy District, Andhra Pradesh, India.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album58/3_ace_college.jpg" alt="ACE college"></img>
<p>I have addressed “i-want-2-do-project. tell-me-wat-2-do-fedora”, “Packaging RPM”, “Badam Halwa of Embedded Systems” <a href="http://shakthimaan.com/downloads.html">presentations</a>. The attendees were Computer Science and Information Technology Department students, and faculty. I would like to thank Mrs. K. Jaya Bharathi, Head of the Computer Science Department, for coordinating with me for the past one month in organizing this workshop.</p>
<p>They don’t yet have a Fedora Lab. I have provided them with Fedora 10, 11 repositories for their offline use (53 GB). I have also given them Fedora 10, 11 DVDs.</p>
<p>Ghatkesar is 25 km from Hyderabad, and one hour drive from Hyderabad through <a href="http://en.wikipedia.org/wiki/National_Highway_7_%28India%29">NH-7</a>.</p>
<p>As customary, here are some <a href="http://www.shakthimaan.com/Mambo/gallery/album58">pictures</a> taken during the visit.</p>]]></description>
    <pubDate>Sat, 22 Aug 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/08/22/Fedora-workshop-ACE-College/news.html</guid>
</item>
<item>
    <title>GNUtsav, NIT, Agartala</title>
    <link>http://www.shakthimaan.com/posts/2009/07/20/GNUtsav-NIT-Agartala/news.html</link>
    <description><![CDATA[<p>I had conducted a Fedora workshop (“GNUtsav”) at National Institute of Technology (NIT), <a href="http://groups.google.co.in/group/nitalug
">Agartala</a>, Tripura, India on July 18-19, 2009.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album57/4_banner.jpg" alt="GNUtsav poster"></img>
<p>I would like to thank the Fedora project for sponsoring the event. Special thanks to the student volunteers who worked hard in organizing the event. Mention must be made for the support of the faculty, Prof. Swapan Debbarma, Prof. Anupam Jamatia (“ajnr” on freenode), and Prof. Dwijen Rudrapal.</p>
<p>My presentation sessions included:</p>
<ul>
<li>i-want-2-do-project. tell-me-wat-2-do-fedora.</li>
<li>Badam Halwa of Embedded Systems</li>
<li>di-git-ally managing love letters</li>
<li>Fedora Electronic Lab (demo)</li>
<li>Packaging RPM – Red hot, Paneer (butter) Masala</li>
</ul>
<p>The presentations are available from <a href="http://www.shakthimaan.com/downloads.html">http://www.shakthimaan.com/downloads.html</a></p>
<p>It has only been two years since this Institution has started. It is 25 km from Agartala city. The Institute has 50% reservation for State students, and 50% for students coming through an All India Engineering Entrance Examination. People speak Hindi, English, Bengali, and Kokborok.</p>
<p>Guwahati, Assam is the main connectivity for this part of the world, or, flying from Kolkatta, West Bengal is the other option. Subsidized rate flights are available from major domestic carriers in India. Helicopter service between North-Eastern States is also available, but, is expensive. Bus journey from Guwahati, Assam to Agartala, Tripura is very tedious, and might take atleast 24 hours. When passing through the dense forests, <a href="http://en.wikipedia.org/wiki/Central_Reserve_Police_Force">CPRF</a> escort is required due to insurgency problems in forest areas.</p>
<p>Students have access to distros at the labs, as well as in the hostel. Power cuts are quite common here. Mobile cell coverage is nil or works at only few places. Internet connectivity is nil or very slow on campus. Hence, we have provided them with an offline Fedora 10 repository (around 24 GB) that they can use in their computers or in the LAN. Special thanks also goes to <a href="http://dgplug.org/intro/">dgplug user group</a> from Durgapur, West Bengal for the offline repos. There are few browsing centers in the city that students can use, but have to travel the distance from the campus. Work is in progress to provide students with a Fedora 11 repository.</p>
<p>Agartala is a very scenic, lush green, and very peaceful place. Hopefully when the construction work on campus is completed in the next six months, they will be better equipped with Internet access for communicating online, and for VoIP sessions.</p>
<p>As customary, here are few <a href="http://www.shakthimaan.com/Mambo/gallery/album57 ">photos</a> that I took during the trip.</p>]]></description>
    <pubDate>Mon, 20 Jul 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/07/20/GNUtsav-NIT-Agartala/news.html</guid>
</item>
<item>
    <title>Fosjam.in, Jaipur</title>
    <link>http://www.shakthimaan.com/posts/2009/05/18/fosjam-jaipur/news.html</link>
    <description><![CDATA[<p>I would like to thank the Free/Open Source Software <a href="http://lugj.in">user group members of Jaipur</a> and the Jaipur Engineering College and Research Centre Foundation for organizing http://fosjam.in between May 16-17, 2009 at their college premises, Jaipur, Rajasthan, India.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album56/7_fosjam_poster.jpg" alt="fosjam poster"></img>
<p>The event has been organized in 10 days time, with heavy discussions on #lug-jaipur on irc.freenode.net. I was overwhelmed by the enthusiasm of the students. The online registration rose to 280+.</p>
<p>We had students coming from outside Jaipur as well, and it was a mad rush. The organizers didn’t have the heart to say “no”, but, they still managed to accommodate 200 people. This, I assume, is the first time that this kinda workshop has been planned at this place. People, there is no need to panic! It is not the end of the world, yet, and this is not the last workshop that we are going to do in Jaipur.</p>
<p>The profiles of the user group members are at http://fosjam.in/about/about-lug-jaipur.</p>
<p>Special thanks to all of them for their energy, spirit, dynamism in organizing the event.</p>
<p>I also met students from Malaviya National Institute of Technology, (MNIT), Swami Keshvanand Institute of Technology (SKIT), Gyan Vihar Institute of Technology et. al.</p>
<p>It was a pleasure to meet the Director of the Institution, Mr. Arpit Agarwal, a young, open-minded entrepreneur, who was very happy and eager to hear students talking about Free/Open Source. His continued support for this cause, is greatly appreciated. He is happy to help us in organizing more workshops for the young minds, or even a national FOSS unconference in Jaipur!</p>
<p>There are about 17+ colleges around Jaipur, and workshops have to be taken to other places like Kota, Udaipur, Jodhpur, Bikaner et. al. Most of them are affiliated to Rajasthan Technical University (RTU).</p>
<p>Some students are fluent in English. Most of them prefer to converse in Hindi. Of course, technical jargon is in English. So, it is mostly <a href="http://en.wikipedia.org/wiki/Hinglish">Hinglish</a>.</p>
<p>A separate IRC session was organized to show people how to login and use IRC.</p>
<p>Lot of them use Fedora or some distribution, and are extremely happy with it. Those who enjoy it have realized the power of Free/Open Source Software. The others have started to realize that there is something important here that they can work with.</p>
<p>My presentations, code, documentation are available at <a href="http://www.shakthimaan.com/downloads.html">http://www.shakthimaan.com/downloads.html</a>.</p>
<p>Some photos taken during the trip are at <a href="http://www.shakthimaan.com/Mambo/gallery/album56">http://www.shakthimaan.com/Mambo/gallery/album56</a></p>
<p>The organizers could possible provide more concrete statistics on the event. Please bear for some time for people to get back their sleep, and you will hear more from blogs, event reports, photos.</p>]]></description>
    <pubDate>Mon, 18 May 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/05/18/fosjam-jaipur/news.html</guid>
</item>
<item>
    <title>Fedora workshop, NBKR Institute</title>
    <link>http://www.shakthimaan.com/posts/2009/05/02/fedora-workshop-nbkr/news.html</link>
    <description><![CDATA[<p>I addressed the following topics for a Free Software workshop at NBKR Institute of Science and Technology, Vidyanagar, Nellore district, Andhra Pradesh, India on Saturday, May 2, 2009:</p>
<ul>
<li>Career opportunities with Free Software</li>
<li>i-want-2-do-project. tell-me-wat-2-fedora</li>
<li>Mailing list guidelines</li>
<li>Communication guidelines</li>
<li>Fedora sub-projects</li>
<li>Embedded Systems concepts</li>
</ul>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album55/11_audience.png" alt="Audience"></img>
<p>I would like to thank Rajesh Sola, Lecturer, for organizing the workshop, and for coordinating with me for the past couple of months for this workshop.</p>
<p>The CS labs have Fedora installed. I have given them Fedora 10 DVDs and stickers (thanks to Rahul Sundaram) which they can distribute to other engineering departments.</p>
<p>Pointers to fedora mailing lists, IRCs have been given to the students.</p>
<p>Some photos taken during this trip and at the venue are available at: <a href="http://www.shakthimaan.com/Mambo/gallery/album55">http://www.shakthimaan.com/Mambo/gallery/album55</a>.</p>]]></description>
    <pubDate>Sat, 02 May 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/05/02/fedora-workshop-nbkr/news.html</guid>
</item>
<item>
    <title>gEDA workshop, GEC, Barton Hill</title>
    <link>http://www.shakthimaan.com/posts/2009/03/23/geda-workshop-gec-barton-hill/news.html</link>
    <description><![CDATA[<p>I would like to thank Prof. Ranjith Kumar, Department of Mechanical Engineering, Government Engineering College (GEC), Barton Hill, Thiruvananthapuram, Kerala, India for coordinating with me for the past one month for the National Seminar event on Embedded Design with GNU/Linux that was held on Saturday, March 21, 2009 <a href="http://fsc.gecbh.ac.in/">http://fsc.gecbh.ac.in</a>.</p>
<img src="http://www.shakthimaan.com/Mambo/gallery/albums/album54/13_poster.png" alt="Poster"></img>
<p>I would also like to thank the Directorate of Technical Education, and Kerala State Council for Science, Technology, and Environment for organizing the event.</p>
<p>I discussed basic concepts of embedded systems, and gave a demo of gEDA tools suite (gschem, pcb, qucs, iverilog, gtkwave) on Fedora 10.</p>
<p>Some photos taken during the visit are available at: <a href="http://www.shakthimaan.com/Mambo/gallery/album54">http://www.shakthimaan.com/Mambo/gallery/album54</a></p>]]></description>
    <pubDate>Mon, 23 Mar 2009 00:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/03/23/geda-workshop-gec-barton-hill/news.html</guid>
</item>
<item>
    <title>Badam Halwa of Embedded Systems, FOSSConf 2009, Madurai</title>
    <link>http://www.shakthimaan.com/posts/2009/02/28/badam-halwa-embedded-fossconf/news.html</link>
    <description><![CDATA[<p>I would like to thank the organizers, sponsors of fossconf.in 2009, students, faculty, ILUGC members and well-wishers for a wonderful event. It was good to catch up with lot of ILUGC members after a really long time!</p>
<img alt="stage banner" src="http://www.shakthimaan.com/Mambo/gallery/albums/album53/6_stage_banner.jpg"></img><br />
<p>Please find my presentation slides on “Badam Halwa of Embedded Systems” at: <a href="http://shakthimaan.com/downloads/glv/presentations/badam.halwa.of.embedded.systems.odp">[odp]</a><a href="http://shakthimaan.com/downloads/glv/presentations/badam.halwa.of.embedded.systems.pdf">[pdf]</a></p>
<p>Few photos that I took are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album53">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 28 Feb 2009 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2009/02/28/badam-halwa-embedded-fossconf/news.html</guid>
</item>
<item>
    <title>Göteborg, Sweden</title>
    <link>http://www.shakthimaan.com/posts/2008/10/25/goteborg-sweden/news.html</link>
    <description><![CDATA[<img alt="Stora Nygatan" src="http://www.shakthimaan.com/Mambo/gallery/albums/album52/9_stora_nygatan.jpg"></img><br />
<img alt="Lindholmen" src="http://www.shakthimaan.com/Mambo/gallery/albums/album52/8_lindholmen.jpg"></img><br />
<img alt="Sanatoriegatan" src="http://www.shakthimaan.com/Mambo/gallery/albums/album52/13_sanatoriegatan.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album52">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 25 Oct 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/10/25/goteborg-sweden/news.html</guid>
</item>
<item>
    <title>Emacs a day keeps the vi-zing away, Osmania University, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2008/10/18/emacs-session-osmania/news.html</link>
    <description><![CDATA[<p>Thanks to all those who attended the FOSS session on “Emacs a day keeps the vi-zing away” on Saturday, October 18, 2008 at <a href="http://www.osmania.ac.in/Science%20College/Astronomy1.htm">Department of Astronomy, Osmania University</a>.</p>
<p>The key bindings used in the session are available at <a href="http://shakthimaan.com/downloads/glv/hyd/emacs-a-day-keeps-the-vi-zing-away.txt">emacs-a-day-keeps-the-vi-zing-away.txt</a></p>
<p>Eighteen people attended the session. We explained few key bindings, and then the participants tried it out on their systems. If they got stuck, then we helped them out. We waited for everyone to get the commands working on their system, before moving to the next set of key bindings. No-one is left behind :)</p>
<p>Those who didn’t know keyboard typing, had to search for the keys, most of the time. When they finally did, they were not looking at the monitor to see the output, because they were keen on typing the keys correctly! It will take them some time and practice to get used to it.</p>
<p>Most of them were able to understand the commands and try it out by themselves though. It was good to see some hands-on experience in the labs.</p>
<p>Nikhil suggested on doing a vim session, and I welcome the same. I’d encourage anyone to come forward to take sessions, or make requests to the group.</p>
<p>Thanks to Prof. Hasan for arranging the labs for the session. He suggested inviting the adjacent Mathematics Department students in future sessions. They are in the process of setting up another lab too.</p>]]></description>
    <pubDate>Sat, 18 Oct 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/10/18/emacs-session-osmania/news.html</guid>
</item>
<item>
    <title>Software Freedom Day, Primora, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2008/09/20/software-freedom-day-hyderabad/news.html</link>
    <description><![CDATA[<p>I gave a brief session on installation concepts, and methods, FOSS - history, and communication tools at the Software Freedom Day celebrations at Primora, Hyderabad. Krish gave a demo of LiveCDs, and Manish gave a demo on Compiz.</p>
<img alt="cake cutting" src="http://www.shakthimaan.com/Mambo/gallery/albums/album50/1_cake_cutting.jpg"></img><br />
<p>Thanks to Primora for offering us their office space for this meet-up.</p>
<p>Few photos taken during the meet are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album50">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 20 Sep 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/09/20/software-freedom-day-hyderabad/news.html</guid>
</item>
<item>
    <title>mukt.in, Osmania University, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2008/08/03/mukt-in-hyderabad/news.html</link>
    <description><![CDATA[<p><a href="http://mukt.in">mukt.in</a> was organized in <a href="http://www.osmania.ac.in/Engineering%20College/Comp-Science-Eng1.htm">CSE department, Osmania University, Hyderabad</a>, between August 1-3, 2008. Thanks to all the volunteers, speakers, organizers, and sponsors for their support and contribution.</p>
<img alt="group photo" src="http://www.shakthimaan.com/Mambo/gallery/albums/album49/11_day_two_group_photo.jpg"></img><br />
<p>Couple of my presentations are available: <a href="http://shakthimaan.com/downloads.html#inky-pinky-poky">Inky Pinky Poky</a>, and <a href="http://shakthimaan.com/downloads.html#openmoko-free-your-phone">Openmoko - Free Your Phone</a>.</p>
<p>Some pictures taken by <a href="http://picasaweb.google.com/jigish.gohil/MuktIn">Jigish Gohil</a>, and few at my <a href="http://www.shakthimaan.com/Mambo/gallery/album49">/gallery</a>.</p>]]></description>
    <pubDate>Sun, 03 Aug 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/08/03/mukt-in-hyderabad/news.html</guid>
</item>
<item>
    <title>LinuxTag, Berlin, Germany</title>
    <link>http://www.shakthimaan.com/posts/2008/06/16/linuxtag-berlin/news.html</link>
    <description><![CDATA[<img alt="LinuxTag entrance" src="http://www.shakthimaan.com/Mambo/gallery/albums/album46/68_myself_at_lt2008_entrance.jpg"></img><br />
<img alt="Reichstag" src="http://www.shakthimaan.com/Mambo/gallery/albums/album46/18_reichstag_building.jpg"></img><br />
<img alt="Meet at Maredo" src="http://www.shakthimaan.com/Mambo/gallery/albums/album46/52_gang_at_maredo.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album46">/gallery</a>.</p>]]></description>
    <pubDate>Mon, 16 Jun 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/06/16/linuxtag-berlin/news.html</guid>
</item>
<item>
    <title>Espoo, Helsinki, Finland</title>
    <link>http://www.shakthimaan.com/posts/2008/05/25/espoo-travel/news.html</link>
    <description><![CDATA[<img alt="Helsinki cathedral" src="http://www.shakthimaan.com/Mambo/gallery/albums/album48/24_distant_view_helsinki_cathedral.jpg"></img><br />
<img alt="Leppävaara station" src="http://www.shakthimaan.com/Mambo/gallery/albums/album48/5_lepp_vaara_station.jpg"></img><br />
<img alt="Helsingin rautatieasema" src="http://www.shakthimaan.com/Mambo/gallery/albums/album48/17_helsinki_central_railway_station.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album48">/gallery</a>.</p>]]></description>
    <pubDate>Sun, 25 May 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/05/25/espoo-travel/news.html</guid>
</item>
<item>
    <title>Debian installation, SLC, Andhra Pradesh</title>
    <link>http://www.shakthimaan.com/posts/2008/05/16/debian-installation-slc-andhra-pradesh/news.html</link>
    <description><![CDATA[<p>I conducted a “Debian GNU/Linux Installation” session as part of the first day of the 15-day Industry oriented summer school program, conducted by FSF-AP chapter, today, May 16, 2008, at <a href="http://www.slc.edu.in/">Satyam Learning Centre Institute of Engineering and Technology, Piglipur village, Hayath Nagar, Andhra Pradesh</a> (few kilometers past Ramoji Film City).</p>
<img alt="group photo" src="http://www.shakthimaan.com/Mambo/gallery/albums/album44/8_labs_to_debian.jpg"></img><br />
<p>I would like to thank FSF-AP for the arrangements. Due to official work, I was able to spend only one day. This program is conducted in parallel in three other colleges outside of Hyderabad. In the evening, they provide training on team-building, communication skills, personality development, and other soft skills. Please check <a href="http://swecha.org/"></a> for more details.</p>
<p>Students were mostly from Andhra Pradesh, and few from Tamil Nadu. The INR 1500 cost for the program is inclusive of stay, food, and training (lectures, and lab-usage) for the 15 days.</p>
<p>Most of organizers are volunteers - students, academicians or people working in the Industry in Hyderabad. They also meet during the weekends at:</p>
<p>FSF India A.P Chapter, Flat No.201, Karan Apartments, (exactly opposite to petrol bunk) Paradise, Secunderabad. Landmark: Beside Sandarshini hotel.</p>
<p><a href="http://www.hyderabadcityinfo.com/city-bus.html">Hyderabad bus routes</a> for reference.</p>
<p>Few photos are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album44">/gallery</a>.</p>]]></description>
    <pubDate>Fri, 16 May 2008 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2008/05/16/debian-installation-slc-andhra-pradesh/news.html</guid>
</item>
<item>
    <title>FOSS VLSI tools, Osmania University, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2007/12/15/foss-vlsi-osmania-hyderabad/news.html</link>
    <description><![CDATA[<p>I was able to get a 30-minute session during the “VLSI-Trends and Applications” workshop to talk about FOSS VLSI tools, conducted by the <a href="http://www.osmania.ac.in/physics/">Department of Physics, Osmania University, Hyderabad</a>, today, Saturday, December 15, 2007. Thanks to Jagan Vemula (Qvantel), and Dr. Lingam Reddy (Professor, Department of Physics, OU) for their help in this regard.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album38/1_audience.jpg
"></img><br />
<p>I did a short 10-minute presentation (with screenshots): <a href="http://shakthimaan.com/downloads/glv/presentations/vlsi-foss-1.0.odp
">[odp]</a> <a href="http://shakthimaan.com/downloads/glv/presentations/vlsi-foss-1.0.pdf">[pdf]</a></p>
<p>I then gave a demo of VHDL examples, and showed them FOSS project websites (<a href="http://opencores.org">opencores.org</a>, and <a href="http://opencollector.org">opencollector.org</a>, and <a href="http://www.shakthimaan.com/downloads/glv/embedded-howto/
">Embedded HOWTO</a>).</p>
<p>As usual students didn’t ask any questions during the session, but, had a long offline Q&amp;A, and discussion after the session.</p>
<p>Few photos are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album38">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 15 Dec 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/12/15/foss-vlsi-osmania-hyderabad/news.html</guid>
</item>
<item>
    <title>Embedded/VLSI workshop, BMSCE, Bengaluru</title>
    <link>http://www.shakthimaan.com/posts/2007/11/17/embedded-vlsi-workshop-bmsce-bengaluru/news.html</link>
    <description><![CDATA[<p>A one-day embedded/VLSI Free/Open Source workshop at <a href="http://www.bmsce.in/">BMS College of Engineering, Bengaluru (Bangalore), Karnataka</a> was organized today, Saturday, November 17, 2007.</p>
<p>I handled embedded, system architecture concepts, Linux device drivers, and an introduction to OpenMoko. Aanjhan addressed FOSS EDA tools, Verilog, embedded GNU/Linux labs HOWTO et. al.</p>
<p>I would like to thank Shashank Bharadwaj for working with me during the past few weeks in coordinating/organizing the event.</p>
<p>Students were mostly from EEE/ECE background. According to the few interested students, the institution management are quite willing to help/invest for the students, but, very few takers for it.</p>
<p>There are few permanent faculty, who teach different courses every semester. But, most of them move to the Industry.</p>
<p>During the workshop, I did emphasize on the need to use FOSS tools to enhance their skills, and get exposure to the Industry, FOSS community, and the real world.</p>
<p>Relevant links:</p>
<ul>
<li><p><a href="http://fci.wikia.com/wiki/Bangalore/BMSCE">fci wikia on BMSCE</a></p></li>
<li><p><a href="http://www.shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">i-want-2-do-project-tell-me-wat-2-do</a></p></li>
<li><p><a href="http://www.shakthimaan.com/downloads.html#mailing-list-guidelines">Mailing list guidelines</a></p></li>
<li><p><a href="http://www.shakthimaan.com/downloads.html#openmoko-free-your-phone">OpenMoko introduction</a></p></li>
<li><p><a href="http://www.shakthimaan.com/downloads.html#linux-device-driver-programming-code-examples">Linux device driver code examples</a></p></li>
</ul>]]></description>
    <pubDate>Sat, 17 Nov 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/11/17/embedded-vlsi-workshop-bmsce-bengaluru/news.html</guid>
</item>
<item>
    <title>OpenMoko talk, Osmania University, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2007/10/28/openmoko-osmania-hyderabad/news.html</link>
    <description><![CDATA[<p>I gave an introductory talk on the <a href="http://www.openmoko.org">OpenMoko</a> project at the <a href="http://www.osmania.ac.in/Science%20College/Astronomy1.htm">Department of Astronomy, Osmania University, Hyderabad</a>, Andhra Pradesh on Sunday, October 28, 2007.</p>
<p>The audience were introduced to the Neo1973 device and its accessories. The <a href="http://openmoko.org">openmoko.org</a> project documentation website was shown. The recommended flavor for working on OpenMoko is Debian or Debian-based distributions like Ubuntu.</p>
<p>The different methods of installation - online and through <a href="http://openembedded.org">openembedded.org</a> were mentioned. SSH into the device, and exporting the user interface were demonstrated. Software emulation through QEMU was also shown. Building a simple “Hello World” application was explained using autotools, Makefile and the ipk, bitbake packaging system. Audio and video were tested on the device. The next version of Neo and Openmoko is expected to have better hardware and more features.</p>
<p>The feeds of Neo and OpenMoko are at <a href="http://scap.linuxtogo.org">scap.linuxtogo.org</a>.</p>]]></description>
    <pubDate>Sun, 28 Oct 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/10/28/openmoko-osmania-hyderabad/news.html</guid>
</item>
<item>
    <title>Free Software workshop, University of Hyderabad, Gachibowli</title>
    <link>http://www.shakthimaan.com/posts/2007/10/27/free-software-workshop-uoh/news.html</link>
    <description><![CDATA[<p>I conducted a one-day Free(/Open Source) Software workshop for <a href="http://dcis.uohyd.ernet.in/">Department of Computer and Information Sciences, University of Hyderabad, Gachibowli, Hyderabad</a> in association with IEEE Student Chapter, Hyderabad, on Saturday, October 27, 2007.</p>
<img alt="IEEE poster" src="http://www.shakthimaan.com/Mambo/gallery/albums/album37/3_ieee_poster.jpg
"></img><br />
<p>Students were mostly from the Masters’ programme. The forenoon sessions included technical discussions/presentations - system, embedded, device driver concepts; Linux device drivers; introduction to OpenMoko: build, development for OpenMoko; demo of Neo1973.</p>
<p>The afternoon sessions were non-technical discussions - <a href="http://www.shakthimaan.com/downloads.html#i-want-2-do-project-tell-me-wat-2-do">i-want-2-do-project.tell-me-wat-2-do</a>, <a href="http://www.shakthimaan.com/downloads.html#mailing-list-guidelines">mailing list guidelines</a>, <a href="http://www.shakthimaan.com/downloads.html#free-software-communication-guidelines">Free Software communication guidelines</a>, and brainstorming sessions.</p>
<p>More than half of the faculty from the University have done their MS/PhDs abroad. The university and the faculty have the freedom to implement whatever they like, which is cool.</p>
<p>The labs use Fedora/Red Hat/SuSE distributions. They run their own mail+web servers, and use NFS. There are few professors who give assignments with Makefiles, gdb, Linux kernel compilation, but, they are just starting, and experimenting with these. It was announced that INR 20,000 will be alloted each year for Free/Open Source events.</p>
<p>If anyone is interested in working with this team, contact me offline, and I shall provide the contacts.</p>
<p>Thanks to Dr. Vineet, Prof. Anupama, Dr. Madhav Negi (IEEE), Dr. Atul Negi for their help, coordination in planning this workshop.</p>
<p>Few photos are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album37">/gallery</a>.</p>
<p>Feedback/criticisms/suggestions on the presentations welcome, as always.</p>]]></description>
    <pubDate>Sat, 27 Oct 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/10/27/free-software-workshop-uoh/news.html</guid>
</item>
<item>
    <title>Arendal, Norway</title>
    <link>http://www.shakthimaan.com/posts/2007/06/20/arendal-norway/news.html</link>
    <description><![CDATA[<img alt="Beautiful Arendal" src="http://www.shakthimaan.com/Mambo/gallery/albums/album41/17_beautiful_arendal.jpg"></img><br />
<img alt="Boats and buildings" src="http://www.shakthimaan.com/Mambo/gallery/albums/album41/25_boats_and_buildings.jpg"></img><br />
<img alt="bridge to Tromøy" src="http://www.shakthimaan.com/Mambo/gallery/albums/album41/37_connecting_bridge.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album41">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 20 Jun 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/06/20/arendal-norway/news.html</guid>
</item>
<item>
    <title>Traditional Norwegian style dinner</title>
    <link>http://www.shakthimaan.com/posts/2007/05/15/traditional-norway-dinner/news.html</link>
    <description><![CDATA[<img alt="Departure" src="http://www.shakthimaan.com/Mambo/gallery/albums/album42/1_departure.jpg"></img><br />
<img alt="Houses" src="http://www.shakthimaan.com/Mambo/gallery/albums/album42/9_beautiful_houses.jpg"></img><br />
<img alt="Dinner" src="http://www.shakthimaan.com/Mambo/gallery/albums/album42/7_with_company.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album42">/gallery</a>.</p>]]></description>
    <pubDate>Tue, 15 May 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/05/15/traditional-norway-dinner/news.html</guid>
</item>
<item>
    <title>Grimstad, Norway</title>
    <link>http://www.shakthimaan.com/posts/2007/04/25/grimstad-norway/news.html</link>
    <description><![CDATA[<img alt="Teknologisenter" src="http://www.shakthimaan.com/Mambo/gallery/albums/album40/2_teknologisenter.jpg"></img><br />
<img alt="View from Østereng &amp; Benestad" src="http://www.shakthimaan.com/Mambo/gallery/albums/album40/13_from_ostereng.jpg"></img><br />
<img alt="Fields" src="http://www.shakthimaan.com/Mambo/gallery/albums/album40/22_fields.jpg"></img><br />
<p>More photos available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album40">/gallery</a>.</p>]]></description>
    <pubDate>Wed, 25 Apr 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/04/25/grimstad-norway/news.html</guid>
</item>
<item>
    <title>Embedded/VLSI workshop, JEC, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2007/03/24/embedded-vlsi-jec-chennai/news.html</link>
    <description><![CDATA[<p>I conducted couple of sessions for the ECE, EEE and EIE department students of <a href="http://www.jec.ac.in/">Jaya Engineering College, Thiruninravur, Tamil Nadu</a>, today, Saturday, March 24, 2007.</p>
<p>I started off with an introduction to Free/Libre/Open Source Software, taught them examples of <a href="http://www.shakthimaan.com/downloads.html#alliance">Alliance VLSI CAD tools</a>, and <a href="http://www.shakthimaan.com/downloads.html#embedded-gnu-linux-labs-howto">embedded GNU/Linux HOWTO</a>. I gave a demo of an embedded development kit. After the sessions, we had an informal discussion with the faculty of EEE, EIE.</p>
<p>After lunch, we had an informal discussion with few students in the FOSS lab about their final year project work. Most of them knew only about Java, as that was what was “prescribed” in the syllabus. But, I gave them an insight on the different domains that they could work on, and possibilities available in the Industry.</p>
<p>The FOSS lab is running Red Hat 9. The systems have 256 MB RAM, so, I asked them to upgrade to a recent distro ASAP. They also are in the process of moving to PHP, MySQL for their website.</p>
<p>Their servers have been obtained from our good friends at <a href="http://www.deeproot.in/">DeepRoot</a>, so they can try to setup an internal portal (PHP, mysql) for intra-department communication.</p>
<p>The system administrator in the lab wanted few tips on networking with Red Hat. I showed him how to use scp to transfer files between two Red Hat systems. He was so happy! During summer holidays, Prof. Kumaran wants to do some FOSS camp for the staff. Should be fun, if you guys can help out, and if you are in town.</p>
<p>I would like to thank Prof. Kumaran for his continued support. Special thanks also to Harish for coordinating and organizing the event.</p>]]></description>
    <pubDate>Sat, 24 Mar 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/03/24/embedded-vlsi-jec-chennai/news.html</guid>
</item>
<item>
    <title>F/OSS workshop, Osmania University, Hyderabad</title>
    <link>http://www.shakthimaan.com/posts/2007/03/10/foss-workshop-osmania-hyderabad/news.html</link>
    <description><![CDATA[<p>I conducted a “Careers with GNU/Linux and Free Software” workshop on Saturday, March 10, 2007 at <a href="http://www.osmania.ac.in/">Osmania University, Hyderabad</a>.</p>
<p>This is the first time that I actually “flew” to a workshop. Indian Airlines flight was delayed by two hours. The workshop was to start at 10:15, but, I reached Hyderabad only at 1200 noon. Hyderabad is a Pretty Hot Place (PHP?). It was 30 degree celsius, but, felt like 50! I presented the following: <a href="http://www.shakthimaan.com/downloads.html#careers-with-gnu-linux">Careers with GNU/Linux</a>, <a href="http://www.shakthimaan.com/downloads.html#free-software-for-engineers">Free Software</a>, GNU/Linux desktop, <a href="http://www.shakthimaan.com/downloads.html#embedded-gnu-linux-labs-howto">Embedded HOWTO</a>, <a href="http://www.shakthimaan.com/downloads.html#alliance">Alliance VLSI CAD Tools HOWTO</a>.</p>
<p>The posters made for the workshop are available: <a href="http://shakthimaan.com/downloads/glv/posters/flyer_workshop.pdf">[Flyer I]</a> <a href="http://shakthimaan.com/downloads/glv/posters/flyer_workshop_2.pdf">[Flyer II]</a></p>
<p>There were about 180 students from in and around Hyderabad. There were students who came all the way from Vijayawada (300 km) by bus, overnight, and I was elated. Students from other colleges who participated in the workshop were eager to have similar workshops for their colleges. I have agreed for the same.</p>
<p>I was able to meet folks from Free Software Foundation, Andhra Pradesh Chapter. I shall provide the organizers’ contacts to NRC-FOSS.</p>
<p>I would like to thank Dr. Atul Negi (Vice-Chairman, IEEE Hyderabad Section), Dr. Madhav Negi (Chairman, IEEE Computer Society, Hyderabad Section) for their support.</p>
<p>Thanks also to Santosh Arjun (Vice-Chairman, IEEE Student Chapter, Osmania University) for working with me for more than a month in organizing this workshop.</p>]]></description>
    <pubDate>Sat, 10 Mar 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/03/10/foss-workshop-osmania-hyderabad/news.html</guid>
</item>
<item>
    <title>FOSS VLSI talk, NIT, Calicut</title>
    <link>http://www.shakthimaan.com/posts/2007/03/03/foss-nitc/news.html</link>
    <description><![CDATA[<p>I gave a couple of talks: <a href="http://www.shakthimaan.com/downloads.html#alliance">“Alliance VLSI CAD Tools”</a>, and <a href="http://www.shakthimaan.com/downloads.html#careers-with-gnu-linux">“Careers with GNU/Linux”</a> at <a href="http://www.nitc.ac.in/">National Institute of Technology, Calicut, Kerala</a> on Saturday, March 3, 2007.</p>
<p>The code examples and presentation are available. I’d like to thank Praveen for inviting me over (which he didn’t have to do). The interaction with the students was good.</p>
<p>The schedule was a bit tight, and I didn’t take any pictures.</p>]]></description>
    <pubDate>Sat, 03 Mar 2007 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2007/03/03/foss-nitc/news.html</guid>
</item>
<item>
    <title>Bioinformatics FLOSS workshop, Karpagam Arts and Science College</title>
    <link>http://www.shakthimaan.com/posts/2006/09/09/bioinformatics-floss-workshop-karpagam/news.html</link>
    <description><![CDATA[<p>Deepan Chakravarthy and myself conducted a one-day workshop for the Bioinformatics department, <a href="http://www.karpagamuniv.com/">Karpagam Arts and Science College, Coimbatore, Tamil Nadu, India</a> on Saturday, September 9, 2006.</p>
<p>I introduced them to FLOSS, and then Deepan spoke on how FLOSS is useful in bioinformatics. He showed a demo of <a href="http://emboss.sourceforge.net/">Emboss</a>, and lot of other applications. After lunch, I gave a demo of the GNU/Linux desktop environment, and also explained basic commands that they can use in the console environment. Deepan then continued with his demo of bioinformatics applications and discussed about FLOSS projects at <a href="http://bioinformatics.org">bioinformatics.org</a>.</p>
<p>The students/faculty were really enthusiastic, and wanted follow-up sessions. I emphasized that they should get started with setting up a FLOSS lab, and a GNU/Linux user group on-campus. They are ready to provide facilities, stay, food even if you want to spend a week there, and give them hands-on training. There are no distractions until October 5, 2006, after which they have model exams, followed by holidays and exams.</p>
<p>I would like to thank Prof. Hemalatha for working with us for the past couple of weeks in coordinating and organizing this event. Special thanks to the department faculty and management for the facilities and hospitality offered.</p>]]></description>
    <pubDate>Sat, 09 Sep 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/09/09/bioinformatics-floss-workshop-karpagam/news.html</guid>
</item>
<item>
    <title>FLOSSAGE, Jaya Engineering College</title>
    <link>http://www.shakthimaan.com/posts/2006/08/20/flossage-jaya-engineering-college/news.html</link>
    <description><![CDATA[<p>The photos taken during “FLOSSAGE 2006”, between August 19-20, 2006 at <a href="http://www.jec.ac.in/">Jaya Engineering College, Thiruninravur, Tamil Nadu, India</a> can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album35">/gallery</a>.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album35/4_audience.jpg"></img><br />
<p>I shall make a CD copy of the photos (high resolution) and send it to Harish (Secretary, Jaya Engineering College GNU/Linux Campus Club). Thanks to Harish for coordinating and helping us around. I must congratulate Prof. Kumaran for doing a very good job in organizing the whole event. Thanks also to the management, faculty, students of Jaya Engineering college for the wonderful hospitality offered.</p>
<p>Students were very enthusiastic about FLOSS. It was something very new to them, and they were very eager to learn it and try it. I was particulary impressed by the ‘Blender team’ who picked it up so easily, and were doing cool animations! If we can continue to guide them, they will definitely make good contributions to FLOSS.</p>
<p>Thanks to the other <a href="http://ilugc.in">ILUGC</a>, <a href="http://nrcfoss.org.in">NRCFOSS</a> volunteers too. I had a great time!</p>]]></description>
    <pubDate>Sun, 20 Aug 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/08/20/flossage-jaya-engineering-college/news.html</guid>
</item>
<item>
    <title>FLOSS training, Jaya Engineering College</title>
    <link>http://www.shakthimaan.com/posts/2006/08/13/floss-training-jec/news.html</link>
    <description><![CDATA[<p>Members of <a href="http://ilugc.in">ILUGC</a>, <a href="http://nrcfoss.org.in">NRC-FOSS</a> conducted a FLOSS training session to Jaya Engineering College (Thiruninravur) students, today, Sunday, August 13, 2006.</p>
<img alt="Lab session in progress" src="http://www.shakthimaan.com/Mambo/gallery/albums/album34/11_training_in_progress.jpg"></img><br />
<p>The photos taken during the session can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album34">/gallery</a>.</p>
<p>Please contact Raman P (raamanp at yahoo.co.in), if you are interested in volunteering for the LDD at Jaya Engineering College, on August 19-20, 2006.</p>]]></description>
    <pubDate>Sun, 13 Aug 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/08/13/floss-training-jec/news.html</guid>
</item>
<item>
    <title>FLOSS workshop, Karpagam Arts and Science College</title>
    <link>http://www.shakthimaan.com/posts/2006/08/05/floss-workshop-karpagam/news.html</link>
    <description><![CDATA[<p>I conducted a full-day “Introduction to Free/Libre Open Source Software” workshop on Saturday, August 5, 2006 at <a href="http://www.karpagamuniv.com">Karpagam Arts and Science College, Coimbatore, Tamil Nadu, India</a>.</p>
<img alt="Revolution OS movie" src="http://www.shakthimaan.com/Mambo/gallery/albums/album33/8_rms_rev_os.jpg"></img><br />
<p>I covered <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opportunities with FLOSS</a>, Free/Libre Open Source Software that is available for students/engineers, the GNU/Linux desktop, localization with GNU/Linux, and played the movie, <a href="http://www.revolution-os.com/">“The Revolution OS”</a>.</p>
<p>The students were from the CS and MCA department. Usually, I prefer to speak in Tamil within Tamil Nadu, but, because the audience comprised of people from Tamil Nadu and Kerala, English was preferred. The college has recently received autonomous status. I have given <a href="http://www.au-kbc.org/">AU-KBC</a> contacts to them to take up FLOSS projects, and to start taking FLOSS initiatives to serve the community in and around Coimbatore.</p>
<p>They <em>will</em> be starting a GNU/Linux Campus Club/User Group on campus, soon. They do require technical support and guidance (initially, atleast) from <a href="http://ilugc.in">ILUGC</a>, AU-KBC members for FLOSS work.</p>
<p>I would like to thank Prof. E. Karthikeyan, Senior Lecturer, Computer Science Department to have arranged for the workshop in one week’s time, and for the wonderful hospitality offered.</p>
<p>You can check out the photos from my <a href="http://www.shakthimaan.com/Mambo/gallery/album33">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 05 Aug 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/08/05/floss-workshop-karpagam/news.html</guid>
</item>
<item>
    <title>FLOSS workshop, MNM Jain Engineering College, Thorappakkam</title>
    <link>http://www.shakthimaan.com/posts/2006/07/31/floss-workshop-mnm-jain/news.html</link>
    <description><![CDATA[<p>I conducted an “Introduction to FLOSS” workshop today, Monday, July 31, 2006 at <a href="http://www.mnmjec.ac.in/">MNM Jain Engineering College, Thorappakkam, Tamil Nadu, India</a>.</p>
<p>I would like to thank Prashant Mohan (<a href="http://ilugc.in">ILUGC</a>), Vidhya Shankar (student), Assitant Professor Muthu Sundar (Assistant Professor, CSE) for taking the initiative.</p>
<p>I discussed <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opporunities with FLOSS</a>, introduced the GNU/Linux desktop, and played the movie, <a href="http://www.revolution-os.com/">“The Revolution OS”</a>.</p>
<p>IBM has started doing some good projects using GNU/Linux with the college.</p>
<p>Prof. Muthu Sundar is already in touch with <a href="http://nrcfoss.org.in">NRCFOSS</a>, and is planning to get more students to work on FLOSS projects with them.</p>]]></description>
    <pubDate>Mon, 31 Jul 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/07/31/floss-workshop-mnm-jain/news.html</guid>
</item>
<item>
    <title>FLOSS workshop, Jaya Engineering College, Thiruninravur</title>
    <link>http://www.shakthimaan.com/posts/2006/07/22/floss-workshop-jec/news.html</link>
    <description><![CDATA[<p>The photos taken during the “Introduction to FLOSS” workshop held today, Saturday, July 22, 2006 at <a href="http://www.jec.ac.in/">Jaya Engineering College, Thiruninravur, Tamil Nadu, India</a> can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album32">/gallery</a>.</p>
<img alt="Session in progress" src="http://www.shakthimaan.com/Mambo/gallery/albums/album32/5_session_in_progress.jpg
"></img><br />
<p>It was an introductory session with talks on <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opportunities with FLOSS</a>, Free/Libre Open Source Software, and the GNU/Linux desktop.</p>
<p>I would like to thank Prof. Kumaran, HOD, CSD for taking the initiative and following it up. Thanks also to Harish for his correspondence and help.</p>
<p>There were about 200 students during the workshop, and they are very eager to <em>learn</em> using FLOSS. They already have a FLOSS lab setup. The <a href="http://ilugc.in">ILUGC</a> mailing list has been provided to them for technical support.</p>
<p>They are planning for an LDD for August 18, 19, 2006 (Friday, Saturday) - will be confirmed by them. It will be open to the public and will be primarily useful to the schools, colleges in and around Thiruninravur, and Chennai.</p>
<p>To those new colleges/schools who haven’t had a taste of FLOSS, I shall provide them with the contact of <a href="http://nrcfoss.org.in">NRCFOSS</a>, so they can take it further - with support from ILUGC too.</p>]]></description>
    <pubDate>Sat, 22 Jul 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/07/22/floss-workshop-jec/news.html</guid>
</item>
<item>
    <title>Introduction to Quilt, IIT, Madras</title>
    <link>http://www.shakthimaan.com/posts/2006/04/22/quilt-iit-madras/news.html</link>
    <description><![CDATA[<p>I gave an introductory session on <a href="http://savannah.nongnu.org/projects/quilt">Quilt</a> on Saturday, April 22, 2006 at 1500 IST at CSD, #320, <a href="http://www.iitm.ac.in/">IIT, Madras</a>.</p>
<p>Quilt is a tool to manage patches in project code development/documentation. The tutorial session was filled with illustrative examples on how to use quilt. The <a href="http://shakthimaan.com/downloads.html#quilt-tutorial">tutorial</a> and the code samples that I had written are released under the GNU Free Documentation License.</p>
<p>Thanks to Ashok Raj (Intel), Thomas Petazzoni (Enix), and Jordan (AMD) for their feedback regarding the tutorial.</p>]]></description>
    <pubDate>Sat, 22 Apr 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/04/22/quilt-iit-madras/news.html</guid>
</item>
<item>
    <title>FLOSS workshop, Arunai Engineering College, Tamil Nadu</title>
    <link>http://www.shakthimaan.com/posts/2006/03/26/floss-workshop-arunai/news.html</link>
    <description><![CDATA[<p>The photos (more than 120) taken during the two-day FOSS Exhibit held on March 25-26, 2006 organized by ILUGC, and NRC-FOSS at <a href="http://www.arunai.org/">Arunai Engineering College, Thiruvannamalai, Tamil Nadu</a> are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album26">/gallery</a>.</p>
<img alt="Arunai gateway" src="http://www.shakthimaan.com/Mambo/gallery/albums/album26/106_arunai_gw.jpg
"></img><br />
<p>I would like to thank the management, faculty of Arunai Engineering College (AEC) for their wonderful support. My hearty congratulations to the students for their valiant efforts in this event.</p>
<p>Special thanks to our fellow <a href="http://ilugc.in/">ILUGC</a> and <a href="http://nrcfoss.org.in">NRC-FOSS</a> folks, and Dr. Srinivasan for taking the initiative. We had a very good time :)</p>
<p>A brief summary of the events and the fun we had:</p>
<h1 id="day-i-saturday-march-25-2006">Day I : Saturday, March 25, 2006</h1>
<p>Team I began on Saturday, March 25, 2006 morning by 0500 IST. I was picked up first, then Suman (Triplicane), Dr. Srinivasan (Saidapet), Aanjhan and Parthan (Kathibara junction), Raman and Bhaskar (Tambaram). Aanjhan came by bus from Bangalore to Chennai, the previous night, and joined Parthan in the morning.</p>
<p>We did break for breakfast. We got back in the Toyota Qualis after breakfast and were about to leave when we realized that Suman was not there. We found him in the hotel.</p>
<p>We arrived at around 0830 IST in the morning. After a formal inauguration, Raman began the day’s proceedings with introduction to FLOSS, followed by Fedora Core installation. Team 2a arrived and were introduced to the audience. They moved to the labs to train the students. After installation demo, I discussed about career opportunities with FLOSS. Meanwhile Team 2b, Asokan and Thyagurajan, had arrived and introduced themselves. Suman gave an introduction on Qt programming. We had lunch between 1300-1400.</p>
<p>Post-lunch session began with an excellent presentation by Asokan Pichai on shell scripting and the power of scripting. Thyagurajan gave a talk on GLAMP after Asokan’s talk. Tea break was at 1530 IST. Two folks from Sun Microsystems, Bangalore had come, Arindam and Moinak. So we had to give them some time for a session. They gave a demo of Opensolaris and wanted more developers for the same.</p>
<p>Aanjhan spoke on how students can contribute to FLOSS. At 1700 we moved to the labs to help the other teams who were training students. We finally left at 1900 to the hotel. When we reached the hotel, one of the students told us that we had left someone behind. Guess who? Suman. Nevertheless, he was dropped to the hotel.</p>
<p>We had good dinner, and in Room #203, Saravanan, Raman, Parthan and myself had good discussions about FLOSS and ILUGC activities. We hit the sack only at midnight.</p>
<h1 id="day-ii-sunday-march-26-2006">Day II, Sunday, March 26, 2006</h1>
<p>Many folks visited the temple in the morning, and then went to the college to help in the stalls. Preparations were in full-swing with students helping in setting up the stalls, putting up banners, etc. Team III arrived in the morning.</p>
<p>The auditorium session began around 1000. Audience were school students, college students, and the general public. I introduced them to FLOSS, showed the *nix desktop environment, software that they can use with GNU/Linux etc.</p>
<p>The chief guest, M. R. Rajagopalan, Director, C-DAC, Chennai inaugurated the stalls. They along with the college management and administration folks then came to the auditorium for a quick inauguration session. Lunch was at 1330. The stalls were bustling with activity.</p>
<img alt="Stalls" src="http://www.shakthimaan.com/Mambo/gallery/albums/album26/95_stalls.jpg
"></img><br />
<p>We resumed sessions in the auditorium at 1500 and Moinak introduced folks on Bellenix and OpenSolaris. Arindam then began talking about core kernel hacking to newbies, and continued on and on and on till 1700, and most of them left for the stalls. I was happy they moved to the stalls as they were to close by 1700. We didn’t have time to play The.Code.linux or have a Q&amp;A discussion session (interactive, like in day one).</p>
<p>There was a big thanks-giving at the end of the day to all volunteers, and we departed at 1800.</p>
<p>Overall, I was overwhelmed by the enthusiasm of the AEC students, and given a chance, I would go there again.</p>]]></description>
    <pubDate>Sun, 26 Mar 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/03/26/floss-workshop-arunai/news.html</guid>
</item>
<item>
    <title>FLOSS workshop, SSN College of Engineering</title>
    <link>http://www.shakthimaan.com/posts/2006/03/18/floss-workshop-ssn/news.html</link>
    <description><![CDATA[<p>The photos taken during the “Introduction to FLOSS” workshop at <a href="http://www.ssn.edu.in/">SSN College of Engineering, SSN Nagar, Tamil Nadu, India</a>, today, Saturday, March 18, 2006 are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album25">/gallery</a>.</p>
<img alt="laptops" src="http://www.shakthimaan.com/Mambo/gallery/albums/album25/6_ibmr_and_my_t41.jpg
"></img><br />
<p>Thanks to the Management, SSN College of Engineering, Dr. Aravindhan (HOD, CSD), Prof. Balasubramanian (Lecturer, CSD), and to students and faculty/staff of SSN College of Engineering. Thanks also to Naren who has been coordinating this event for the past three weeks.</p>
<p>Vijay Kumar began the day’s proceedings with an introduction to Free Software. I then conducted the <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">“Careers with GNU/Linux”</a> presentation. Joe Steeve handled installation of Fedora Core. We had lunch between 1130 and 1230 IST. Ashwin began the afternoon session with his talk on <a href="http://www.shakthimaan.com/downloads/glv/presentations/ssn.ashwin.mar.18.2006.pdf">“Squid, GLAMP, ntop”</a>. Vijay then gave an introduction to GUI programming with GTK. Sujith, from <a href="http://nrcfoss.org.in/">NRC-FOSS</a>, followed with his presentation on Scilab and GNU Octave. I then gave a demo of “Multimedia on GNU/Linux” and played the the demo video of xgl/opengl.</p>
<p>The audience were from different departments, and we had good interactive sessions. SSN folks are very keen on *nix environments, and are interested in many follow-up sessions. Suggestions were provided to start a user group within campus so students can participate.</p>
<p>Thanks to Vijay Kumar, Joe Steeve, Naren, Ashwin, Sujith for their company and participation. I had a great time!</p>]]></description>
    <pubDate>Sat, 18 Mar 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/03/18/floss-workshop-ssn/news.html</guid>
</item>
<item>
    <title>Free Software workshop, FISAT, Kochi</title>
    <link>http://www.shakthimaan.com/posts/2006/03/11/free-software-fisat-kochi/news.html</link>
    <description><![CDATA[<p>The final day of “Bharatham 2006” on Saturday March 12, 2006 at <a href="http://www.fisat.ac.in/">Federal Institute of Science and Technology, Angamaly, Kochi, Kerala</a> was cancelled due to a fatal accident, the previous night, to students from a nearby college. After the cultural festival on Friday night, the students had left in their car at around 2230 IST. They didn’t have control of the car at one turning near a small bridge, skidded across, and drowned in the river. The doors were locked and had got jammed. Out of five students, only one managed to escape. A tragedy to all students, faculty, friends in and around Angamaly.</p>
<p>Since I had come all the way, they just wanted me to conduct an informal session to the faculty and few students who were there. I spoke on Free Software and GNU/Linux. As a mark of respect to the loss of life, I didn’t take any photographs.</p>
<p>I spent the remaining time with the students there, and got to know more about Free Software activities in Kerala, right from Calicut, to Palghat, Trichur, Angamaly, Kochin, Kollam, Thiruvananthapuram.</p>
<p><a href="http://pramode.net/">Pramode</a> is the inspiration in Government Engineering College, Trichur and other places in Kerala.</p>
<p><a href="http://space-kerala.org/">Space Kerala</a> promote Free Software and do good work in promoting the same to schools, colleges, NGOs throughout Kerala.</p>
<p>Thanks to Sumod (final year, ICE) for coordinating with me for the past three weeks, and for the hospitality offered.</p>
<p>We want to collaborate more with our folks in Kerala and will organize more workshops in future.</p>]]></description>
    <pubDate>Sat, 11 Mar 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/03/11/free-software-fisat-kochi/news.html</guid>
</item>
<item>
    <title>Embedded/VLSI workshop, Kongu Engineering College, Erode</title>
    <link>http://www.shakthimaan.com/posts/2006/03/04/embedded-vlsi-kongu/news.html</link>
    <description><![CDATA[<p>I would like to thank Kongu LUG, management, Prof. Jayapathi, HOD, CSE department, staff and students of <a href="http://www.kongu.ac.in/">Kongu Engineering College</a> (KEC) for the opportunity to conduct a one-day “GNU Embedded/VLSI” workshop at Kongu Engineering College, Perundurai, Erode on Saturday, March 4, 2006.</p>
<img alt="Embedded demo" src="http://www.shakthimaan.com/Mambo/gallery/albums/album24/5_embedded_demo.jpg
"></img><br />
<p>The <a href="http://shakthimaan.com/downloads.html#alliance">VHDL code examples</a> and <a href="http://shakthimaan.com/downloads.html#embedded-gnu-linux-labs-howto">Embedded HOWTO</a> presentations are available.</p>
<p>I spent about an hour and a half with the students in the morning in their RMS laboratory (0900 to 1030 IST). The morning session was on “Embedded GNU/Linux labs HOWTO” (1030 to 1230 IST). Lunch was between 1230 and 1400 IST. The afternoon session was on “Alliance VLSI CAD tools” (1400 to 1600 IST).</p>
<p>KEC have started an FM studio (90.4 MHz) for listeners in and around (10 km radius) Erode. So, they caught me by surprise and conducted an interview. The questions were on Free Software, higher education, GNU/Linux community work etc. They were using soundforge as suggested by the management. I had told them about Audacity and how I use it on GNU/Linux for sound recording/editing etc. I have asked for a copy of the same, if possible, so I can upload it. It should be aired on March 13, 2006, sometime between 1630 to 1930 IST in Erode.</p>
<img alt="Interview" src="http://www.shakthimaan.com/Mambo/gallery/albums/album24/15_interview_in_progress.jpg
"></img><br />
<p>Special thanks to Vijay Anand, final year, CSD for working with me for the past couple of weeks in coordinating the event.</p>
<p>The photos taken during the presentation can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album24">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 04 Mar 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/03/04/embedded-vlsi-kongu/news.html</guid>
</item>
<item>
    <title>Embedded/VLSI workshop, IIT, Madras</title>
    <link>http://www.shakthimaan.com/posts/2006/02/25/embedded-vlsi-workshop-iitm/news.html</link>
    <description><![CDATA[<p>The code examples and presentation slides used during the GNU Embedded/VLSI workshop on Saturday, February 25, 2006 at Central Lecture Theater, IIT-M are available at <a href="http://shakthimaan.com/downloads.html#embedded-gnu-linux-labs-howto">Embedded HOWTO</a>.</p>
<img alt="On stage" src="http://www.shakthimaan.com/Mambo/gallery/albums/album23/6_myself_intro.jpg
"></img><br />
<p>I would like to thank Dr. Nitin, EE, IIT-M for working with us for the past one month in planning this event, and for providing us with the needed support.</p>
<p>Thanks to Kumar Appaiah for coordinating the event. Thanks also to Aanjhan and Bharathi for their talks and presence.</p>
<p>The photos taken can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album23">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 25 Feb 2006 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2006/02/25/embedded-vlsi-workshop-iitm/news.html</guid>
</item>
<item>
    <title>Tuxedo, Sri Jayachamarajendra College of Engineering, Mysore</title>
    <link>http://www.shakthimaan.com/posts/2005/11/13/tuxedo-sjce-mysore/news.html</link>
    <description><![CDATA[<p>I would like to thank the team of “Tuxedo 2005”, <a href="http://sjcemysore.org/index.aspx">Sri Jayachamarajendra College of Engineering, Mysore, Karnataka, India</a> for the opportunity and hospitality offered during the two-day workshop held between November 12-13, 2005.</p>
<img alt="Poster" src="http://www.shakthimaan.com/Mambo/gallery/albums/album21/32_tuxedo_05.jpg
"></img><br />
<p>Thanks to Joy, Chairman, IEEE-SJCE Student Branch for working with me for the past one month (answering all my queries :), and the student volunteers for taking good care of us, and doing the needful during the occasion. Special thanks to Dr. C. R. Venugopal (IITB), who has taken so much initiative, and continues to motivate SJCE students into FLOSS. Thanks to Aanjhan, Ramanraj and Bharathi for their talks and company.</p>
<p>SJCE, has Dr. C. R. Venugopal (CRV), Coordinator IIPC, Staff Advisor, IEEE, who has guided students in the past and continues to guide them with FLOSS. Under his guidance they have done projects on RTOS, minix and GNU/Linux.</p>
<p>HP, Bangalore selects students from SJCE to do their Free Software projects. This is only for final year students. As usual, I insisted working on Free Software projects during their course. CRV also works closely with Texas Instruments, Bangalore in getting projects for their students so they can get hands-on experience.</p>
<p>Bharathi began day one (Saturday) with a session on “GNU, FSF”. In the afternoon, Ramanraj spoke about “CALPP and AI”. The quiz prelims and finals were conducted the same day.</p>
<img alt="Ramanraj session" src="http://www.shakthimaan.com/Mambo/gallery/albums/album21/16_audience.jpg
"></img><br />
<p>Aanjhan spoke about “Embedded GNU/Linux” on day two (Sunday). They had a “virtual treasure hunt” contest for students on Sunday. I spoke on <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">“Careers with GNU/Linux”</a> and <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">“Free Software for Engineers”</a> in the afternoon. We screened the movie <a href="http://www.revolution-os.com/">Revolution OS</a> in the evening.</p>
<p>We have decided to have more collaboration between Chennai and Mysore LUGS, and probably conduct lot of contests for students to make them do <em>practical</em> stuff and get hands-on experience. We can plan install fests, hack fests, coding contests etc.</p>
<p>The photos taken during Tuxedo 2005 can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album21">/gallery</a>.</p>]]></description>
    <pubDate>Sun, 13 Nov 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/11/13/tuxedo-sjce-mysore/news.html</guid>
</item>
<item>
    <title>Embedded/VLSI workshop, Crescent Engineering College, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2005/10/22/embedded-vlsi-crescent/news.html</link>
    <description><![CDATA[<p>I would like to thank Prof. Raja Prabhu, Prof. Bhaskar, Krishnaswamy (EEE), Prasanna (EEE) from <a href="http://www.crescentcollege.org/">Crescent Engineering College, Chennai, Tamil Nadu, India</a> for the opportunity to conduct a GNU/Linux workshop for their IEEE Chapter on Saturday, October 22, 2005 at their college premises.</p>
<img alt="Embedded Labs HOWTO" src="http://www.shakthimaan.com/Mambo/gallery/albums/album20/6_embedded_labs.jpg
"></img><br />
<p>The workshop had two sessions. The <a href="http://shakthimaan.com/downloads.html#alliance">Alliance VLSI CAD tools</a> with GNU/Linux session was meant to get students started on VHDL, and to introduce them to Alliance VLSI CAD tools. The <a href="http://shakthimaan.com/downloads.html#embedded-gnu-linux-labs-howto">Embedded GNU/Linux Labs HOWTO</a> presentation was on how to get started on setting up GNU/Linux labs for embedded, hardware and VLSI.</p>
<p>Few photos taken during the workshop are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album20">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 22 Oct 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/10/22/embedded-vlsi-crescent/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop for NGOs, Ma Foi Academy, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2005/10/16/gnu-linux-workshop-ngo-chennai/news.html</link>
    <description><![CDATA[<p><a href="http://ilugc.in">ILUGC</a> in collaboration with <a href="http://www.ciosa.org.in">CIOSA</a> organized a GNU/Linux workshop for NGOs on Sunday, October 16, 2005 at Ma Foi Academy, Chennai.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album19/16_gnu_linux_desktop.jpg
"></img><br />
<p>It was an introductory session on Free Software, OpenOffice, desktop applications, Internet applications, multimedia on GNU/Linux. Thanks to Prasanna (CIOSA) for taking the initiative, Asokan Pichai (Ma Foi) for providing us with the facilites at Ma Foi, and Vamsee Kanakala (Ma Foi) for coordinating the events.</p>
<p>Thanks also goes to ILUGC volunteers Bharathi, Raman, Hariram, Sudharshan, Ramanathan and others. You can check out the photos taken during the workshop from my <a href="http://www.shakthimaan.com/Mambo/gallery/album19">/gallery</a>.</p>]]></description>
    <pubDate>Sun, 16 Oct 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/10/16/gnu-linux-workshop-ngo-chennai/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Adhiparasakthi Engineering College, Melmaruvathur</title>
    <link>http://www.shakthimaan.com/posts/2005/09/24/gnu-linux-workshop-aec/news.html</link>
    <description><![CDATA[<p>I would like to thank the Computer Science Department, <a href="http://adhiparasakthi.in/">Adhiparasakthi Engineering College, Melmaruvathur, Tamil Nadu, India</a> for inviting me, and for helping me organize a GNU/Linux workshop for CSE students. Special mention goes to Mr. Ramabadran for working with me for the past three weeks in coordinating this event.</p>
<p>The workshop was held today, September 24, 2005 at the college premises. The topics covered: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opportunities with GNU/Linux</a> and <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for engineers</a>.</p>
<p>The engineering college is interested in working towards bringing more FLOSS industry exposure to their campus, and for conducting more workshops. If anybody is interested, I can put you on to the concerned individuals.</p>]]></description>
    <pubDate>Sat, 24 Sep 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/09/24/gnu-linux-workshop-aec/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Stella Maris College, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2005/09/10/gnu-linux-workshop-stella-chennai/news.html</link>
    <description><![CDATA[<p>I organized a GNU/Linux workshop at <a href="http://www.stellamariscollege.org/">Stella Maris College, Chennai, Tamil Nadu, India</a>, today, September 10, 2005.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album17/3_audience.jpg
"></img><br />
<p>I discussed the various <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opportunities related to GNU/Linux</a>, gave a demo of the GNU/Linux desktop, and gave an introduction on <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for engineers</a>.</p>
<p>I would like to thank the faculty, CS department, and management of Stella Maris College for the opportunity.</p>
<p>Few photos taken during the workshop are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album17">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 10 Sep 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/09/10/gnu-linux-workshop-stella-chennai/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Saveetha Engineering College, Chennai</title>
    <link>http://www.shakthimaan.com/posts/2005/09/03/gnu-linux-workshop-saveetha/news.html</link>
    <description><![CDATA[<p>I would like to thank Srinivasan, from <a href="http://www.saveetha.com/engineering/">Saveetha Engineering College, Chennai, Tamil Nadu, India</a> for taking the initiative for a GNU/Linux workshop, the faculty (CS and IT departments), and management of Saveetha Engineering College for making the necessary arrangements for the workshop.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album16/6_audience_house_full.jpg
"></img><br />
<p>The workshop was conducted, today, Saturday, September 3, 2005 at the college premises. I addressed the following: <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Introduction to Free Software</a>, <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">Careers with GNU/Linux</a>, and the GNU/Linux desktop.</p>
<p>More photos can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album16">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 03 Sep 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/09/03/gnu-linux-workshop-saveetha/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Thiagarajar College of Engineering, Madurai</title>
    <link>http://www.shakthimaan.com/posts/2005/08/20/gnu-linux-workshop-tce/news.html</link>
    <description><![CDATA[<p>I would like to thank Senthil Kumaran, Arpit Sud, Praveen, Joe Steeve, Prof. Shalini (HOD, CSE), and other volunteers for working with me for the past one month in planning, and coordinating the GNU/Linux workshop that was held on Saturday, August 20, 2005 at <a href="http://www.tce.edu/">Thiagarajar College of Engineering, Madurai, Tamil Nadu, India</a>.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album15/audience_5.jpg
"></img><br />
<p>The following topics were addressed: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">careers with GNU/Linux</a>, <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for Engineers</a>, and the GNU/Linux desktop. An interactive Q&amp;A session was also organized. We also played “The.Code.Linux” movie.</p>
<p>You can check out more photos from my <a href="http://www.shakthimaan.com/Mambo/gallery/album15">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 20 Aug 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/08/20/gnu-linux-workshop-tce/news.html</guid>
</item>
<item>
    <title>FOSS Road Show, Bannari Amman Institute of Technology, Sathyamangalam</title>
    <link>http://www.shakthimaan.com/posts/2005/08/06/floss-road-show-bit/news.html</link>
    <description><![CDATA[<p>I would like to thank Hariram Aatreya for the opportunity given to me to accompany Murali, Chandrasekhar, and Venkatesh from the <a href="http://www.au-kbc.org/">AU-KBC</a> center, Madras Institute of Technology for the FLOSS road show to <a href="http://www.bitsathy.ac.in/">Bannari Amman Institute of Technology, Sathyamangalam, Tamil Nadu, India</a> on August 6, 2005.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album14/invocation2_13.jpg
"></img><br />
<p>The faculty, management and students were very much interested in GNU/Linux, and are planning to start a GLUG and increase their activities with GNU/Linux. Representatives from seven different colleges in and around Sathyamangalam had also come for the workshop.</p>
<p>On the way back we checked out the FLOSS lab at <a href="http://www.kongu.ac.in/">Kongu Engineering College, Erode</a>, and the projects they had been working on. I must thank them for staying back till eight in the night as we finished late in the evening at Bannari Amman Institute of Technology.</p>
<p>Kongu Engineering College LUG started with six members in 2003, and it has now grown to 170 members from all the departments. They meet every week. A former student (just graduated), Arvind Kalyan, was responsible for taking the initiative in 2003. Professors (like Prof. Jayapathi, HOD, CSE department) and the management provided the support for the FOSS activities, and continue to do so. The juniors are now continuing the tradition :). They have also agreed to collaborate with Bannari Amman Institute of Technology for FOSS projects.</p>
<p>You can view the photos of the trip and the workshop from my <a href="http://www.shakthimaan.com/Mambo/gallery/album14">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 06 Aug 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/08/06/floss-road-show-bit/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Alagappa University, Karaikudi</title>
    <link>http://www.shakthimaan.com/posts/2005/07/23/gnu-linux-workshop-alagappa/news.html</link>
    <description><![CDATA[<p>I would like to thank the Correspondent, Dr. (Tmt.) Umayal Ramanathan, the Registrar, Mr. Dhandapani, CSE HOD, Dr. S. Sakthivel, <a href="http://www.alagappauniversity.ac.in/">Alagappa University, Karaikudi, Tamil Nadu, India</a> for providing me with an opportunity to conduct a GNU/Linux workshop for the MCA students on Saturday, July 23, 2005.</p>
<img alt="Audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album13/floss_4.jpg
"></img><br />
<p>The labs already run Red Hat, but, it is used at a basic programming (bash scripting, desktop usage) level. I conducted the following sessions: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">career opportunities with GNU/Linux</a>, and on <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for engineers</a>.</p>
<p>The download speeds are not that high at the Institute. I gave them Knoppix 3.6, Fedora Core 3, The.Code.Linux.avi, C-DAC tamil fonts, and the presentation slides in CDs. BSNL provides Internet connection facilities for the University. Sify has netcafe centers in the city, which have much better download speeds. Most of them have a computer at home. I have told them to send e-mails if they require any CDs, and we can simply send the CDs to them through courier.</p>
<p>The students were very much interested in GNU/Linux. You should have seen their eyes, the eagerness and willingness to really learn, and to understand the fundamental concepts.</p>
<p>Few photos taken during the trip can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album13">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 23 Jul 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/07/23/gnu-linux-workshop-alagappa/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Saranathan College of Engineering, Tiruchirapalli</title>
    <link>http://www.shakthimaan.com/posts/2005/07/16/gnu-linux-workshop-saranathan/news.html</link>
    <description><![CDATA[<p>I would like to thank the Tiruchirapalli MySQL group and CSE department faculty, students, and the management of <a href="http://www.saranathan.ac.in/">Saranathan College of Engineering, Tiruchirapalli, Tamil Nadu, India</a> for giving me an opportunity to conduct a one-day GNU/Linux workshop. The workshop was announced in the newspapers, “The Indian Express” and “The Hindu”.</p>
<img alt="Staff" src="http://www.shakthimaan.com/Mambo/gallery/albums/album12/before_workshop_2.jpg
"></img><br />
<p>The following topics were addressed: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">Careers with GNU/Linux</a>, <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for Engineers</a>, and a demo of the GNU/Linux Desktop.</p>
<p>The MYSQL group is working on using LAMP on GNU/Linux for the Pulivazham village cooperative society milk center farmers. They require to keep track of accounts, volume of milk stored in the facilities, and general book-keeping activities. Good luck to the Tiruchirapalli MySQL team for this project. Hopefully next time when we visit, we will see Pulivazham farmers using GNU/Linux for their day-to-day activities.</p>
<p>Thanks to S. Srinivasan, T. Shivakumar, Arul Jeeva, and Lakshminarayanan of Tiruchirapalli MySQL group, <a href="http://harshainfotech.com/">Harsha Infotech</a>, and <a href="http://www.rajaramsystems.com/">Rajaram Systems</a>.</p>
<p>Special thanks to Ramkumar L who has been working with me in planning this event for the past two weeks. Thanks to Prof. Venkatasubramanian, HOD, CSE Department, Saranathan College of Engineering for coordinating the sessions.</p>
<p>The photos of the workshop (and the trip) can be viewed from my <a href="http://www.shakthimaan.com/Mambo/gallery/album12">/gallery</a>.</p>]]></description>
    <pubDate>Sat, 16 Jul 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/07/16/gnu-linux-workshop-saranathan/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, St. Joseph's College of Engineering</title>
    <link>http://www.shakthimaan.com/posts/2005/07/02/gnu-linux-workshop-sjce/news.html</link>
    <description><![CDATA[<p>The photots taken during the GNU/Linux workshop on July 2, 2005, for MCA and M.Sc. IT students at <a href="http://stjosephs.ac.in/">St. Joseph’s College of Engineering, Chennai, Tamil Nadu, India</a> are available in my <a href="http://www.shakthimaan.com/Mambo/gallery/album10">/gallery</a>.</p>
<img alt="audience" src="http://www.shakthimaan.com/Mambo/gallery/albums/album10/presentation_4.jpg
"></img><br />
<p>I conducted the following sessions: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">careers with GNU/Linux</a>, and <a href="http://shakthimaan.com/downloads.html#free-software-for-engineers">Free Software for Engineers</a>. The.Code.Linux movie was also shown to the participants.</p>
<p>I would like to thank Parvathavarthini Mam (HOD, MCA), Faculty (MCA, M.Sc. IT departments), Anandhi Subramanian Mam, and the Management, St. Joseph’s College of Engineering, Chennai for providing the Audio-Visual hall for the GNU/Linux workshop.</p>]]></description>
    <pubDate>Sat, 02 Jul 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/07/02/gnu-linux-workshop-sjce/news.html</guid>
</item>
<item>
    <title>GNU/Linux workshop, Kongu Engineering College, Erode</title>
    <link>http://www.shakthimaan.com/posts/2005/01/17/gnu-linux-workshop-kongu/news.html</link>
    <description><![CDATA[<p>I would like to thank the Computer Science Department - the students, professors, HOD and Dean, <a href="http://www.kongu.ac.in/">Kongu Engineering College, Erode, Tamil Nadu, India</a> for giving me an opportunity to conduct a one-day workshop/seminar on “GNU/Linux/OSS” on January 17, 2005 (Monday).</p>
<p>Special thanks to Arvind Kalyan (final year, CS) who has been working with me for the past three weeks in meticulously planning the seminar, and answering my questions. Special thanks goes to the Management for the good hospitality and stay provided at the guest house. The infrastructure at your college is <em>state-of-the-art</em>. Thanks for providing all the required facilities for the seminar.</p>
<p>The following is a summary of the workshop events:</p>
<p>Session I: <a href="http://shakthimaan.com/downloads.html#careers-with-gnu-linux">“Careers with GNU/Linux/OSS”</a> (morning)</p>
<p>Session II: <a href="http://shakthimaan.com/downloads.html#linux-device-driver-programming-code-examples">Introduction to device driver programming</a> (morning)</p>
<p>Session III: Knoppix demo and GNU/Linux installation (afternoon)</p>
<p>Session IV: Watched the movie, The.Code.Linux.avi (evening)</p>
<p>We shall organize more events in future as a collaboration between <a href="http://ilugc.in">ILUGC</a> and Kongu Linux User’s Group.</p>]]></description>
    <pubDate>Mon, 17 Jan 2005 10:00:00 UT</pubDate>
    <guid>http://www.shakthimaan.com/posts/2005/01/17/gnu-linux-workshop-kongu/news.html</guid>
</item>

    </channel> 
</rss>
