Mar 7, 2008
I decided some time ago that I wasn’t happy with the way this site looked. Unfortunately I haven’t had much time to do anything about it. I’ve finally got around to making some changes, the most important of which you may notice is the minimalist design. I don’t know if I plan to change this any time in the future, but for now it will do.
I’ve also tried to pull in some data from other services I use (perhaps not as frequently as I would like) such as Twitter, Facebook and Flickr. To that end, my recent Twitter tweets are now displayed, together with my Facebook status. I’ve also pulled in some random images from my public Flickr collection.
Jan 18, 2008
Another aide memoire, but again may be useful to some. I’d like the ability to work from home on some web development projects I’m doing at work. Getting the code locally is not a problem thanks to Subversion over ssh However viewing the results can be tricky when you consider that the development server is behind the work network. The answer is SSH tunneling.
Let’s say you can access SERVER_A directly over ssh The service you want to access is on SERVER_B which you can’t access directly via SSH from your local machine. However, you can access SERVER_B from SERVER_A. I’ll assume that you want to access the service locally on port 12345, and that the remove port is port 80. The following command will allow you to access a service on SERVER_B from your local machine.
ssh -Nf -L 12345:SERVER_B:80 username@SERVER_A
The ‘-Nf’ switch says don’t execute a command with this ssh session, and run this ssh process in the background. The first port is the port you want to use locally; the first server is the usually inaccessible remote server you want access to; and the third port is the remote port you want to use. The final argument gives the login to the remotely accessible server you have ssh access to directly.
One caveat to this is if you are trying to access a web site that is defined using Apache virtual hosts. With this command alone, requesting localhost:12345 in Firefox would only direct you to the site that is listening remotely for requests that match ‘localhost’. If you would ordinarily access this site using mysite.server_b, then you need to use that as the address in Firefox on your local machine. Therefore, this needs to be added in /etc/hosts. With that done, you should be able to request mysite.server_b:12345 in Firefox and be directed to the remote “virtual host” site.
Aug 22, 2007
Recently I had cause to report on the usage staff at work made of the corporate intranet. This would ordinarily be a simple enough task if the logs were plain standard Apache logs. However, I was dealing with Oracle9iAS, a very different beast indeed. Oracle9iAS is built on top of a customised version of Apache and incorporates a caching proxy server, the so-called Webcache; an implementation of J2EE called OC4J (Oracle Containers for Java) and various other bells and whistles, making it something of a behamoth. [Read more]
Aug 21, 2007
As you can see from my previous post, my first attempt at writing a Wordpress Plugin was a success. This plugin is very simple and allows the user to embed a YouTube video into their post. The main function calls a callback function that replaces every occurrence of the tag ["youtube" video_id] (minus quotes) with a flash video corresponding to the video_id parameter.
Just paste the code below into a file called ‘youtube.php’ in your wp-content/plugins directory. You should then be able to activate it via the Plugins admin option. Once activated, you can place a YouTube video in your post by going to code-view and inserting ["youtube" video_id] (minus the quotes). The video_id parameter is the ‘v’ parameter in a YouTube URL. In the example below, the URL is http://www.youtube.com/watch?v=lL4L4Uv5rf0. Therefore, the video_id parameter should be lL4L4Uv5rf0. In the code below, you will need to remove the quotes around the word “youtube” in the regex on line 5, I had to put these in to display the code without it interpreting the tag… it’s a work in progress!
Code (php)
-
-
-
-
define("YOUTUBE_HEIGHT",
350);
-
define("YOUTUBE_TAG",
"/["youtube
" ([[:print:]]+)]/");
-
define("YOUTUBE_LINK",
"<object type="\
" data="\
" height="\
" width="\
">
-
<param name="\" value="\"></param></object>");
-
-
function youtube_plugin_cb($match)
-
{
-
$html = YOUTUBE_LINK;
-
$html =
str_replace("###YOUTUBE_ID###",
$match[1],
$html);
-
return ($html);
-
}
-
-
function youtube_plugin($content)
-
{
-
-
}
-
-
add_filter(‘the_content’, ‘youtube_plugin’);
-
add_filter(‘comment_text’, ‘youtube_plugin’);
-
-
?>
Aug 16, 2007
My work has recently taken a departure from the usual web development as I’ve been “borrowed” by the other development team to help out with a Java project. Now, my Java is reasonable sound but yesterday I came across a curious situation involving passing about the current object.
In common with a lot of languages, the current object is represented by the ‘this’ keyword. I wanted to pass ‘this’ to a static method of another class. Of course, I can’t refer to the object as ‘this’ in the static method context as that would be ambiguous insofar as it could refer to the class with the static method I’m working with. This pattern is often used with callbacks where for example you might want to register a class with a particular listener objcet. To avoid confusion, I named the actual parameter in the static method
I assumed that I would reference the fields and methods of the object using
Code (java)
-
that.someMethod()
rather than
Code (java)
-
this.someMethod()
This is where the fun begins. Let’s call the original object
Code (java)
-
SomeObject theObject
and I want to call the static method
Code (java)
-
SomeClass.doStaticMethod(SomeObject that)
I would call that method, from within theObject, using
Code (java)
-
SomeClass.doStaticMethod(this)
When in theObject, I have access to private fields and methods since private fields and methods are within scope. I assumed the same would be true when I passed “theObject” as “this” to “SomeClass.doStaticMethod(SomeObject that)”. However, when I actually try to access private fields such as “that.privateField”, it would appear that I no longer have access. I could create appropriate accessor methods, but that would defeat the idea of encapsulation.
Does anyone have any ideas? Am I missing some fundamental (and so obvious I missed it) rule of scope or object passing?
Aug 15, 2007
I’ve finally found time to start investigating some other PHP frameworks, and after some brief research I decided to start off with Symfony. All is going well and so far I’m impressed with what Symfony can do compared with CakePHP… with a few exceptions.
I initially tried following the My First Project tutorial, but hit problems pretty quickly. It would seem that there was a problem with the PHP SQLite extension. The phpinfo() function verified that SQLite was indeed installed, but I couldn’t get any further on that trail. After reading a number of forum posts on the issue, it became apparent I should recompile Apache and PHP. I’m still not that confident with Linux to do that so I left it at that.
Then I followed the Askeet tutorial with more success as this tutorial uses MySQL rather than SQLite. However, I can’t get the URL rewriting to work as it should. I’ve checked my Apache configuration, the .htacces file and still no luck. If I load http://<project>/question I get a 404 error. If I load http://<project>/index.php/question or http://<project>/frontend_dev.php/question all is well. I’ll press on with this tutorial until I hit a road block, but this is really bugging me. Again, a few forum posts suggest recompiling Apache and PHP. However, the extensions that should be included in the new build are already present according to phpinfo().
I’m currently running Fedora 7 which installs Apache and PHP in its own odd way. Perhaps I should start from scratch by removing Apache and PHP with yum and compiling both from source. Although as I said I’m kind of reluctant to do that. If anyone has any ideas - let me know!
Mar 15, 2007
Sitepoint have another competition on the go. The winner gets a copy of the new book “Principles of Beautiful Web Design”. The competition involves using CSS to style some simple markup that serves as an advert for the book. Unfortunately the markup hooks available for use with CSS are somewhat lean. I’ve given it a shot, as have others. Why don’t you have a go - you have until the 6th of April to enter as many entries as you like. Happy coding!
Mar 1, 2007
You may already have an OpenID from one of the many providers, for example username.myopenid.com. Wouldn’t it be nice if you could use your own domain name instead? Well you can! You may not actually host an identity provider capable of vouching for your ownership of your own domain, but you can always get username.myopenid.com to vouch for you.
This process is called delegation. You use your own domain name as your OpenID, but add some extra markup to the head element of your homepage that tells the relying party that you are delegating the responsibility of authentication to another server. The markup you need is:
Code (html4strict)
-
-
<link href="http://www.myopenid.com/server" rel="openid.server" />
-
<link href="http://username.myopenid.com/" rel="openid.delegate" />
-
<meta http-equiv="X-XRDS-Location" content="http://yoururl.myopenid.com/xrds" />
This will tell the relying party, that it should instead visit username.myopenid.com. You will then authenticate to this delegate server. Once successful, by implication of having authenticated to the delegate server, you have also proved that you own the domain from which you were directed.
The link tags are used for OpenID 1.x server discovery, and the meta tag for OpenID 2.x server discover. In order to be as compatible with OpenID consumers as possible, you should use both link and meta elements.
Feb 28, 2007
Coming up in April is the inaugural Highland Fling conference. A meet up of web developers and designers aimed at getting the Scottish interweb community involved with some of the big names in web development. There are a number of speakers including Jeremy Keith. The day after the conference, Friday 06 April is Refresh Edinburgh. A more informal gathering where developers can discuss the state of the web with like-minded people. I will be there, and I hope as many other developers in Scotland as possible, who like me don’t often have a chance to meet and greet at conference-type-events, will be there too. See you there!
Feb 21, 2007
We sign up to more and more services online every day. This often involves remembering multiple, often similar (in the case of username1984, user_name_84 etc) usernames and passwords. A solution to this is so called single-sign on, whereby you use only a single identity such as a Microsoft Passport or a Yahoo! username. The problem with this solution is that you can find yourself tied in to one large company’s services.
If you already have a Microsoft Passport, you are unlikely to want to create a Yahoo! account to use their services as this would involve going through a sign up process, replicating friends lists and so on from one provider to the other etc. Besides, I don’t know about anyone else but I don’t like the idea of some large company controlling my identity: storing my username; hashed password and other details. It would be better if I could arbitrarily choose who controlled my identity, or even better, control it myself. This is where OpenID comes in. [Read more]