Sunday, March 15, 2015

Experimenting with ncurses on Linux in Eclipse

Today I'll talk about a new project inspired by a co-worker: to write a "graphical" application to monitor network traffic from the console of an embedded device such as a data gateway or a raspberry pi.
The goal is not to produce a star software but to get back in shape programming with C after years of Perl and Python and learning about ncurses along the way.


A few words about ncurses

ncurses is a C library allowing you to abstract the terminal type while writing ASCII graphical interface. It is used in the Linux kernel menuconfig utility for example.
More information about ncurses can be found on the GNU ncurses page and its wikipedia article.


Setting up the environment

I will start with a Hello World program inspired directly from the Linux documentation project.
#include <stdlib.h>
#include <curses>

int main(void)
{
    initscr();
    printw("Hi!\n");
    refresh();
    getch();
    endwin();

    exit(0);
}

      1. Installation of the ncurses library

Your Linux distribution should come with ncurses already installed. If it is not there, follow the nstructions found in paragraph "1.3. Where to get it" of the tldp ncurses how-to webpage.


      2. Creating a new Eclipse project

I am using the Kepler version of Eclipse. First navigate through the top menu commands:
File > New > C project
Then give your project a name (mine is curses), project type = "empty project", toolchains = "Linux GCC" (for building an executable for your dev machine).
Copy-paste or type the Hello World program above in main.c file for example.


      3. Adding the ncurses library to the ld path

Right-click on your project name from the project explorer window and select the bottom option for Properties.
In "C/C++ General" section, select "Paths and Symbols" then click on the "Libraries" tab.
Add ncurses to the list. End result should look as shown below:

Adding the ncurses library to your project


      4. Building your project

Nothing tricky here: Right-click on your project name then "Build Project" or use the hammer icon from the top menu. Build result, as well as gcc command line, will be displayed in a console:

Project has been built


      5. Launching a terminal from Eclipse

To avoid switching back and forth between Eclipse and your terminal, I have used a trick found on stack Overflow: from the top menu, select Run > External Tools > External Tools Configuration...
Create a new configuration (here: Command_prompt) with the location of your terminal binary, the directory where your executable is and additional arguments for your terminal program to execute your program:

Adding external tool configuration for your terminal


To launch your program, Run > External Tools > Command_prompt (or the name you gave your configuration) and a terminal window should appear with your ncurses program running.

Run Command_prompt opens a new terminal with your program


That's it. You are now set to explore ncurses tutorials that you can find on the web!




Saturday, August 18, 2012

edX: College-quality computer science education


A soft  drum roll can be heard throughout the realm. It slowly grows louder as a herald appears on your screen. The Announcer sounds her trumpet, clears her throat. Drums stop and she exclaims:

    - "The blog heretofore known as 'Damien Learns Perl' is now to be referred to as 'Damien Learns Programming'. This broader title means greater variety and more life (or so it is hoped) to the speculations and musings of an eternal student of computer programming."

Crowd cheers.

    - "No camel was hurt in this process. Go home and spread the good word."

The herald lets out a content sigh then disappears in a puff.


-------

I feel like writing about other topics than just Perl. I contemplated starting a new blog for a few seconds but it made more sense to give a new direction to this site.


Evolve or become irrelevant

This could be the motto of the computing/computer science/IT industry.
Tools keep popping out of thin air, new programming languages are invented, operating systems evolve rapidly, new devices appear that can be programmed, etc.
Those changes answer people's ever demanding requests.

You want to keep up but how to go about updating your skills?

The best motivator is to build something that you need. When my wife became pregnant, I started to build a "Baby Tracker" app to learn C++ and to keep tab on the baby's vaccination schedule, teeth growth, stool color, etc. I eventually abandoned the project because (believe it or not) taking actual care of my first daughter became a higher priority. By the time I had bandwidth again, the "baby tracker" need was moot.
Having a purpose makes you want to keep learning and carry on after you have hit a few too many obstacles.

This self-learning path resembles an obstacle course: the end line is visible but you first have to jump over all those hurdles to attain it.

Another way to learn new skills is through online education. Several sites already exist that put emphasis on learning in a fun way:

  • Codecademy (for beginning web programmers)
  • Khan Academy (originally created to teach mathematics but now proposing many subjects, including computer science)
  • Memrise (to help you learn vocabulary for new languages, including programming languages)
  • LCodeTHW (despite its name, offers a great way to start learning about programming)
  • etc.
Those are quality sites and I encourage you to visit them if you are looking for a first acquaintance with a new topic.
However, I want to share here something that I am truly excited about: online computer science college-quality education for free. Back in 2000 I got involved in the PEOI project whose mission was to bring professional education online to the masses (provided access to an internet link). The site still exists but the design has not evolved since its creation and course content was created by volunteers. Its noble goal though has found a champion today: edX.


Get a quality education

edX is a joint online interactive educational project from MIT, Berkeley and Harvard University, some of the best US universities. You can earn certificates along with knowledge. New classes are about to start this fall and include:

So go forth and upgrade your computing education. 
Evolve and ride the relevance wave!



edX: College-quality computer science education


A soft  drum roll can be heard throughout the realm. It slowly grows louder as a herald appears on your screen. The Announcer sounds her trumpet, clears her throat. Drums stop and she exclaims:

    - "The blog heretofore known as 'Damien Learns Perl' is now to be referred to as 'Damien Learns Programming'. This broader title means greater variety and more life (or so it is hoped) to the speculations and musings of an eternal student of computer programming."

Crowd cheers.

    - "No camel was hurt in this process. Go home and spread the good word."

The herald lets out a content sigh then disappears in a puff.


-------

I feel like writing about other topics than just Perl. I contemplated starting a new blog for a few seconds but it made more sense to give a new direction to this site.


Evolve or become irrelevant

This could be the motto of the computing/computer science/IT industry.
Tools keep popping out of thin air, new programming languages are invented, operating systems evolve rapidly, new devices appear that can be programmed, etc.
Those changes answer people's ever demanding requests.

You want to keep up but how to go about updating your skills?

The best motivator is to build something that you need. When my wife became pregnant, I started to build a "Baby Tracker" app to learn C++ and to keep tab on the baby's vaccination schedule, teeth growth, stool color, etc. I eventually abandoned the project because (believe it or not) taking actual care of my first daughter became a higher priority. By the time I had bandwidth again, the "baby tracker" need was moot.
Having a purpose makes you want to keep learning and carry on after you have hit a few too many obstacles.

This self-learning path resembles an obstacle course: the end line is visible but you first have to jump over all those hurdles to attain it.

Another way to learn new skills is through online education. Several sites already exist that put emphasis on learning in a fun way:

  • Codecademy (for beginning web programmers)
  • Khan Academy (originally created to teach mathematics but now proposing many subjects, including computer science)
  • Memrise (to help you learn vocabulary for new languages, including programming languages)
  • LCodeTHW (despite its name, offers a great way to start learning about programming)
  • etc.
Those are quality sites and I encourage you to visit them if you are looking for a first acquaintance with a new topic.
However, I want to share here something that I am truly excited about: online computer science college-quality education for free. Back in 2000 I got involved in the PEOI project whose mission was to bring professional education online to the masses (provided access to an internet link). The site still exists but the design has not evolved since its creation and course content was created by volunteers. Its noble goal though has found a champion today: edX.


Get a quality education

edX is a joint online interactive educational project from MIT, Berkeley and Harvard University, some of the best US universities. You can earn certificates along with knowledge. New classes are about to start this fall and include:

So go forth and upgrade your computing education. 
Evolve and ride the relevance wave!



Sunday, July 1, 2012

Rebel Code

I just finished reading "Rebel Code" by Glyn Moody and I really enjoyed it so here's a short review.
"Rebel Code" is an older book which relates the story of high profile Open Source projects from the beginning of the free software movement up until 2001.
I picked it up at a local Atlanta library and I had little idea about what I was going to find inside. I saw that it talked about the story of GNU/Linux and that was enough to arouse my curiosity.
The book is a great read for those wanting a short history of Open Source development. The author did a good job transitioning between various stories (The Free Software Foundation, Linux, Perl, etc.) and the result is a fun and instructive read. I finished it in 4 days.
It makes me want to read an hypothetical volume two that would span from 2001 up to the present day.

I highly recommend "Rebel Code - Inside Linux and the Open Source revolution" to all those who want to learn about the mythical free software coding feats, all the way from Richard Stallman's and Linus Torvald's first works.


Rebel Code

I just finished reading "Rebel Code" by Glyn Moody and I really enjoyed it so here's a short review.
"Rebel Code" is an older book which relates the story of high profile Open Source projects from the beginning of the free software movement up until 2001.
I picked it up at a local Atlanta library and I had little idea about what I was going to find inside. I saw that it talked about the story of GNU/Linux and that was enough to arouse my curiosity.
The book is a great read for those wanting a short history of Open Source development. The author did a good job transitioning between various stories (The Free Software Foundation, Linux, Perl, etc.) and the result is a fun and instructive read. I finished it in 4 days.
It makes me want to read an hypothetical volume two that would span from 2001 up to the present day.

I highly recommend "Rebel Code - Inside Linux and the Open Source revolution" to all those who want to learn about the mythical free software coding feats, all the way from Richard Stallman's and Linus Torvald's first works.