Archive for the ‘code jungle’ Tag

_SESSION fun #1: Visit History   Leave a comment

Practically SESSIONS have infinite serious uses. But, being serious is one part, being ‘interesting’ is more serious than that. Usually people won’t agree to include thee types of weird sections in their pages, since your browser will always decolorize the visited links! I thought it might get user attraction and they will pay attention to see their progress in finishing up reading web site contents. Anyway this is fun and those who have just started understanding SESSIONS; this will be a good part to play with … hopes they are also not in the lat minute to production!

The code does this:

  •  Tracks the current and past posts
  • Displays a list in the last visited order

Funny part, it will never show if you ever been here before, simply removes the current page from visited pages list, so visited will never know that they have been her once!

single.php


<?php
// Place this in the single.php

 get_header();
$visited_pages = $_SESSION['vpages'];
 $last_visited_page = $_SESSION['lpage'];

 while ( have_posts() ) : the_post();
   $the_title = get_the_title();
	echo "<h1>".$the_title."</h1>";
	echo "<h2>".get_the_excerpt()."</h2>";
	the_content();

	 if($last_visited_page != $the_title){
    	  if($visited_pages):
     	    $already_pages = explode("~", $visited_pages);
     	    $visited_pages = $last_visited_page;
     	    foreach ($already_pages as $item){
        	    if($the_title != $item && $last_visited_page != $item) :
        	      $visited_pages .= "~".$item;
        	    endif;
    	    }
    	 else:
    	   $visited_pages = $last_visited_page;
    	 endif;
endwhile;	 }
$_SESSION['vpages']= $visited_pages;
$_SESSION['lpage'] = $last_visited_page;

if($visited_pages)
  echo "<BR>Visited Pages:<ol> ". preg_replace("/([^~]+)~*/", "<li>$1</li>",$visited_pages) . "</ol>";

get_footer();
?>

Like always I think if you like this one, try to build one pie chart that shows how many posts are read and how many are left! You can use the Google Chart API to build the graph.

Advertisements

Posted February 4, 2012 by jsusmer in Lesson, mind waves

Tagged with ,

To be a Programmer (#1): What is a system?   Leave a comment

System is conceptually similar to a machine, just that there are no physical of its own. Yes, we are talking about software systems. A machine is that reduces human effort — physical — like a press or typewriter. Software systems or simply computer applications or software are built to reduce information processing effort, usually while dealing with huge amounts of data.
A pessimist may say that systems are tools to hide human incapability. Whatever definition we put, systems are helping us in the way they are built for.

As a programming student one must know the effort that we are trying to minimize by creating a system. There are many ways that a system can be created. Mostly,

  • create one from scratch
  • combine some existing systems to deliver the required feature
  •   or, customize an existing one

Based on the selection we make, the effort will be different that you, as a programmer, put in.

To get the maximum output and flexibility, and you have plenty of time, building from scratch is the best option.

If you have no time and what the easy way out, sacrificing flexibility and control to the highest level, you can go for integrating existing systems in some way to meet the requirements. This method demands a good knowledge of the ingredients that you are going mix to cook the recipe.

If you are in a mood where the off the shelf system needs minor kicks and slaps, and you really know where to apply them. Go for the customization. As in the case of integration method, this ways also needs you to have the location maps and a good compass, otherwise you will be lost in the code jungle. This method is gaining popularity because of the explosions in Open Source Software. Even though not all open sources are free, you can secure the code by paying the cost and start digging around to make it yours.

A programmer needs to do (or be?) SAD (System Analysis & Design) to some extend. This part of system evolution brings in the feel of the size of effort that we are going to ease for the target audience. Now, how good you are in this will decide how effective the system is going to be, eventually how proud you are going to be. A bad execution of this phase will bring SADness into your work. How to do an effective SAD is up to you, there are many guidelines that you can follow, but you should apply and digest it correctly.

It’s usual that people tend to ask which technology I should use, what programming language to opt, what process should I follow, etc. There are no easy answers for this. The answers always depend on the effort you are going to ease (in short we can call it ‘the requirements’). The destination is important, how comfortable the journey will depend on the money & time you are going to spend for it. The thumb rule should be “what am I having at present to tackle the issue at hand”. It may not be always the best rule in all cases, but it’s an effective way to control the spending.  

I suggest you read on these topics and make an understanding of the standards before coming back to read the next part of this series