Aug 11 2008

Why implement PHP in Java?

First of all, why not? Everything else can run on the jvm (yes… even c#), so why not php? Well… I certainly don’t see why not… Java is a fairly robust language with a pile of different libraries and (as you saw if you clicked on any of those links) languages that can run on it. It is ideal!

Don’t like php’s random function? Why not use Java’s? Not your cup of tea? Use ruby’s instead, or python’s, or  write one in COBOL if you are really brave.

It also means that you can implement the functionality in Java, the database transactions in Ruby, then write all of the presentation in PHP, no clearer MVC separation than that eh? Admitedly it might get a bit confusing and I may be over exaggerating about the possibility of these implementation’s cross communication abilities… but it would be great if you could (I might test it later…).

http://www.caucho.com/resin-3.0/quercus/index.xtp

Go check it out!


Aug 6 2008

Xampp Virtual Hosts

One of the tools in my tool box is xampp, which seems to work better than trying to install everything bit by bit (at least it did at work). One thing I never considered was setting up virtual hosts for each project, I always worked from a folder so that to access the site I went to:

    http://localhost/sitename

That is fine, but what happens when you are working with a site that needs to be the root site (ie: it has links like /page_name.php which bounce you out to the root)? In that case you need to set up a virtual server. In xampp they have separated the files out to ‘make it easier’ on a user to find what they want. Sometimes this is not the case… so here is how to setup a virtual server (at least it worked for me) on Windows Vista (and XP, and with some small modifications Linux and Mac as well).

Find the httpd-vhosts.conf file, it should be:

    C:\xampp\apache\conf\extra\http-vhosts.conf

if you installed it in the default location.

Then go to the bottom of that file and add:

<VirtualHost *:80>
  ServerName http://sitename.127.ca
  DocumentRoot C:\xampp\htdocs\sitename
</VirtualHost>

if that doesnt work, then there might be something in the http.conf files that is stopping access to that folder, in that case, add

 <Directory C:\xampp\htdocs\sitename>
    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>

So, you have:

<VirtualHost *:80>
  ServerName http://sitename.127.ca
  DocumentRoot C:\xampp\htdocs\sitename
  <Directory C:\xampp\htdocs\sitename>
    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

While you can probably put the site in any folder on your computer, it makes sense organizationally to keep them all in the htdocs folder (at least it does to me…), so that is why the example uses the path

    c:\xampp\htdocs

You should now be able to access your site by going to:

    http://sitename.127.ca

For why 127.ca see this site.


Aug 4 2008

Job Search Results

One feature that everyone was always pushing us for in Jobba the Site (other than the ability to save your resume) was something simmilar to Monster’s Job Search Agent, where you could save certain job searches as your favourites and then it would notify you when there were new posts under that search.

Now, in theory this is a good idea, you don’t have to come to the site periodically to find out if there is anything good for you, but in practice it is not really that good. I had one set up for Junior Developer on Monster so that I could find out when there were jobs that matched that search. Good idea right? Not really…

Some of the more interesting results:

Tax - Manager - US Corporate Tax Services
Program Manager - Ice Rink
Mechanical Engineer
General Accounting Specialist

Hmm, not really what I was looking for. Originally I had tried to do this with Entry Level Web development, which as it turns out was even worse with it sending me results like:

Coordonnateur courrier / Courrier coordinator
Spécialiste de la paie / Payroll Specialist
Entry Level Marketing and Sales ***** APPLY TODAY, START TOMORROW!
Entry Level Print Based Advertising - Start Immediately
CONFUSED ABOUT WHAT TO DO WITH YOUR DEGREE
Seeking Top Performers to Fill Openings as an Account Manager! Start Now

Wow, all those opportunities! I especially liked the ones that were all in caps! Like they were yelling at me to get a job, theirs! In the end, I found my new job with a simple Google search. Google: 1, Job Sites: 0. I hope we can change this with Jobba the Site, but that feature will be one that is added later, if at all since it seems to be so hit and miss. To be fair, it did actually give me results that were good, but those seemed to be outweighed by the ones that were random and had nothing to do with what I was looking for.


Jul 8 2008

Spartan Coding

I thought it would probably be rude to post this on Coding Horror, as it is rediculously long… but here is my attempt at Spartan coding.

So, the first function… changes a users information in the database:

	function update_User($user,$id) {
 
 
		if (isset($user['deleteprofile']))
		{
			//array(3, 'live', 'Rick'
			$this->db->where('user_id', $id);
			$this->db->delete('users');
 
			$this->db->where('id', $id);
			$this->db->delete('ez_users');
 
			$this->db->where('user_id', $id);
			$this->db->delete('ez_auth');
 
			$this->db->where('user_id', $id);
			$this->db->delete('ez_access_keys');
 
			$this->db->where('user_id', $id);
			$this->db->delete('faves');
 
 
			return true;
		}
 
 
		$user['first_name']= isset ($user['first_name'])? $user['first_name']: "";
		$user['last_name']= isset ($user['last_name'])? $user['last_name']: "";
		$user['academic_status']= isset ($user['academic_status'])? $user['academic_status']: "";
		$user['college']= isset ($user['college'])? $user['college']: "";
		$user['department']= isset ($user['department'])? $user['department']: "";
 
		$data = array(
               'first_name' => $user['first_name'],
               'last_name' => $user['last_name'],
                'academic_status' => $user['academic_status'],
               'college' => $user['college'],
				'department' => $user['department'],
		 		'user_id' => $id
            );
 
		$this->db->where('user_id', $id);
 
		if (!$this->db->update('users', $data)) {
			return false;
		}
 
 
		if (!isset($user['access']))
			return true;
 
		$data = array(
               'access' => $user['access'],
				'user_id' => $id
            );
	//	print_r($data);
		$this->db->where('user_id', $id);
 
		if (!$this->db->update('ez_access_keys', $data)) {
 
			//incorrect parameters. maybe one of your form field names is different from the database fields
			//in the 'users' table?
			//common mistake: using a name for the submit button. don't do that!
			//also: you have to have a hidden field in the form called $user_id with
			//the value of the ID of the user you are playing with.
			return false;
		}
 
		return true;
	}

It became this:

function updateProfile($data, $id){
		$this->db->where('user_id', $id);
		if(!$this->db->update('users', $data)){
			return false;
		}
		return true;
	}

This is possible because arrays can be passed to the function. All of the functionality that was needed in the function is still there, it is perfectly readable, and it does the same tests… I guess it could become this:

function updateProfile($data, $id){
		$this->db->where('user_id', $id);
		if($this->db->update('users', $data)){
			return true;
		}
		return false;
	}

Which is probably better as it will return false automagically if there is a problem…. in fact, I think I will be changing it to that. Yes it does hide a lot of the functionality, but… it allows the functionality to be huge… I can edit the whole table or just one column with this function, unlike the other function where the author apparently wanted to create a function for each of the options that were needed…. sigh… The unfortunate thing is that I have not been able to get rid of this code completely yet because I have not yet looked to find out where else it is used… And yes, I know it would be more complex if it were not for the fact that I was using the code igniter framework, but… not as complex as the one that preceeded it.

Wow, the code for the syntax highlighter needs to be fixed…

<pre lang="php">

works, but

<pre lang = "php">

does not…


Jul 7 2008

Komodo Edit on Ubuntu (Linux)

I use Komodo Edit all the time on Windows (XP and Vista) but up till now I have not used it in any Linux environment. I decided it was time to take the plunge and try things out. First I had to download the tar file from the activestate website (here), that was easy, the one thing that I was wary about was this:

AS package (libcpp6)

I had never heard of that, but as it turns out it is an [A]ctive [S]tate package. So, not a problem. When I got it there was an install .html. It had all of the instructions for all of the operating systems. As it turns out that was a bit overkill considering this was the Linux version not a Windows one or a mac one…

The only thing that I needed from the help file was the information that you had to install these packages (I use apt-get to do it, you might use something else):


scim scim-gtk2-immodule scim-qtimm scim-tables-additional

You might also need to install these ones if they are not already in your Linux of choice:

glibc libjpeg libstdc++

You will also need to have perl installed.

Finally once those packages are all installed you can run the install file

./install.sh

And then once that is done (you get to chose the path that it installs to (I left it as default because I am the only user of this machine), add komodo to your path by entering:

export PATH="/home/[username]/Komodo-Edit-4/bin:$PATH”

in the terminal (well, that is the quick way, you would probably have to type that in every time you wanted to use it… a better way is to add that line to the end of your ~/.bashrc file).

You could also create a symbolic link to it:

ln -s "/home/username/Komodo-Edit-4/bin/komodo" /usr/local/bin/komodo

Finally, you can just type in komodo to run it, or create a link in your menu (or on the desktop) to run it.

Once I get some money, I will probably be buying the full version (Komodo IDE) which has more features in it. Until then, I am more than happy with Komodo Edit 4.

If you have any problems installing it, please refer to the install file that they include as I have skipped some of the stuff that did not have any relevance to me.