Power of Backward Loops

Loops aka cycles (while, for, do until, etc) are common in programming. Actually they are a language level implementation of the iterator pattern.

Those who learned programming in the college/university, remember lots of tasks for sorting an array or traverse a double-linked list in both directions. But in practice, very few people apply the backward loops.

There are a number of tasks where the reverse iteration automatically solves a bunch of problems, for example:

If you need to release all elements of array/collection/list, it is much easier to start from the end and delete the last element each time, rather then go from the beginning, save the length of the container, make the reference for every deleting object, and so on.

Compare this:

var len = someCollection.length();
for (i = 0, i < len, i++) {
    var element = someCollection[i];
    someCollection.delete(i);
    delete element;
}

with that:

var i = someCollection.length();
while (i--) {
    delete someCollection[i];
}

So the backward loop is not only for students, the backward traverse rules in many cases ๐Ÿ™‚

Avoid same IDs for HTML elements

Many back-end developers don’t care about clearance of HTML code. They think it is a front-end developers job…

Yes, but no ๐Ÿ™‚ Developers should create a bulletproof code on both sides.

Very often, calling the PHP code, that generates some HTML template, for the second time creates two sets of HTML elements with the same IDs. This is wrong!

Here is a workaround to avoid same IDs for HTML elements using a global variable:

<?php
global $some_global_variable;
if (isset($some_global_variable)) $some_global_variable += 1; else $some_global_variable = 0;   

$form_id = '';
if ($some_global_variable > 0) $form_id = $some_global_variable;
?>

This is an example of HTML template for this hack:

<form role="search" method="get" id="searchForm<?php echo $form_id ?>" class="searchForm" action="/search/">
    <input type="text" id="searchText<?php echo $form_id ?>" name="search" value="" />
    <input type="submit" id="searchButton<?php echo $form_id ?>" value="" />
</form>

Try to be a good programmer every-time and everywhere!

Business Growth, Research and Development

Initially we’ve purchase BGRND.COM domain as a short URL scheme for wallpapers and background distribution service (codename “Zabor”).

After the SaaS has been shut down due small amount of users, our team decided to use this domain name for internal purposes such as hosting of websites, testing of new technologies, different experiments and so on.

We picked up the transcript: “Business Growth, Research and Development”

Research and Destroy!

"Research and Destroy" is a computer geek joke. It is a misrepresentation ofย Research and Development (aka R&D) term into something scary and funny.

There is a grain of truth in every joke! A small mistake in software development process, especially for public products, could destroys lots of things at once!

BTW, BgRnD abbreviation contains the similar meaning ๐Ÿ™‚

Print any PHP variable easily

PHP developers often need to print value of different variables directly to the HTML code. But very often PHP variable is out of the current scope, so the echo(); function doesn’t help. This PHP function prints any global (or external scope) variable by its name:

function print_var($var = 'domain', $url = '')
{
  global $$var, $$$var;
  if ($url != '')
    echo("<a href=\"$url\">${$var}</a>");
  else
    echo(${$var});
}

If you pass some URL as a second parameter you’ll get a clickable link:

<?php print_var('page') ?>
<?php print_var('domain', '/') ?>
<?php print_var('software', '/download/') ?>
<?php print_var('site', 'http://www.site.com') ?>

We hope this PHP hack will be useful for everybody ๐Ÿ™‚

States List for USA and Canada

Same to the countries list we are publishing the list of USA and Canadian states.

States list

Hint: Click on list, press Ctrl+A to select all, Ctrl+C to copy the list.

ISO 3166 Country Names

Every time programmers create the user panel in some program or website they have to search for a list of countries for dropdown or listview control. It is annoying…

So we’ve decided to palace such list in a public place. This is ISO 3166 Country Name list. You can freely use it in own projects.

Country Names

Hint: Click on list, press Ctrl+A to select all, Ctrl+C to copy the list.