January 2009 Archives

Command Center

| No Comments

VUE open-source concept mapping

| 2 Comments
I came across a cool open-source program for concept mapping: Visual Understanding Environment. It is written in Java, so it is cross-platform, and is freely available under the ECL (Educational Community License).

It seems to be one of the most attractive and flexible FOSS concept-mapping tools I've seen. I'm currently using it to help me do translations for a Latin course I am taking. Here is a screen shot: screen_shot_20090127.png.

I could not find VUE in my Debian repositories. I'm not sure why -- perhaps some technical legal issues relating to the ECL?

Alpine color configuration

| 1 Comment
I was thinking to myself, "Wouldn't Alpine be cool if it supported terminal colors? I wonder why the developers haven't implemented that yet..." And then I found out -- they had. It just wasn't turned on by default.

From the main menu press S + K, then select the option "use-termdef" under "Color Style". Then color is activated.

As soon as I realized that color could be turned on, I asked myself, "Why isn't it turned on by default?" Then I turned color on, and the answer was obvious: the default color scheme is atrocious. I nearly had a seizure, and I've never had a seizure before.

However, if you scroll down the menu a bit, you find under "General Colors" that you can set all the colors for the program yourself. I quickly found, once I had setup my own color scheme, that color made Alpine way cooler. Besides making everything more pleasant to view, some color options were very useful, like the variable depth reply highlighting.

Here's one screen shot: screen_shot_20090127c.png

Ncurses - Making the Cursor Invisible

| 1 Comment
I was having trouble finding out how to make the cursor disappear in my curses application, until someone on my Linux C Programming mailing list pointed on the ncurses function curs_set. From the man page:

The curs_set routine sets the cursor state is set to invisible, normal, or very visible for visibility equal to 0, 1,  or 2 respectively.  If the terminal supports the visibility requested, the previous cursor state is returned; otherwise, ERR is returned.
I was right there in the man pages, but I missed it because I saw it was in the curs_kernel man page, so I assumed it referred to something else.

Anyway, just make the call "curs_set(0)" to make your cursor disappear.

DroidBattles - Program Your Own Troops

| 1 Comment
I think I just found the coolest game ever: DroidBattles. The game is a bit old, and the graphics aren't particularly impressive. But the game has one feature that distinguishes it from any other that I've played: you get to program your own troops.

In DroidBattles, you create droids (they look kind of like spaceships), building them out of parts such as engines, plasma guns, scanners, etc. Each part, or device, has a set of input/output ports that return certain information or do certain things. Then you get to write a program to run your droid, in an assembly-like language!

Then you set up a match, and you can pit as many of these droids against each other as you want, and see which performs the best (i.e., doesn't die).

If you can find a programmer buddy who is willing to write a droid, you can challenge him to see who is the best programmer!

Here's my screen shot:

http://indicium.us/images/screen_shot_20090125.png

Warning: This game is rated UG (Ultra Geeky) for excessive programming language and occasional low-resolution graphics. Player discretion advised.

MinMenu 0.6.0 Released.

| 1 Comment
The source code for MinMenu 0.6.0 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I have implemented a small set of simple color themes, which the user can choose from through the configuration file.

Note: From now on I will only be announcing minor versions of the software (0.7.0, 0.8.0, etc.) instead of all revisions (0.7.1, 0.7.2, etc.) It takes too much of my time to write a blog post for each revision. So check the link above regularly if you want the latest goodies!

Changing the resolution for your virtual console

| No Comments
I practically live in the virtual console on my Debian machines, so I've been wanting to learn how to change the resolution for sometime. By default, the resolution is very small, so the characters show up big and blocky. It is actual quite simple to change the resolution. Here's the answer:

https://lists.ubuntu.com/archives/ubuntu-users/2007-June/117497.html.

Summary:
  1. sudo su (or however you become super user)
  2. apt-get install hwinfo
  3. hwinfo --framebuffer | less (find the hexcode for the resolution you want)
  4. emacs /boot/grub/menu.lst
  5. add the option 'vga=(hexcode)' to your default kernel entry.
  6. restart the computer and log back into a virtual console.
Note: You'll probably want to be sure other kernel entries are available for boot, in case you screw up that one.

MinMenu 0.5.1 Released

| No Comments
The source code for MinMenu 0.5.1 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu.

Changes:
Added a simple color frame.

Minmenu 0.5.0 Released

| No Comments
The source code for Minmenu 0.5.0 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu.

Changes: Incorporated the first elements of color into the program. Warning: Color is not yet terminal-independent, or user configurable, though I am planning to incorporate these features. If you use a terminal that does not support colors, or do not like the current color scheme, you will need to use the previous release.

MinMenu 0.4.5 Released

| No Comments
The source code for MinMenu 0.4.5 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I converted the build system from my simple Makefile to cmake. This means the end-user will need to have cmake installed in order to build from source.

MinMenu 0.4.4 Released.

| No Comments
The code for MinMenu 0.4.4 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I fixed a bug in my config file processing function which was causing a seg fault every time it encountered a line with nothing but a return character (a blank line).

MinMenu 0.4.3 Released

| No Comments
The source code for MinMenu 0.4.3 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I attempted to make signal handling more reliable. I replaced the global sig int with a sig_atomic_t, and adjusted my signal processing function so that it would not be affected adversely by repeated calls to the signal handler.

MinMenu 0.4.2 Released

| No Comments
The source code for MinMenu 0.4.2 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I added rudimentary signal processing through signal.h. The SIGHUP and SIGTERM signals will now set a flag which quickly causes the program to exit and allows the curses interface to be properly closed, returning the terminal to a sane state.

Controlling Terminal Behavior in Perl

| No Comments
I just learned how to use two cool modules for influencing terminal i/o:
  • Term::ReadKey. Allows you to set terminal modes, sizes, and other attributes. Allows you to do nifty things like single-character, non-blocking, and non-echoing input. Does not provide as much functionality as curses, but is simpler to use and more portable.
  • Term::ANSIColor. Allows you to output colored text to a terminal, without having to know the escape codes. This gem is one of the core modules!

Chomp function in C

| No Comments
In my newbie-ish attempt at C programming, I spent nearly an hour today trying to figure out why one string wasn't equal to another another string, even though by all rights they should have been. (And let's just say the thoughts going through my mind weren't exactly pleasant ones...) I found out that one string had a return character ("\n") on the end, and the other one didn't.

So I wrote a chomp function so that hopefully I'd never have that problem again. When I say chomp function, I mean like the one in Perl where it looks at your string, and if it finds a "\n" at the end, it gets rid of it. And now, for your wonder and amazement:

void chomp(char * str) {
  if(*str != '\0') {
    while(1) {
      str++;
      if(*str == '\0') {
        str--;
        if(*str == '\n') {
          *str = '\0';
          break;
        }
        else { str++; }
      }
    }
  }
}
I know, I know... you're overcome with awe and wonder at my amazing programming skills. Actually, the cool thing about this was that it was the first time I coded something involving pointers, and actually understood what I was doing!

MinMenu 0.4.1 released

| No Comments
The code for MinMenu 0.4.1 is available here: http://indicium.us/cgi-bin/pages/get?view=minmenu. I cleaned up the code some more, replacing some nasty string handling with neater and more efficient implementations.

MinMenu 0.4.0 released

| No Comments
The code for MinMenu 0.4.0 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. Now the key assignments for the menu options are not automatically decided by the program, but instead are specified by the user through the configuration file. I believe this makes the menu more useful and more attractive.

Firefox vs. IE Analogy

| No Comments
I'll admit that I'm not much of an expert on browser security. But this would seem consistent with what I read in the past:

http://hackademix.net/2008/12/17/opera-firefox-and-ie-security-updates-all-together-all-the-same/#comment-10121

MinMenu 0.3.4 released

| No Comments
The code for MinMenu 0.3.4 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I cleaned up the Makefile and directory structure somewhat.

MinMenu 0.3.3 released

| No Comments
The code for MinMenu 0.3.3 can be found at http://indicium.us/cgi-bin/pages/get?view=minmenu. To make life a little easier for the user, I added a simple program called "minmenu-edit" which opens the configuration file in an editor. I think that in the future this program could be upgraded into an attractive interface for configuring the menu.

Perl dispatch tables

| 1 Comment
Dispatch tables are an easy way to call subroutines based on the value of some scalar. They also can provide a sort of substitute to make up for Perl's lack of a 'switch' statement. There is a chapter about them in Higher-Order Perl: http://hop.perl.plover.com/book/pdf/02DispatchTables.pdf.

Here is another explanation, which is perhaps a bit easier to understand: https://db.usenix.org/publications/login/2002-06/pdfs/turoff.pdf.

Another useful aspect of dispatch tables, I understand, is that they can be passed back and forth between subroutines as a reference. Although, as someone pointed out to me, it is probably best to explore real object-oriented programming if you come to the place where you need to pass dispatch tables around.

MinMenu 0.3.2 released

| No Comments
The source code for MinMenu 0.3.2 can be found at http://indicium.us/cgi-bin/pages/get?view=minmenu.  Now the program will read configuration details from a default file at /etc/minmenu if it can not find a .minmenu file in the user's home directory. I also created a man page for MinMenu.

MinMenu 0.3.1 released

| No Comments
The code for MinMenu 0.3.1 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. The Makefile has been improved somewhat to allow for easier installation. Also, the program now looks for the configuration file in the home directory of the user running the program.

Placing a package at the end of the Perl script

| No Comments
Something I started looking into a few days ago was how to conveniently place packages at the end of a Perl script, while still employing 'use strict' and 'use warnings'. I like to keep my subs and variables inside of tidy name spaces, but also prefer all my these subroutines and package variables (except for 'Main') to be at the end of the script. I found that this works just fine, for an example:

#!/usr/bin/env perl
use strict
use warnings

MyPkg::var2 = 'abc'; # assigns value to $var2 in MyPkg
MyPkg::do_this(); # runs sub do_this from MyPkg

Package MyPkg;
{ #  extra brackets needed to keep scope of $var1, etc. inside of MyPkg

our $var1; # our assigns name $var1 to $MyPkg::var1
our $var2; # and allows subs in MyPkg to use $var1 instead of $MyPkg::var1
our $var3;

sub do_this() {
    print $var2; # didn't have to use $MyPkg::var2, just $var2
    (do something else with $var1, $var3)
}

}

With this format, I can use simple names inside the package itself. This is good, because then I can rename the package easily if I need to. But outside the package, I have to qualify variable names and subroutine calls with the package name. This is also good, because it keeps me from getting my name-spaces all mixed up when part of my program is interacting with several packages.

Important note: If you wish to assign values to the package variables from within the package itself (but outside of a subroutine), you'll need to use an INIT block. Say you had a package like this:

package Hello;
{
our $greeting = "hi";
sub greet_someone { print "$greeting\n" }
}
If you tried to call Hello::greet_someone earlier on in the script, it wouldn't print "hi". The reason is that, although 'our' variable scoping occurs at compile time, actual value assignments do not occur until run-time. So when you try to call Hello::greet_someone, $greeting is a valid variable within Hello, but it has not yet been assigned the value "hi".

You can fix this by using an INIT block:

package Hello;
INIT {
our $greeting = "hi";
sub greet_someone { print $greeting\n" }
}
Anything inside of INIT blocks will be run early, just before the Perl runtime begins execution. (According to Perlmod, this could be an issue if you are running inside a mod_perl environment, or eval'ing string code).

Preventing Ctrl-C exits in a curses program

| No Comments
It seems that one way to prevent Ctrl-C from aborting a curses program is to put the program into raw input mode:
http://www.faqs.org/docs/Linux-HOWTO/NCURSES-Programming-HOWTO.html
http://opengroup.org/onlinepubs/007908799/xcurses/intov.html#tag_001_005_002

MinMenu 0.2.1 released

| No Comments
The code for MinMenu 0.2.1 is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. I switched the interface to raw mode, meaning the user can not exit by pressing Ctrl-C, but must exit through a menu option.

MinMenu 0.2.0 released

| No Comments
MinMenu 0.2.0 code is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. Includes a new feature: a custom greeting message can be specified through the config file. The greeting message can be any one-liner, including:
  • Hello hot stuff... what can I do for you?
  • M' Lord? What is your wish?
  • Yeah, yeah... whadda ya want already?

MinMenu 0.1.1 released

| No Comments
MinMenu 0.1.1 code is available at http://indicium.us/cgi-bin/pages/get?view=minmenu. Non of the program functionality was changed (intentionally), but the code was cleaned up considerably.

Linux puzzle game of the week: Block Attack

| 1 Comment
If you're willing to set aside your FPS for a few minutes, and try a game that challenges your mind, take a look at Block Attack. Here's my screen shot:

screen_shot_20090101.png

And here's some more screen shots.

I found the game in the Debian Lenny repositories, though there is also a Windows version of the game on the website (haven't tried it). The basic idea for the game is not a novel one, but I find Block Attack to be a very colorful and challenging implementation. (Not to mention that it is FOSS!)


CZaudio 0.6.0 code released

| No Comments
This is a small Perl project I'm working on: http://indicium.us/cgi-bin/pages/get?view=czaudio.

Quote from the page:
This is a small project I'm working on for making audio files available on the web, indexed by date. I'm currently implementing this on a church website, to make their audio sermon recordings easily accessible.

MySQL and multi page results: Limit and Offset

| No Comments
Anyone who has an intermediate level of experience knows this already, but for the rest of us: Two MySQL tools that makes it much easier to code multi page results are the limit and offset features. Here's a link with an explanation: http://www.petefreitag.com/item/451.cfm.

Those can be used to get a limited set of results you want. And the better known count(*) feature can be used to calculate the number of pages that can be made available.
The site blog for indicium.us.
Linux Projects
Online Games
Unsung Linux Games

RSS Feed

Powered by Movable Type 4.21-en
and GNU/Linux


Creative Commons License
The content of this blog is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License. See my copyleft page for more details.