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 2008

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 ()

How to Create a JavaScript Key Listener

Posted by chris on October 27th, 2008 Comments(0)

Need help with JavaScript key listeners? Using a key listener in JavaScript is great way to make your web application react like a desktop application. If you’re not using a javascript framework such as MooTools or JQuery (I’ll go over these after covering generic javascript) then the first thing you need to do is place this code in your body onload event. This will call the returnKey function every time the browser detects a key press.

1
document.onkeypress = returnKey;

We will listen specifically for key code 13, the return key, where a text node has focus. Next we create a switch statement that looks at the text nodes id. We will put in a case to look for the text node id of search. This will call a getProduct function and also highlight the search field.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function returnKey(evt)
{
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
 
	if ((evt.keyCode == 13) && (node.type == "text")) 
	{
		switch(node.id)
		{
			case 'search':
				getProduct();
				$('search').select();
				break;
		}
	}
}

To do the same thing using the JQuery framework is a bit more simple. This example JavaScript code will create keyup event:

$(document).ready(function(){
    $('#IDofTextInput').bind('keyup',function(e){
        // your function/code to execute goes here
    })
});

Here is some example code for creating a keypress event using the MooTools Framework for JavaScript:

window.addEvent('domready',function(){
	$('IDofTextInput').addEvent('keypress',function(event){
		// your function/code to execute
	})
})

Drop me a comment if this helped your or if you feel I missed something, thanks for reading.

In JavaScript and Ajax (, , , , , , )

JavaScript snippet for handling EFT check scanners

Posted by chris on October 17th, 2008 Comments(0)

This piece of code will separate out the account number and routing number from a scanned check. I yanked this function out of a payment class I wrote for a point of sale web application I recently developed. It’s a mootools class, but the core logic can be pulled out and applied pretty much anywhere.

  1. First pass a string into the function, where the string is the string from the check scan
  2. I immediately validate the information is correct. Scanners will send a series of question marks if the check was scanned in at an odd angle. They are very picky, but I tested many ways of sending the check through and this should catch most scenarios
  3. The routing number is stored between two “T” characters in the string. So I look for the T’s, remove them and store off the routing number
  4. The end of the accounting number has a “U” character immediately after it so and the account number starts immediately after the routing number, so I substring that out
  5. I then do some more error checking. Since both the account and routing number should be numeric I use isNan() to verify this.
  6. The entire snippet is wrapped in a try catch so should anything fail it can be logged and reported to the end user
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
29
30
31
32
33
34
35
	setCheckAttributes: function(string){
		try{
			if(string.charAt(0)=='?' || string.charAt(1)=='?' || string.charAt(1)=='?')
			{
				displayMessageWindow('Invalid Check','Please verify the check was scanned properly with the check facing in and the routing/account numers at the bottom','error');
				return false;
			}
 
			var t1=string.search("T"); // start of routing number indentifier
			string = string.replace("T","");
			var t2=string.search("T"); // end of routing number indentifier, start of account number indentifier
 
			this.routing = string.substring(t1,t2); // set routing number
 
			var u=string.lastIndexOf("U"); // end of account number indentifier
 
			var account = string.substring((t2+1),u);
			var accountArr = account.split(" ");
 
			this.account = accountArr.join(""); // set account number
 
			if(isNaN(this.account) || isNaN(this.routing)){
				this.account='';
				this.routing='';
				this.payment_method_id=0;
				this.type='';
				displayMessageWindow('Invalid Check','The system encountered an error reading the check and has invalid (non-numeric) information for either the routing or account number.','error');
				return false;
			}
			return true;
		}
		catch(err){
			 pushToErrorLog('class Payment::setCheckAttributes() ' + err);
			 return false;
		}

To determine when a check has been scanned you can use the code in my post, JavaScript snippet for handling credit card readers.

In JavaScript and Ajax ()

JavaScript snippet for handling credit card readers

Posted by chris on October 16th, 2008 Comment(1)

This JavaScript function will successfully extract a credit card number, name of the card holder, and expiration date from any standard credit card reader. I’ve tested this on numerous card types from American Express to Visa and many in between. This function was originally a method within a MooTools class that I wrote for a web application. So it will look a little strange, but is easily modifiable if you know your way around JavaScript, especially if you have played around with any JavaScript framework. A typical string stored with in the magnetic strip of a credit card will look something like the string below. In this string you can see the card belongs to Jon Fubar, the credit card number is 123401230123012, and the expiration date is 01/09. It is not possible to extract the CVV from this string (good for security purposes).

Read the rest of this entry »

In JavaScript and Ajax ()