news

2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 FOSS documentation emacs fedora foss freedom gnome haskell install laptop photo ruby travel verilog vhdl vlsi xmonad


[Published in Open Source For You (OSFY) magazine, April 2016 edition.]

This article in the GNU Emacs series takes readers on how to use HTML mode, do indentation, and use the Magit interface.

HTML mode

You can use HTML mode to effectively edit HTML and CSS files using GNU Emacs. To start the mode, use M-x html-mode. You will see the string ‘HTML’ in the mode line.

Default template

A default HTML template can be started by opening a test.html file, and using C-c C-t html. It will produce the following content:

<html>
  <head>
<title>

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:

<html>
  <head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>

<address>
<a href="mailto:user@hostname">shakthi</a>
</address>
</body>
</html>

Tags

You can enter HTML tags using C-c C-t. GNU Emacs will prompt you with the available list of tags. A screenshot of the available tags is shown in Figure 1:

HTML tags

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 Enter key, and the anchor tag will be completed. The final output is shown below:

<a href="http://www.shakthimaan.com"></a>

You can insert a h2 tag by specifying the same after C-c C-t. You can also add any attributes, as required. Otherwise, simply hitting the Enter key will complete the tag. The rendered text is as follows:

<h2></h2>

You can insert images using the alt tag. You can specify the src attribute and a value for the same. It is also a good practice to specify the alt attribute for the image tag. An example is shown below:

<img alt="image" src="http://shakthimaan.com/images/ShakthiK-workshop-A4-poster.png">

Unordered lists can be created using C-c C-t followed by ‘ul’. It will then prompt you for any attributes that you want included in the tag. You can hit the Enter key, which will prompt you with the string ‘List item:’ to key in list values. An example of the output is shown below:

<ul>
  <li>One
    <li>Two
      <li>Three
</ul>

You can neatly align the code by highlighting the above text and indenting the region using C-M-\. The resultant output is shown below:

<ul>
  <li>One
  <li>Two
  <li>Three
</ul>

If you wish to comment out text, you can select the region and type M-q. The text is enclosed using “<!--” and “-->”. For example, the commented address tags in the above example look like what follows:

<!-- <address> -->
<!-- <a href="mailto:shakthi@achilles">shakthi</a> -->
<!-- </address> -->

A number of major modes exist for different programming environments. You are encouraged to try them out and customize them to your needs.

Accents

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:

Shortcut Character
C-x 8 ’ a á
C-x 8 " e ë
C-x 8 / E Æ
C-x 8 3/4 ¾
C-x 8 C ©
C-x 8 L £
C-x 8 P
C-x 8 u µ
C-x 8 R ®
C-x / / ÷

Indentation

Consider the following paragraph:

“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.”

You can neatly fit the above text into 80 columns and 25 rows inside GNU Emacs using M-q. The result is shown below:

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.

You can also neatly indent regions using the C-M-\ shortcut. For example, look at the following HTML snippet:

<table>
<tr>
<td>Tamil Nadu</td>
<td>Chennai</td> 
</tr>
<tr>
<td>Karnataka</td>
<td>Bengaluru</td> 
</tr>
<tr>
<td>Punjab</td>
<td>Chandigarh</td> 
</tr>
</table>

After indenting the region with C-M-\, the resultant output is shown below:

<table>
  <tr>
    <td>Tamil Nadu</td>
    <td>Chennai</td> 
  </tr>
  <tr>
    <td>Karnataka</td>
    <td>Bengaluru</td> 
  </tr>
  <tr>
    <td>Punjab</td>
    <td>Chandigarh</td> 
  </tr>
</table>

If you have a long line which you would like to split, you can use the C-M-o shortcut. Consider the quote:

“When you’re running a startup, your competitors decide how hard you work.” ~ Paul Graham

If you keep the cursor after the comma, and use C-M-o, the result is shown below:

"When you're running a startup, 
                                your competitors decide how hard you work." ~ Paul Graham

Magit

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:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)

When you do M-x list-packages, 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.

When you open any file inside GNU Emacs that is version controlled using Git, you can start the Magit interface using M-x magit-status. I have bound this key to C-x g shortcut in ~/.emacs using the following:

(global-set-key (kbd "C-x g") 'magit-status)

The default magit screenshot for the GNU Emacs project README file is shown in Figure 2.

Magit

Pressing ‘l’ followed by ‘l’ will produce the history log in the magit buffer. A screenshot is provided in Figure 3.

History

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 M-x magit-status to update the Magit buffer status.

A sample screenshot of the modified files and staged changes is shown in Figure 4.

Staged

You can hit TAB and Shift-TAB 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.

You can create and checkout branches using the ‘b’ shortcut. A screenshot of the magit branch pop-up menu is shown in Figure 5.

Branch

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 ( https://magit.vc/ ) to learn more.

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.

After reviewing many models and configurations, I purchased the Lenovo E460 model that comes with FreeDOS, and swapped the default HDD for SSD (< 500 GB).

Lenovo E460 screen

Specification

  • Intel(R) Core(TM) i5-6200 CPU @ 2.30 GHz (4 processors).
  • 14" display
  • 437 GB SSD disk
  • 8 GB RAM
  • Intel Corporation HD Graphics 520
  • Intel Dual Band Wireless-AC 3165 Plus Bluetooth
  • Intel I219-V Ethernet Controller
  • 3 USB ports
  • 1 HDMI port
  • 4-in-1 Card Reader
  • FreeDOS
  • 1.81 kg

Parabola GNU/Linux Libre

I tried Trisquel GNU/Linux first on on this laptop. It is a derivative of Ubuntu without non-free software. I experimented with Qubes OS, but, its dom0 has proprietary blobs. GNU Guix 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 Parabola GNU/Linux Libre, a derivative of Arch, without the binary blobs.

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 Mate desktop environment with XMonad setup as a tiling window manager.

Lenovo E460 screen

Audio works out of the box. I do not use the web cam. I had to use the package scripts to install Grisbi as it was not available in the base repository. Virtualization support exists on this hardware, and hence I use Virtual Machine Manager, QEMU and libvirt.

Command Output

All the hardware worked out of the box, except for the wireless which requires a binary blob. So, I purchased a ThinkPenguin Wireless N USB Adapter for GNU/Linux which uses the free ath9k Atheros wireless driver.

As mandatory, I am providing some command outputs.

$ 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

Conclusion

Lenovo E460 screen

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 “Inside GNU/Linux” sticker covers the web cam, and the “Free Software Foundation” sticker is pasted behind the screen. The folks at #parabola IRC channel on irc.freenode.net are quite helpful. The Parabola GNU/Linux Libre Wiki has excellent documentation for your reference.

DLF I
DLF II
DLF III

[Published in Open Source For You (OSFY) magazine, March 2016 edition.]

In this next article in the GNU Emacs series, you will learn how to use its calendar, center text, macros and drawing tools.

Calendar

You can use and display a calendar inside GNU Emacs using the following command (also see figure below):

M-x calendar
Calendar

Day

You can move forward by a day using the C-f shortcut, and move back a day using the C-b keys. You can move to the current date using the ’.’ key.

To start the week on a Monday, set the following in your ~/.emacs.

(setq calendar-week-start-day 1)

Week

If you wish to move forward by a week, you can use the C-n shortcut, and to move back by a week, use the C-p shortcut. The C-a shortcut can be used to move to the beginning of the week, while the C-e shortcut can be used to move to the end of the week.

Month

You can move to the beginning of a month using the M-a shortcut. To move to the end of the month, use M-e.

You can move forward and backward a month using the M-} and M-{ shortcuts, respectively.

If you wish to scroll forward three months, use the C-v shortcut. To scroll backward three months, use the M-v shortcut.

Year

In order to move forward a year, you can use the C-x ] shortcut, and to move back a year, you can use the C-x [ shortcut.

You can go to a specified date using the g d key combination. It will then prompt you with the messages “Year (>0):”, “Month name:” and “Day (1-31):”, and will take you to the specified date.

You can move to the beginning of the year using the M-< shortcut, and to the end of the year using the M-v shortcut.

You are encouraged to read the ‘Calendar’ section in the GNU Emacs manual at https://www.gnu.org/software/emacs/manual/html_node/emacs/Calendar_002fDiary.html#Calendar_002fDiary, to learn more.

Centering

Consider the following poem that I wrote in 2015:

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.

You can center the title “Poem” by placing the cursor on it, and typing “M-x set-justification-center”.

Marking and highlighting the poem, and using M-x center-region will center the poem. The output is shown below:

         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. 

Macros

Macros are recorded key strokes that can be stored and replayed. You can start defining a keyboard macro using C-x ( command or the F3 key. You can then type a series of keys that constitute the macro. To finish defining the macro, you can use C-x ) or the F4 key. In order to execute the previous defined macro, you can use C-x e shortcut or F4.

Consider the following text in a buffer that contains a serial number, date and an examination subject list:

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

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:

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

Using C-x e or F4 repeatedly will turn the above input CSV text into the following:

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

You can give a name (say, ‘comma’) to the previously defined macro using C-x C-k n. You can then execute the macro using M-x comma. You can also insert the named macro into a file using M-x insert-kbd-macro command. You can bind a macro to a key using C-x C-k b shortcut.

If you wish to apply the macro to each line in a region, you can use C-x C-k r keys. In order to cycle between the previous and next macros in the macro ring, you can use C-x C-k C-p and C-x C-k C-n shortcuts respectively. You can also delete a macro using C-x C-k C-d key combination.

Picture mode

You can draw diagrams inside Emacs using Picture mode. To start Picture mode, use M-x picture-mode command, and to exit use the C-c C-c shortcut.

The cursor movement keys in a buffer are also applicable in picture mode. To move the cursor right, you can use the C-f keys, and to move left by one character, you can use the C-b shortcut. To move the cursor up and down by one character, use the C-p and C-n shortcuts, respectively. The C-d shortcut is used to delete a character.

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.

Shortcut Direction
C-c ^ Up
C-c . Down
C-c > Right
C-c < Left
C-c ` Northwest
C-c ’ Northeast
C-c / Southwest
C-c
Southeast

If you want to move the cursor forward in the drawing direction, you can use the C-c C-f shortcut. To move the cursor backward, use the C-c C-b key combination. If you want to delete a line, use the C-k command. You can insert a new line using the C-o shortcut. You can also draw a rectangle around a region using the C-c C-r shortcut. A drawing done using Picture mode is shown in Figure 2.

Diagram using Picture mode

Artist mode

Artist mode can also be used to draw diagrams in GNU Emacs. You can enter this mode using M-x artist-mode, and exit the same using C-c C-c.

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 Enter key. This is equivalent to putting the pen down when drawing, and lifting it up when you want to perform a different action.

The buffer navigation commands to move right and left are the same as C-f and C-b shortcuts respectively. You can move up a column using the C-p shortcut, and move down a column using the C-n key.

You can draw geometric shapes using Artist mode. To select a shape or operation you can use C-c C-a C-o key combination. This will provide a list of shapes and actions you can perform. This list is shown in Figure 3:

Artist mode operations

The shortcuts listed in the following table are available for drawing specific shapes:

Shortcut Shape
C-c C-a e Ellipse
C-c c-a p Polylines
C-c C-a r Rectangles
C-c C-a l Lines

Figure 4 depicts an ellipse drawn using Artist mode:

Ellipse

Figure 5 is an example of polylines:

Polylines

You can fill a shape using C-c C-a f key combination. The following Figure 6 shows a circular representation filled with dots.

Circle fill

You can also spray characters in the buffer using the C-c C-a S shortcut keys. An example is shown in Figure 7:

Spray

The character to be used for drawing can be changed using C-c C-a C-l shortcut. The character to fill shapes can be set using C-c C-a C-f key combination.

If you want to cut an area, you can draw a rectangle around it using C-c C-a C-k key combination. You can also copy the image area using the C-c C-a M-w keys, and paste the same using C-c C-a C-y or C-x r y shortcuts. To set the operation to erase text, you can use C-c C-a C-d key combination.

You can refer to the Emacs Wiki Artist mode for more documentation and help - http://www.emacswiki.org/emacs/ArtistMode.

I attended Functional Conf 2016 at Hotel Chancery Pavilion, Bengaluru between October 13-16, 2016. The conference was on October 14-15, 2016 and there were pre- and post-conference workshops.

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.

Kanteerva Stadium

Pre-Conference Workshop

I had registered for the “Deep Dive into Erlang Ecosystem” workshop by Robert Virding, one of the creators of the Erlang programming language. 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 Open Telecom Platform (OTP) 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.

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 Lisp Flavoured Erlang (LFE). 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.

Day I

Robert Virding

The keynote of the day was from Robert Virding on “The Erlang Ecosystem”. 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:

<<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, 
      ID:16, Flgs:3, FragOff:13,
      TTL:8, Proto:8, HdrChkSum:16,
      SrcIP:32,
      DestIP:32, RestDgram/binary>>

Robert’s keynote was followed by another keynote by Brian McKenna on “No Silver Bullets in Functional Programming”. 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.

The next talk that I attended was by Aloïs Cochard on “Welcome to the Machines”. He gave an overview on the history of various Haskell libraries for data stream processing (pipes, conduit) and finally provided a tutorial on machines.

Abdulsattar Mohammed introduced the need for dependent types using Idris with simple examples in his “Dependently Typed Programming with Idris” talk. The concepts were well narrated with numerous code snippets.

The next talk by Debasish Ghosh on “An algebraic approach to functional domain modeling” 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.

Ravi Mohan started his talk titled, “Equational Reasoning - From Code To Math and Back Again”, 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.

“Implementing Spark like system in Haskell” was an interesting session by Yogesh Sajanikar 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 https://github.com/yogeshsajanikar/hspark.

Day II

The second day began with the keynote by John Hughes on “Why Functional Programming Matters”. 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 famous paper with the same title.

This was followed by a series of demos on cool features in Functional Programming languages - Erlang, Idris, APL, F# and Julia.

“Using F# in production: A retrospective” was a talk by Ankit Solanki 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.

“Real world functional programming in Ads serving” was a talk by Sathish Kumar 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.

I skipped the next talks, and spent time with Robert Virding in the Erlang booth.

Rethinking “State Management.” was presented by Tamizhvendan S. He narrated examples on state management for a cafe application using F#. He also gave a demo of Ionide text editor and its features.

Post-conference workshop

I attended John Hughes workshop on Property-based Testing. Initially, I thought he would be using Haskell QuickCheck, but, in the workshop he used the Erlang implementation. John mentioned that the Haskell and Erlang implementations are different, and their interests have diverged.

John Hughes

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.

The property-based testing has been used by his company, QuviQ, 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:

3,000 pages of specification
20,000 lines of QuickCheck
1,000,000 LoC, 6 suppliers
200 problems
100 problems in the standard

He also shared his experience in generating tests for Klarna - an invoicing service web shop that uses Mnesia - the distributed Erlang database. He concluded by saying that we should not write tests, but, they shoud be generated.

Overall, the workshops were quite useful. It was good to have met both Robert Virding and John Hughes.

[Published in Open Source For You (OSFY) magazine, February 2016 edition.]

In this next article in the GNU Emacs series, we shall learn how to use GNU Emacs as a news reader.

Elfeed

Elfeed is an Emacs web feed reader that is extensible and supports both Atom and RSS feeds. It has written by Christopher Wellons.

Installation

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:

(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

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

The above code snippet has been taken from the MELPA project documentation website http://melpa.org/#/getting-started, and has been tested on GNU Emacs 24.5.2.

You can now start GNU Emacs using the following command:

$ emacs -Q -l ~/elfeed-start.el

You can obtain the list of available packages using M-x list-packages, 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.

Configuration

You can create a shortcut to start Elfeed using the following code snippet in your ~/elfeed-start.el file.

(global-set-key (kbd "C-x w") 'elfeed)

The list of feeds can be defined as shown below:

(setq elfeed-feeds
      '(("http://www.shakthimaan.com/news.xml" people)
        ("http://arduino.cc/blog/feed/" projects)
        ("http://planet-india.randomink.org/rss10.xml" people planet)
        ))

Tags can be added at the end of the feed. The above feeds include ‘people’, ‘projects’ and ‘planet’ tags.

Usage

You can use the C-x w 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:

Elfeed

The RSS entries are stored in ~/.elfeed directory on your system.

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.

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”.

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:

Elfeed filter

You can also use regular expressions as part of your filter text. The default search filter can be changed by modifying the value of elfeed-search-filter. For example:

(setq-default elfeed-search-filter "@1-month-ago +unread")

The search format date can be customized as shown below:

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

Elfeed also has an export option to view the feeds in a browser. If you install the elfeed-web package from the packages list, you can then start it using M-x elfeed-web-start. You can then start a browser, and open http://localhost:8080/elfeed/ to view the feeds. A screenshot is shown below:

Elfeed web

The entire contents of the elfeed-start.el configuration file are shown below:

(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

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

(global-set-key (kbd "C-x w") 'elfeed)

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

(setq elfeed-feeds
      '(("http://www.shakthimaan.com/news.xml" people)
        ("http://arduino.cc/blog/feed/" projects)
        ("http://planet-india.randomink.org/rss10.xml" people planet)
        ))

Gnus

Configuration

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 emacs -Q in the terminal, you can start Gnus using M-x gnus. 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:

Gnus

Usage

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.

Gnus articles

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:

Gnus blog entry

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.

[Published in Open Source For You (OSFY) magazine, January 2016 edition.]

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.

Shell mode commands

You can run a shell command from GNU Emacs using the M-! 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 C-u M-! command sequence.

Consider the following poem that I wrote:

"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."

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 M-| shortcut. It then prompts with the string ‘Shell command on region’, and when I type in ‘wc -w’ it returns ‘90’.

Shells

There are three shells available in GNU Emacs - shell, ansi-term and eshell. Using M-x shell will invoke a shell for you. This starts a new buffer with the name ‘shell’ in it. You can use all the GNU Emacs buffer commands in this window. For example, C-p will move the cursor up, and C-n will move the cursor down. In order to interrupt a current job in the shell buffer, you can use C-c C-c. If you want to suspend the current job, you can use C-c C-z. You can also clear the output from the previous command using C-c C-o. For example, the output of ‘ifconfig’ command is shown below:

/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 $

After executing ‘C-c C-o’, the previous command output gets cleared as shown below:

/tmp $ ifconfig docker0
 *** output flushed ***
/tmp $

You can move the cursor up to the previously executed commands using C-c C-p and move down using C-c C-n. You can also cycle backwards and forwards through the command history using the M-p and M-n shortcuts respectively. The C-c C-r 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 C-c C-e. The C-r key binding allows you to search for a previously typed command from history.

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 C-u M-x shell. The new shell buffer will be called ’shell<2>". You can, of course, rename this buffer. You can thus open multiple shells to work inside GNU Emacs.

GNU Emacs also has a terminal emulator that you can invoke using M-x ansi-term. 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 M-x eshell. The advantage of using this is that you can extend it, write your own customized Elisp functions and use it similar to shell scripting.

Screenshots of shell, ansi-term and eshells in GNU Emacs are shown in Figure 1, 2 and 3 respectively:

shell ansi-term eshell

Spell check commands

You can check the spelling of a word by placing the cursor on it and using M-$ shortcut. For example, for the word ‘hte’, GNU Emacs provides the following spelling options:

(0) hate (1) HT (2) ht (3) GTE (4) the (5) He (6) Te (7) he (8) Hts
(9) hie (:) hoe (;) hue (<) Rte (=) Ste (>) Ute (@) ate (B) rte

It also lists some options in the minibuffer:

C-h or ? for more options; SPC to leave unchangedo Character to
replace word

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 M-x ispell-region and a buffer using M-x ispell-buffer. If you would like to stop the spell checker while it is running, you can use M-x ispell-kill-ispell. There is a flyspell mode that can check your spelling as you type. You can enable it using M-x flyspell-mode. If you want this mode only in a buffer, you can use M-x flyspell-buffer.

Word abbreviation

GNU Emacs can complete words for you. If you type ‘ba’ and then hit M-/, 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 M-x abbrev-mode followed by the Enter key.

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 C-x a i l 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 C-x a i g command sequence. If you would like to remove all abbreviations for the current session, you can use M-x kill-all-abbrevs followed by the Enter key.

You can save the abbreviations to a file, say ~/.emacs.d/.abbrev_defs, using M-x write-abbrev-file for future use. You can also edit the stored abbreviations using M-x edit-abbrevs shortcut. If you would like to view all the defined abbreviations, you can use M-x list-abbrevs. The relevant contents of ~/.emacs.d/.abbrev_defs are shown below:

;;-*-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
  '(
    ("intl" "international" 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 '())

Printing

You can print the buffer contents from GNU Emacs using M-x print-buffer command. If you would like to print a selected region, you can use M-x print-region command. These will be printed with page numbers and headers. You can also print a buffer without page numbers using M-x lpr-buffer. Similarly, to print a region without page numbers, use M-x lpr-region. If you are already using the Dired mode, you can select the files that you want to print using the P shortcut, and then execute in Dired mode to print them.

[Published in Open Source For You (OSFY) magazine, December 2015 edition.]

In this article in the GNU Emacs series, we shall learn how to play games and try out some software for fun.

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.

Tetris

Tetris is available in GNU Emacs and you can launch it using M-x tetris. 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:

112 shakthi shakthi <author@shakthimaan.com>  Mon Nov  2 21:12:04 2015
52 shakthi Shakthi Kannan <author@shakthimaan.com>  Mon Nov  2 15:24:43 2015
11 shakthi shakthi <author@shakthimaan.com>  Mon Nov  2 15:29:39 2015

A screenshot of Tetris in GNU Emacs:

Tetris

Pong

You can play Ping Pong in GNU Emacs with two players using M-x pong. 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:

Pong

Doctor

GNU Emacs comes with a psychotherapist with whom you can chat. Simply type M-x doctor 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:

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.

Bubbles

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 M-x bubbles. 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:

Bubbles

At the end of the game, a summary of the score is shown.

Selected:    9
Score:    1932
Game Over!

GNU Emacs also keeps a record of the scores:

01959   Mon Nov  2 21:26:41 2015        shakthi <author@shakthimaan.com>
01932   Mon Nov  2 21:20:38 2015        shakthi <author@shakthimaan.com>

Conway’s life

The shortcut M-x life 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:

Conway's Life

Morse and NATO conversions

You can convert text to Morse code and vice versa by selecting the text in a buffer and using M-x morse-region. For example, the text ‘morse code’ gets converted to the following:

--/---/.-./.../. -.-./---/-../.

You can get back the text by selecting the Morse text and applying M-x unmorse-region. Similarly, if you have a word that you would like to spell using the NATO phonetic alphabet, you can use M-x nato-region. To convert it back, you need to use M-x denato-region. For example, the text ‘abc’ gets converted to:

Alfa-Bravo-Charlie

Snake

The Snake game can be started using M-x snake. 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:

Snake

Dunnet

Dunnet is a text based adventure game that needs to be started in batch mode as shown below:

$ 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.

The help command gives you the context of the game:

>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

You can then give directions and proceed with the game. An example of a session is shown below:

>n
You can't go that way.
>s
You can't go that way.
>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.
>in
You can't go that way.
>w
Dead end
There is a shovel here.
>d
You can't go that way.
>e
E/W Dirt road
There is a large boulder here.
>n s e
You can't go that way.
>in
You can't go that way.
>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.
>w
E/W Dirt road
There is a large boulder here.

You can exit the game by typing ‘quit’ at the prompt (>).

Gomoku

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 Enter 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:

Gomoku

Le Solitaire

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 Shift key with the arrow keys to move a stone. A screenshot of the game in progress:

Le Solitaire

All the games and examples were tried on GNU Emacs 24.5.1.

[Published in Open Source For You (OSFY) magazine, November 2015 edition.]

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.

Search

You can copy the following poem, which I wrote in 2013, in the scratch buffer or a file inside GNU Emacs to try out the search commands:

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.

You can search for a word in a buffer using C-s shortcut. You will then be prompted with I-Search: 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 Enter key, or abort the search using the C-g 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 C-r shortcut.

If you place the cursor on the letter ‘E’ in ‘Emacs’ in the poem’s first line, and press C-s C-w, 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 C-s C-y shortcut. You can repeat the previous forward search using C-s C-s, and the previous backward search using C-r C-r shortcuts.

The first occurrence of a text can be looked up in the forward direction using C-s. This will prompt you in the minibuffer with a Search: string where you can type the text that you want to search for, and then press the Enter 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 C-r. You can then input the search string to be searched for, followed by the Enter key.

Regular expression searches are very useful too. In order to search forward for an expression, you can use C-M-s followed by the Enter 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 C-M-r shortcut. To perform an incremental forward search, you need to use C-M-s 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 C-M-r for an incremental backward regex search.

A common use case is to find and replace text in a buffer. The sequence to be used is M-x query-replace followed by the Enter 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 C-M-% shortcut key combination.

Frames

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.

You can create a new frame using C-x 5 2 key combination. You can move the cursor to the next frame using C-x 5 o (letter ‘o’), and delete the current frame using C-x 5 0 (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 C-x 5 f. You can also open a file in a new frame in read-only mode using C-x 5 r. To switch to the buffer in a new frame, use C-x 5 b key combination.

Windows

You can split a frame vertically to create two windows using C-x 2 (Figure 1).

Split frame vertically

To split horizontally, you can use C-x 3 (Figure 2).

Split frame horizontally

To move the cursor to the next window, use C-x o (the letter ‘o’). You can delete the current window using C-x 0 (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 C-x 1.

You can open a file in a new window using C-x 4 f. You can also select an existing buffer in another window using C-x 4 b. If you have multiple windows that you would like to be balanced equally, you can use C-x +. Figure 3 shows an Emacs screenshot with three windows that are balanced.

Balanced windows

You can scroll the contents in the other window using C-M-v. You can scroll backwards using C-M-Shift-v.

You can also use the following shortcuts in your ~/.emacs to simplify the shortcuts used to split and remove windows.

(global-set-key (kbd "C-1") 'delete-other-windows)
(global-set-key (kbd "C-2") 'split-window-below)
(global-set-key (kbd "C-3") 'split-window-right)
(global-set-key (kbd "C-0") 'delete-window)

If you would like to make a window wider, you can use C-x } shortcut and to reduce it horizontally, you will need to use C-x {. You can use a prefix count to perform the operation ‘n’ times. For example, C-u 5 C-x { to shrink a window horizontally. To make a window taller, you can use C-x ^ shortcut; and to make it smaller, you have to use a negative prefix. For example, C-u -1 C-x ^. A screenshot of a custom Emacs frame with three windows is shown in Figure 4.

Custom windows in a frame

I attended Deep Learning Conference 2016 at CMR Institute of Technology, Bengaluru on July 1, 2016.

Deep Learning Conference 2016 poster

Anand Chandrasekaran, CTO, Mad Street Den 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 LeNet, Deep Belief Network by Geoffrey Hinton, 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.

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).

After a short tea break, Abhishek Thakur 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 CIFAR.

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.

Food was arranged by Meal Diaries and it was delicious!

The post-lunch session began at 1410 IST with Arjun Jain 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.

Vijay Gabale 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.

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 Machine Learning course and Reinforcement Learning course were recommended. CS231n: Convolutional Neural Networks for Visual Recognition 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. Data Nuggets and Kagil are two good sources for datasets. The Kaggle Facial Keypoints Detection (KFKD) tutorial was also recommended. Data science does involve both programming and math. We then headed for a short tea break.

Nishant Sinha, from MagicX, 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 Predible Health. He spoke on the difficulties in dealing with medical data, especially biometric images. Their solution won the Multiple Sclerosis Segmentation Challenge in 2015.

The last talk of the day was on “Making Deep Neural Networks smaller and faster” by Suraj Srinivas 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.

Overall, it was a very useful one day conference.

« OLDER POSTS