Tales of an IT Nobody

devbox:~$ iptables -A OUTPUT -j DROP

Worthy of distribution: PHPUnit’s dbunit testing rundown June 27, 2011

This is by far the most complete and best example of a rundown of database testing using PHPUnit‘s “dbunit” extension. It seems it’s difficult to track down a whole rundown on the more technical aspects of ‘getting into it’.

No Comments on Worthy of distribution: PHPUnit’s dbunit testing rundown
Categories: php programming testing

Interfaces in PHP are worthless. Blasphemy? yes. June 6, 2011

What is the purpose of an interface? One would simply say “they’re a contract, etc.”, and you’d be right.

Long story short, all PHP interfaces do – is enforce:

– What methods are implemented
– What their signatures look like

However there’s one HUGE (in my book) fundamental lack: RETURN TYPES.

Thus, I will call interfaces ‘half a contract’.

The PHP developers and contributors often examine other ‘big brother’ languages to determine some direction for the PHP OO offerings. I think this is where this half-assed implementation came from – an aspiration of the language trying too hard to implement features of strongly typed langauges.

Need examples?

http://en.wikipedia.org/wiki/Interface_(Java)
http://msdn.microsoft.com/en-us/library/64syzecx.aspx

PHP misses a very important component of the ‘contract’, return types. In Java / C#  you can define your methods as such:

public string foo() {}

Now, if you’re willing to shell out for the honor system of implementation or to add some spice to your inductive reasoning – go for it. For what little an interface really does for you, it’s not worth the added complexity and lack of piece of mind interfaces in PHP bring to the table.

I believe that in the current state of PHP, developers will end up implementing additional checks and balances to ensure interface implementors are still behaving correctly.

No Comments on Interfaces in PHP are worthless. Blasphemy? yes.
Categories: php programming

PHPUnit and apache ant junitreport task May 13, 2011

There’s not a whole lot of ‘purdy’ interfaces for parsing junit results. For what little that’s out there – it’s even a bit more difficult when you consider the PHP camp looking for a parser for the output from the likes of PHPUnit

If you’re looking for an easy way out with a reasonable result on the unit test report – take a look at my quick and dirty conversion script.
Basically, the default output from PHPUnit’s –log-junit argument doesn’t jive 100% with ant’s junitreport task. This is due to the nested ‘testsuite’ elements in the results. All the script does is flatten those into several files, something the junitreport task expects.
Take a look, maybe it’ll help someone besides myself. 
Someday I may get around to writing a straight up php parser to deal with either the junit xml or the json output from phpunit… maybe…
No Comments on PHPUnit and apache ant junitreport task
Categories: ant php programming purdy

Add “th” (“nd”, “st”) to a number … painlessly – Part 2 April 26, 2011

So in the previous post I posted my recipe for adding rank suffixes to numbers.

Sometimes – a simple problem can be frustratingly goofy to solve. I took a lazy shortcut by passing the number through mktime – then to date to do it for me.

After analyzing what I came up with – it occurred to me that my final approach could be streamlined even better.

Logically we add ‘st,nd,rd’ to numbers 1-3 in all circumstances except when they’re in what I call an ‘eleventh’ verbal range – meaning ‘111’, ‘213’ – we simply do ‘th’.

Since I’ve already determined the wrap around (mod 10) – I gathered maybe just a straight up switch statement would be faster in the big picture …

So here’s the 2nd rendition of my function:

It’s longer for sure – but when run through a simple benchmark:
10 passes of a 100,000 iteration loop the results are pretty clear on how mktime+date can drag it down, it’s not the most scientific method but the gap is big enough to call the results conclusive:

Version 1 (With mktime+date)
Time: 7.79 seconds

Version 2 (See above – switch)
Time: 4.81 seconds

For some reason – solution #2 doesn’t feel as ‘cool’ as the first solution; I like the hackish appeal of it, but there seems to be more elegance in the simplicity, with more truth in it’s nature.

No Comments on Add “th” (“nd”, “st”) to a number … painlessly – Part 2
Categories: php programming

Add “th” (“nd”, “st”) to a number … painlessly. April 25, 2011

There’s not enough out there about this trick – but you don’t need a convoluted solution to add rank indicators to a number, so to add more noise to google search, here my variant is:

Make sure you visit part 2!

Logical breakdown:

First we get mod of $n against 10 – essentially stripping away base 10 from rolling over.

Then, since we word 1 = 1st, 2 = 2nd, 3 = 3rd – see if we have to do anything special for numbers with modulo in that range – otherwise anything from 4-9,0 is nth.

Additionally, we take characters in the ‘eleventh’ verbal range and simply make them all ‘nth’ – so we skip our special date logic and cut straight to $n.’th’.

We check this by sloppily looking for the 2nd to the last character of our number using substr. If it is NOT 1 (Indicating an ‘eleventh’) – we take the logic block for using date to deal with the markup (st, nd, rd)

The only exception to all of this is the substr will wrap the number ‘1’ and take the logic, so we make sure that if it’s explicit value is 1 – we take the logic as well to indicate ‘1st’….

In hindsight… I will expand on whether or not using date() + mktime() is worth it versus the extra effort for manually figuring the st/nd/rd suffixes.

Follow up: I have made a new rendition with speed comparisons

No Comments on Add “th” (“nd”, “st”) to a number … painlessly.
Categories: php programming

JQuery UI tip: floated divs inside JQueryUI tabs December 1, 2010

There’s a somewhat confusing problem that can happen if you want to use a multi column (floated div) chunk of content for a tab in JQuery UI tabs.

Basically, the floats inside the tab container cause the tab container to lose it’s height, making your content appear outside of the tab box.

Let us assume our code looks something like this:

The problem is that the floats inside the tab container cause the tab container height to be incorrect (Shown via Firefox)

The solution to this, was to apparently make the tab container float as well, by adding a float:left; width: 100%; to the ‘myTabs‘ div; making the content all appear correct.

End result css:

12 Comments on JQuery UI tip: floated divs inside JQueryUI tabs
Categories: CSS Design php programming

PHPCodesniffer and Zend Studio/Eclipse – Part 3 April 29, 2010

( Double-click the video to view more clearly )

No Comments on PHPCodesniffer and Zend Studio/Eclipse – Part 3
Categories: php programming

PHPCodesniffer and Zend Studio/Eclipse – Part 2

( Double-click the video to view more clearly )

No Comments on PHPCodesniffer and Zend Studio/Eclipse – Part 2
Categories: php programming

Take it to the next step March 14, 2010

Very cool (albeit somehow hectic page) on pythian on a recent Rasmus session.

There’s a HUGE amount of information in this for people wanting to ‘step to the next level’ with web application development. You’ll have to turn over some stones of your own and reapply some of this to you independent scenario, but still a wealth of info!

http://www.pythian.com/news/9337/liveblogging-at-confoo-not-just-php-performance-by-rasmus-lerdorf/

No Comments on Take it to the next step
Categories: linkspam php programming

Configuring Aptana/Eclipse with PHPUnit – Part 4 of 4 June 25, 2009

No Comments on Configuring Aptana/Eclipse with PHPUnit – Part 4 of 4
Categories: php

Configuring Aptana/Eclipse with PHPUnit – Part 2 of 4

No Comments on Configuring Aptana/Eclipse with PHPUnit – Part 2 of 4
Categories: php programming

Configuring Aptana/Eclipse with PHPUnit – Part 3 of 4

No Comments on Configuring Aptana/Eclipse with PHPUnit – Part 3 of 4
Categories: php programming

Configuring Aptana/Eclipse with PHPUnit – Part 1 of 4

As mentioned in the video, you can obtain the phpunit file for extraction here: http://pear.phpunit.de/get/

2 Comments on Configuring Aptana/Eclipse with PHPUnit – Part 1 of 4
Categories: php programming

Running parallel versions of PHP – Part 2 May 14, 2009

The hard part is over, now for the easier stuff – for this part you’ll need:

  • Coffee
  • Patience

Now we compile and install:

Now if all goes well – the prefix you used in your configure (--prefix=/whatever)
will have the following directories in it:

The file we care about the most is located in the bin/ directory – called php-cgi.

Apache
First we need to enable the action module in Apache if it isn’t already:

Now we need to modify either a specific config file in the sites-enabled/ directory or your actual apache2.conf , add this line to where you deem appropriate:

* Make sure you change “/home/rovangju/misc/php53” to where you set your --prefix=/whatever/ value is. Leave the /bin at the end.

Next, simply reload apache: /etc/init.d/apache2 force-reload, if done right you shouldn’t get any errors.

We’re almost there!

Ok, now for the magic part, for demonstrative purposes – make a the following file structure in a browser-visible spot on your server:

Fill the index.php files with phpinfo(); – the idea is to just show the php version.

Now place this into php_test/php53/.htaccess:

This will re-map all .php files under that path to the newly compiled php-cgi file I mentioned earlier.

Now point a browser to both of those index files and hopefully you should see the version differences.

Troubleshooting notes:

  • Depending on where you actually put these files – the .htaccess may not be allowed to override the server defaults.
  • Your Apache error log is your friend !
  • If you get the timezone error like I did for strtotime, you can set it in your php.ini
  • Try restarting Apache once more – sometimes .htaccess files can be fiesty.
No Comments on Running parallel versions of PHP – Part 2
Categories: apache php

Running parallel versions of PHP – Part 1

With RC2 of the php5.3 release coming out, I wanted to run the new version alongside the stable version on our development server at M State. I wanted to be able to control this behavior via .htaccess files to control particular projects.

What you’ll need:

  • Reasonable compiling experience
  • Ability to satisfy dependencies
  • Understanding and access to your httpd.conf and to be able to reload/restart apache.

Do NOT compile now unless you completely understand how to install to a directory other than the default!

Start off by downloading and extracting the source and cd into the extracted directory.

Getting ready to configure:

Modules:
Before you configure, make sure you know which modules you want.
These are enabled by the myriad of --with-gd type switches.
If you don’t know what modules you have, run phpinfo(); and look for the configure string – OR you can try the command line tool php-config (or) php5-config if it’s been installed.

Prefix (*important*)
You’re not going to want php to be installed into the default path, this will rewrite your stable php5. Instead you want it to go into a custom directory – You can do this by setting the --prefix option when you run configure

Example: ./configure --prefix=/home/rovangju/misc/php53

Using current php.ini (Optional, recommended)
Change the paths to wherever your php.ini file is located. If you’re running older php and don’t have the conf.d folder – don’t use that line. This step may save you any nuances setup in your php.ini files.

--with-config-file-path=/etc/php5/apache2 \
--with-config-file-scan-dir=/etc/php5/apache2/conf.d \

Configuration summary
Now we’re ready to run the gauntlet of trying to configure and build. Expect to fulfil dependencies. At a minimum our configure will look like this: ./configure --prefix=/path/you/want

When/if your ./configure throws up that a library isn’t found – this is the least fun part when you have to install the dev libraries for those modules. So if your getting an error about libxml2 – You’ll likely want to install libxml2-dev. If you use apt this can be handy: apt-cache search libxml2 | grep "dev" – once you’ve installed it, try the configure again. It took me about half an hour of configure and installing the dev libs …

You can see my configure string as a comment to this post for example.

Continue to Part 2 when your configure doesn’t throw errors!
1 Comment on Running parallel versions of PHP – Part 1
Categories: apache php

Tapping flickr, Part 1 April 13, 2009

This first quickie will be on iterating through the photos in a photoset (essentially, an album) and pitting them out in a thumbnail format with links to the larger versions.

References:
http://www.flickr.com/services/api/misc.urls.html
http://www.flickr.com/services/api/
http://us2.php.net/manual/en/ref.simplexml.php

Requirements:
PHP with SimpleXML
Flickr Account, and a developer API key.

This will spit out a nice dump of what you have to work with.
We’re mainly concerned with making sense out of the $oXML->photoset values.

Using from what we know off of the references we can generate thumbnails easily:

I hope this sparks some ideas – and Part 2 will involve some more detail oriented things.

No Comments on Tapping flickr, Part 1
Categories: php purdy