Opening up to the world

Posted in Programming, Sites at 12:28 pm by Toby

We have an internal php app that we use everyday. I wanted to make it available to our staff when they are out and about, but wanted to add a little extra security.  We now run on Apache after having run on IIS for years, so I reckoned a .htaccess file was the way to go, but I only wanted the user to be asked for an extra password if they were accessing it externally.

I asked a question on stackoverflow.com (which is for programming questions what google is for search), which lead me to the my answer on this site.


document.location vs document.location.replace

Posted in Programming at 2:38 pm by Toby


seems to replace (!) the contents of the window, and although it replaces the url in the address bar it doesnt really refresh the page as you will notice if you try the back button as it will look like you are going two pages back.

document.location = ‘http://mysite.example.com/myurl.html’

will go to the new location.


Adding a Module to YUI3 using YUI.add

Posted in Programming, YUI at 10:43 am by Toby

I have been using YUI 2 and now YUI 3 for the last year or so.  I’m not a major javascript developer by any means but I started with Douglas Crockfords excellent book and series and javascript and YUI have finally started to make sense and I’m begining to put together a few bits and pieces for an internal app we have.  I started using YUI 3 recently as there is no reason not to since it works almost seemlessly with YUI 2 with only a little moving around.  However I was never quite sure how to put it all together.  The standard YUI template looks a bit funny at the begining.

YUI().use(''yui2-tabview', 'yui2-element', 'yui2-connection',  function(Y) {

//Do all sorts of cool things here.

You see this pattern all over the place, and infact it is how you use YUI3.

After watching some of the excellent videos at YUI Theatre, I figured out that it was really easy to use the YUI.add method to add my own module, but all the code I could find was one slide in the presentation which sort of described how to do it, so I thought it would be useful to do a little how to here to help people out.

Basic Module

Adding a module to YUI is super easy, so easy infact that you will never write YUI code again that isnt part of a module.  I guess thats the point.

Instead of just writing functions or objects in your .js file, do this.

YUI.add('mycoolmodule-core', function(Y){

var privatevariable = 'Private Value';

var privatefunction = function(){ //dos something };


Y.mycoolmodule.core = {

//declare object with public functions and variables.


}, '0.1.1' //Version String is Third parameter to add function

//,RequirementsObject  //if you wish fourth param can be a Config Object, see API reference for details.


Note we do not execute YUI as in the use pattern.

In the above code, the object assigned to Y.mycoolmodule.core is our public module.   The public code you would have had in your .js file is in this object, and available to your other code .  In order to use it you just need to include the .js file in your page as expected, and call use.

YUI().use(''yui2-tabview', 'yui2-element', 'yui2-connection','mycoolmodule-core',  function(Y) {

//Do all sorts of cool things here with my own module.

Thats it!  It works, and you have all the sandboxing that YUI provides for your code.  How brilliant is that?

How do I reference Stuff

One of the things I found confusing initially was how to reference stuff within this module structure, so I’ll show you what I did (if someone wants to correct me to make this better please do, I find the whole this, that, these, those a bit confusing).


Most people are still using YUI 2 so a reference to the YAHOO object is essential, the way to do this is to declare YAHOO as a private variable in your module, which makes it available to all your module functions.

YUI.add('mycoolmodule-core', function(Y){

var YAHOO = Y.YUI2;

var privatefunction = function(){ //dos something };


Y.mycoolmodule.core = {


Your Module

Stuff within your module, such as dialogs, functions, objects , array etc, can be referenced in a number of ways, I suppose you can use ‘this’, but I find this confusing.   In my case it works well to refer to it by full namespaces

YUI.add('mycoolmodule-core', function(Y){

var YAHOO = Y.YUI2;

var privatefunction = function(){ //dos something };


Y.mycoolmodule.core = {

PublicVar : 'A Value',

PublicObj : {a:'A', b:'B'},

afunction : function(){





I hope this helps out with someone needing to get a YUI module working by using YUI.add


Setting up PHP to run your scripts inside EditpadPro

Posted in EditPadPro, Programming, tools at 1:39 pm by Toby

As mentioned in  a previous post I am a fan of Editpadpro, it is now my text tool of choice,  I find it very powerful, quick and easy to use.  I have recently made an addition which is a nice little improvement.  I set up an Editpadpro tool to run the current file as a php script and dump the output to a new file in Editpadpro.  No more need to jump to your webbrowser and keep refreshing windows.

Follow the steps below to get this up and running.

  1. Create  a new tool by going to Tools – Configure Tools – New
  2. Give it a name (I’ve called mine PHP File)

Set the options on the first screen

  1. Command line – path to php.exe and the %FILE% placeholder (places the current filename on command line).
  2. We must set the Working folder or any included files in your script wont be found.  – use %Path% to set to the currently selected files path.
  3. Select any file type this should apply to probably just php.

If you wish ask Editpadpro to Save your current file to take advantage of any changes you might have made.

Now comes the fun bit,

  1. In the ‘How to capture the tool’s standard output’ select Into new tab to give us the output of our phpscript.
  2. Dump any error into the message pane.

This works a treat and for many text processing tasks I no longer need to go near a browser which makes me happy.


Learning Objective-C

Posted in Programming, Uncategorized at 2:38 pm by Toby

Like many many people who have decided to jump (maybe a bit too late) onto the IPhone development bandwagon, I have had to do two things I never thought I would do!

  1. Buy a Mac (a lovely little mac-mini)
  2. Learn how to write code in Objective-C (the bastard unwanted love-child of C, C++ and Small-talk)

Its been great fun, and I’ve learnt a few things on the way.  While I have a long way to go, I’ve already run foul of Apples policy of silence – buying my mac-mini 3 weeks before they released a new beefier version with double the memory of the one I purchased.

I eventually purchased an IPhone about 5 months ago after starting off with a loathing of them when they were initially released and slowly gaining a gruding respect for them as more and more of my friends turned up in the pub with them, before it turning into a burning ‘I MUST HAVE ONE’.  This got so bad that I bought myself out of the last 9 months of my 3 contract to change to O2 so I could get an Iphone.

Saffron Pears

I havent been disappointed.  I like many others find that the IPhone is what I have been looking for for the last 3 or 4 years since phones began to get ‘smart’ but not quite smart enough.

[NSString init]

I then moved on as a developer to needing to write apps for it.  I swallowed my pride and after several false starts where I went into the apple store stared for a while and walked out, I finally one day came out with a Mac-mini under my arm.  After two solid days of downloading (upgrade os, critical updates, xcode, sdk) I finally sat down to see what I could do.  That is when I came face to face with Objective-C.  I spend most of my programming career writing Delphi code and never managed to learn either C or C++ infact the only { language I have any knowledge of is php but I think thats where the similarity ends.

I took a look at the rather interesting Stanford IPhone course which is available for download via ITunes University, but after a couple of failed attempts at connecting things in Interface Builder I abandoned ship went Old-fashioned and bought a book on Amazon:  Beginning iPhone 3 Development: Exploring the iPhone SDK This book has been well worth it and I am slowing working my way through it.  Objective-C is slowly begining to make sense.  I am begining to understand it in terms of other languages which makes it a bit easier.  I will write here as I work my way along.


Why is Visual Basic bad?

Posted in Programming, Uncategorized at 5:52 am by Toby

In a series of posts starting with Stiff asking a few programmers a series of open-ended questions about programming and being commented on by a few people including Jeff Atwood on Coding Horror. One of the comments was on how Linus Torvalds had made a small comment about how Visual Basic was quite instrumental in moving forward the cause of programming (moreso than more object-oriented languages).

For example, I personally believe that Visual Basic did more for programming than Object-Oriented Languages did. Yet people laugh at VB and say it’s a bad language, and they’ve been talking about OO languages for decades.

And no, Visual Basic wasn’t a great language, but I think the easy database interfaces in VB were fundamentally more important than object orientation is, for example.

I am opening myself up to be flamed badly here, but I think most of us would give a grudging respect to visual basic – even while burning Visual Basic books and chanting incantations of exercism on those still aflicted with the ill. Visual Basic was easy to pick up, it really put the rapid into rapid application design (though I think the phrase was introduced by Borland). It allowed very fast proto-typing, it allowed the creation of COM objects and ActiveX controls faster than anyone had previously though possible and it is was so much faster to generate code in than C++ that any company that wasnt writing device drivers in the mid 90’s to late 90’s would have been very foolish not to at least investigate its use in their development departments. It was also from Microsoft so “had to be good!”.

So what went wrong?

I can’t abide Visual Basic. I started learning a newly released product that I had saved up my pocked money to buy back when I was in university in 1995. It was called Delphi (I was one of the few people who didnt learn Pascal in university – instead I did POP11 – I studied Artificial Intelligence). Delphi had it all it. It had everything Visual Basic had, it made making Windows applications a breeze, it came out of the box with about 120 different components (Visual Basic at the time came with about 30), it was easy to create and on top of all this it gave you the control that Visual Basic did not when you wanted to dig a little bit deeper. I thought myself Delphi, as many people did and have remained a huge fan of this great system from then till now (although one must wonder how much longer it will last), I believe it was superior to Visual Basic from the day it was released to the day Visual Basic was axed (I dont count VB.NET), but history has shown that these emotional responses have little to do with the reality of the sucess of a product. As the 90s passed Delphi held it own while Visual Basic exploded out of all control possibly becoming the most utilised business software language in the entire world*1.

I inserted the previous paragraph by way of saying I am not a Visual Basic fan, but yet I am going to defend it after a fashion. The problem with Visual Basic is again as with so much that touches our lives – Microsoft.

Microsoft are responsible for the dirth of rubbish, unmaintainable, badly written, memory leaking utilities, business applications, enterprise applications and help us Lord mission critical applications running on almost every machine in the world that runs windows. They know this and that is the reason they created VB.NET and ensured it was not backward compatible and would require often an entire rewrite to get a VB6 application working on VB.NET. You see Visual Basic was victim of its own sucess.

I may be naive but I don’t think Microsoft actually ever expected Visual Basic to become quite the monster it did. I think they had a nifty idea to release a RAD application development environment for people to play around with. Maybe it would help some students to learn programming, write that little app for their parents business and then they’d move on to a ‘proper’ programming language like C++, but it didnt work like that. Sure the students learnt it, they wrote that application for their parents business, maybe they even sold a few copies of it to their parents friends who ran businesses, but then they went out and tendered for work against software houses writing in C and C++. The VB guys could do it in a third the time and at a third the cost. The people buying the time didnt know or care whether the language it was going to be written in was up to the job.

Further details to follow.

*1 – I made this statistic up, I dont know if it was but it certainly seemed like it.