Languages

Pimsleur Russian

<![CDATA[Pimsleur really does rule. After trying the first lesson of Russian, a language I have no previous experience in, I can confidently say Pimsleur is great. If you want to learn another language find out if your local library has the Pimsleur course in it first.

Actually I think Pimsleur should make the first lesson of all the courses freely available on their website or something. I really think that people are skeptical about how useful they could be and a lot would be convinced after trying them.

On a rather insignificant note, I think Russian is easier to pronounce in general than German.

Russian, Pimsleur]]>

Games

Antique SNES?

<![CDATA[I was in a computer game shop today. It's own of those places that does trades and has a lot of preowned stock. Much to my surprise they have a second hand Super Nintendo with one game for the same price as a GameCube with 4 games! Admittedly the one game was Legend of Zelda but still…

Zelda, Nintendo, SNES, GameCube, games, video games]]>

PHP

PHP code generator online

<![CDATA[I've just finished a very early version of the PHP code generator I mentioned a while ago. The code for it is rather messy at the moment so I'm not releasing it, but a web form is available to demonstrate it:

PHP Code Generator

At a simple level it takes class fragments you define and includes them in the file. The only fragment defined at the moment is Singleton. To include it you would use:

//cg fragment=Singleton&className=MyClass

Running the generator on just that basically just returns the Singleton fragment with the specified class name. The clever part is it correctly assembles code based on multiple fragments as well as using the code in the file itself. This means if you define MyClass in the file and give it some other methods, these will remain in the generated code.

You can also add code to methods defined in fragments and they still remain, providing you follow a few rules. Only certain fragments will allow code to be added to their methods – they will have //Code Start and //Code End lines. Anything you add between these will remain – all other code will be stripped when the code regenerated.

Issues

Any comments between methods will be removed – with the exception of docblock comments. Comments inside methods are treated like any normal line – they must be inside //Code Start ... //Code End.

At the moment support of visibility keywords and static is a little dodgy. The method should have the properties in it’s first definition.

A methods parameters however will be the same as the last definition. For example the Singleton defines a constructor with no parameters. If you then give it parameters it will keep them.

At the moment the opening brace for a method must be on the same line as the function declaration (i.e. it doesn’t support “one true brace”). This should be easy to fix, but it means methods must be defined like:

function myFunction() {
}

A little bit of cleverness

Although I’m not going to reveal exactly how just yet, there is a small bit of markup supported in the fragments allowing bits to be dynamically defined. To see this generate a Singleton and then add a parameter to it’s constructor (and regenerate). The Init method magically has the same parameters.

Finally…

This is very early and very untested with regards to complicated scripts. Any odd behaviour, feel free to let me know. 🙂

PHP5, OOP, code generation]]>

PHP, Web Programming

A working Microformats extension to SimpleXML

<![CDATA[I've completed a basic version of a class that (sort of) extends SimpleXML. When I say sort of I mean it extends a wrapper class (ExtendXML) that inlcludes all the functionality of SimpleXML.

Download the following to try it out:

MicroformatXML
ExtendXML

The object is created the same way as ExtendXML. After creating it you must also call:

// $mf is a MicroformatXML object
$mf->mf_init();

This adds a new property, $mfHCards, which is an array of hCards. You can access the various hCard values as properties of these objects. As an example:

$mf = MicroformatXML::create_from_file($xmlFile);
$mf->mf_init();
foreach ($mf->mfHCards as $hCard) {
    print $hCard->fn .'
'; }

Please note this is a very early version that is undocumented and largely untested. It also doesn’t contain every hCard property.

hCard, microformats, XML, SimpleXML, extending SimpleXML, PHP5]]>

PHP, Web Programming

Extending SimpleXML

<![CDATA[I posted a while ago about problems with extending SimpleXML (which I intend to do so I can add automatic microformat support). Well I think I’ve come up with a solution.

I’ve created a class called ExtendXML that is completely extendable (see the other post for an explanation of why SimpleXML isn’t extendable) that provides all of the functionality of SimpleXML.

The initial call is similar to using SimpleXML (except I made the functions static class methods instead):

ExtendXML::load_string($xmlString, [$class, [$simpleClass]]);
ExtendXML::load_file($xmlFile, [$class, [$simpleClass]]);

The $class argument contains the name of the class that will be returned. This should extend ExtendXML and defaults to ExtendXML.

The $simpleClass argument contains the name of the SimpleXML class that will be passed to SimpleXML functions. This should extend SimpleXMLElement and defaults to SimpleXMLElement.

The object returned can then be used the same as a SimpleXMLElement object.

I haven’t tested it much or documented it yet, but it supports child tags (returning objects are of the class ExtendXML or whatever you specified), attributes and xpath expressions.

ExtendXML

PHP5, OOP, ArrayAccess, SPL, programming, code, tutorial, microformats, XML, SimpleXML]]>

Google

Google Adwords CPM campaigns

<![CDATA[I'm experimenting with a CPM site-targetted campaign on Google Adwords and so far the results are promising. I have two campaigns advertising the same site one with a max CPC of 20¢ and the other with a max CPM of $2.00 targetted to a single site.

So far the CPC campaign is producing more traffic, but it's costing me on average 18¢ per click whereas the CPM campaign is only costing me 4¢ per click.

I think because of my very selective targetting I've managed to find a site that has visitors looking for what I'm advertising, but not offering competition (hence a higher CTR and lower effective CPC).

Google, Adwords]]>

PHP

PHP5 book review

<![CDATA[http://rcm.amazon.com/e/cm?t=galaxia-20&o=1&p=8&l=as1&asins=1590593804&fc1=000000&lc1=0066cc&bc1=ffffff&lt1=_blank&nou=1&IS2=1&f=ifr&bg1=ffffff&f=ifr

PHP 5 Objects, Patterns, and Practice

Put simply, after reading this book I finally “got” how to use OOP usefully in a web application. Too many OOP tutorials use examples of objects too abstract and literal to be useful (like animals or shapes). This book takes real world examples and explains what sort of things really should be objects and how to use them.

The book is basically split into three sections, as the title suggests. The first part is a very quick overview of OOP and the new features of PHP5. This is thankfully short (and as such this book is aimed at people with a fair bit of PHP experience).

The second section is the largest and basically goes through the most common design patterns and explains situations you’d use them in.

The third section is less focused on OOP and covers some practical considerations including version control and unit testing.

I would say this is probably the best book I’ve bought (except my first Perl/CGI book) and I recomend it for anyone who has to yet to be conviced about PHP as a robust OOP language.



PHP, PHP5, book review, OOP, programming]]>