What is the Role of an Algorithm in Computer Programming by Dr Pandula Siribaddana | Inside Technology 360

Algorithm is a term used to describe a process which executes in a pre-defined manner to achieve a known end-point. In most instances, such processes are short, simple and repetitive, although there are instances, especially in computer programming, where the tasks carried out by an algorithm is either complex or non-repetitive.In order to understand the functioning of an algorithm, let us consider an everyday example.If someone needs to travel 3 km each day from home to the office, there may be more than one method of travelling. One option may be to walk from home to the bus stop and take the bus to the office. The second option may be to take a taxi from home to the workplace. A third option may be to cycle 3 km from home to the office. Although these methods achieve the same outcome by beginning and ending at pre-determined positions, the methods used to arrive at the end-point are very different.Although taking the bus may be the cheapest way to travel, it may be rather slow compared to other methods. Taking the taxi, on the other hand, will be the costliest method, although it may be the fastest mode of travel. Cycling being the healthiest option would be the slowest and probably the most tiresome.As you can see, there can be more than one method of achieving the same goal although each method would be executed differently and therefore would have its own pros and cons.In computer programming, similar concepts have to be developed and implemented in order to process data, and in most instances the term algorithm is reserved to describe the simplest and the most efficient instructional sequence achieving the intended result. In general, algorithm would be part of the computer programme which itself would be a sequence of instructional events. However, the term algorithm is not used for describing the whole programme, but is reserved to describe only a portion of the sequence with the characteristics described previously.What is the use of having algorithms within the computer programme?When the correct algorithm is used to solve a problem, it would be the most efficient way of dealing with the situation. In a computer system, this means efficient use of memory, hard disk space and processor power, as well as other resources. However, if the wrong algorithm is being used, the outcome can be far from efficient.Furthermore, being a pre-defined and simple task, use of an algorithm may be far easier than to develop coding repeatedly. It eases the task of the programmers and makes the programme appear readable and less complex.At the same time, algorithms will have the capacity to function as a linear instructional set, or simultaneously as parallel sets of instructions in instances where the computer runs parallel processors.In addition to these uses, there are many other advantages in using the same and it is up to the programmers to determine which algorithm is suited best for the intended purpose.

taken from What is the Role of an Algorithm in Computer Programming by Dr Pandula Siribaddana | Inside Technology 360.


Let’s talk about drupal.

Drupal is a free and open-source content management framework written in PHP and distributed under the GNU General Public License. It is used as a back-end framework for at least 2.1% of all websites worldwide.ranging from personal blogs to corporate, political, and government sites including whitehouse.govand data.gov.uk. It is also used for knowledge management and business collaboration.

The standard release of Drupal, known as Drupal core, contains basic features common to content management systems. These include user account registration and maintenance, menu management, RSS feeds, page layout customization, and system administration. The Drupal core installation can be used as a simple website, a single- or multi-user blog, an Internet forum, or a community website providing for user-generated content. To work with drupal, you should start from the Wikipedia page [1], there are a lot of basic concepts given about drupal.

Current drupal version is 7.23, it has about 23945 registered modules and 1847 themes [2]. Drupal has a healthy documentation available in [3].

If you are interested, download and start reading this (https://drupal.org/documentation/install)




[2] https://drupal.org/

[3] https://drupal.org/documentation



How to write comments and an introduction to CDD

Read the following wikipedia page :http://en.wikipedia.org/wiki/Comment_(computer_programming)#Uses

Written well enough for me 🙂

about using TODO, here is an example:

// TODO:2008-12-06:johnc:Add support for negative offsets.

// While it is unlikely that we get a negative offset, it can

// occur if the garbage collector runs out of space.


see that the todo tag is followed by date then developer name, as it will help other developers to understand who is writing this todo and why.

level of details: The level of detail in the documentation is an important element. Too much detail renders the documentation ina ctive; rather the tool should generate documentation as intended by the author and not as produced by an exhaustive parsing tool.

alright, lets talk about comment driven development (CDD). Comment programming, also known as comment-driven development (CDD) is a software development technique that is based on the regular use of comment tags. In comment programming the comment tags are not used to describe what a certain piece of code is doing, but rather to stop some parts of the code from being executed. The aim is to have the commented code at the developer’s disposal at any time he might need it. This is especially useful when the requirements change rapidly. In this case they happen to revert to older versions of themselves, thus making the programmer either write the code again, or revert parts of the code from the versioning repository, which would be more time-consuming. With comment programming, when such a request for reverting to an old implementation arises, the developer just comments the current implementation and uncomments the previous. It is advisable to add short descriptive comments to blocks of commented code.

another good definition i found: This is a programming methodology that encourages the developer to start out complex projects by building a wireframe of their procedures using little more than comments – and basic pseudocode – to describe each step of the algorithm. CDD helps the developer encounter and work out problems before they write a line of actual code; it also has the advantage of helping clearly delineate the routes between the high-level problem and the many small-picture fractals it is composed of. The comments created using CDD may survive the process of actual coding and development as line comments throughout the programming unit; however, it will sometimes make sense to delete them after their purpose has been served. (better then wikipedia i hope)

here is the video from MSDN sweden, http://channel9.msdn.com/Blogs/MSDNSweden/Comment-Driven-Development-the-art-of-removal hope that helps you, will write more about it.

reference and read more:


http://www.approxion.com/?p=39 http://en.wikipedia.org/wiki/Comment_programming


http://allthingsoracle.com/how-to-make-comments-the-most-important-code-you-write/ (a good article, i would suggest you to read it)

Example: PHP array to Javascript Array

in php

$colorCodes = array("Restaurants"=> "#FFD014", "Bars"=> "#FBA10C", "Beauty Shops"=> "#12CBE1", "Automotive"=> "#0C93A5", "Health Services"=> "#C17FB5", "Clothing & Accessories"=> "#C22A9A", "Home Furnishings"=> "#97B63F", "Pets"=> "#CDDE61", "Other"=> "#8DD9CC");
$color = array();
//$spendByCategory is a array that hold the category name with spend amount and total count of transection
foreach ($spendByCategory as $spend) {
// json encoding the array $color.
$color = json_encode($color);

at Javascript i do the follow:

var colors = <?php echo $color ?>;

another alternative:
var js_array = [<?php echo '"'.implode('","', $php_array).'"' ?>];
taken from: http://stackoverflow.com/questions/5618925/convert-php-array-to-javascript

PHP5 chaining methods example

// This Person class encapsulates a couple of properties which
// a person might have: their name and age.
// We also give the Person the opportunity to introduce themselves.
class Person
private $m_szName;
private $m_iAge;

public function setName($szName)
$this->m_szName = $szName;
return $this; // We now return $this (the Person)

public function setAge($iAge)
$this->m_iAge = $iAge;
return $this; // Again, return our Person

public function introduce()
'Hello my name is %s and I am %d years old.',

// We'll be creating me, digitally.
$peter = new Person();

// Let's set some attributes and let me introduce myself,
// all in one line of code.

// another one example


Read more: http://www.talkphp.com/advanced-php-programming/1163-php5-method-chaining.html


PHP Pagination Class (PS_Pagination)

Here it is in action:

//Include the PS_Pagination class

//Connect to mysql db
$conn = mysql_connect('localhost', 'username', 'password');

//Query to pass to pagination class
$sql = 'SELECT * FROM pages';

//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 8, 3);

//The paginate() function returns a mysql result set for the current page
$rs = $pager->paginate();

//Loop through the result set just as you would loop
//through a normal mysql result set
while($row = mysql_fetch_assoc($rs)) {
echo $row['title'];
}//Display the navigation
echo $pager->renderFullNav();

View more and for download: http://phpsense.com/2007/php-pagination-script/

array_unique in php

array_unique — Removes duplicate values from an array (available from PHP4)

here is the definition,

array array_unique ( array $array[, int $sort_flags = SORT_STRING ] )

It takes an input array and returns a new array without duplicate values.

Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.

Short flags:

  • SORT_REGULAR – compare items normally (don’t change types)
  • SORT_NUMERIC – compare items numerically
  • SORT_STRING – compare items as strings
  • SORT_LOCALE_STRING – compare items as strings, based on the current locale.


$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);

read more: http://php.net/manual/en/function.array-unique.php


Nodize is an open source Content Management System for Node.js, written in CoffeeScript.

Nodize is an adaption of Ionize, a PHP CMS, to the Node.js platform.

Nodize is developed on top of Express and Zappa and is using Sequelize to manage the connection to the MySQL database.


– Multilingual content management
– Live update of articles (using Socket.io & JQuery)
– Easy backoffice interface that your customers will love
– WYSIWYG editor (TinyMCE)
– Eco and CoffeeKup templates
– Node.js stability & low memory footprint
– Page caching (when Redis is installed)
– Easy integration of articles in your HTML design with helpers
– Cloud hosting with AppFog
– Pages & articles sorting with drag & drop
– A good looking media manager, with drag & drop uploads
– SEO friendly URLs

Application stack

nodejs >0.6.x





redis (optional)


My note: Although i did not get much success on this CMS, but you can try out, let me know if you do something good (i am not considering best yet) using this CMS.

From : http://nodize.com/ download and installation instruction: https://github.com/nodize/nodizecms

A simple site master and an index view in asp.net

Code for site master [site.master].

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <asp:ContentPlaceHolder ID="head" runat="server">
 <title>Hello World</title>
 <asp:ContentPlaceHolder ID="MainContent" runat="server">




Here is the code for view file [Views/Home/index.aspx]

<%@ Page Language="C#" MasterPageFile="~/site.master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:content id="Content1" ContentPlaceHolderID="MainContent" runat="server">
 <%= Html.Encode(ViewData["Message"]) %>


Manipulating checked box using jquery

$('#alldays').attr('checked','true'); // make the checked box true
 $('#alldaysAnyTime').attr('checked','true'); // another one example