Echo – lazy-loading HTML5 images with data-* attributes via JavaScript

Echo  is quite handy for web developers.  On those pages that feature a lot of images, things can get slow and the server might get too much of an abuse (with more traffic thrown at it).  One way to work around this is to only load those images that are in the visible part of the screen.  Here is a demo of how it works.  Just keep scrolling down and notice how by default you have a blank.gif image shown, with a standard loading indicator and a split second later you see the actual image which was supposed to be in there.

Simple, easy, elegant – and that’s how I like it.

An Introduction To Full-Stack JavaScript

An Introduction To Full-Stack JavaScript

There is more JavaScript discussion and references in this article than I can handle in go.  Reading it parts is recommended, if you are not too experienced with the recent explosion in all kinds of JavaScript tools and frameworks.

Beautifying PHP’s json_encode() output

I’ve been working a bit more with PHP and JSON recently and one of the things that annoyed me quite a bit was the single line output of the json_encode() function.  Here is an example:

<?php
$data = array(
'foo' => 'bar',
'bar' => 'qux',
'blah' => 'blah',
);

echo json_encode($data);
?>

Poorly readable result (imagine having larger, more complex data structures like nested arrays):

{"foo":"bar","bar":"qux","blah":"blah"}

Apparently, since PHP 5.4.0 it became much easier to optionally format the output with some indentation.  json_encode() function has an $options parameter, which was given an extra option – JSON_PRETTY_PRINT.  Here is an updated example:

<?php
$data = array(
 'foo' => 'bar',
 'bar' => 'qux',
 'blah' => 'blah',
);

echo json_encode($data, JSON_PRETTY_PRINT);
?>

And an updated output:

{
 "foo": "bar",
 "bar": "qux",
 "blah": "blah"
}

Very handy for debugging and for those bits of JSON that should be editable by hand.