Tag Archives: emacs

Plotting a weight chart using Emacs Org-Mode and Gnuplot

I discovered about Org-Mode a couple of years ago. Since then, I have started using it for various tasks. One of the recent usage is to track my daily weight. This article describes how to use Org-Mode and Gnuplot to plot your weight measurements.

Here is the list of software that I use in my setup.

For the purpose of this article, it is assumed that you have a similar setup that works for you.

As part of my daily measurement, I track three measurements namely, weight, body fat percentage and body water percentage. This data can be represented in an Org table that has four columns as follows. Please note that the data provided below is hypothetical.

#+PLOT: script:"Weight.plt"
| Date       | Weight |  BF% |  BW% |
|------------+--------+------+------|
| 05/01/2011 |  145.2 | 30.3 | 50.3 |
| 05/02/2011 |  145.1 | 29.4 | 50.7 |
| 05/03/2011 |  144.2 | 30.1 | 50.4 |
| 05/04/2011 |  144.0 | 29.0 | 50.8 |
| 05/05/2011 |  144.1 | 28.7 | 51.0 |
| 05/06/2011 |  144.2 | 29.2 | 50.7 |
| 05/07/2011 |  144.4 | 27.8 | 51.4 |
| 05/08/2011 |  143.7 | 27.6 | 51.5 |
| 05/09/2011 |  143.2 | 28.5 | 51.0 |
| 05/10/2011 |  142.8 | 30.1 | 50.4 |
| 05/11/2011 |  142.2 | 30.1 | 50.4 |
| 05/12/2011 |  142.4 | 29.8 | 50.5 |
| 05/13/2011 |  142.2 | 29.9 | 50.5 |
| 05/14/2011 |  141.2 | 27.4 | 51.6 |
| 05/15/2011 |  141.5 | 27.2 | 51.7 |
|------------+--------+------+------|
| 05/16/2011 |  141.2 | 28.8 | 51.0 |
| 05/17/2011 |  140.8 | 28.9 | 50.9 |
| 05/18/2011 |  140.2 | 29.5 | 50.7 |
| 05/19/2011 |  140.5 | 26.8 | 51.9 |
| 05/20/2011 |  140.4 | 28.1 | 51.3 |
| 05/21/2011 |  139.2 | 26.7 | 51.9 |
| 05/22/2011 |  137.1 | 27.0 | 51.7 |
| 05/23/2011 |  137.5 | 27.0 | 51.7 |
| 05/24/2011 |  137.4 | 28.5 | 51.1 |
| 05/25/2011 |  136.8 | 29.6 | 50.6 |
| 05/26/2011 |  136.3 | 28.8 | 51.0 |
| 05/27/2011 |  136.3 | 28.2 | 51.2 |
| 05/28/2011 |  136.3 | 28.9 | 50.9 |
| 05/29/2011 |  136.2 | 28.0 | 51.3 |
| 05/30/2011 |  135.9 | 28.8 | 50.9 |
| 05/31/2011 |  135.5 | 28.2 | 51.2 |
|------------+--------+------+------|
| 06/01/2011 |  135.1 | 28.2 | 51.2 |
| 06/02/2011 |  135.5 | 28.2 | 51.2 |
| 06/03/2011 |  134.8 | 28.9 | 50.9 |
| 06/04/2011 |  134.4 | 29.6 | 50.6 |
| 06/05/2011 |  134.2 | 27.9 | 51.3 |
| 06/06/2011 |  134.4 | 28.1 | 51.3 |
| 06/07/2011 |  133.2 | 29.2 | 50.8 |
| 06/08/2011 |  133.1 | 28.8 | 51.0 |
| 06/09/2011 |  133.0 | 28.6 | 51.0 |
| 06/10/2011 |  133.2 | 27.8 | 51.4 |
| 06/11/2011 |  132.2 | 27.9 | 51.4 |
| 06/12/2011 |  132.0 | 27.9 | 51.4 |
| 06/13/2011 |  132.1 | 28.9 | 51.0 |
| 06/14/2011 |  131.0 | 29.0 | 50.9 |
| 06/15/2011 |  130.2 | 27.6 | 51.5 |
|------------+--------+------+------|

I use the following Gnuplot script, Weight.plt that plots the weight, body fat percentage, absolute body fat, body water percentage and absolute body water.

# Weight plotter.

set terminal aqua title "Weight plot"
set xdata time
set timefmt '"%m/%d/%Y"'
set xlabel 'Date'

set multiplot

set size 1, 0.33

# Weight.
set origin 0, 0.66
set ylabel 'Weight in lb'
plot '$datafile' using 1:2 title 'Weight' with lines linecolor 2

set size 0.5, 0.33

# Body fat.
# Percentage.
set origin 0, 0.33
set ylabel 'Body fat %'
plot '$datafile' using 1:3 title 'Body fat %' with lines linecolor 1
# Absolute.
set origin 0.5, 0.33
set ylabel 'Body fat in lb'
plot '$datafile' using 1:($3 * $2 / 100) title 'Body fat' with lines linecolor 1

# Body water.
# Percentage.
set origin 0, 0
set ylabel 'Body water %'
plot '$datafile' using 1:4 title 'Body water %' with lines linecolor 3
# Absolute.
set origin 0.5, 0
set ylabel 'Body water in lb'
plot '$datafile' using 1:($4 * $2 / 100) title 'Body water' with lines linecolor 3

unset multiplot

Here is the screenshot of the generated plot. Click the thumbnail to get the actual size.

Making GNU Emacs detect custom error messages – A Maven Example

GNU Emacs‘s compilation mode is capable of detecting error messages from various standard compilers and build tools. However, it is fairy common for one to run into a format of error message that Emacs can’t handle by default.

As you know, Emacs is highly extensible and it provides compilation-error-regexp-alist for accomplishing this. I have done this a couple of times earlier and I had to do it one more time lately for adding regular expression for Maven error messages. Construction of these regular expressions is not fun for everyone. However, regexp-builder makes it easier to construct the regular expression interactively.

Because the documentation around compilation-error-regexp-alist isn’t very intuitive for most, I have decided to make this screencast that describes how to approach this from scratch. Sorry about the typos! For best quality, watch it in HD.

Read more »

GNU Emacs and MIT Scheme on Mac OS X

Today, I planned to go back to the basics by taking 6.001 Structure and Interpretation of Computer Programs offered by MIT OpenCourseWare. I’ll save the reason behind it for another post.

For running the programs that are used in the class, I decided to use MIT/GNU Scheme. I am running GNU Emacs 23 on my Mac OS X. After some research, I figured out the best way of doing this is through xscheme.

First, download the MIT/GNU Scheme binary for Mac OS X and copy it to your Applications directory. Then configure Emacs to use the downloaded binary by adding the following lines to your .emacs.

(setq scheme-program-name
      "/Applications/mit-scheme.app/Contents/Resources/mit-scheme")
(require 'xscheme)

Now write your Scheme program.

; Compute the square root of a given number using successive
; approximation.
 
(define (sqrt value)
  (define (is-good-enough? guess value)
    (< (abs (- (* guess guess) value)) 0.0000001))
 
  (define (try guess value)
    (if (is-good-enough? guess value)
	guess
	(try (/ (+ guess (/ value guess)) 2) value)))
 
  (try 1 value))
 
(sqrt 4.0)

Invoke the Scheme process by 'M-x run-scheme'. Send the Scheme buffer to the Scheme process by 'M-o' and now you are able to run Scheme programs from Emacs.

Below is the screenshot of Scheme running under my Emacs session.

Emacs and Scheme

MIT Scheme running under GNU Emacs

Introduction to Test-Driven Development in C++ using Boost Test Library

I have been following Test-Driven Development for a few years now. Even though TDD is widespread, often I come across a few friends who aren’t very familiar with TDD approach. It took a while for me to really appreciate TDD since I was introduced to it. When I demonstrated TDD in action, I got a few of my friends interested.

We have our own test framework that we use in our project which was primarily developed by David Carlton. It works very well for our needs. However, for my personal projects, I wanted to try something that is more widely used in the industry. I started using CppUnit for a while until I found Boost Test Library coming a long way. Now, I use Boost Test Library for all my personal projects. It is very easy to setup tests and I really like it.

I also wanted to write a quick introduction to Boost Test Library. So, I thought that I will put down a screencast that will solve two purposes of demonstrating Boost Test Library and serve as an introduction to TDD. This is not an extensive demo or an introduction. I have chosen a really simple problem that is often asked in preliminary rounds of technical interviews. But, it is a good place to start. I don’t guarantee that the solution is efficient. But, it is correct to my knowledge. Please feel free to suggest issues or improvements.

Please note that a HD version of this video is available when viewed on Vimeo’s site.

Introduction to Test Driven Development in C++ using Boost Test Library from Praveen Kumar on Vimeo.

Read more »

Simple GNU Emacs keyboard macro demonstration

My obsession for GNU Emacs has grown over years to an extent where I managed to get a significant amount of users to adopt Emacs. In the past 10 years, I have learned a lot of nice tricks that I can do on Emacs to improve my productivity. So, I have decided to create a series of screencasts demonstrating some of those.

I will start with a very simple one, macros. Quoting from Emacs documentation, “A keyboard macro is a command defined by an Emacs user to stand for another sequence of keys. For example, if you discover that you are about to type C-n M-d C-d forty times, you can speed your work by defining a keyboard macro to do C-n M-d C-d, and then executing it 39 more times.”

In this demo, I have taken a real world example where you have to add C++ class member variables and accessors. There are other efficient ways to do such tasks in GNU Emacs. I personally use yasnippets to do these things. However, this approach is shown just to demonstrate keyboard macros. To supplement this video, please take a look at the keyboard macro documentation that is available within Emacs.

Random links for week 46

  • Editing big chunks of text in Firefox text area is a pain. I am using “It’s all Text” Firefox add-on to edit text from a text area in external editors like Emacs, Vim, etc. I have configured my add-on to use emacsclient. I use this heavily when I have to edit text in TWiki, Bugzilla, WordPress, etc. This post is written in Emacs using this add-on.
  • Speaking of TWiki, I discovered last week that there is an Emacs major mode for editing TWiki markup. It is erin.el, named after Erin Gray. It has some WYSIWYG capabilities and a markup sampler. I will start using it to see how useful it would be.
  • I started using Org-babel, that lets you to execute source code in various languages within Org-mode documents. It is really cool! It can also do cool syntax highlighting in the exported files.
  • I store my daily weight measurements as an Org table in Emacs. I was using Gnuplot to plot these values to track progress. Last week, I learned about R project and started experimenting a bit with it as well. Data visualization really helps.
  • From next week, I am adding HIIT cardio sessions to my exercise routine. I am going to have my HIIT sessions on non-lifting days, which seems to be the most recommended strategy. I don’t love cardio as much as lifting weights. But, I am eagerly looking for experimenting with HIIT.

Random links for week 45

  • I have an Apple TV and I run XBMC and Boxee on my Apple TV using Patchstick. Apple introduced Apple TV 3.0 Software last week. Somehow, the software just got upgraded automatically causing me to lose XBMC and Boxee. Patchstick isn’t available for Apple TV 3.0 yet. So, I had to downgrade it using another Patchstick product (Canadian based).
  • I am using Whey protein supplement as my post workout drink for a while now. Recently, I came across Casein protein supplements and started using it too. I take Whey after workout and take Casein before going to bed (only on workout days). Here is an article that compares Whey and Casein.
  • I am using magit mode in Emacs with my git repositories. It is quite helpful most of the times.
  • DTrace is a powerful tool for tracing a process. Recently, we have started working on defining Statically Defined Tracing for our system. I feel that it is a quite powerful way to approach system tracing.

Random links for week 44

  • Since I updated to OpenSolaris update snv_124, I am facing issues with Indic fonts rendering. I have created a bug describing the problem. The root cause of the problem isn’t diagonized yet. If someone knows what could be wrong, please let me know.
  • I keep hearing a lot about Haskell lately and wanted to get introduced to functional programming through Haskell. David Carlton and friends recently started a Haskell study group. It was a great opportunity and wonderful setting for learning Haskell! I just joined the group. We are studying Real World Haskell. The book is available online. I am currently on chapter 3 and it is engaging. Please feel free to join the mailing list, if interested.
  • My latest Emacs addiction is Org-Mode. I started using Org-Mode to maintain my GTD workflow. I am also using it as my note taking tool and daily/weekly status reporting tool at work. Org-Mode is very powerful! Give it a try and you will find out.
  • I just got back into the habit of going to gym regularly after a couple of busy months at work. This time, one of my primary goal is to able to do unassisted chin-ups. Here is an article on how to increase one’s chin-ups. Currently, I am focusing on negatives.
  • I am a big fan of Hyderabadi Chicken Biryani. I came across this great recipe on YouTube and tried it out a couple of times. The one I prepared yesterday turned out really great! If you are a Biryani fan, I would strongly recommend this recipe.

Random links for week 36

  • My (ex-)manager David Carlton has decided to leave us to join Playdom. I learned a lot in the past two years working with him. We are going to miss him a lot! Playdom is fortunate to have such a talented individual on board. I am sure he will be bringing a multitude of perspectives into the game development at Playdom. I wish him all the very best in his new exciting game development career.
  • I am using git as my primary version control system at work. Lately, more of my friends have shown interest towards using git. For them, I would recommend knowing why git is better than other version control systems.
  • Recently, I have started editing multiple files with the same name (under different directories) simultaneously on my GNU Emacs more often. This got me confused easily and made me prone to making mistakes by editing wrong files. Here is a cool way to make buffer names unique in GNU Emacs.
  • Due to certain changes that are happening recently in our team, being agile is more of a necessity that ever before. I am seriously thinking of attending Agile Open California. Agile Open California is a coalition of agile practitioners and advocates with an intention to provide an opportunity for learning, networking and growth to the Agile community in California and others who are interested.
  • We are currently working on transitioning our software to 64-bit on Solaris. We run into interesting problems each day. Solaris 64-bit developer’s guide is a source of must know information for anyone who is working on developing 64-bit applications on Unix like platforms, especially Solaris.
  • Since I returned from India after my recent vacation, I haven’t got much chance to workout in the gym. I would like to use this opportunity for refreshing my appreciation of the basics of weight training and get a fresh start as early as next week.

Completely clueless

On my OpenSolaris. What could be more exciting than this?

praveen@athena:~$ /opt/sfw/bin/emacs
Fatal error (11).Segmentation Fault (core dumped)
 
praveen@athena:~$ file core
core:           ELF 32-bit LSB core file 80386 Version 1, from 'emacs'
 
praveen@athena:~$ gdb -c core /opt/sfw/bin/emacs
GNU gdb 6.3.50_2004-11-23-cvs
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...(no debugging symbols found)
 
Core was generated by `/opt/sfw/bin/emacs'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /opt/sfw/lib/libXaw3d.so.5...(no debugging symbols found)...done.
Loaded symbols for /opt/sfw/lib/libXaw3d.so.5
Reading symbols from /usr/lib/libXmu.so...done.
Loaded symbols for /usr/lib/libXmu.so
Reading symbols from /usr/lib/libXt.so.4...done.
Loaded symbols for /usr/lib/libXt.so.4
Reading symbols from /usr/lib/libSM.so.6...done.
Loaded symbols for /usr/lib/libSM.so.6
Reading symbols from /usr/lib/libICE.so.6...done.
Loaded symbols for /usr/lib/libICE.so.6
Reading symbols from /usr/lib/libXext.so.0...done.
Loaded symbols for /usr/lib/libXext.so.0
Reading symbols from /usr/lib/libtiff.so.3...done.
Loaded symbols for /usr/lib/libtiff.so.3
Reading symbols from /usr/lib/libjpeg.so.62...done.
Loaded symbols for /usr/lib/libjpeg.so.62
Reading symbols from /usr/lib/libpng12.so.0...done.
Loaded symbols for /usr/lib/libpng12.so.0
Reading symbols from /lib/libz.so.1...done.
Loaded symbols for /lib/libz.so.1
Reading symbols from /lib/libm.so.2...done.
Loaded symbols for /lib/libm.so.2
Reading symbols from /opt/sfw/lib/libungif.so.4...done.
Loaded symbols for /opt/sfw/lib/libungif.so.4
Reading symbols from /usr/lib/libXpm.so.4...done.
Loaded symbols for /usr/lib/libXpm.so.4
Reading symbols from /usr/lib/libX11.so...Segmentation Fault (core dumped)
 
praveen@athena:~$ file core 
core:           ELF 32-bit LSB core file 80386 Version 1, from 'gdb'