Compile a k/ubuntu kernel

Because of the issues that I have had with a 4GB of RAM and the nvidia onboard graphics trying to grab memory where the system RAM was placed. The nvidia onboard graphics was told to grab the memory from 0xb0000000 – 0xbfffffff because that was where the ACER BIOS was telling it where to go!!. (Here for more details)

Anyway, because of this, I am having to compile up the linux kernel ubuntu style. I am using 9.10 kubuntu at present.

I have used this ubuntu guide on how to compile up a linux kernel from this ubuntu website, kernel/compile.

The main parts that I have run are, (I am not using sudo because I setup the root password so that I do not have to type in sudo all of the time, I setup the root password by sudo passwd root)

cd /usr/src/
apt-get install fakeroot kernel-wedge build-essential makedumpfile
 
apt-get build-dep linux
 
apt-get build-dep linux-image-$(uname -r)
apt-get source linux-image-$(uname -r)
 
debian/rules updateconfigs
 
cd debian.master/scripts/misc 
chmod a+x *
cd -
debian/rules updateconfigs

I go into the /usr/src, because when you get the apt-get source of a the latest linux-image it places the files within the present directory that you are using and usually the linux kernel source files are placed in /usr/src.

The reason for the chmod a+x * is because some of the debian(.master)/scripts/misc need to be updated to have there execute permissions granted.

Make some changes to the kernel files, in my case the arch/x86/pci/i386.c file. Then to compile up the kernel

fakeroot debian/rules clean
CONCURRENCY_LEVEL=2 AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic

Extends class

Extends a class within php, as described in more detail here. Basically is making a second class extended from the first class with either making amendments to some of the functions or adding some, this makes the second class the version 2 from the first class (version 1).

The extended class can still call the parent (version 1) class via the

parent::<function etc to call>

syntax, which basically means, calling the parent class to do something, for example the parent class may setup the variables of a array whilst the extended version 2 class may sort them into alphabetical order.

Here some code that may make more sense.

<?php
 
/* the base class, version 1 as such of a class */
class BaseClass {
    function HiFromMe()
    {
	echo "\nHi from the base class\n";
    }
 
    function BaseFunction()
    {
	echo "\nHi from base function\n";
    }
}
 
/* the extended class, this extends from the base class to make it a better (version 2) class */
class ExtendedClass extends BaseClass {
    function HiFromMe()
    {
	echo "\nHi from the extended class\n";
    }
 
    function CallBaseFunction()
    {
	echo "\nCalling base (parent) class";
	// need to put parent:: which means call the parent class
	parent::BaseFunction();
    }
}
 
$base = new BaseClass();
 
$base->HiFromMe();
$base->BaseFunction();
 
$extended = new ExtendedClass();
 
$extended->HiFromMe();
echo "\nYou can still call the base functions because you extended it";
$extended->BaseFunction();
echo "\nTo call from within a function";
$extended->CallBaseFunction();
?>
 
and the output would be... 
 
<pre lang="bash">
Hi from the base class
 
Hi from base function
 
Hi from the extended class
 
You can still call the base functions because you extended it
Hi from base function
 
To call from within a function
Calling base (parent) class
Hi from base function

Interfaces – the abstract class

An interface, as described further on the php.net website here, is basically a abstract class that defines a skeleton of what a class will have to at least implement, this allows for classes to implement a set skeleton and you will know what functions that class will have to implement.

The interface is just that, a skeleton of a base class. e.g. a interface could be a shape, and the classes that implement the interface called shape could be circle, square etc..because they will all have the basic functions for example, shape sides, colour etc.

Here is some php code, I always find looking over code easier to understand the basics of things.

<?php
 
/* this is a adstract class, e.g. any class that implements this class will have to implement all of the 
  skeleton functions that this class as defined 
 
  the abstract class is defined with the "interface" type */
 
interface Skeleton {
    public function printOutAWord($theWord);
 
    public function printOutAArray($theArray);
}
 
/* 
  this class, TheWorker, will actually "implement" the abstract class Skeleton, via the 
  implemets syntax  */
 
class TheWorker implements Skeleton {
    // these are the functions code that was defined by the abstract class.
    public function printOutAWord($theWord)
    {
	echo "\n$theWord\n";
    }
 
    public function printOutAArray($theArray)
    {
	echo "\n". print_r($theArray)."\n";
    }
}
 
$newWorker = new TheWorker();
 
$newWorker->printOutAWord("Printing out a word");
 
$newWorker->printOutAArray(array("Array","words","are","here"));
?>

And the output would be this

Printing out a word
Array
(
    [0] => Array
    [1] => words
    [2] => are
    [3] => here
)

Joining program

Since I was downloading a couple of files that needed to be joined together, I thought that I would write a bash script to do this for me.

The file that I was getting was from a friend whom had created a home movie of his son walking but could not send the whole thing but had to send in parts, he used a program called HJSplit, but I wanted to join them together using just linux command line commands. So after doing that I have done a small bash script that will do a similar task for me every-time without needing to type in a few commands.

#!/bin/bash
# Ian Porter : http://www.codingfriends.com
# joining program, that will join files together similar to hjsplit.
 
# get the input values
input=$1
output=$2
 
# if input is equal to 2 parameters then
if [ $# -eq 2 ]
then
        # ls all of the files that meet the requirements of the 1st parameter
        for i in `ls $input*`;
        do
                echo "Adding file $i to $output"
                cat $i >> $output
        done
else
        echo "input filename(s) | output filename"
        echo "..."
        echo "example arv arv.avi"
        echo "Please input the searchable filename and the output filename"
fi

If you save that as hj.sh and then change the execute writes on it

chmod 755 hj.sh

This will allow you to run the program without typing in sh , to use it for example just use

./hj.sh files_to_join big_file

Wordsearch php – Words to search for

As from the main project, wordsearch, here is the part that will either load the words from a xml file or from a input string on a web page. The grid class can be found here.

The basics of the word class, is to load a xml file (or via a user input string/s) and then generate words to search from the words that have either been loaded or inputted.

The word class can again be inherited so that each part can be re-done differently if there is another way to open a file etc.

I have included comments in the code, the __construct and __destruct are what happens when the class is created (via the “new” command) and destroyed respectively. Just a nice way to create the class/object and also clean up after itself.

The parameters that are passed to the __construct have default values, words.xml and 5, these can be over written when creating the class as shown in the code (instead of the maxSearchNum being 5 it is 3. But this gives more control over the construction of the class.

<?php
 
class Word {
    /* private section of the class word */
 
    private $_words;
 
    /* constructor for the word class 
       default action to load a xml file to gain 5 words
    */
 
    public function __construct($wordsOrFilename = "words.xml", $maxSearchNum = 5)
    {
	$this->_words = array();
 
	// if the filename is actually words from the input screen then just add in them instead
	if (is_array($wordsOrFilename)) 
	{
	  $_loadedWords = $wordsOrFilename;
	}
	else
	{
	  // load the file of words into a array
	  $_loadedWords = $this->loadWords($wordsOrFilename);
	}
	// create a array of words to be searched for, max number as above
	$this->_words = $this->searchableWords($_loadedWords, $maxSearchNum);
    }
 
    // unset the class words variable.
    public function __destruct()
    {
	unset($this->_words);
    }
 
    // load in the words file 
    public function loadWords($filename)
    {
	$xmlFileLoad = simplexml_load_file($filename);
	$returnWords = array();
	$i=0;
	foreach ($xmlFileLoad->word as $theword)
	{
	  // only the string, because otherwise it would be a simpleXMLObject
	  $returnWords[$i++] = (string)$theword;
	}
	return $returnWords;
    }
 
    // searchableWords will create a array of words to search for from the searchablewords parameter, with maximum number of searchs (maxsearch)
    public function searchableWords($searchableWords, $maxSearch)
    {
	$returnSearchWords = array();
	$numberSearchWords = count($searchableWords);
	// if the maxsearch value is greater or equal to the number of searchable words just fill in the return will all of the words
	if ($numberSearchWords <= $maxSearch)
	{
	    for ($i = 0; $i < $numberSearchWords; $i++)
	    {
	      $returnSearchWords[$i] = $searchableWords[$i];
	    }
	}
	else
	{
	  // randomly pick out words from the array of searchable words
	  for ($i = 0; $i < $maxSearch; $i++)
	  {
	    // re-index the array
	    $searchableWords = array_values($searchableWords);
	    // obtain a random index value
	    $searchWordNum = rand(0, count($searchableWords)-1);
	    // insert into the return value
	    $returnSearchWords[$i] = $searchableWords[$searchWordNum];
	    // delete the word from the array
	    unset($searchableWords[$searchWordNum]);
	  }
	}
	return $returnSearchWords;
    }
 
    public function wordsArray()
    {
	return $this->_words;
    }
 
    public function printOutWords()
    {
	prit_r($this->_words);
    }
};
 
 
$wordsToSearch = new Word("words.xml",3);
$wordsToSearch->printOutWords();
?>

and the output would be something like, of course since it is random generated, then could be the same words or different ones!!.

Array ( [0] => was [1] => sole [2] => old )

Wordsearch php – grid class

From the post on the projects page, wordsearch, here is a basic design of a grid class that can be used to link together with the other aspects of a wordsearch game. This will be able to create a basic grid and populate it with characters.

The reason why I created the createGridRow function was because this class could be inherited and thus alter any aspects of the class to suit the future needs.

The

$this->

within the code references the local variables of the class and not any other variables e.g. local to that function.

The

chr(rand(0,25) + 97);

means create a chr (character) from a random generated value within a range of 0 to 25 (26 letters in the English alphabet) and then add the value 97 to it, because the integer value of 97 – 125 are the ascii codes for a-z characters.

<?php
class Grid {
 
  /* private section of the class grid */
 
  // store the size and the grid
    private $_size = 0;
    private $_grid;
 
 
  /* the public section of the class grid */
 
    // construct the grid with a given size
    public function __construct($size=0) 
    { 
      // set the private variables
      $this->_size = $size; 
      $this->_grid = array();
      for ($i =1; $i <= $this->_size; $i++)
      {
	// create each row of the grid with the class function createGridRow
	$this->_grid[$i] = $this->createGridRow();
      }
    }
 
    // delete the grid 
    public function __destruct()
    {
      // clear up the grid, each line and then the whole object.
      for ($i = 1; $i <= $this->_size; $i++)
      {
	unset($this->_grid[$i]);
      }
      unset($this->_grid);
    }
 
    /* createGridRow, this can be inherited and thus altered to create any type of character in the grid */
    public function createGridRow()
    {
	$_grid_insert = array();
	for ($j = 1; $j <= $this->_size; $j++)
	{
	  $_grid_insert[$j] = chr(rand(0,25) + 97);
	}
	return $_grid_insert;
    }
 
    /* basic print out of a grid */
    public function printOut()
    {
      echo "The grid<br/>";
      for ($i = 1; $i <= $this->_size; $i++)
      {
	echo "$i .. ";
	for ($j = 1; $j <= $this->_size; $j++)
	{
	    echo " $j = ".$this->_grid[$i][$j];
	}
	echo "<br/>";
      }
    }
 
    /* return the size of the grid */
    public function returnSize()
    {
      return $this->_size;
    }
 
    /* insert a character into the grid at position X, Y and the character */
    public function insertCharIntoGrid($pX, $pY, $char)
    {
	$this->_grid[$pY][$pX] = $char;
    }
 
    /* return the grid reference */
    public function returnGrid()
    {
      return $this->_grid;
    }
}
$wordsearch_grid = new Grid(6);
$wordsearch_grid->printOut();
?>

The output of the code as above is

The grid
1 .. 1 = l 2 = l 3 = z 4 = m 5 = h 6 = m
2 .. 1 = u 2 = r 3 = z 4 = s 5 = k 6 = y
3 .. 1 = f 2 = k 3 = j 4 = n 5 = k 6 = p
4 .. 1 = h 2 = p 3 = x 4 = o 5 = c 6 = q
5 .. 1 = s 2 = s 3 = x 4 = r 5 = u 6 = v
6 .. 1 = r 2 = f 3 = g 4 = q 5 = s 6 = o