I experienced really slow internet connections all of a sudden through a wired connection to my Ubuntu desktop. It was weird as the wireless connections were all faster and the router was getting good signal. Anyway, it turned out (after much tweaking & a fresh install!) that it was something to do with DNS resolution!?

sudo gedit /etc/nsswitch.conf & change:

# hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
hosts:          files dns

I reckon mdns is to blame…

At the end of the day, I wanted to upgrade to 10.10 anyway and it forced me to backup my files. A good spring clean & learning experience.

As an addendum to this post…

Since I made it, the network connection on the “fresh” install ground to a halt. It turns out that its the default network manager which is to blame (thus far). I’m not sure how it manages it, but it breaks networking in some fashion.

What you need to do is install “wicd” network manager in place of the default installed network-manager.

1
apt-get install wicd

Then remove the network manager using synaptic or the Ubuntu software centre(er).

Ubuntu window control locations

If you want to get the buttons back onto the right hand side on the windows use:

tim@laptop:~$ gconftool-2 --set /apps/metacity/general/button_layout --type string menu:minimize,maximize,close

This is for 10.10 which I just dual booted on the laptop.

Xdebug .htaccess settings

You’ll need to add these to get it working.

php_value xdebug.remote_host <your IP.0.0.1>
php_value xdebug.remote_enable 1
php_value xdebug.show_exception_trace 1

FizzBuzz Test

This morning someone on twitter (@brooklynDev) commented about how good the FizzBuzz test was to weed out bad programmers. I’ve been interviewing for a few jobs recently and by co-incidence so I wanted to give it a go.

In essence it is as follows:

"Write a program that prints the numbers from 1 to 100.
But for  multiples of three print “Fizz” instead of the number and for the  multiples of five print “Buzz”.
For numbers which are multiples of both  three and five print “FizzBuzz?”."

Pretty straight forward right? I thought so anyway… Here’s my solution. It took about 5 minu

$i = 1;
while($i <= 100) {  
$divThree = (($i % 3) > 0) ? false : true;
$divFive = (($i % 5) > 0) ? false : true;

if($divThree) echo 'Fizz';
if($divFive) echo 'Buzz';

if(!$divThree && !$divFive) echo $i;

echo '';

$i++;
}

I saw another solition which involved the use of a case statement with a “true” test condition which I also liked, but it is not something which immediately jumped to mind for me.

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)

Whats the Procedure?

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.