Same height for elements

A while ago I wrote a jquery plug-in that allows you to easily make selected elements all the same height. Well, it turns out that it could be a little better because it didn’t take in to consideration margins, padding and such. So here’s a slightly more robust version.

Did you like this? Share it:

Zend OPcache – some info and a GUI

I’ve just started to use Zend OPcache in place of APC in a few places and so far it’s great!

Because documentation seems a little scarce right now, I’ve decided to jot down the methods available (mainly so I don’t forget).

Should be pretty obvious given the name – resets the opcache

This will return an array with three indices, one for the directives that have been set, one for version information and one for any blacklisted paths. For example:

    [directives] => Array
            [opcache.enable] => 1
            [opcache.enable_cli] => 1
            [opcache.use_cwd] => 1
            [opcache.validate_timestamps] => 1
            [opcache.inherited_hack] => 1
            [opcache.dups_fix] => 
            [opcache.revalidate_path] => 
            [opcache.log_verbosity_level] => 1
            [opcache.memory_consumption] => 134217728
            [opcache.max_accelerated_files] => 4000
            [opcache.max_wasted_percentage] => 0.05
            [opcache.consistency_checks] => 0
            [opcache.force_restart_timeout] => 180
            [opcache.revalidate_freq] => 2
            [opcache.preferred_memory_model] => 
            [opcache.blacklist_filename] => 
            [opcache.max_file_size] => 0
            [opcache.error_log] => 
            [opcache.protect_memory] => 
            [opcache.save_comments] => 1
            [opcache.load_comments] => 1
            [opcache.fast_shutdown] => 1
            [opcache.enable_file_override] => 
            [opcache.optimization_level] => 2147483647

    [version] => Array
            [version] => 7.0.2-dev
            [opcache_product_name] => Zend OPcache

    [blacklist] => Array


This will return that holds information about whether the opcache is turned on or not, whether it’s in a restart phase, the memory usage and hit statistics, and any files that have been cached along with hit and memory details. For example:

    [opcache_enabled] => 1
    [cache_full] => 
    [restart_pending] => 
    [restart_in_progress] => 
    [memory_usage] => Array
            [used_memory] => 9395880
            [free_memory] => 121987104
            [wasted_memory] => 2834744
            [current_wasted_percentage] => 2.1120488643646

    [opcache_statistics] => Array
            [num_cached_scripts] => 353
            [num_cached_keys] => 1546
            [max_cached_keys] => 7963
            [hits] => 27055
            [start_time] => 1365412384
            [last_restart_time] => 0
            [oom_restarts] => 0
            [hash_restarts] => 0
            [manual_restarts] => 0
            [misses] => 509
            [blacklist_misses] => 0
            [blacklist_miss_ratio] => 0
            [opcache_hit_rate] => 98.153388477725

    [scripts] => Array
            [/http/includes/libs/ZF-1.12.2/Zend/Loader/Autoloader.php] => Array
                    [full_path] => /http/libs/ZF-1.12.2/Zend/Loader/Autoloader.php
                    [hits] => 175
                    [memory_consumption] => 63320
                    [last_used] => Mon Apr  8 16:21:14 2013
                    [last_used_timestamp] => 1365434474
                    [timestamp] => 1343660895

            [/http/www-includes/libs/ZF-1.12.2/Zend/Db/Adapter/Oracle.php] => Array
                    [full_path] => /http/libs/ZF-1.12.2/Zend/Db/Adapter/Oracle.php
                    [hits] => 17
                    [memory_consumption] => 60600
                    [last_used] => Mon Apr  8 16:21:14 2013
                    [last_used_timestamp] => 1365434474
                    [timestamp] => 1325795702

            [/http/libs/ZF-1.12.2/Zend/View/Helper/Placeholder/Container.php] => Array
                    [full_path] => /http/libs/ZF-1.12.2/Zend/View/Helper/Placeholder/Container.php
                    [hits] => 175
                    [memory_consumption] => 2744
                    [last_used] => Mon Apr  8 16:21:14 2013
                    [last_used_timestamp] => 1365434474
                    [timestamp] => 1325795702



APC did have a GUI which was quite handy to see what had been cached, settings and memory usage but Zend OPcache doesn’t (currently as far as I could see) have anything similar.

It is possible to get information from looking at the output of phpinfo() which contains all of the key information.

However, I’ve just pushed the start of a GUI to GitHub. If you want to make changes and improvements then please feel free! It’s only had a very little amount of work done on it so far so is pretty raw.

Did you like this? Share it:

My CodeMagic fork (a TinyMCE plugin for code editing)

I’ve used TinyMCE for a while – it’s an excellent WYSIWYG editor for web applications. However, the code editor in it is really simplistic. Enter CodeMagic, a plugin that allows you to replace the standard code editor with one that used the excellent CodeMirror library for syntax highlighting. So I started to use CodeMagic but found a number of issues with it. For example, it used CodeMirror 2 and not 3, had issues with using IE and the word wrapping functionality and the window resizing was never great. But with the joy of things being on GitHub and up for a bit of a forking, that’s exactly what I did.

Check out my CodeMagic fork on GitHub and feel free to give me any feedback, or fork it yourself and make it better.

Did you like this? Share it:

MSC Executive Mobile Charger review

The other day I was asked if I’d like to review a solar charger battery pack for portable devices that comes from Mobile Solar Chargers. At first I was a little dubious because I’ve seen some battery packs and solar chargers that have been rather badly constructed/have a flimsy design and provide as much power a lemon-powered battery. But as I had just gotten a new phone that likes battery power, I thought I’d give it a shot… and I was genuinely happy that I did!

Continue reading “MSC Executive Mobile Charger review”

Did you like this? Share it:

Handy little function

Quite often I find myself wanting to run the same script by either cli or through a browser. But I don’t want to fill my echo statements with <br /> tags if I’m on cli because that’d just look ugly, but at the same time I don’t just want to use \n when outputting in the browser because everything would be on the same line.

This handy little function helps to do simple output that will be readable in the browser as well as the command line:

$_ = function($str) {
    if (PHP_SAPI == 'cli') {
        echo $str;
    } else {
        echo nl2br(str_replace("\t", str_repeat('&nbsp;', 6), $str))."\n";

Then when I want to echo something I just do:

$_("This is a test\n");
$_("\tTime:" . time() . "\n\n");

Simple but handy.

Did you like this? Share it:

Dreamhost and procmail – parsing your mail with a script

I have a Dreamhost account and have done for some while. Typically I’m happy with their service, but yesterday was the first real frustration I had with them. I wanted to use procmail to send email to a script for processing. I was sure I had done this before on Dreamhost, but couldn’t seem to get it to work in the wee hours of the night. So after a quick email to support asking if it was possible, they came back with this response:

Unfortunately this is not possible. We do
not offer or support any type of email to script functionality on our

And this pretty much backed up all the searches I had been doing on line in regards to Dreamhost and using procmail.

Now, where they may not support people doing this, it is my pleasure to tell you that it is possible! And here’s how you do it…
Continue reading “Dreamhost and procmail – parsing your mail with a script”

Did you like this? Share it:

Using CSS3 sucks (right now, but I’m sure it’ll get better)

Am I the only one to think that using a number of aspects of CSS3 right now really sucks? The potential it offers is great, but does anyone really think doing something like this for a gradient is a productive use of time?

    background: #9880cc; /* Old browsers */
    background: -moz-linear-gradient(top, #9880cc 0%, #bab3cc 93%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9880cc), color-stop(93%,#bab3cc)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #9880cc 0%,#bab3cc 93%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #9880cc 0%,#bab3cc 93%); /* Opera11.10+ */
    background: -ms-linear-gradient(top, #9880cc 0%,#bab3cc 93%); /* IE10+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9880CC', endColorstr='#BAB3CC',GradientType=0 ); /* IE6-9 */
    background: linear-gradient(top, #9880cc 0%,#bab3cc 93%); /* W3C */

Once upon a time, not that long ago, the trend setters/leaders of the web development community would have lynched you if you so much as dared to use a proprietary tag, be it in the css or the html. Now they’re actively encouraging the above kind of usage?! It’s ridiculous! Firefox, Chrome, Safari, IE and Opera all require different proprietary rules, and then you have the W3C recommended way and then the fallback for older browsers.

A Transform in CSS3 is just as bad:

-moz-transform: scale(0.8) rotate(deg) translate(px, px) skew(deg, deg);
-webkit-transform: scale(0.8) rotate(deg) translate(px, px) skew(deg, deg);
-o-transform: scale(0.8) rotate(deg) translate(px, px) skew(deg, deg);
-ms-transform: scale(0.8) rotate(deg) translate(px, px) skew(deg, deg);
transform: scale(0.8) rotate(deg) translate(px, px) skew(deg, deg);

And this time it’s not the rule value that’s different for each, it’s the rule name!

I think HTML5 (well, XHTML5 for me – I do love a properly closed tag!) and CSS3 are great, don’t get me wrong, and I think we’ve already seen a lot of examples of wonderful sites and demos created using them. But surely how it’s getting there and the asinine number of rules we have to put in for each browser is a major step backwards in what people were trying to achieve only a few years ago? (Ie, a nice compliant standard way of doing things.)

Incidentally; there are a couple great sites that help out doing fancy new CSS3 stuff:

The Ultimate CSS Gradient Generator
CSS3 Generator

Using sites like those can save a bit of sanity.

Did you like this? Share it:

Sorting an array of objects by one or more object property

Quite often I find myself having an array of objects and needing to sort that array of objects by property (either one property or multiple)…

Imagine, for example, getting a large result set from your database and ordering in the query just takes too long. Or perhaps you’re getting results from a web service and that service doesn’t return the results in the order you’d like to use. Have you ever found yourself in that situation, too? On looking at the usort documentation one day I came across a comment by someone called Will Shaver that did almost what I wanted. With a little adaptation for my own use (being able to change the sort order, for example), it has become one of my favourite functions to use for sorting.

loading gist...

Now a few cools things about the function:

  1. It uses anonymous/lambda functions (or closures, whatever your prefer to call them), and that’s just plain fun
  2. You can sort on more than one property and because the sorting is recursive, it’ll sort the second property within the confines of the first, the third within the confines of the second, and so on. Think sorting in SQL
  3. You can sort in ascending or descending order for any of the properties
  4. It retains key associations so you could use this on an associative array of objects
  5. If the parameter you want to sort on is an array itself then you can use any value (by specifying it’s key) in that array as the sorting value
Did you like this? Share it: