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!
Posted by Tim Massey at 9:00 am on July 20th, 2010.
Categories: PHP, Uncategorized.
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.
Posted by Tim Massey at 9:33 am on June 7th, 2010.
Categories: Uncategorized.
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…
Posted by Tim Massey at 11:56 pm on June 2nd, 2010.
Categories: Uncategorized.
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.
Posted by Tim Massey at 8:15 am on June 1st, 2010.
Categories: PHP, Uncategorized.
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)
Posted by Tim Massey at 3:56 pm on May 28th, 2010.
Categories: Uncategorized. Tags: Command Line.
My first stored procedure in MySQL. I hope it doesnt open a can of worms for me. I’ve already experienced the pitfalls of putting too much logic in the database (SP’s) and don’t intend on allowing history to repeat itself.
CREATE PROCEDURE CreateReportUnits(IN num INT, unit VARCHAR(20))
SQL SECURITY INVOKER
BEGIN
TRUNCATE test.report_days;
SET @i = 0;
WHILE @i < num DO
SET @i = @i + 1;
SET @query = CONCAT("INSERT INTO test.report_days ( report_day_timestamp ) VALUES ( DATE_SUB(CURDATE(),INTERVAL ",@i," ",unit,") );");
PREPARE statement FROM @query;
EXECUTE statement;
END WHILE;
END
# To invoke use:
CALL CreateReportUnits(6 'MONTH');
The invocation will create a record for the last 6 months based on today’s date to use in reports.
Posted by Tim Massey at 10:46 am on May 21st, 2010.
Categories: MySQL.
Posted by Tim Massey at 3:38 pm on May 6th, 2010. Enter your password to view comments
Categories: MySQL.
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.
Posted by Tim Massey at 8:38 am on March 11th, 2010.
Categories: Uncategorized. Tags: Bash, Shell.
The command to add an external is:
- Navigate to the directory you want the external brought into.
-
sudo svn propset svn:externals 'http://{path to repo}/ {name of dir}' .
- 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.
Posted by Tim Massey at 9:21 am on November 1st, 2009.
Categories: Uncategorized.
I had some weirdness with the __LINE__ constant reporting the incorrect line. A colleague helped me get to the bottom of it.
There were too many line endings in the file. The only way to “see” them was in vi. They appeared as ^M characters.
The solution, replace them with nothing. I’m certain there are other ways, but this worked for me.
:%s/^M//g
To get the ^M you need to Ctrl+v then Ctrl+m.
Thanks superspace!
Posted by Tim Massey at 11:18 am on October 8th, 2009.
Categories: PHP.