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

My Blog

Here is my awesome blog.

Archive for the ‘rant’ Category

MooTools Table Sorter 0.9.5 – For Sorting MySQL Data via XHR…and looking good doing it.

Posted by chris on May 31st, 2010 Comments(0)

Well its been a long weekend and I’m starting to wrap it up. But I couldn’t go to bed without redoing the documentation for my baby the MooTools TableSorter and updating the demo page. The documentation will loosely follow what you see in the demo page.

HTML Setup

You’ll need to include 3 files: MooTools 1.2 or higher, the CSS file, and the Table Sorter javascript class. You’ll also want to make sure all the images are there and update the CSS image paths to jive with the location on your web server.

1
2
3
	<link rel="stylesheet" media="screen" href="/mootools/table-sorter/table-sorter.css" />
	<script type="text/javascript" src="/js/mootools1-2.js"></script>
	<script type="text/javascript" src="/mootools/table-sorter/table-sorter.js"></script>

PHP Setup

You’ll want to use the TableSorter php class I included to make things easy one you.

1
	include_once 'TableSorter.class.php';

Server Side First

Notice setting the table headers is important. For instance when a user clicks on city the TableSorter will send the ORDER BY stored in the TH Title. This is how your server side code will know what to order by. Reply to this post if you have any questions on the server-side PHP code.

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	function returnGeoHtmlTableStr($whereClause='',$startingFromRecord=0,$rowsPerPage=100,$orderBy='city ASC')
	{
		mysql_connect('localhost','user','password','database');
		mysql_select_db('database');
 
		$startingFromRecord = (int) $startingFromRecord;
		$rowsPerPage = (int) $rowsPerPage;
 
		$sql = "SELECT 
					count(*) as count 
				FROM 
					cnizz_geo 
 
				$whereClause
 
				";
		$result = mysql_query($sql);
		$countArr = mysql_fetch_assoc($result);
		$totalRows = $countArr['count'];
 
		if($orderBy==''){
			$orderBy='city ASC';
		}
 
		$sql = "SELECT SQL_CALC_FOUND_ROWS
					* 
				FROM 
					cnizz_geo 
 
				$whereClause
 
				ORDER BY 
					$orderBy
				LIMIT 
					$startingFromRecord,$rowsPerPage
				";
		$result = mysql_query($sql);
		$arr = array();
		while($row=mysql_fetch_assoc($result)){
			$arr[]=$row;
		}
 
		$sql = "SELECT FOUND_ROWS() as totalRows";
		$result = mysql_query($sql);
		$foundArr=mysql_fetch_assoc($result);
 
		$str = '
			<table class="DefaultTable" style="width:500px;">
			'.TableSorter::returnMetaStr($startingFromRecord,$rowsPerPage,$foundArr['totalRows'],count($arr),$orderBy).'
			<tr style="background:#FFF;"><td colspan="10" style="height:5px;">&nbsp;</td></tr>
			<tr id="GeoHead" class="DefaultTableHeader">
				<th id="City" title="'.(($orderBy=='city ASC')?'city DESC':'city ASC').'">City</th>
				<th id="State" title="'.(($orderBy=='state ASC')?'state DESC':'state ASC').'">State</th>
				<th id="Abbrev" title="'.(($orderBy=='state_abbrev ASC')?'state_abbrev DESC':'state_abbrev ASC').'">State</th>
				<th id="County" title="'.(($orderBy=='county ASC')?'county DESC':'county ASC').'">County</th>
			</tr>
			';
		$x=1;
 
		foreach($arr as $i)
		{
			if($x%2){
				$class='';
			}
			else{
				$class='zebra';
			}
			$str.= '<tr class="'.$class.'">
								<td><a id="'.$i['city'].'" title="'.stripslashes($i['city_id']).'">'.stripslashes($i['city']).'</a></td>
								<td>'.$i['state'].'</td>
								<td>'.$i['state_abbrev'].'</td>
								<td>'.$i['county'].'</td>
							</tr>';
			$x++;
		}
 
		$str.= '<tr style="background:#FFF;"><td colspan="10" style="height:5px;">&nbsp;</td></tr>';
		$str.=$meta.'</table>';
		return $str;
	}

Your Server Side Controller

1
2
3
if($_GET['action']=='returnGeoHtmlTableStr'){
	die(returnGeoHtmlTableStr('',$_GET['start'],$_GET['rows'],$_GET['orderBy']));
}

Now the JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
	window.addEvent('domready',function(){
		sorter = new TableSorter({
			request: 'action', 
			action: 'returnGeoHtmlTableStr', 
			destination: 'XhrDump', 
			prev: 'PagePrev', 
			next: 'PageNext', 
			head: 'GeoHead',
			rows: 100,
			startWait: "",
			endWait: ""
		});
	})

Lets explain this line by line.

  1. request: ‘action’, This is how you name the GET parameter. So in this instance the GET looks like $_GET['action']
  2. action: ‘returnGeoHtmlTableStr’, This is the value of GET parameter defined in step 1, so $_GET['action'] = ‘returnGeoHtmlTableStr’
  3. destination: ‘XhrDump’, This is the element id where TableSorter will write results too
  4. prev: ‘PagePrev’, This is the element that the class will listen on for Previous Page requests.
  5. next: ‘PageNext’, Same as above except it goes to the next page when this element is clicked
  6. head: ‘GeoHead’, This tells the class where to look for all those TH tags, which it uses to do sorts on if a Title is defined on the TH tag.
  7. rows: 100, How many rows should the request return.
  8. page: location.href, Where to send the GET request
  9. method: ‘get’, The type of method (GET or POST). By default the method is get, but you can change it to post.

Other cool stuff you can do

You can add additional parameters to the GET request in the form of parameter name => parameter value.

1
sorter.addParameter('zipcode','84101');

You can remove these user-defined parameters by calling removeAllParameters.

1
sorter.removeAllParameters();

You can remove a specific parameter by calling removeParameter.

1
sorter.removeParameter('zipcode');

You can initiate a sort anytime you want by calling sort.

1
sorter.sort();

At the moment this is all it does. There are some known issues in IE where the up/down arrows will not appear on sorts. Also the visual-effects are a bit degraded in IE as well. However it does work in IE and all other major browsers. I have windows-only clients using this right now, as well as FireFox and Safari only clients using it. I’ll be releasing a new version later this Summer based on bug fixes to production installs and feature enhancements I have running in the wild. Please reply to this blog post with any comments, bugs, or questions. Enjoy.

In rant (, )

Holiday Weekend: Why not redesign my site!

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

I’ve been sitting on this new design for over two months now and found myself up early Saturday morning with no pressing matters or client work to be done. Reward myself with a relaxing morning, right? Nah, find something to program! I based the design off many designs I’ve seen out there in the wild from other developers and designers. The polaroid type image of me was done in about 30 minutes using a GIMP tutorial I found last week. I then installed the awesome WP Syntax plugin for the neat syntax highlighting you see in some of my posts. Still have some work to do, but I’m spent for now.

Now I’ll reward myself with some beer pong and barbecue. Enjoy your memorial day.

In rant ()

So What Is The Difference Between Web Developers and Web Designers?

Posted by chris on February 24th, 2010 Comments (2)

I get asked this question one way or another all the time. Either its someone actually trying to understand the difference (and there is a huge difference) or by people I am introducing myself to when they ask me what I do for a living. In the later sense they usually respond with “Oh so you know how to build web pages.” This doesn’t bother me, but I’m still a little dumbfounded with the prevalence of obvious web applications like facebook, myspace, and twitter in peoples lives.

We’re all guilty of this though, right? I have a friend who is a plumber and he had to explain the difference between commercial and residential plumbing to me, and even within those branches of plumbing there are specialties but we won’t go into those today.

I was explaining the difference to my girlfriend the other night. I was a bit intoxicated so I came up with an over the top analogy of the Sistine Chapel. The way I broke it down was you can liken the architect and the builders to web developers and Michelangelo and the painters as the web designer. So the web developer gives a website functionality. Its the web developer that enables you to submit your latest tweet, update your facebook status, and add all those images to myspace. Its the web designer who makes it look good. Now I over simplified the web designers job, they need to know a lot about how users view a page, how to catch a users eye, and web designers are usually damn good in PhotoShop (which has gotten pretty complex).

Another example is the engine and drivetrain in an automobile (web developers) versus the body, interior, and paint job (web designer). These two analogies are fairly accurate. Thoughts?

In rant ()

Twittrash – Twitter Trash and Other Scum on the Internet

Posted by chris on February 17th, 2010 Comments(0)

So I recently started using twitter and you can follow me by going to http://www.twitter.com/cnizzdotcom. I had long been opposed to twitter because I thought it was useless. Of course I was initially opposed to myspace and facebook as well which I am currently using on or have used at one point. I guess I am sometimes a bit reactionary when it comes to knew things. Not just technology, but even certain technologies and methodologies in programming. This is a dangerous thing in my field, but I’m getting more progressive by the day. I laugh thinking about how years ago I stated to a co-worker “extending classes is a horrible idea.” Hey, if we were never wrong, then we’d never improve, right? So I take comfort in my opinions evolving as I become more knowledgeable.

So about a month ago I began using twitter. My use of twitter is really just an exercise in marketing my most important product across the internet, which is me! What I’ve learned in my month with twitter is that twitter is not much different than SEO blackhat, whitehat, and greyhat that you see with ranking in Google. In the SEO world you have scum that write bots (actually they are quite easy to write) which like graffiti in parks (the trashy kind) spam blogs and forums in an effort to win backlinks.

In the twitterverse its the same. You have twitbots, employed by twittrash that will follow someone for a few hours, maybe a few days (its hard to tell) and then unfollow them. All this is done automatically so the twittrash doesn’t have to do it manually. You’ve probably noticed this before. I noticed it right away and assumed it was some bot, but it was confirmed while reading a forum post over at DP. The poster advised another poster to “use a twitter automation program to auto follow then unfollow after time has passed and they don’t follow back.” The term twittrash immediately popped into my head.

There are legitimate ways of winning followers in twitter. It’s hard starting from ground zero and doing things legit (trust me I’m doing it now) but it can be done.

  1. Find people you know and start following them
  2. If you already know the person and they know you are now following them its likely they will reciprocate.

  3. Use hashtags to reach a broader audience
  4. When you use a hash tag such as #php or #embarassing it reaches everyone else listening for that hashtag. Of course spammers use these as well, but you glance over the spam and find the good stuff just like with anything else on the web.

  5. Write good twits and links to quality content
  6. This is a no brainer and its the exact same thing you do when optimizing for google.

  7. Include links to your twitter page everywhere
  8. Add a link to your twitter page on your facebook, myspace, blog, and to forum signatures

On the web and in life, when ever something good comes a long there will be [insert prefix here]-trash to try and ruin it. Twittrash is no different than snake oil salesman, politicians, and blog spammers. Thanks for reading.

In rant, seo ()

well my word press theme got hosed

Posted by chris on February 3rd, 2010 Comments(0)

I upgraded word press, thinking to myself “wow, this wordpress updater is really awesome.” Next thing I know the costume theme I created for my site was just gone. This really sucks and I don’t have time to fix it. So this blog will look like crap for a while. I don’t like how it doesn’t match the rest of the site now. Anyways one of my goals is to redesign this site anyways so this is just more motivation to do so. Now on to the blog post I was working on….arggh.

In rant ()

Multiple Monitor Software

Posted by chris on January 4th, 2010 Comments(0)

Check out http://www.mediachance.com/free/multimon.htm

In rant ()

Goals for the year

Posted by chris on December 31st, 2009 Comments(0)

What are your goals for the year. We all like to make resolutions, I’ll just make goals, that way I don’t feel bad if I don’t make them. In no particular order I’ll list some goals I want to accomplish this year:

Become Zend Certified
I read over the certification guide and I am confident I could pass 80% of the test, it will look good on a resume (and for this site), and will just be kinda cool to say “yeah, I’m Zend Certified.”

Redesign Cnizz.com
Yup it could use a more modern personalized look. Same with this blog, but I won’t worry about that for a while.

Spend less
I went over my expenses and I have way too much frivolous spending. I’d like to cut this rampant expenditures by $100.00 per month and put that money in my savings account.

Get my side projects up
I have two of them. One is a lead generation site and the other is helping my friends with their online retail site.

Pay Off Debt
Luckily I don’t have a lot, just student loans and a car loan, but I would really like to pay off (or at least make a huge dent) in my car loan.

Take Guitar Lessons
I have an old acoustic, but don’t know many songs or chords. Would love to be able to play it more often.

How about you?

In rant ()

MooTools Table Sorter added to MooTools Plugin Repo

Posted by chris on December 23rd, 2009 Comments(0)

I’ve added my mootools table sorter to the newly created plugin repo created by mootools called, mootools forge. I’ll be enhancing the documentation over the holidays and adding much needed updates to the code. If you’re a mootools user or have been thinking about using mootools this is a huge step forward for the team over at mootools. The plugin site is much better than JQuery’s.

I’m also on twitter now.

In rant ()

The Four Core PHP Development Principles

Posted by chris on November 13th, 2009 Comments(0)

We’ve all written bad code. Look at the code you wrote 2 years ago, 6 months ago, or heck even yesterday. When I do this I find that I failed to follow my 4 core development principles. That’s okay we are not perfect, but we should always be striving to accomplish something more than just getting the job done when we program. Just getting the job done in a quick manner will almost always produce poor quality code that at best doesn’t scale and at worst isn’t secure.

1. Scalable
Big apps get more lovin’. If your code isn’t scalable, it probably sucks.

What do I mean by scalability? One way to look at scalability is how easy is it to add in new features to your application. The best way to create scalable code is through planning, understanding what you want the application to be when its complete, where you want the application to be in 3 years, and what other markets/tasks you might want the application to handle down the road.

Read the rest of this entry »

In rant (, , , , , , , )

google wave, next generation collaboration platform, google exchange killer

Posted by chris on July 24th, 2009 Comments(0)

Reading Slashdot I came across this article on Googles latest yet-to-be-released product called, Google Wave.

http://developers.slashdot.org/story/09/07/22/220226/Google-Wave-Reviewed

I was interested enough to sit through the 1 hour video demo on the product and it was worth every minute. I am thoroughly ecstatic about this product and the Google Wave API makes the possibilities endless. Think about all those iphone style apps or all those great FireFox Addons rolled into an enterprise (or something great for you and some friends) collaboration suite.

In thinking about Wave, Google thought about what they would include in email if they could completely rewrite it today. What they ended up doing is making email interactive like an instant messenger client, to the point where you can see what recipients (yes thats plural you can add multiple people to an email) is typing character by character as it happens real time. Now say you add a new person to a “thread” that has hundreds of responses, enter the playback feature. You can playback the life cycle of the thread, message-by-message and edit-by-edit from beginning to the most recent response. This thing is jam packed with other neat features like a slick drag and drop photo gallery (gears only right now but they are pushing to get it adopted into HTML 5), spell checker, setting pieces of a thread private etc.

The whole thing is open source so you’re not locked into Google as your Wave vendor. You can install it at home or work and modify the code to tailor the Wave to your organizations needs. If modifying the application is a bit much you can tie into the Wave API and create your own extensions. If you have an hour and twenty minutes to kill I would watch the demo, it really is awesome!

In rant ()