April 1st, 2008
Posted in GTA |
Print | No Comments »
February 5th, 2008
I don’t know why it happens, but I go through spurts writing on this (my) blog. It’s been a while.. I know.. and I have no real explanation as to why. December was a busy month for a bunch of different reasons: holidays, Vegas, a couple projects… time flies. Watch out for the roaming charges if your a Canadian going to the States, your cell phone bill will be through the roof. January started off on the wrong foot with a close family friend passing and a bunch of other things that consumed a lot of my time.
I just got back from Italy - Milan, Venice, Florence and Rome - it’s a great country. I was there for 2 weeks and everything other than the flights there and back, was great. I’ll go on the record as saying I’ll never fly US Airways again. 3 of our 4 flights were delayed, they lost our luggage when we arrived in Milan and when we arrived back home and because they made the connection flights so close together I never ran so fast through an airport in my life.
Other than that, the trip was honestly great. If you ever get a chance to go to Italy, make sure Venice is at the top of the list. The city is amazing, not place like it in the world. Choosing a good restaurant in Italy can be tricky, but I have a pretty good strategy: If the music is in English, the menu has green leaf salad and everyone around you speaks English, then your in the wrong place. I quickly learned to ask around (especially the people at your hotel) were the good places to eat are. These are the places were the locals go, their hidden away in obscure alleys, but the food is amazing. I took some pictures that you can see here.

Posted in Coffee, Italy, Pictures |
Print | No Comments »
January 3rd, 2008
I don’t normally read programming books, but I was given a copy of Learning PHP Data Objects as a gift a couple moths ago and thought I’d give it a spin. Though the book is a beginners guide to PDO, it requires the reader to have a working knowledge of PHP and Data Abstraction. I was particularly curious to read more about PDO, since I had always used the PEAR database abstraction classes (now MDB2), and wanted to see what, if anything, I was missing out on. I know what your thinking: PDO is compiled into PHP and the PEAR classes need to be parsed just like any other PHP script. This is true, but when you add in op-code level caching like APC, I doubt the speedup is THAT drastic (though I could be very wrong). As a beginners guide, I would have liked the book to compare the various database abstraction options available (i.e. PDO, MDB2, ADOdb, etc.) and provided a quick cost/benefit analysis. Overall the book is a good beginners guide and will teach you what you need to know to get started quickly.
Posted in PHP/MySQL |
Print | No Comments »
November 13th, 2007

Paros, Greece - I hadn’t posted in a while and thought November deserved something.
Posted in Greece, Pictures |
Print | No Comments »
October 3rd, 2007
This was surprisingly a lot harder to figure out than I initially expected. I was doing a lot of searching and kept finding either solutions for windows or packages that cost money. To add to the problem, I needed a solution that ran in a command line only version of Linux (Ubuntu Server). I guess I was naive to think the PHP gd library would support this. After a lot of digging last night, I found webthumb. Getting it work was surprisingly easy using the instructions provided, just replace mozilla for firefox and add the xwd package:
Code:
apt-get install xvfb
apt-get install firefox
apt-get install netpbm
apt-get install xwd
wget http://www.boutell.com/webthumb/webthumb.tar.gz
tar xvzf webthumb.tar.gz
cd webth*
./webthumb http://www.sematopia.com/ | pnmscale -xysize 100 100 | pnmtojpeg > thumb.jpg
Enjoy
Posted in Linux, Ubuntu |
Print | 4 Comments »
October 2nd, 2007
It seems these days I spend more time figuring out annoying problems rather than doing any real work. The following gave me another big headache: Getting SVN to auto-update properly via it’s hooks. SVN provides you the ability to specify hooks after certain events occur with the repository in question. For example, say you have a live application under version control and you want SVN to auto-update the live copy (on the server) after every commit. I guess that makes sense, especially if you want to develop and test in your production environment, on the fly.
In the directory were your repository exists there should be a hooks directory. This directory includes a bunch of tmpl files that get called depending on the event that just occurred. The file that I cared about was the post-commit.tmpl file.
Assuming your running SVN using Apache, then most likely when your post-commit script gets called it will be executed using the user www-data. This is important because it means your repository needs to be checked out via the same user to ensure no permission problems occur. Assuming that OK, then add the following line to your post-commit.tmpl file:
Code:
/usr/bin/svn update <path to repo> --username xxxxxx --password xxxxxx
Hardcoding your SVN password in the file is probably not the best idea, but if your the only one who would have access to the file, then who cares. Notice how I put a full path to SVN, that’s because when the hook scripts get called all environment variables, etc. get removed. The next step, and probably most important, rename the file removing the .tmpl extension and change the ownership so the file becomes executable.
Code:
cp post-commit.tmpl post-commit
chmod +x post-commit
That should do it, so when you update your repository, SVN should auto-update your live working copy. Most likely you’ll run into problems, if so check the links below for more info.
Helpful Link #1
Helpful Link #2
Helpful Link #3
Posted in Linux, PHP/MySQL, Ubuntu |
Print | 6 Comments »
September 27th, 2007
This caused me a headache tonight. I’ll explain below how to forward requests from one Apache HTTP server to another on your network. Here are the main characters:
Server0: Your primary HTTP webserver that all external requests come to initially.
Server1: A secondary server you have setup (with Apache) to handle requests for xyz.com. The (internal) server IP is 192.168.2.10.
At the heart of making this possible is the mod_rewrite module available with Apache. This module seems very powerful and I only understand a small portion of it. First off you need to enable mod_rewrite and mod_proxy on Server0:
Code:
a2enmod rewrite
a2enmod proxy
/etc/init.d/apache2 force-reload
mod_proxy needs to be enabled and configured (proxy.conf), otherwise Apache won’t allow mod_rewrite to forward the request. Here is the relevant portion of proxy.conf (found in /etc/apache2/mods-enabled):
Code:
<Proxy *>
Order deny,allow
Deny from all
</Proxy>
<Proxy http://xyz.com>
Order deny,allow
Deny from all
Allow from all
</Proxy>
Now that you have the prerequisites ready, you can create the site definition on Server0 (/etc/apache2/sites-available/xyz.com):
Code:
<VirtualHost *>
ServerName www.xyz.com
# RewriteLog "/var/log/apache2/rewrite.log"
# RewriteLogLevel 9
RewriteEngine On
RewriteRule ^(.*)$ http://xyz.com$1 [P]
ServerAlias xyz.com
</VirtualHost>
Notice the rewrite rule, which will forward the request. Since xyz.com (on server0) will now point to server1, you need to update your /etc/hosts file accordingly:
Code:
192.168.2.10 xyz.com
192.168.2.10 www.xyz.com
Now enable the the new site and restart Apache:
Code:
a2ensite xyz.com
/etc/init.d/apache2 restart
Now your done with Server0. You’ll be glad to know there is nothing out of the ordinary for you to do on Server1. All you have to do is create the site definition and enable (like you normally would). So in /etc/apache2/sites-available create a site definition called xyz.com:
Code:
<VirtualHost *>
ServerName www.xyz.com
DocumentRoot /var/www/xyz
ServerAlias xyz.com
</VirtualHost>
Then enable the site, restart Apache and everything should work. Odds have it something will go wrong and if it does, make sure to look in the Apache logs (/var/log/apache2/). Also, enable the rewrite log (see above). The logs will most likely always tell you exactly what went wrong.
Posted in Linux, Ubuntu |
Print | No Comments »
September 20th, 2007
There’s a lot of examples on the internet about creating and using the singleton pattern within your application. From the PHP Docs:
The Singleton pattern applies to situations in which there needs to be a single instance of a class. The most common example of this is a database connection. Implementing this pattern allows a programmer to make this single instance easily accessible by many other objects.
Within any class you want to have use the singleton pattern, just add a getInstance method, like I have in the Obj code listing below. To access that instance use the scope resolution operator:
Code:
$obj = Obj::getInstance();
A problem arises when you want to serialize/unserialize that object from the session variable. The issue is this: When unserialize is called, PHP will attempt to reconstruct the object in question - everything will get created properly but the $instance variable will now be NULL because it would be pointing to the object reference from the previous page. So the next time you would call getInstance, the function would return an entirely new object with no serialized data. All the serialized data would exist in whatever variable the unserialize function was assigned to initially.
Once you understand this subtlety fixing the problem is easy. Create a function called setInstance, which takes in an object reference and assigns the object to the static $instance variable within the class. So once you unserialize your object from the session, immediately call setInstance to let the class know the object exists:
Code:
$obj = unserialize($_SESSION['SessionControl']);
$obj->setInstance($obj);
The full code listings follow so you can test this out. Someone out there is probably thinking, why not just called setInstance from within the __wakeup function with $this as a parameter? That won’t work, the object won’t serialize properly.
Code:
<?php
class Obj {
static private $instance = NULL;
public function __construct() { }
public static function getInstance() {
if (self::$instance == NULL) {
self::$instance = new Obj;
}
return self::$instance;
}
public function setInstance($o) {
self::$instance = $o;
}
public function __sleep() {
return array_keys(get_object_vars($this));
}
public function __wakeup() { }
}
?>
Code:
<?php
require 'obj.class.php';
session_start();
if(!empty($_SESSION['SessionControl'])) {
$obj = unserialize($_SESSION['SessionControl']);
$obj->setInstance($obj);
} else {
$obj = Obj::getInstance();
}
function save_session() {
$obj = Obj::getInstance();
$_SESSION['SessionControl'] = serialize($obj);
}
register_shutdown_function(save_session);
?>
Posted in PHP/MySQL |
Print | 3 Comments »
September 11th, 2007
Isn’t racism and hate already a big problem in our society? Do we really want our children growing up in schools were all the kids around them are exactly the same race and religion? In a surprising and somewhat depressing statement, John Tory (the conservative MPP leader) has said if elected he would give public funding to faith based schools. The elections are October 10th 2007. I know many of you despise McGuinty, but the sad reality is that both leaders have no grasp on reality and only seek to satisfy their own personal agendas. Is it time to start looking at Hampton?
It’s interesting how Tory even believes that funding for faith based schools even exists. With all the cuts that are happening, wouldn’t the money be better severed improving our existing infrastructure? I guess I’m surprised that he didn’t see the backlash that would occur by taking this stance. On the other hand, I know that the Greek Patriarch of Canada is telling us to vote Conservative cause he wants to push his Greek Schools and I hear radio advertisements on 680 news supporting faith based schools by the Jewish Congress of Canada.
The argument of funding catholic schools is a good one, but I believe we first need to stabilize our existing structure before we can start rationing what little money we have already. Furthermore, I really feel raising the future generation of children in schools were everyone is the same race and religion can’t be positive, irrespective of what the catholic’s have.
Clio-maria has a good post on this topic.
I started a Facebook group about this.
Posted in GTA, Toronto |
Print | 12 Comments »
September 3rd, 2007
This surprised me today: Using PHP you can include scripts from within a class functions and access the included functions globally. It seems to go against what I feel should occur, but it works perfectly fine. I posted on a discussion forum at devshed to see if anyone has some insight into this.
temp_include.php:
Code:
<?php
function test_funct() {
echo "function called";
}
?>
Main script:
Code:
<?php
Class ABC {
public function __construct() {
require_once 'temp_include.php';
}
}
$o = new ABC();
test_funct();
?>
Posted in PHP/MySQL |
Print | No Comments »