Friday, December 14, 2007

Exciting things are afoot

The Summer Semester Project this year is working on extending the SwinGame API that was started last year. This is a really exciting project with some great outcomes already, and we're less than half way through...

So what have the students achieved? The most visible part is the SwinGame web site. This site will be used to promote and distribute the SDKs when they are finished. The site uses a combination of MediaWiki and phpBB, combined together with a common theme. The wiki will be used to document the API while the forum will offer a place to discuss the games, and any issues with the API. You can read their comments on the SwinGameSDK Development blog.

I've used the SDK to create a small game, "Alien Flight". Its been great fun to have a chance to play around with this, though I guess I'll need to get back to work soon :(. I'll be putting the game up on the site some time soon.

Anyway check out the site and let me know what you think. Its a little empty at the moment, but we're working on getting content in soon.

Have a great christmas, and new year!

Monday, October 29, 2007

PS Printing in Leopard

Back in February I created some Automator scripts to automate the process of printing and publishing my lecture notes. These scripts hinged on the ability to use a small printer script that send the printer output to file, simple ps script. Upgrading to Leopard has caused me some issues in this regard.

The first issue is the fact that the Print Center has been removed. In the past you could Option click the Add Printer button to enable the Advanced options. With the new Printer Preferences Pane this option has been removed. So my first issue was adding the printer back at all. After some searching I found that the cups process can be administered remotely using http://localhost:631. To create the new printer you can do the following:

  1. Add a generic printer using Printer Preferences Pane
  2. Open a web browser and navigate to http://localhost:631
  3. Navigate to the printers tab
  4. Choose Modify Printer
  5. Step through the process configuring the printer as you would have in the Print Center Advanced options.
Following this process I was able to add back the printer, which unfortunately was not able to print :(.

On Tiger the cups process is run by the root user, however on Leopard the security has been tightened and now the printer is run using a low privilege account, _lp. My old postscript saving scripts would output the file to any folder you chose, and then alter the ownership to the calling user. The new script can no longer do this. I've listed the new script below for anyone interested the corrected script. Please note that you will need to setup the printer with reference to a location that can be written to by this user, I have used /tmp.

I'll look into this again later, but for the moment this meets my needs. Other suggestions are welcome.

---

#!/bin/sh
#
# Michael Goffioul
# Updated by P T Withington for Mac OS X
# Updated by Richard Bronosky
# Updated by Steve Palm (N9YTY) - case insensitive URI, unique output files
# Recreated as PS copy by Andrew Cain
 
LOGFILE=/tmp/psprinter.log

FILENAME=
CPBIN=/bin/cp
ECHOBIN=/bin/cat
RUNAS=`/usr/bin/whoami`

echo "Script: $0" > $LOGFILE
echo "Run as: $RUNAS" >> $LOGFILE

echo "job: $1" >> $LOGFILE
echo "user: $2" >> $LOGFILE
echo "title: $3" >> $LOGFILE

echo "num-copies: $4" >> $LOGFILE
echo "options: $5" >> $LOGFILE
echo "filename: $6" >> $LOGFILE

 
# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
echo "direct PS \"Unknown\" \"PS Writing\""

exit 0
fi
 
# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then

echo "Usage: ps job-id user title copies options [file]"
exit 1
fi
 
# get ps directory from device URI, and check write status
URI_PRE=`echo $DEVICE_URI | cut -c 1-2 | tr "[a-z]" "[A-Z]"`

URI_BODY=`echo $DEVICE_URI | cut -c 3-`
DEVICE_URI="${URI_PRE}${URI_BODY}"
echo "Device URI: $DEVICE_URI" >> $LOGFILE

 
PSDIR=${DEVICE_URI#PS:}
if [ `echo $PSDIR|cut -c1-3` = //~ ]; then

PSDIR=/Users/$2`echo $PSDIR|cut -c4-`
# This step added by Richard Bronosky to allow referencing the users home directory
fi
 
echo "PS DIR: $PSDIR" >> $LOGFILE

 
if [ ! -d "$PSDIR" -o ! -w "$PSDIR" ]; then
echo "ERROR: $PSDIR not writable" >> $LOGFILE

echo "ERROR: directory $PSDIR not writable"
exit 1
fi
 
echo "ps directory: $PSDIR" >> $LOGFILE

 
# generate output filename
OUTPUTFILENAME=
if [ "$3" = "" ]; then

OUTPUTFILENAME="$PSDIR/unknown.ps"
else
OUTPUTFILENAME="$PSDIR/${3//[^[:alnum:]]/_}.ps"
fi
 
FBASE=`basename ${OUTPUTFILENAME} .ps`

typeset -i I=1
while [ -e $OUTPUTFILENAME ]
do

OUTPUTFILENAME="${PSDIR}/${FBASE}_$I.ps"
I=$I+1
done
 
echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE

 
# move ps to destination
if [ $# -eq 6 ]; then
echo "copy $6 $OUTPUTFILENAME"
$CPBIN $6 $OUTPUTFILENAME >> $LOGFILE

# $GSBIN $6 -o $OUTPUTFILENAME >> $LOGFILE
else
#cp /dev/stdin $OUTPUTFILENAME
echo "$ECHOBIN - >> $OUTPUTFILENAME"
$ECHOBIN - >> $OUTPUTFILENAME

# $GSBIN -i -o $OUTPUTFILENAME >> $LOGFILE
fi
 
# modify ownership and permissions on the file
# - world readable
# - owns to user specified in argument
chmod a+r $OUTPUTFILENAME
if [ "$2" != "" ]; then

echo "Change ownership with: chown $2 $OUTPUTFILENAME" >> $LOGFILE
chown $2 $OUTPUTFILENAME
fi
 

exit 0

Friday, October 26, 2007

Meow...

Ok installing Leopard was a little more complicated that I thought! 

The main problem related to a lack of resources...

Yes, thats right, we were nearly out of diesel and with the current diesel shortage finding some so we could get home was an issue :)

Ok, now seriously. Install = insert DVD, double click (install icon), enter username/password, click, click, click, wait, wait, click, done. It ... well ... just worked.

Total time almost 2hrs. Validating the DVD took 1hr, install took 1hr.

I did need to login with my admin account to finish the registration. Most apps are working, though I found that Menu Shades doesn't... 

Alpha Geek

Last launch party I went to was for Windows 98... which was a bit disappointing, and as Raj reminds me took me until 4 in the morning to install. If I remember correctly... the issue was drivers for my SCSI HDD.

So does it make me a Geek to say that even though I should be home in bed (... I'm not well), tonight I'll be there at the Leopard "Launch Party" down at the nearest store?

I hope so :)

More details once this Tiger has gone, and a Leopard takes its place. That is assuming the update goes to plan... I'm dreaming right... this never really works... Well I'll let you all know soon enough.

Thursday, October 25, 2007

Whats up?

Well I haven't blogged for a while... and I just found a nice little Blogger Widget that allows me to post from Dashboard.

So what exciting has happened lately? Well not much, actually. The semester went slowly at the start but the last few weeks have really shot by.

In OOP the SwinTrek assignment appears to have causes some students issues, but those who really put in the effort are now showing the benefits. I definately think the assignment has proven itself in terms of learning outcomes.

Advanced .NET is crusing along. The students are now starting to push themselves. Maybe I need to make the assignments due a bi earlier.

Well thats enough for now. If your studying one of my subjects please let me know what you think...

Tuesday, September 11, 2007

What should we aim for?

There has been renewed discussion of another round of curriculum review. If we are to review the PSD degree what should we change? What should the aims of the degree be?

I think we need to build good basic software development skills, but focus more on generic skills like the ability to learn independently, investigate/research topics etc.

Any ideas?

Monday, September 10, 2007

How important is being open?

I've been so busy since I got back from leave that I haven't had ten minutes to put any of my thoughts down in writing. Today I've finally got some time to spare so I thought I would write a quick blog entry.

Over the last two years we have been planning, developing, and delivering the new Bachelor of Science (Professional Software Development) or PSD for short. This is a new degree program aimed at teaching students about modern software development, agile processes, etc. This semester I have been teaching the new Database Programming subject, the last of their programming subjects, and so I've been looking back to see how the program has turned out.

I think in general that the new degree has been quite a bit of an improvement over previous degrees, in that very few of the students "hate" programming. However I think we can improve further in some areas. The one the has surprised me the most is how fixed in their ways some of the students are. Anything that offers a slight challenge is a major obstacle, and the tool is always seems to be to blame. Its not that they are not capable of using the tools, its their attitude that I am finding intriguing. The old saying "A poor worker blames his tools" keeps popping into my mind... Having said all of this, there are also students who are doing well, and are handling the challenges in an admirable fashion. I just want to improve the odds...

I think its really important to be open to new ideas, and to be prepared to spend time to understand how a tool works. As software developers these students are going to be constantly faced with configuration/installation/integration types of problems. They will need to be able to work out how other software works in order to be able to work effectively with it.

Anyone have any ideas for how we can encourage these students to be more open in their thinking?

I want them to be inquisitive about technology, prepared to explore the potential of various solutions.

I think what shocked me most (and got me wanting to write this) was one conversation I overheard... it went something like this:

"My notebook is running too slow. I think I will install Linux and Beryl like X did."
"Really! You dont want to do that. He will have spent ages tweaking it... do you really want to do that... etc. etc."
"Yeah your right, installing Linux is too difficult... etc. etc."

This really isn't what you want to hear. Playing around with another OS is a really good learning experience, and a good working knowledge of Linux is a real advantage. Not installing it because you may have to learn how to configure it is a really lame excuse. My suggestion, install Linux. Play with Beryl. What have you lost if you end up going back to Windows? Setup a dual boot, then you can play with Windows and Linux. Learning should be fun.

Wednesday, July 25, 2007

Back to work

The holiday had to end at some stage... I'm back at work now, and not much has changed. Currently getting ready for the semester which starts in a few weeks.

My main problem at the moment is finding tutors for a new subject on Database Programming. If you know anyone good who is interested in teaching, and knows Java + C# (or one and happy to learn the other) please let me know. We currently have 6 hours of laboratories that need a tutor. Any ideas?

Thursday, May 10, 2007

To Thread or Not To Thread

Today I have been asked a few threading questions from students studying at Swinburne. Usually these were about the "How to" do something with threads, when I think the real question was should threads be used at all?

From what I know these students are developing a torrent like application and network protocol. The issue is that they need to accept data from a number of peers at the same time. Initially this appears to suggest the need for threads... but are they really needed?

In this case I think not. The project indicate potentially thousands of peers... a threaded client with one thread per client will kill the machine with context switches before any real work can be done. So what is the answer? Non-Blocking IO.

With Non-Blocking IO you dont need to block, waiting for data to arrive from a peer. Rather you keep a list of connected peers and then loop through those that have data currently available. This can all be performed on a single thread, giving good performance and throughput.

Java offers a number a library of non-blocking IO utilities. Have a look at the NBTimeServer.java example. This shows a time server that accepts connections using non-blocking IO. A quick look through the Java API and you will find the SelectableChannel and the SelectionKey class. Using the register methods, and the various SelectionKey options you can loop through only those connections that actually have data waiting to be processed.

There is a good article, with a good source code example at http://tim.owlmountain.com/tutorials/NonBlockingIo.htm though there is an interesting note at the start.
As suggested in the article, you could also look at MINA the Multipurpose Infrastructure for Network Applications. If you use MINA just stick with the basic "getting started" code and build on top of that. There is no real need to worry about fiddling with the thread model. But... check with the subject convener first...

Tuesday, May 08, 2007

Programming 2D Games

Are you interested in programming 2d games? Got a PC, Mac, or linux box? That all you need with the new SwinGame API.

The SwinGame API was developed initially by Daniel Chambers as a Windows API for developing small games. Over the last few weeks I have been modifying the code to extend its features, and to make it cross platform. The latest version is still in testing, but is worth looking at if you are interested in creating a 2D game.

SwinGame features:

  • Window drawing is double buffered
  • Create a Window of any size
  • Load and display images of various formats including bmp, png, and jpg
  • Works with 32 bit images, including alpha blending
  • Load true type fonts
  • Read and write text
  • Draw lines, and shapes
  • Sprite management routines
  • Load and play sounds in various formats including wav, ogg, and mp3
  • Detect collisions between sprites, bitmaps, and areas of the screen
  • Perform pixel level collision detection
  • Vector manipulation routines
  • Use matrices to manipulate game vectors
There are a couple of games in the process of being built by the 1st year PSD students at the moment, and I will make these available for download from SwinBrain as soon as they are complete.

Tuesday, March 27, 2007

Empty your Mind

Today one of the PSD students showed me what he had started for the game he was developing for Algorithmic Problem Solving. He had started on the game yesterday, and it already looks quite impressive. Basically this is going to be a scrolling space arcade game. So far he has the weapon firing in a number of shot combinations. The screenshot below shows the largest fire pattern.



Looks like some of the students are having fun with this assignment. The SwinGameAPI is a real hit, making this possible without having to worry about many complexities.

Keep the games coming...

Wednesday, February 14, 2007

Another Web Development Position

I have another request for anyone interested in some web development work. Please get in touch with me if you are interested. Details follow...

I'm currently looking for a student (2nd year or higher) to take on some web
development work for us here in Corporate Marketing - 1 to 2 days a week
fitting in with their study schedule.

Here's a brief outline:

Essential skills
- HTML, CSS, graphics and JavaScript

Other desirable skills
- PHP, SQL/Databasing, Flash, design, audio and video

Software
- Dreamweaver, Fireworks, Flash

Thursday, February 08, 2007

Postscript Automator Actions

Having played with Automator some yesterday I thought it would be interesting to create an Automator action to perform the Postscript manipulation. This would mean that I could package the scripts together in a workflow to make producing the PDFs for my subjects even easier...

Creating an Automator action is actually quite easy. It basically uses an architecture inspired by Unix pipes. You can pass output from one action to the input of the next. I decided to create script actions as I already had the bash script all worked out. With this script the input is passed via the standard input. Automator also allows you to provide arguments via a simple user interface. These arguments are then passed in as environment variables. The following script illustrates the Postscript to PDF Automator action...



#!/usr/bin/env sh

if [ -e "$PS2PDFBIN" ]; then

while read line; do

if [ -e "$line" ]; then
FILETYPE=`/usr/bin/file -b -i "$line"`
if [ "$FILETYPE" = "application/postscript" ]; then

OUTDIR=`/usr/bin/dirname "$line"`
FBASE=`/usr/bin/basename "$line" .ps`
OUTNAME="${OUTDIR}/${FBASE}.pdf"

typeset -i I=1

while [ -e $OUTNAME ]
do
OUTNAME="${OUTDIR}/${FBASE}.$I.pdf"

I=$I+1
done

PATH=$PATH:`/usr/bin/dirname "$PS2PDFBIN"`
$PS2PDFBIN -q -sPAPERSIZE="$PAPER" -dNOPAUSE -dBATCH -sDEVICE=pdfwrite "$line" "$OUTNAME"

/bin/echo "$OUTNAME"
else
/bin/echo $line
fi

else
/bin/echo $line
fi
done
else

echo "Cannot locate executable: '$PS2PDFBIN'" 1>&2
exit 1
fi

I will upload the action bundles soon if anyone is interested...

Wednesday, February 07, 2007

Presentation to PDF

Today I have spent a significant time preparing my lecture notes for my subjects. The subject that I am preparing has a large number of PowerPoint files that need to be printed as PDF. I wanted to print all of the PowerPoint files to double sided PDFs. Rather than doing this manually I wanted to create a script to automate the process.

Opening the Files: the first part of my process involved creating a script to automate the process of opening the PDF files. I organise my documents in folders, so all of the documents that I wanted to print are located in a tree under a single directory.

The Automator workflow to open the PowerPoint files is actually very simple (shown here). I attached three finder actions. The first is the Get Folder Contents action. This action is used to process all of the items within the selected folder. Select the Repeat for each subfolder found, so that all of the subfolders are processed.

Following this action is the Filter Finder Items action. I use this action to filter the items to those that end with "Handout.ppt" as this is the ending to all of the presentations that I want to open. The last action in the workflow is the Open Finder items action. This action will open all of the items that are passed to it from the previous actions.

Printing the Presentations: The next step should have been simple... but it isn't. I started approaching this by creating a Applescript that printed via PDF. Getting the Print dialog to appear was simple, and examples all over the web illustrate how to click that PDF button, but none of them worked for me. I ended up using the UI element explorer and finding that the path to this menu is not easily achieved. In fact the explorer had issues highlighting it... If anyone knows how to get this working please let me know.

My next approach was to find a PDF printer... yes I know you can save as a PDF, but not with a script as far as I can tell. This was actually much easier than I first thought. Following the discussion on this forum. The best description is on the second page. Using this and some simple VBA script (basically for each presentation, print out the presentation) I can now print all of the open presnetations using the selected printer. Using the new PDF printer allows me to print these to PDF.

Next I wanted to have the PDFs printed two per page. Adjusting the print settings and printing via the script did not work. I started looking around and found some useful postscript editing utilities... So I had gone to all that effort to get the PDF printer and what I really wanted was a postscript printer. I created a modified version of the PDF script that copied the passed in postscript to a file, allowing me to use the existing scripts. Using this I was able to create postscript files of the notes for all of the presentation.

Scripting PS manipulation: To get the postscript modifying programs download Fink. This installer allows you to download common Unix utilities compiled to run on Mac OS X. Install the ghostscript, gv, and psutils-a4 package (for the A4 version). From the command line run the following instructions...

find . -type f -path "*.ps" -exec psnup -b0 -m0 -l -pa4 -2 {} "{}.ps"
find . -type f -path "*.ps.ps" -exec ps2pdfwr -sPAPERSIZE=a4 {}


This will create some strangely named file (a.ps becomes a.ps.ps and then a.ps.pdf), however the script will create the files as two per page PDF. The script also allows you to quickly process large numbers of presentations at once. With a little more work I am sure that I can create a better script, but this one has worked fine for the moment.

Monday, February 05, 2007

Interested in some part time PHP

With Uni about to go back, I have been asked if I know anyone who would be interested in a part time Job at Swinburne working on their web content using PHP... Are you interested?

Who are they looking for? A Swinburne student who is interested in programming, and in learning PHP and working with MySQL.
Do you need to already know PHP? No... as long as you are a capable programmer that should be fine.
How about MySQL? You need to know SQL...
How much time/money? One or two days a week in 2007 at $21 an hour
Who do I contact? Please contact me initially. I can then put you in touch with the person in question. You will need to have an interview...
When? You need to get in contact with me ASAP... before the start of semester 1.

Let me know if you are interested.

Thursday, February 01, 2007

More Mac Tools

After having watched a vast number of MacBreak issues over the last week I have started to play around with a number of new applications. I thought that I would share these with you...

The first piece of software that I have played with is Growl, a notification tool for the Mac. This allows me to display notification of various events, such as network address changes, track changes in iTunes, email, Adium etc. Growl also provides a nice network feature that allows me to get notifications from my notebook on my desktop. This allows me to work without having to look at the notebook screen for "interesting" events.

I have really enjoyed the Distracted Mac and related episodes with Merlin Mann and as a result have started playing around with the tools that he mentions in the episode. The first productivity enhancing change I have made is to clean up my desktop...

To really clean this I have been playing with Path Finder and its ability to hide the desktop icons. In addition to hiding the desktop icons this program provides a replacement for Finder. I am still using the trial and I am not sure that its worth the $, so I have been looking for alternatives. Path Finder is quite nice, but the interface is a little too busy. I'm not sure but I will think about it when my trial hsa run out.

Rather than switch to Path Finder on both my Macbook and my desktop I decided to look for another alternative. What I found was Desktop Sweeper, which is a Application Enhancer plug-in that hides desktop icons. This has worked really well, and I absolutely love the icon :)

The next tool is Menu Shades. This program provides the ability to hide the menu bar, removing another source of distraction. It is quite a nice program, but the problem is that it takes up space in the Dock. It would be much better is this had a menu bar icon... So I started looking for a way to remove the icon from the dock...

Having a look around I found the Dockless program. This provides an easy way to indicate to programs that you don't want them to load in the Dock. The program is a little "interesting" but it does work. The quit and relaunch buttons are used to quit or relaunch the selected applications... Anyway it all worked fine once I understood how it worked. Don't relaunch the Menu Shades program from this as it then fails to load it preferences. I got Dockless to remove it from the Dock and then manually restarted and it worked fine. Menu is shaded, and it is not in the Dock.

I have been playing around with some other applications, but more on those at another time. If you have some other interesting Mac applications let me know.