SpectraCyber Control Software

September 27th, 2009

To my amazement, I have recently been contacted about my senior project at Hastings College entitled “Design, Construction, and Implementation of a Radio Telescope to study Neutral Hydrogen.” Because of this, I posted the project summary and the presentation to the Nebraska Academy of Sciences on my portfolio page.

As for the control software, it is written for the SpectraCyber 1st
generation units in C# and is packaged as a Visual Studio 2005
project. The software is presently configured to push data into a
database, but should be changed to use a flat file, similar to the
original software. Additionally, adding Linux/Mac compatibility
shouldn’t be too difficult because it will only involve changing a few
lines of code involving the RS-232 connection after the database
portion is removed. Also, with a little refactoring, the code could
be made to work with both the SC I and SC II units

Unfortunately, I don’t have time to maintain the project and am no
longer in possession of a SC with which I may test my code so I have
decided to open up the source code to the public. The source code is
now located in a Subversion repository on my home webserver. Anyone
should be able to check out the source code, but you will need to
request access to write changes (just send me an email).

You may check out a copy of the code via:

svn co http://finiteline.homeip.net/svn/SpectraCyber

or, if you prefer to use Visual Studio directly, there is a nice, free
program that integrates SVN control with Visual Studio
. I’ve checked it out and actually like it so it may be a good solution
for those who have never used subversion via. command line before.

Please feel free to send me an email with any questions.

Django: Serving Media Files During Development Process

September 6th, 2009
This entry is part 4 of 3 in the series Making a Website with Django

One problem I quickly encountered was how to serve media files during development. Although Django is not as efficient at serving media pages as a full-blown webserver, it is acceptable to serve media files using the Django development server during development.

The first thing you need to do is add a custom entry into the urls.py file:

...

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
    )

I like to use the variables defined in settings.py and also allow for directory listings so my code is slightly different:

from django.conf.urls.defaults import *
from django.conf import settings    

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    ...
    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),

)

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
         'django.views.static.serve',
         {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    )

Now, I wanted all of my media files served from the /media directory on my webserver, unfortunatly the admin interface defaults to “/media/” and therefore handles all incoming requests to the media directory. Therefore, I moved the admin directory in my settings.py file and cleaned things up a little so I can quickly deploy my website:

if(DEBUG):
   # Settings on Development Server
    MEDIA_ROOT = '/path/to/development/media/'
else:
    MEDIA_ROOT = '/path/to/deployed/media/'

MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'

Further information on serving static content with the development server can be found in the Django Static File Documentation page.

New Control Software for the SSP-4 Photometer

September 3rd, 2009

I have released the latest version of my alternative control software for the Optec SSP-4 Photometer. See my portfolio page for details:

Portfolio Page

Automatically Backing Up Firefox Bookmarks

August 26th, 2009

As part of my “grand” backup scheme, I also needed to backup my bookmarks in Firefox. As of version 3, Firefox now places bookmarks in a SQLite database instead of the bookmarks.html file as was done circa version 2.

You could, of course, write a program to parse the SQLite database and export your bookmarks, but there is a built-in way to export that is much simpler. Firefox can automatically export your bookmarks whenever the browser is closed by setting the following field:

Open up the about:config page (i.e. type “about:config” in the address bar) and set:

browser.bookmarks.autoExportHTML = true

This will export your bookmarks to a file called “bookmarks.html” in your profile directory (/home/user/.mozilla/firefox/_uniqueID_/bookmarks.html for Linux or inside of the C:\Documents and Settings\username\Application Data\ folder on Windows). That is useful, but if you want the bookmarks in a convenient locaiton for some other automated backup process (i.e. rsync or Offline Files) you should also tell Firefox where to place the file using the browser.bookmarks.file setting in about:config. You will need to add the (string) key because it does not exist by default:

browser.bookmarks.file

With the (string) value being the location to which you want the file saved. For Linux users you simply specify the full path and name of the file (i.e. /home/user/bookmarks.html). For Windows users, you need to do the same but you must include two slashes between the drive letter and path (i.e. C:\\Documents and Settings\username\bookmarks.html).

For more information, see Mozilla’s documentation:
browser.bookmarks.autoExportHTML and browser.bookmarks.file

Django: CSS-Friendly Dynamic Navigation Menus

August 25th, 2009
This entry is part 3 of 3 in the series Making a Website with Django

In the last post in this series, I showed how to create a custom context and include the navigation template. These two, taken together, would allow you to include a navigation menu on every page in your website with minimal effort.

In this post, I’ll extend what we have completed thus far to create a navigation menu that can turn into a CSS-driven navigation menu with pop-outs similar to what you can find on the left hand side of this page.

One design principle I have read is to keep your navigation menu to a depth of two or less. Following this principle, the code I will discuss below will produce a navigation menu that will have a maximum of one pop-out for each primary link.

The key to getting the navigation menu to work is to have the output be in the form of an HTML unordered list so that CSS can be applied to the & and & tags. Django has a filter, entitled unordered_list, that can parse an array of strings (or nested arrays of strings) into an unordered list. I copied the “defaultfilters.py” from the Django source code and removed everything except the unordered_list function (and any necessary import lines) and then rewrote the unordered_list function to work on a list of MenuItems objects.

The modifications to the unordered_list function were few and basically involved changing the output method from a string to a call to the yet-to-be-written MenuItem.render() function. A copy of that file can be found in my navigation_filters.py file. Place this fine in the “navigation/templatetags” directory along with blank file called “__init__.py” so the directory will be treated as a Python class. Just like the unordered_list function, navigation_list takes an array (or a nested array), but unlike unordered_list, navigation_list will only output from MenuItems objects.

Now we write a template that uses the new navigation_list filter:

<div id="navmenu">
	<ul>
		<li class="top">Navigation</li>
	{% load navigation_filters %}
	{% if nav_menu %}
		{{ nav_menu|navigation_list }}
	{% else %}
		<li>No Navigation Menu</li>
	{% endif %}
		<li class="bottom">nbsp;</li>
	</ul>
</div>

With the template and filter written, now all that needs to be done is to create the navigation module. The ideal method of storing the navigation menu would be in a hierarchical list (see django snippets, and the django-mptt project), but the status of the django-mptt project seemed unnecessarily complicated for this task. Additionally, a full hierarchical list would encourage the creation of navigation lists more than two deep, something against design principles.

I therefore created a very simple semi-hierarchical model to store the navigation menu that also contains the MenuItem.render() function I mentioned above:

from django.db import models

# Create your models here.
class MenuItem(models.Model):
    ParentID = models.ForeignKey('self')
    text = models.CharField(max_length=20)
    url = models.CharField(max_length=200)

    """ Returns the title of the news item. """
    def __unicode__(self):
        return self.text

    def render(self):
        return '<a href = "' + self.url + '">' + self.text + '</a>'

I enabled the administrative interface for this class and inserted some junk data. I then wrote a context processor to pull the necessary information from the database:

from django.template import Context
from finiteline.navigation.models import MenuItem

def navigation_context(request):
    # Define a variable in which we store the output list
    output_list = []

    # Run a query to get the top-level objects
    nav_menu = MenuItem.objects.filter(ParentID=1).order_by('text').exclude(pk=1)

    # For each top level object, run a query to get the subitems.
    for item in nav_menu:
        sub_menu = MenuItem.objects.filter(ParentID=item.id).order_by('text')

        output_list.append(item)

        if sub_menu.count > 0:
            sub_list = []

            for subitem in sub_menu:
                sub_list.append(subitem)

            output_list.append(sub_list)

    c = Context({'nav_menu': output_list})
    return c
Output of navigation_list.

Output of navigation_list.

After including the navigation template mentioned above, I included “navigation/base.html” in another page and opened it up in a web browser. The output looks like the image shown to the right. After applying CSS to the & and & tags, the navigation menu changes considerably and even supports pop-out navigation.

The unformatted menu with CSS formatting applied.

The unformatted menu with CSS formatting applied.