simple php data encryption cipher class November 28, 2008
Posted by chris in : php , add a commentI 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:
class Cipher
{
private $key,$iv_size,$iv;
function __construct($key)
{
$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));
}
}
what to know when taking on a new development project November 26, 2008
Posted by chris in : rant , add a commentI’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.
whats new with mocha ui 0.95 November 25, 2008
Posted by chris in : ajax/dom/javascript , 3commentsGreg 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:
using taskkill to kill windows processes from the command line November 21, 2008
Posted by chris in : windows , add a commentI 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:
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).
adding an event to a cell using insertCell November 18, 2008
Posted by chris in : ajax/dom/javascript , add a comment
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.
updated web design for cnizz.com November 16, 2008
Posted by chris in : rant , add a commentIts been a long time coming. The cnizz.com website really needed an overhaul to reflect the maturity in what I’m doing. I was a fan of the green color scheme, but decided to go with the more boring professional look of grey, white, and blue. The theme with the puzzles at the top is something I wanted to go with because I get the sense that a lot of my clients are puzzled with the lack of quality consultants they find or are puzzled with how there current web application functions (or doesn’t in many case).
Now the redeployment of the website came a bit faster than anticipated. I’ve been working on the web design for several months in between various client projects. Most of my clients are on a development server. I treat them better than I treat my own site which is not on a development server. With a bit of embarrassment in saying this. I accidentally overwrote some files. Rather than restoring backups (yes I do keep daily backups of the site) I became rather gung-ho and just deployed the entire thing.
So now there are no client pages (still need to get the CSS from them fixed) and this blog looks a little funky as modding the CSS for the blog and such was going to be the last thing I did. Well I’m happy with the design. Thanks for reading. Don’t worry I’ll eventually get everything straightened out.
capturing and storing echo or include data into a php variable November 11, 2008
Posted by chris in : php , add a commentHave 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:
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.
moving innodb mysql tables & database to a new server November 11, 2008
Posted by chris in : SQL , add a commentA 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:
adding an innodb mysql foreign key with phpmyadmin November 11, 2008
Posted by chris in : SQL , add a commentIdeally you should be using MySQLs InnoDB engine in the database layer of your web applications. InnoDB is a “better” database engine and therefor a “better” web development practice. InnoDB allows for referential integrity and makes it easier to have a normalized database. In MyISAM you have to do this in your code, one little error and your database can get out of whack. In some cases MyISAM is the way to go. For instance, your client already has a MyISAM based system or you are developing an application that may be running on multiple platforms where you have no idea what the system administrator may have installed. MyISAM is the default storage engine for MySQL and is widely used, but InnoDB is the new kid on the block and should see widespread adoption in the coming years.
Below is a look at how to setup InnoDB foreign keys with phpMyAdmin. I will also provide the SQL statements used as well.
interesting conversation with a friend on the “web 2.0″ November 8, 2008
Posted by chris in : rant , add a commentTaking 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.