Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.

Archive for November, 2008

PHP Data Encryption Class Implementing RIJNDAEL 256 AES standard

Posted by chris on November 28th, 2008 Comments(0)

I am writing a pretty awesome web application and needed a way of encrypting data. So I wrote a quick class using PHPs mcrypt functions. It uses the super secure Rijndael 256 bit American Encryption Standard (AES).

Here is the class (also available for download on phpclasses.org):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * Crypt :: two-way encryption class using RIJNDAEL 256 AES standard
 * @uses MCRYPT_RIJNDAEL_256
 */
class Crypt
{
	private $key,$iv_size,$iv;
 
	/**
	 * constructor
	 * @param $key (string:'DefaultKey')
	 * @return void
	 */
	function __construct($key='DefaultKey'){
		$this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
		$this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
		$this->key = trim($key);
	}
 
	public function encrypt($string){
		$string=trim($string);
		return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $string, MCRYPT_MODE_ECB, $this->iv));
	}
 
	public function decrypt($string){
		return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$this->key,base64_decode($string),MCRYPT_MODE_ECB,$this->iv));
	}
}

Usage

1
2
3
4
5
6
<?php
include_once 'Crypt.class.php';
$crypt = new Crypt('My_Awes0me-Key!_');
echo $crypt->encrypt('password').'<br/>'; // returns string '5IWS0SagfDMrolmoVIzkAuYbIYkHrRyymG8DdhvNKvc='
echo $crypt->decrypt('5IWS0SagfDMrolmoVIzkAuYbIYkHrRyymG8DdhvNKvc='); // returns string 'password'
?>
In Programming ()

What to Know Before Taking a New Development Project

Posted by chris on November 26th, 2008 Comments(0)

I’ve put together a simple list of expectations when I take on a new web development project, some must-haves, and questions to ask clients. This article can help you in giving your client an accurate deadline, projected cost, and will make it much easier on yourself and your client.

Know the clients business
Listen to your client describe to you what there business is, what they do, and where they are going.

Make sure you know what the clients goal is
You wouldn’t write a web application for yourself without knowing what the primary goal is would you? Well don’t just start hammering out some code without understanding your clients goal. They are investing money in you and knowing their goal will help make a good return on investment for them.

Ask what the client likes about the current system and what they don’t like
Knowing what the client likes and dislikes about the current system will give you a good idea about what you need to do and don’t need to do.

Avoid rewriting existing code
This could very easily be number 1 on the list. I’ve burnt myself before rewriting some absolutely horrendous code. Yeah it was ugly, yeah it was a pain to work with, and yes it was a hack job making it do what was needed, but remember that code has been tested and most likely works. If its not working then go to the client and explain to them why it needs to be rewritten. Explain to them it will cost them extra etc… I can’t stress this enough, rewriting existing code is opening a can of worms.

Use a development server
You’re walking a tight rope if you’re coding on the clients live server. The margin of error is small, you could delete files, tables, and crash the server. Don’t do it. You can get cheap web hosting to use as your development server very easily.

Proper QA
If you’re a private consultant you will most likely be doing the QA yourself. For bigger projects I will hire a temp to do some QA testing, but for most projects I do it myself. Make sure you test every single feature and think of scenarios out of the norm to test for. Another good idea is to make what I call a testing matrix. A testing matrix is writing a list of all possibilities and then trying all those different scenarios. This will help you find a lot of bugs.

Project management software
If you’re not using project management software your managing your project. Even Excel will do while your small. You can write your own, but yuo should focusing on developing for you clients. I suggest taskfreak and for invoicing I suggest bamboo invoice. Both are free and open source.

Getting money up front
You should collect at least some money up front to avoid getting burned to bad and to ensure that the client is serious about the project. Some clients won’t do it up front. Its up to you in the end.

This should help you get started, meet deliverable’s, and keep your clients happy.

In Programming ()

whats new with mocha ui 0.95

Posted by chris on November 25th, 2008 Comments (3)

Greg Houston has done a great job with the Mocha UI plugin for MooTools. I started using Mocha UI when it was on version 0.8 which was based off MooTools version 1.1. The latest release is based on MooTools 1.2 which is a much more solid and cleaner looking release. Mocha UI followed suite getting rid of a few minor bugs, improving the plugins modal, and adding some nice features including workspace.

I’ve been working on updating existing web applications based on Mocha UI 0.8 and MooTools 1.1 over to the latest versions and the process has been pretty painless. I’ll post another blog on the workspace later when I have time for more web development. In the meantime here’s how to use the basic Mocha UI functionality:

Read the rest of this entry »

In JavaScript and Ajax ()

Kill Windows Processes from the Command Line

Posted by chris on November 21st, 2008 Comments(0)

I recently opened a remote desktop connection to my home PC running Windows XP Pro. For some reason when I attempted opening firefox I received a message saying the process is already running and needs to first be terminated. So naturally I opened the run box and typed in taskmgr. Unfortunately it wouldn’t show me more than 10 of the 75 active processes. After some quality time with the googler and fumbling around with the windows taskkill utility I was able to terminate firefox with the following command:

1
taskkill /F /IM firefox.exe

The /F switch tells taskkill to forcefully terminate the process and /IM switch tells taskkill that you are referencing the human-readable name of the executable rather than its PID (process ID).

In Software ()

adding an event to a cell using insertCell

Posted by chris on November 18th, 2008 Comments(0)
1
2
3
4
5
var row = $(element).insertRow(1);
var qty = row.insertCell(1);
qty.innerHTML = productArr[i].qty;
qty.id='qty_'+productArr[i].service_id;
qty.addEvent("click",function() {mod(this) });

You actually have to nest your function call inside of function(){} and especially if you want to pass additional parameters into the function.

In JavaScript and Ajax ()

capturing and storing echo or include data into a php variable

Posted by chris on November 11th, 2008 Comments(0)

Have you ever included a file into your php web application or used a function that executes an echo rather than a return? Have you ever wanted to capture the data returned into a variable instead? Well here’s how:

1
2
3
4
ob_start(); // always start with this
the_title(); // this function does an echo
$title = ob_get_contents(); // this grabs the echo and stores the data as $title
ob_end_clean(); // always end with this

This will store the data echoed from the_title() as $title. For more information take a look at PHP.net’s entry on ob_start.

In Programming ()

moving innodb mysql tables & database to a new server

Posted by chris on November 11th, 2008 Comments(0)

A standard mysqldump will not work for moving InnoDB tables to a new server. It will create the tables and the structure, but will fail on inserting the data. Why? If you have any foreign key constraints mysqldump is not “smart” enough to insert the rows containing the primary keys before the rows using those keys as foreign keys. You will get MySQL error 150: Foreign key constraint is incorrectly formed.

There are two methods two get around this:

Read the rest of this entry »

In SQL ()

Interesting Conversation with a Friend on the “Web 2.0″

Posted by chris on November 8th, 2008 Comments(0)

Taking the day off from work due to a particularly nasty illness I certainly didn’t feel obliged to take part in my usual Friday rituals. My friend, whom was in the area, gave me a call and asked if it was alright to stop by. As is typical, we engaged ourselves in lengthy conversations. That eventually lead to a discussion on the new web, or “web 2.0″ as fancy marketing-types, and buzz-word addicts like to call it.

He started rattling off all the pod castes he’s subscribed to, how much great music he gets, the stuff he learns, and the best of youtube series he enjoys. I’m a web developer and have been in I.T. since 2004. So you would think that I would be on top of stuff like this, but there are a lot of new web applications and such out there that I have no idea about. Hell, it takes me weeks to get fluent with a new cell phone. Maybe’s I’m just busy keeping my head above water in this fast moving industry and don’t have time to learn stuff all the other web developers are churning out.

What perturbs me about some of these newer things going on in the web is that they’ve been around since I first started using the internet in the mid-90′s. It just seems like “they” put fancy wrappers around the pre-existing web by ditching the bad page designs. Then some slick marketing guru got a hold of a cutting-edge logo, some jazzy slogan, a hyped-up name, and hey-hey welcome to the new web 2.0. Pod castes, what are these but audio and video files that you can download? MySpace, it’s just a bunch of personal web pages like tripod and geocities (p.s. RIP) with some additional features, right?

Shortly thereafter I would feel naive as my friend came back with an interesting rebuttal. It’s not about new technologies so much, its about the integration of multiple technologies into one and the better organization of data. Which is completely true. Downloading these Pod castes through iTunes gives you one location, to get lots of information. You can then subscribe to your favorites and get notified of new ones. It even stores where you left off on a particular caste. Myspace was able to integrate numerous features such as photo album, messaging, music, and building a web page into one and they made it really easy to do.

This stuck in line with something I’ve been wrestling with for a while. It seems to me that the web today has its own particular illness. There is nothing new left to create. While I’m sure thats not the case, it does feel like all the really easy stuff has been done already. What we should be focusing on in today’s new web is more effectively organizing data and features. That’s where tomorrows money will be.

Anyways, I hate sick days.

In Rant ()

Using perror to Help Debug Mysql Errors

Posted by chris on November 4th, 2008 Comments(0)

Print a description for a system error code or an error code from a MyISAM/ISAM/BDB table handler. Example, type “perror 150″ in the linux shell.

1
2
# perror 150
MySQL error code 150: Foreign key constraint is incorrectly formed
In Linux, SQL (, , )

posting to and searching twitter with the twitter api and php

Posted by chris on November 4th, 2008 Comments(0)

I asked a co-worker today if he ever used twitter. His response was “No, I have friends.” The feeling was mutual, however twitter seems very popular and its been a while since I’ve played around with an API. So I created a twitter account, and then began looking through the API documentation. I was happy to see they had support for JSON.

Read the rest of this entry »

In Programming ()