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 2010

Calculating Sample Size in PHP

Posted by chris on December 13th, 2010 Comments(0)

How to return a sample size by population using PHP.

The formula is s = Z^2 * (p) * (1-p) / c^2 where , Z is the confidence level, and c is the confidence interval. Then:

ss = s / [1+(s-1 / pop)] where ss = sample size and pop = population size. Here is a simple PHP function I wrote the implements the formula.

function getSampleSize($pop){
	//$pop = 10000; // population
	$Z = 1.99; // confidence level
	$c = .03; // confidence interval
	$p = .5;
	$top = pow($Z,2)*($p)*(1-$p);
	$bot = pow($c,2);
	$ss = ($top/$bot);
	return round($ss/(1+($ss-1)/$pop));
}

I wrote this as a way to randomly sample a table  for errors.  We’ll see if it works.

Resources:

http://www.surveysystem.com/sscalc.htm

In Programming (, , , )

Three Failed Tech Startups Later and What I’ve Learned

Posted by chris on November 30th, 2010 Comment(1)

A few years back I had what I thought was a great idea for a slick web 2.0 app. I had LIMITED programming knowledge, no SEO skills, and I guess what you could call passable Linux and Networking skills. I decided to go for it anyways. A few years and thousands of lines (of code) later I had another great idea. This time around I was better in all of the aforementioned areas. Today that idea likely ended with “I regret to inform you that I have decided to purchase a different program.”  Both ended up failing and I won’t even mention the third.

So what happened? My first idea was fairly awesome. At it’s peak thousands of users (maybe tens of thousands) were cannibalizing my T1 connection. I ranked at, or very near the top of Google for some strong keywords. How could this fail?

Read the rest of this entry »

In Rant (, , , )

MySQL Temporary Tables Example – Optimizing PHP Applications

Posted by chris on November 24th, 2010 Comments (7)

Shortly after starting a new job as Web Application Developer with an e-commerce company I was tasked with rewriting a legacy application. After analyzing and flow charting the current application I found numerous performance penalties, bloated code, linear programming (non-OOP), and many other areas for optimization. Even after refactoring the code and removing these performance barriers the application was a bit sluggish. Though I had improved overall application execution time by 90% I still knew there was more I could do. This is where temporary tables came into play.

MySQL Temporary Tables have the same functionality as standard disk-based tables except they exist in memory. Since memory is not long term storage, they are temporary tables, hence the name. Operating in memory makes working with these tables fast, your only limit is the amount of memory/swap space available to you.

Read the rest of this entry »

In Programming, SQL (, , , , , )

MooTools Table Sorter 0.9.6 released

Posted by chris on November 24th, 2010 Comments(0)

MooTools Table Sorter version 0.9.6 released on November 15, 2010. This post is just for reporting bugs and feature requests for the new version. For documentation please refer to the version 0.9.5 post. This documentation is still valid. 0.9.6 just fixes bugs in Internet Explorer 6 and Internet Explorer 7 as well as validating the code works in IE9.

In JavaScript and Ajax, Programming (, )

My Top 5 Favorite FREE Word Press Plugins

Posted by chris on November 22nd, 2010 Comments (2)

I love to blog and I love finding plugins that make my blog better and blogging easier. Here are a few plugins that I’ve discovered over the years that I’ve fallen head over heels for.

Read the rest of this entry »

In Software (, )

MooTools Form Snippet – Easy Ajax Form Submissions

Posted by chris on November 18th, 2010 Comments(0)

I wrote this function a long time ago when I had just begun using MooTools. They likely have native functionality for this sort of thing, but I’m posting it anyways. Maybe I’ll build a class out of this one day and submit it to mooforge.

This function just gets all the data in a form and returns it in a string fit for AJAX communication over either HTTP POST and HTTP GET. Just pass the form element as the parameter. Works great for MooTools Ajax form submissions. You don’t even have to modify the Ajaax post/get object when adding new input fields, just modify your server-side code.

Read the rest of this entry »

In JavaScript and Ajax (, , , , , )

MySQL Trigger – How To, Example, Tutorial, and Syntax

Posted by chris on November 12th, 2010 Comments (3)

A MySQL trigger defines a course of action for MySQL to take when data is changed within a table. These changes can be inserts, updates, or deletes made to a table. Support for triggers was added to MySQL 5.0.2. An example of a trigger would be updating inventory each time a product is purchased.

In this example I’ll use a MySQL trigger to compute a numerical hash of a varchar field everytime the varchar is updated or when a new row is inserted. Our example table will have a simple auto-incrementing primary key, the products_model column as a varchar (because models can contain dashes and even letters in this case), and model_hash which will be a numerical representation of the products model using a hashing function.

Read the rest of this entry »

In SQL (, )

Enable or Disable MySQL 5.0 Slow Query Log Dynamically Without a Server Restart

Posted by chris on October 28th, 2010 Comments (2)

Okay so you can’t really do this dynamically without a mysqld server restart, but there is a little trick that can do this. The log-slow-queries option is either set in /etc/my.cnf or it isn’t and changing that does require a server restart. Of course this absolutely sucks on production systems. You either have to do it during business hours or log on late at night to do it. If you’re like me, both those options sound pretty bad.

There is a way to effectively disable the MySQL slow query log dynamically without restarting the MySQL daemon. Go ahead and enable your slow query log and set whatever long_query_time time you desire. Our setting currently looks like this:

Read the rest of this entry »

In SQL (, )

How to Remove and Add Rules to IP Tables Chains in Centos Linux

Posted by chris on October 12th, 2010 Comments(0)

Occasionally our IP Tables at work will block us. I finally got tired of looking up how to resolve this and decided to document the fix on my blog. I’m not a System Administrator (but by defacto rule I am) and I’m definitely not an IP Tables expert, so follow at your own risk. You’re IP Tables list is probably pretty long so you’ll want to pipe the output of iptables -L into a file to be viewed by VIM. This command will give you a rule number and a list. Be sure to see which chain the rule is in (ie INPUT, LOCALINPUT, LOCALOUTPUT etc).

Read the rest of this entry »

In Linux (, , )

Setting up SubVersion (SVN) on Local Ubuntu with Netbeans

Posted by chris on October 5th, 2010 Comments (4)

Assuming you have SVN installed follow these steps from the shell (where “proj” is your project). You can put this anywhere you want really, this is how I decided to do it though to keep it out of my default apache directory. I’ll show steps for configuring this to work with apache if you’re doing this as a PHP repo on your localhost. You may need to sudo yourself for these commands. Also, I’m an SVN novice so follow at your own risk. I’m pretty sure I did this poorly…

Read the rest of this entry »

In Linux, Programming, Software (, , )