Category: Uncategorized

Retrospective coding

Its interesting that since my last post I’ve been made redundant from my position at The Sound Alliance. They cut back the development team to bare bones as the good work we did made maintenance a lot easier. Effectively we coded ourselves out of a job! I wont go into it here though.

Anyway, I’ve found another position at The Royal College of Physicians and have had a week and a half off. Well not really “off” but working on a freelance project for an old client. It involves implementing some workflow automation within their Intranet that I developed about over the last 4 years and haven’t touched for 2 years .

What I’m amazed by in this is how my code style and even logic evolves over time. Its made me realise that I learned a lot of good technique while at TSA. Its also highlighted some of the great design decisions and techniques I already posessed.

If you look at your old code and cant see room to improve, you’re missing something – or its genuinely good code!

We have lift off!

We released a new version of inthemix.com.au yesterday. My feeling is that it went really well. There were only very minor oversights which we had pre-determined solutions in place for. Ut was a real case of “Fail to prepare, prepare to fail”.

We had prepared.

Android

Well. I made my first attempt at development on Android tonight. Im excited by it as it leverages off the Java skills I got back at TAFE. Excellent Eclipse integration and the backup of the future monopoliser, Google…

The dynamic nature of PHP defines – you don’t need to declare all variables, inherently adding the notion that adding them initially was a pursuit to be avoided.

So why re-implement a feature people bothered to un-impliment?

$this->that;

VS ~

$this->getThat();
function getThat(){
    return $this->that;
}

At least make redundant set/get [tters] dynamic. Use of the magic __set() and __get() methods means the benefit of protecting access to your objects properties can be encapsulated into your base class easily enough.

nohup 2>&1 & WTF

Let me explain… As a relative command line newbie the characters 2>&1 & at the end of commands are quite intreguing. I figured out what they mean

The command line apps have 3 types of output

  • Standard input (STDIN)
  • Standard output (STDOUT)
  • Error output (STDERR)

So, when you run this command:

[tim@desktop]$ programName > filename.log 2>&1

The output of the program is output into the file and the output from output 2 (STDERR) is sent to output 1 (STDOUT). This effectively sends any errors into the file also.

If you add a space& like so to the end of the command it sends it to the background and returns the pid (in case you need to track/kill it).

[tim@desktop]$ programName > filename.log 2>&1 &

Thanks to: http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/comment-page-3/ for the detail (& Sasha for clarifying some things)

Pipe sed awk curl

Here’s a script I had to write at work for moving files into a backup directory if they’d been moved to S3. It was very interesting for me to write as it used the holy grail of bash “pipe, sed, && awk”!

#!/bin/bash
site=$1
file=$2;
# Establish the name of the file.
name=`basename "$file"`;
# Establish the numbered directory to backup into.
dir=`dirname "$file" | awk '{print $NF}' FS=\/`
# Form the backup location.
backup="/data/images/$site/backup/"$dir"/"
# Create the backup location (if it doesnt exist).
mkdir -p $backup;
# Check the file exists on S3
uri=`echo http://images.$site.com.au.s3.amazonaws.com$file | sed "s/ /%20/g"`

curl -I $uri 2>&1 | grep 'HTTP/1.1 200'
if [ $? = 0 ]; then
# More user feedback
echo "Moving "$file" into "$backup$name;
# Perform the move (@todo logging & deletion based on $mode).
mv "$file" "$backup$name";
else
echo "Warning: file doesnt exist on S3 ($uri)";
fi
echo ""; # A new line just to space the feedback out a bit.

SVN External

The command to add an external is:

  1. Navigate to the directory you want the external brought into.
  2. sudo svn propset svn:externals 'http://{path to repo}/ {name of dir}' .
  3. Commit then update to receive the external files.

Note the quotes around the {path to repo} and {name of dir}. Also note the dot at the end of the line to indicate the property setting on the current directory.

My initial playing with this proves changes made & committed in the externally included files will arrive in the external repo when it is updated. I’m impressed. With great power comes great responsibility – be warned.

SVN Eats Leaves & Branches

I spent the entirety of yesterday untangling a mess of subversion branches. What had happened was lots of (3) development branches had been merged into trunk, but not back out into the other branches. This caused some changes to be mising when the branches were merged back into trunk. This happened for 3 different sites repositories.

I’d like a mechanism for alerting or automatically reverse merging from trunk into the active development branches. This “hook” would:

  • Alert admins trunk has been updated.
  • Perform the reverse merge to active dev branches (provided there are no conflicts).
  • Possibly perform fresh export the dev branches after merge?
  • Perform a fresh export of trunk to the server for UAT.

This would avoid the situation in future. It has been an interesting excercise which I will not be doing again! Lesson learned.

Ableton Live on Linux

http://dasacc22.wordpress.com/2008/08/27/ableton-live-linux-and-wine/

I live in hope.

Personally, I think all “new” PHP applications should be autoload aware.

http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/

Provided that the codebase respects its own standards, it really isn’t hard to do. The real tragedy comes when a codebase has sections which can not be readily streamlined by _autoloaders() (as in – breaks the standard). An unavoidable indicator of a messy codebase is too many exceptions to the rule of class naming || code inclusion.

Sigh.