Archive for the 'programming' Category

Introducing GMemory v0.1

For the last few weeks I’ve been working on a small concentration game called GMemory. This was done as a part of the Openismus trainee program.

Update: See below.

For those not familiar with the game Concentration, or Memory as I grew up knowing it, the basic idea is that one has a number of matching card pairs turned face down. The player(s) then attempt(s) to match these pairs by turning over two cards. If the cards match those two cards remain face up. Otherwise, the cards are returned to the face down position. This is repeated until all cards are face up. Here’s a screencast of GMemory being played.

As you can hopefully see, GMemory is currently in a playable state and it actual quite enjoyable if you’re into these types of games. However, there is a lot more to do to reach what I’d consider a 1.0 release. Besides some code reworking and some known bugs, I’d like to see a score tracker, multi-player mode, card animation and selectable themes.

The game is written in C using GTK+, GObject, Clutter and Cairo. In the course of writing GMemory I ran into a few bugs in clutter-gtk. The first bug was that no events were being received when using the embedded clutter gtk widget. You can find the bug report here. The second major bug I ran into was that once I got a version combination that gave me events, I always received double the events that I expected. This is a known bug and I’ve got a work around in the code for that.

There are also a number of known bugs. As you may have noticed from the screencast, the last card of the last successful match does not get shown before the statistics dialog box pops up. It seems the dialog blocks the drawing even thought the function to draw the card is called before the call to show the dialog box. Another bug is that once the game is over the playing area does not resize when the window is resized. I’ll tackle this once I’ve reworked the code some.

You can find GMemory’s git repository at Gitorious and the tarball can be had here.

Unfortunately, right now I’m building against the master branches of clutter and clutter-gtk. Expect breakage.

Btw, I'm attending GUADEC right now.

Update: After trying this on Ubuntu Lucid, I experienced none of the event-related problems with clutter-gtk. This seems to be Fedora 13 specific. Thus, I’ve removed the workaround for the double event issue and changed the configure.ac file to rely on the clutter and clutter-gtk versions shipped with Ubuntu Lucid. The new tarball is here.

Senior Design Project

In order to graduate from the Engineering program at San Diego State University, each student needs to complete a senior design project with a team of between 6 to 10 students. The group that I’m apart of is working on building a system to localize nodes in a wireless sensor network (WSN). We do this by using signal strength and, when nodes are in line of sight of each another, ultrasonic transducers to measure the time difference of the received ultrasonic signal and the radio signal. This is a problem that has been tackled many times and I’m pretty sure we won’t be able to come up with anything novel in the short time we have, but the task of building the working system is what is important.

Partially populated node rototype board

Partially populated prototype board

I’m in charge of building the GUI and integrating the software side of the system. For the GUI I’m using Qt. I’ve used this before and found it pleasant enough although I still run into issues that cause me to waste more time than I’d like. The most important thing for me was that Qt is cross-platform and has great documentation. Having some high-profile applications such as Google Earth and Skype using it makes it easier to “sell” to the other team members as well.

For the WSN we chose Atmel Zigbit modules. These have a ZigBee wireless chip and an ATMEGA128 microcontroller embedded within. This module was chosen because much of the difficult circuitry was taken care of, previous good experiences with AVRs, and the low-cost of the hardware and development tools. Thus far we’ve created custom PCB’s to hold the Zigbit modules, a pair of ultrasonic transducers, and the accompanying circuitry. We are currently testing those so that we can get about 20 boards professionally made.

We’ve got less than a month to finish up and are working feverishly to get everything brought together and integrated. With luck we’ll have a working system in a couple of weeks.

Setting background color of SWT buttons in Windows not supported

Just wasted a while to figure this out only to find out that it’s not supported because it’s not supported in the Windows native widget.

Top 30 Django Tutorials and Articles

As a response to the Top 30 Ruby on Rails Tutorials, I’ve compiled a list of the top 30 Django tutorials and articles. These links are in addition to the great documentation on the Django project site.

For those who don’t know, Django is a Python web development framework that makes development super fast.

The list in no particular order…

  1. Are you generic?
  2. Sending E-Mails via Templates
  3. Django admin for your PHP app?
  4. Hacking FreeComment
  5. the difference between ‘blank’ and ‘null’
  6. Using Django’s TemplateTags
  7. A Django website that took (a lot) more than 20 minutes
  8. Forms With Multiple Inline Objects
  9. Extending Generic Views
  10. Template context processors
  11. Custom SQL In Django
  12. How Django processes a request
  13. Write better template tags
  14. Extending the User model
  15. Django’s Undocumented contenttype app
  16. Django, gzip and WSGI
  17. Django for non-programmers
  18. Django Templates: The Power of Inheritance
  19. Django Templates: An Introduction
  20. Setting up Django on Dreamhost
  21. Django on Windows HOWTO
  22. Django Admin Hack – Fields varying with user permissions
  23. Some django gotchas
  24. Django Templates are not limited
  25. Develop for the Web with Django and Python
  26. An AJAX ComboBox Widget for Django
  27. Using Django’s Free Comments
  28. MochiKit and Django
  29. RSS made stupidly simple
  30. Installing Django on OSX

Note: keep an eye out at Django’s community page for new tutorials and articles.

Related Links

If you have an additional tutorial, put it in the comments.

digg story

In search of the perfect vimrc

I’ve been using Vim for the last couple years on and off. Over the last few months (since the Vim 7 release) I’ve been forcing myself to use it exclusively. To make working with Vim more intuitive for me, I’ve been trying to get my vimrc just right. Of course, this will probably be a never ending quest.

Currently it looks like this…


" set appearance
syn on
colorscheme torte
set vb " visual beep instead of audible beep
set nu

" tab behavior
set ai
set tabstop=4
set sts=4
set et
set shiftwidth=4

" backspace behavior
set backspace=2
set backspace=indent,eol,start " redundent?

" backup behavior
set backup
set backupdir=~/.vim/backup/

" search behavior
set incsearch

I’ve been googling and adding, googling and adding. I’ve tried to avoid the complicated stuff so far. The vim documentation is great but a little overwhelming at first. Jonathan McPherson has a nice series of articles that gives a really friendly intro to Vim.

I’m mostly doing python programming so if you have any tips please leave a comment.

Django Nicities

I’ve been working on a project using Django for the last couple days and am falling in love with it. There are so many nice features that make the life of the developer much more enjoyable. The nicest thing is the automatic administration panel. For many projects it’s enough to define a model and activate the admin panel. Another nice feature that I just discovered is the automatic api documentation for you project. If you click on the ‘documentation’ link at the top right of the admin panel, the documentation is presented in a very well organized and attractive manner. You’ll need docutils installed for this. Whenever an error occurs in you code and you set ‘DEBUG’ to ‘True’ in settings.py, you get a really clean error report. Generic Views saves you a huge amount of coding.

I’m still trying to get my head around everything, but so far everything has been going quite well. I would like to have a way to automatically choose the current user in the Admin panel and some of the included apps (comments, for example) need to be documented. Most aspects of the framework have quite nice documentation, though.

Ok, back to the project.

Setting Up Django on Dreamhost

Jeff Croft has a nice tutorial on how to set up Django, a python web framework, on Dreamhost.

If you want to use the sweetness that is Python to do web development, are a Dreamhost customer and would like to be able to avoid this in the future, I propose that you vote to have it included as a standard feature. Go to Home > Suggestions in the Admin Panel, search for Django and then cast your vote. This is how Ruby on Rails got included.

While you’re at it, cast a vote for Postgresql, Django’s preferred database and a vote for mod_python.

read more | digg story

Blogging Boxes and Python for Artists

A friend of mine just finished up his Masters of Arts thesis project. Basically the project consists of two moody boxes, Otto and Ada, blogging about how they feel. So you ask, “How do the know how they feel?” Otto and Ada have built in sensors that detect changes in their environment. They then express themselves via their blog. Their grammar is not always great but they are both still quite young.

In a recent post, Sam discusses his experience with Python which he used for the project. In the post, Sam mentions the aspects of Python that make it ideal for artists. Those points are equally as valid for general programmers, though.

As a side note, I hereby take credit for introducing him to Python. Seems as if my persistant nudging paid off. :)

digg story

My first contribution

Late last night (or early this morning), I submitted my first ever patch. Hopefully this is the start of a long line of contributions. It fixes a problem in Monodevelop with the Code Template drop-down in the options panel. It’s bug #78082.

Every day I work on my soon-to-be-announced project I get more confident in C#. For anybody learning C# on linux with Mono, I recommend you look at Banshee for an example to help you along. The ActionManager class is very helpfull. Here is another good resource for tutorials. And lastly, You can go to the Mono Project sight for a good intro to the Gtk Treeview widget. Treeview is a beast at first but is really nice once you get the hang of it.