Thursday, December 29, 2011

The Cost of Expertise

What is an expert?
They are someone who knows their subject front to back, is very experienced, therefore knows the history behind it, and is quick.  What about just from programming? An expert knows the syntax 99%.  They know the little tricks, they know the base language, they can recall functions from memory, etc.

Base language?
A real jQuery expert is also a Javascript expert.  A lot of people now a days are jumping right to jQuery without ever learning Javascript first. That's a tough choice.  When you choose to learn only a library first, you are basically ignoring the way it works under the hood.  And that is OK for libraries that expose nearly all the features you're going to need, or change the language. Like PHP does from C++. You now write PHP code instead of C++ code. However, jQuery is not like that. It is a utility library to Javascript.  It doesn't have it's own syntax, or it's own operands.  It still uses the dot operator, the square brackets, the curly braces, even the same built in Javascript options.

So why does an expert cost so much more money?  You can go find a freelancer for $15 or $20 an hour, sure.   And they might be an "up and coming" expert, or an "expert to be".  But right now, they aren't an expert.  So what do you get with a "non expert"?  You get your results slower, your code my be convoluted, it may not abide by standards, it may not hold up the test of time.  All of the things normally learned through experience.

So when you pay $100 or $200 an hour for an expert, you are paying for all of these things, BUT you're paying for one other VERY IMPORTANT thing that experts have.  When an expert is compensated well, money is no longer a concern. Obviously right?

The funny thing about experts, is that money is NOT the most important thing - The work is.  So by filling the pot with more than enough water (money) the pasta (expert) can boil freely.  (Sorry my metaphor is terrible).  Basically, when money is no longer on the mind of the person doing the work, they are now free to do amazing work.

With your $20 an hour guy, he's gonna stretch his 1.5 hours to 2 hours, he's gonna work while thinking about the time - "is this project really worth it?", "I can't go back and optimize it, it wasn't in the budget".

Experts can do their jobs without any of those concerns, because they are already being paid enough, so you allow them to do what they do best, and nothing else.  People generally do not work their best when they are concerned about money (or time), or if they don't feel the time spent is worth it.

In the past, before I was an "expert", I would charge $30 an hour.  And I would be doing work that others would pay $100 an hour for.  I always kind of felt that, even if I did good work, I should be charging more.  I felt like my time wasn't well spent and it kept me from really going wild on the code, from being really creative.  Later, now that I'm much better compensated, I don't even think about the money. I charge enough now, that if I want to spend 3 hours re writing some method or some function to make it way better, I can.  I can slow down on some parts because I'm not worried about spending time I shouldn't be spending.  Time is no longer a concern, because money is no longer a concern.

This is a similar point to being paid on salary vs hourly.

Tuesday, November 29, 2011

Great Design makes for Great Programming

I can't really express enough how much I believe in great design.  Part of making a really great web application, or any software in general, is ascetic appeal.  This is really 3 fold.  There is the actual visual design / look and feel of the application.  The user experience design, which is how the application is designed to function, and then the internal structure design.

I'm going to soon rant about internal design, and how imperative that is, but that is not what this post is about.  This post, is about interfaces.

There is something to be said about amazing interfaces.  I am by no means a designer, and I have really no artistic skill.  The only artistic thing I do, or am trying to do, is photography.  But as an engineer, my brain respects, and expects exceptional design.

When you create something great with code, the public won't really be able to understand that unless it's coupled with good design.  If the application feels great, looks beautiful, and is always pleasant to look at, then you've got something.  Then you have a success on your hands.

Whenever I've made some new web app, or software app, the very next thing I think about is the icon.  I don't know what it should look like, but I go right to my favorite icon guys to make me a beautiful icon.

RealTime Logo

A good icon really makes your application legitimate.

I think thats the best thing about good design. It makes your work Real. It makes it professional.  Sure I can tell people, I made a PHP framework.  But if I say, "I made this amazing PHP framework that you can build custom frameworks out of, It's called CornerStone". And couple that with the icon on the left here. Then yea, you want this framework.  It shows a level of legitimacy, that your applications wouldn't normally have.

The same goes for websites.  having a website with a bad, or mediocre design is just not acceptable.  If you want to make it in todays web world, you have to have designs that make people notice the design. Not just pass it by.

You want people to love your company, love your brand, and respect your work. Great functionally is only half the battle, Great design is what brings it all together.

*the icons were designed by

Monday, October 17, 2011

Token Replacement inside DocX

Before I get into this.  YES you can do this same thing with some standard microsoft tools like excel and access.  There is even a PHP class already built for this.


So have you ever needed to work with "less than computer savvy" clients?  And maybe they need to have document templates for whatever reason.  Well normally when you generate a word document or PDF you have to get a PHP class to generate that, and code in the document. That way you can dynamically generate the document on the fly when you need to.

Well that would take you a long time to type up say.. 20 documents.  Wouldn't it be cool if you (or the client) could just create their own templates in word, and your system would understand that? AND be able to generate a document based on that template?

Well I wouldn't be writing this blog if the answer was "sorry we can't do that".

Opening the Docx

So whats the technique?  It turns out that docX files are just zip files.  You literally can rename docx to zip and unzip it.

You get the following files when you unzip

Well inside the word folder is a file called document.xml. That file is the actual content of your word doc. Which means you can replace the text right there.

Re-Creating the DocX
So now that you have edited these files, you need to make them into a docx again. Just zip it back up, and rename it docx. Done and done.

PHP can do this for us
So all of the things we just did, php can do for us. So that means we can build this into our systems.

Step 1) Create a temp folder to store the extracted contents of the docx file

All this code does is create the temp directory if it does not exist. If it already exists, clean it out. Refer to the youtube video for the full code, and to see what recursive_remove_directory does (if you haven't figured it out)

Step 2) make sure the directory path is safe for shell use
So were going to be executing linux commands using shell_exec, and you can't have spaces and other random things in the path. So we just need to escape that first.
Step 3) Unzip to the temp folder
This is just a shell command
Step 4) Replace tokens.
So now we get the contents of the document.xml file, use str_replace to replace our tokens, then save it back.
Step 5) Re-zip ONLY the files we need.
we are going to specify the files here, because mac os x likes to create random folders when it unzips from the command line...
And thats it!
Now we have programmatically token replaced a docx file.

Here is the full tutorial

Thursday, August 18, 2011

When you know you should give up

I needed to know how to play vimeo videos inside and iPhone App.  So I googled for "vimeo videos inside iPhone app"

I found the first stack overflowlink to

Which had the accepted answer of using some "tips and tricks" which was a link to

I read that PDF and the code looked really familiar.  So I went to the blog post that the PDF came from.

And on it was:
Thanks to YouTube user “optikalefxx” for posting his solution for everyone.

So turns out... I wrote the solution a year ago. Haha.  Too bad it doesn't work anymore.

Thursday, August 4, 2011

Which E-Commerce Solution Works for Me?

One of the higher paying jobs that I come across is E-Commerce jobs.  That's because clients know that they need to spend more money to ensure they can collect theirs.

There are quite a few popular choices when it comes to online payments, here are the most common in my eyes.

1) Donate button
2) Selling 1 or 2 things
3) Selling a bunch of products
4) You're serious about selling a lot of products
5) Payments integrated into your website
6) Recurring payments

1) Donate Button
This payment option should cost you next to nothing. You just create a paypal account, go create a button, say its for donate, and bam paste some HTML code onto your page.  If someone charges you for this, tell them they should be ashamed.  Just take them out to dinner or something, this payment option is really simple to do.

2) Selling 1 or 2 things
When you just have less than 5 things to sell, you have basically 2 ways of going about this.  You can go the easy way and just create buttons like we did for the donate button.  Thats really easy, and you can just paste those into your site.  But lets say you want a shopping cart now that you have multiple items.  Well paypal gives you this really easy to use FREE api called "3rd party shopping cart" that lets the developer have a bit more customization.  To sell a product you just put this HTML on the page

<form action="" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="submit" value="PayPal">

So you can sell any number of products in a shopping cart type way using this HTML.  You can even incorporate discounts by using discount_amount_cart and discount_rate_cart.  You can even discount individual items with discount_amount_x and discount_rate_x.  Where rate is a percentage and amount is a dollar amount off.

3) Selling a bunch of products
If your selling lots of products, more than 10 I would say, then you need a store.  An online store is a solution that allows you add products, edit them, save user information, view order details etc.  Its quite a full featured solution for managing an online store.  This option should not cost that much either, because as the developer you can install something FREE like OpenCart and then let your client add all the products.  Then you just charge for design work making it look better.  OpenCart is really a great store and it allows you have users checkout with paypal (free) or by taking credit cards ($30 a month)

4) Serious Online Store
While OpenCart is great, its not advanced. It doesn't do fraud store checkout, it doesn't integrate with UPS world ship, or USPS Dazzle (these are both shipping programs).  It also has a very primitive inventory control.  A paid / hosted online store like Volusion or Magento is a better solution.  They will give you support agents, and have a very fully functional store, that even integrates right with quickbooks.  Customers can pay by credit card, paypal, check, money order or smoke signal.  If you are buying one of these stores, it can cost 6 to 800 a month, and  you will need someone full time to manage CRM (customer reports), Products and orders.  This is the real deal.

5) Integrated Payments
Lets say you already have a bunch of products on your site, and you already love the way it looks.  Or say you need some super custom shopping cart, or even a affiliate payment program.  All of these tasks can be accomplished with an integrated solution.  This is where you start paying a lot.  These solutions require a programmer that really knows the paypal APIs well, and knows how to integrate Paypal payments pro and payments standard as well as express checkout.  This is the most fun type for me because its by far the most challenging.

6) Recurring Payments
This is also a fun one.  Sometimes you need to handle monthly payments or any kind of recurring payment really.  There are again 2 ways to go about this. You can do the "free" way and use the "3rd party shopping cart" to integrate this. Or use Paypal payments Pro ($30 a month) if you wanna take credit cards and have recurring fees. Here are the needed variables for the free way.

$_POST['business'] = "";
$_POST['cmd'] = "_xclick-subscriptions";
$_POST['a3'] = 30.00;
$_POST['p3'] = "1";
$_POST['t3'] = "Y";
$_POST['src'] = "1";
$_POST['item_name'] = "Single User Yearly Subscription";
$_POST['item_number'] = 2;
$_POST['sra'] = "1";
$_POST['no_shipping'] = "1";
$_POST['no_note'] = "1";
$_POST['return'] = "http://come/back/after/complete;
$_POST['currency_code'] = "USD";
$_POST['lc'] = "US";
$_POST['bn'] = "PP-SubscriptionsBF";

This sets up a 1 year recurring payment of $30 a year.

So you can see there are many ways to accept payments on your site, and this is only a few of them.  There are many more ways included Mass pay, parallel payments, working directly with your bank and more!  If you want to make good money as a web developer, learn the paypal apis.

Thursday, July 14, 2011

I Love Regex

regex is awesome. Its powerful, its fun, and it can make you extremely efficient. There are 2 places where regex is most needed.

1) fixing code.
You've seen maybe 3 videos on my youtube channel about using regex with text wrangler.  I don't know about you, but I have to fix code sometimes.  And sometimes, it requires replacing some text a thousand times.  Or say you have a long list of stuff, and you wanna make it into a comma list.  That regex is simply

Replace with:

So, it's quite often that I need to replace a bunch of stuff in some HTML or PHP, or even CSS and knowing regex makes this task very simple.  If you didn't know regex, you would either have to pay some kid to do the same task 1000 times, or you would have to waste your time doing it.  Or, if you didn't know how to use regex in your text editor, you'd have to write a script to do the replacement for you.  So get to know your text editor. This function is also called "grep".

2) Pattern Matching
This is pretty generic.  This can mean anything from page scraping, to dom crawling, to email syntax checking, to curse word validation.  It's all pattern matching.
There are 2 extremely useful regex you should know about.

1) match until character.  This is great for DOM crawling.  But it's also great for email addresses.  The regex is [^c]+  Where "c" is the character your are matching until.  So to match every div on the page, you would do div[^>]+  That would match <div however many times it was on your page. If you wanted the closing > you would just add it on.  div[^>]+>  ta da.

2) match until string.  This is extremely useful, and a lot of people never know about it. Lets say you have a div of class "hello" and inside maybe 20 divs down, is a class "world"  You can't use the "match until character" to find "world".  You would use this awesome regex.


Complicated right?  yea, well just copy and paste it when you need to use it.  Lets explain.

  1. We start with hello. Pretty simple.

  2. Then we first use a negated lookahead.  (?!world).  Which basically says "match one time the string "world" NOT followed by anything. (which is the .)  So again, were matching 1 time, the word "world" that is NOT followed by anything.

  3. Then, we need to not just match 1 time. That would just give us 1 character. We need to match everything until we get there. Just like the "match until character" had the +, we need a + here as well.

  4. But you can't just add a +.  And you can't wrap the whole thing in square brackets like a normal regex.  So we need to wrap in parentheses so we can use the +  ((?!word).)+

  5. BUT, we have a problem that we just used parentheses, which are going to capture the result.  So we now need to NON CAPTURE those parentheses so they stay out of the way.

And that is the "match until string".

You could also use another regex instad of a string.  say we wanted to find hello world or hello planet.

Heres a video explaining this if I didn't do a good job writing it.

Tuesday, July 5, 2011

Source Code Release - Load After Scroll / ForeverScroll

The video

Also to note:
You could pass in a number into the load function and load different content, you don't always have to load the same thing over and over, that was just for the example.

 <style type="text/css">
  #flickr {
  .flickr_results, .loading {
  .loading {
 <script type="text/javascript" src=""></script>
 <script type="text/javascript">
  var loading = true;
  function loadFlickr() {
   var url = "";
   $.getJSON(url, function(data) {
    var photos =;
    $.each(photos, function(i,photo) {
     var title = photo.title;
     $("#flickr").append("<div class='flickr_results'>"+title+"</div>");
    // once we've loaded
    // kill the loading stuff
    loading = false;
  $(function() {
   // load initial photos
   // scroll event of the main div
   $("#flickr").scroll(function() {
    // get the max and current scroll
    var curScroll = $(this)[0].scrollTop;
    var maxScroll = $(this)[0].scrollHeight - $(this).height();
    // are we at the bottom?
    if( (curScroll == maxScroll) && loading == false) {
     // when you start, set loading
     loading = true;
     // add the loading box
     $("#flickr").append("<div class='loading'>Loading...</div>");
     // scroll to the bottom of the div
      $(this)[0].scrollTop = $(this)[0].scrollHeight - $(this).height();
     // load more photos
 <div id="flickr">

Source Code Release - CSS3 Animation Menu

Here is the video

 <style type="text/css">
  body {
  div.moving_arrow {
   margin:50px auto;
  .moving_arrow ul {
    left top, 
    left bottom, 
    color-stop(0, #fff),
    color-stop(1, #e5e5e5)
   ) #e5e5e5;
   -webkit-box-shadow:0px 0px 6px #555;
  .moving_arrow ul li {
  .moving_arrow ul li a {
   padding:4px 8px 8px 8px;
   text-shadow:0px 1px 1px white;
  .moving_arrow li img {
   padding:4px 3px 8px 8px;
  #arrow {
   -webkit-transition:margin-left 400ms ease-out;
  #arrow svg, #arrow polygon {
  #arrow.home {margin-left:54px;}
  #arrow.apps {margin-left:150px;} {margin-left:233px;}
  #arrow.about {margin-left:339px;} {margin-left:457px;} {margin-left:569px;}
  #arrow polygon {
   text-shadow:0px 1px 1px black;
   -webkit-box-shadow:0px 0px 6px black;
 <script type="text/javascript" src=""></script>
 <script type="text/javascript">
  $(function() {
   $(".moving_arrow ul li a").mouseover(function() {
    return false;
 <div class="moving_arrow">
    <img src="icon.png"/>
    <a class="home" href="">Home</a>
    <img src="icon.png"/>
    <a class="apps" href="">Apps</a>
    <img src="icon.png"/>
    <a class="blog" href="">Blog</a>
    <img src="icon.png"/>
    <a class="about" href="">About Us</a>
    <img src="icon.png"/>
    <a class="support" href="">Support</a>
    <img src="icon.png"/>
    <a class="contact" href="">Contact</a>
  <div id="arrow">
   <svg xmlns="" version="1.1" width="12px" height="7px">
    <polygon id="arrow_thumb_shadow" points="0,0 6,7 12,0" fill="#333"/>
    <polygon id="arrow_thumb" points="0,0 6,6 12,0" fill="#e5e5e5"/>

Monday, June 20, 2011

How to Learn Web Programming

There are a lot of different ways to learn anything.  Reading,  listening, watching, doing.  In programming, I find the best combination of learning is watching then doing.  Some people really like to read, but I think when it comes to programming, reading is the wrong way to go.

Why video?
The cool thing about video is that you get to see and hear at the same time. And its in the tone at which the trainer wanted you to hear it.  So you also get their inflection and emphasis on certain parts.  This is why I chose to produce a bunch of videos and why you won't really see tutorials on this blog.  I think programming, even straight code, needs to be seen, visualized and explained. Sometimes just watching someone type something out is way more helpful then reading a final code block.

Errors will also occur on video.  And thats not a bad thing.  One thing I've had to work on in doing these videos is being able correct errors really quickly and explain what went wrong. Honestly some of the best learning you can get is from watching someone else make errors.  I used to stop the video and correct it, or re make the video because of the errors. But now I think it's even more valuable to let people watch me debug on the fly and figure out how to fix whatever the problem may be.

Why not programming books?
"Books suck. Watch videos."  That was going to be my tagline for square bracket. Catchy no?  While I don't think books suck, I do think they aren't ideal for learning to program.  For a short period of time they are good as references, but the internet is fast enough now where that is even becoming irrelevant.  See, printed books lose their relevance very quickly.  Programming languages get updated all the time.  I mean just 3 years ago it was all about web 2.0, 2 years ago was all about html5, and this year is all about CSS3 transformations.  Not only that, the syntax for this stuff is changing all the time.  Of course if you buy books on languages that are frozen then you will be safer.  But still, you can't see a piece of code, then see it work, and interact with it at the same time.  You have to read the code example, type it in, then try it.  It's too many steps and leaves you too disconnected from the learning.

So what about online books or written tutorials?
So written tutorials online are good when coupled with other media.  That is if your able to provide an interactive example along with the tutorial you are halfway there.  So the person learning can get that hands on access to play with the code.  I think the perfect example of this is  I went to this site probably 10,000 times while learning CSS. I could never remember everything when I was 15.  But they provide examples of every single CSS class and selector.  That really helped.  That kind of "try it now" is a perfect way to learn.

What is most important?
Just do it™.  If you are trying to learn something, go with video first to get a good idea of what is going on, then dive right into code. That is THE best way to learn.

My learning process generally goes:
1) look for a "how to" on youtube.
2) look for some sample code online.
3) Launch the example and see if it works
4) try to change something about that example and not break it
5) try to apply new modifications specific for a project

And by then you should pretty much understand how it works, how it breaks, and how you can use it in your application.

Sunday, June 19, 2011

Javascript Before jQuery

I get asked all the time how I learned as much as I have about jQuery.  And then answer really consists of 2 things.

1) I already knew Javascript really well.
2) I do a lot of jQuery Projects.

I really want to focus on number one.  Because jQuery makes coding javascript a lot easier, I find more and more new javascript coders, or new coders in general strictly using jQuery.  They even refer to jQuery as a programming language.  This of course is not true, because jQuery is just a javascript library.  But it demonstrates an important point that people are starting to skip a huge step in front end development.

jQuery is the most popular javascript library.  And IMO for good reason. But when people want to start making some kind of front end project, they turn straight to jQuery.  Now I won't say that "there are things jQuery can't do". But I will say that you shouldn't do everything in jQuery.

There are 2 main purposes of jQuery.
1) Simplify otherwise tedious javascript processes.
2) Handle cross browser craziness.

Basically something like $.post() for ajax makes it both simple to use and handles IE's differences with the XHR object.  What is the XHR object? Well if you started with Javascript you would know.

At any rate, lets talk about a few cases where you would NOT want to use jQuery.

1) Extreme speed without caring about browser compatibility.
Lets say you need to develop something for iPad.  Well you know there will only ever be 1 browser.  So you can write your javascript specifically for that, and not have to have jQuery do all it's extra stuff or if conditionals to check for IE and Firefox and opera and the rest. I'm not saying you have to, but if something in jQuery is being slow for you, maybe a loop is taking way too long, writing it in pure javascript can help.  Because with any javascript library there will always be SOME (maybe very small) latency because its not core  javascript, its a layer on top.

Its the same principal as, code will be faster in C than it is will be in PHP.

2) Element properties
This one I just found because I was doing something in jQuery I wasn't supposed to. This is actually correct behavior, but I really love this hack.  What I'm about to talk about is in this video

Basically this little plugin allows you set the "value" attribute on an html SELECT box (just like every other html input element) and it will select the correct OPTION in the drop down. So no need to load in PHP or anything, you can load the form data just like all its brothers and sisters. The problem though, is that jQuery's .val() and .attr("value") methods actually all call DOMElement.value.  Which, when set on a select box is actually the current value, not the value attribute.  Your not technically supposed to set a value on a select box because the OPTIONs  have the value, which is why jQuery isn't using the actual value attribute. So to get around this, you need to use plan javascript element.getAttribute("value") and that will work.  If I didn't know javascript I never would have gotten this hack to work.

3) Respect
You need to respect how much time you are saving by using jQuery instead of straight javascript.  Because it makes you appreciate the code more.  And I really believe that coding is an art form, and we are all artists.  Artist love their work and respect it, and understand it's roots. Take a look at this video I did on what doing AJAX looks likes WITHOUT jQuery. Its actually from the first time I learned about jQuery and jQuery Ajax.  I used to write out 20 lines of code for ajax.  And now its just 1 or 2 lines.  You really do appreciate what jQuery has done, and it I think it helps make you as a web developer want to make your clients feel that way about your creations. Respect.

4) Debugging
jQuery is software.  Like all software there are bugs. (What you write bugless code?) So what happens when something isn't working right? Or you need to do something that jQuery didn't write a nice little function for?  Your out of luck.  Better start learning the entire javascript language real fast now.  Which is going to seem incredibly hard now that you are used to jQuery.  And lets say something you want to do isn't working right, or is slow.  You could easily write it in javascript if you knew how, and move on with the project.

So long story short.  Its important to understand the core of something before you start using layers on top.  But we can't expect too much, this is how the world is going now a days.  We use computers on a daily basis but how many of us know how they actually work inside?  As time goes on, we as people tend to ignore how things became how they are, and I think thats not a good thing. We should always learn from the past, respect it, and appreciate why things are the way they are now.

Friday, June 17, 2011


Preface: This is an email I just received from Chas.  If you don't have a Chas, I suggest you get one.

Sean: A million thanks for covering the packing/shipping today. Despite what I hear, you're a stand-up dude.

I'll be studying in a coffeeshop like a hipster most all day today. Feel free to holler at me through one of the following approved methods:

1. SMS
2. electronic mail
3. telefon anrufen
4. telegram, stop.
5. homing pidgeon--i left one in the shipping room.

Stephen and Rob, same goes for you--let me know if you need anything. Stephen, I'll hammer out some CRM's today, too.

Suck it nerds, 



Thursday, June 16, 2011

Debugging like a pro

I can't tell you how important it is to know how to debug code.  So as many of you know, I'm on the youtube making training videos.  Most of these videos are not geared towards beginners and assume some level of programming.  Time and time again I get hundreds of people asking me

"Whats wrong with my code"

Your failure to debug. Thats whats wrong. Lol.  I'm throwing that "lol" in there to be more lighthearted about it. I'm not mad, and not upset that people aren't debugging.  I'm able to fix 70% of peoples bugs with the following 2 steps.

1) Paste into TextWrangler.
Literally the syntax highlighting alone will go "HEY LOOK AT ME.. IM A SYNTAX ERROR".  If you paste your code into your text editor and its all one color.. Chances are you have a syntax error. Better check that out.  Not using an editor that has syntax highlighting?  Get one.  For mac you have text wrangler, coda, netbeans, text mate.  For windows you have eclipse, notepad++, dreamweaver.

.click(function() should not be pink

2) Firebug's net tab.
So if the code checks out in the text editor, I just open firebug on their site and click the "net" tab.  What the net tab will do is simply highlight all the resources in red that failed to connect.  Whats a resource?  Its a javascript file, a css file or an image.  Basically anything you try to link to is a resource.  So if your getting "$ is not defined". Chances are your jQuery.js file is not connected. Click the net tab and see confirm that.

"I don't use firefox"
Don't care.  Get it, use firebug, deal with it.  YES you can use safari and chrome's inspector.  But honestly I think they are harder to navigate around.

OK, so thats 70% of the errors fixed. Whew. What about the other 30%? Well 10% of those are bad CSS selectors for your jQuery.  I can understand this one though. Sometimes you put a # instead of . and you get confused. The best way to debug these, are to use firebug's console and test your selector out.

So now that we've discussed the most common debugging techniques. Lets talk about more advanced ones.

"I feel like my changes aren't being saved"
Happens all the time. Sometimes you're editing the wrong file, or whatever.  There are times when you just have to CTRL A > Delete > CTRL S.  Yes, select all, delete, and save.  Just to see if your changes are even being made.  Chances are - you were editing the wrong file.

"I'm using an MVC but my URLs won't work"
So an MVC is a PHP framework model called "Model View Controller".  The basis for almost every MVC out there is the htaccess redirect everything to the index.php file thing.  So if your URL's aren't working, either you don't have this file, or its not enabled to work.  If your using apache, I made a tutorial on how to fix this.

"500 error!"
This means 1 of 2 things.  You have a syntax error in your htaccess, or a syntax error in your PHP.  So look at your htaccess first, but if you haven't recently made changes to it, its time to get into PHP.  First place to look is your error log.  This should be logging all your PHP errors.  Its normally located in /var/log/apache2/errors.log or phperrors.log.  If its not there, you need to enable it (or check the location) in your php.ini file.  If you can't do any of that then you need to display your errors. So turn on errors.


If you are scared about doing this on a live site (which you should be) Check out this tutorial on how to style your fatal errors so its not THAT huge of a concern (for that 1 minute while you debug it)
Now load your error again, and you should be able to see exactly where it is.

NOTE: Coda (for mac) has a really handy PHP syntax checker as a plugin.  I highly recommend it.

"mySQL is giving me the wrong results"
Or you are giving mySQL the wrong query. :D
I suggest you echo out your query in full, paste it into a database app on your desktop and debug it in the console.  I use sequelPro for mac, and I think windows has some microsoft something.  You can use PHPmyAdmin as well, but I really got away from that a long time ago.

Basically you are just gonna look for the mysql error, and if you don't find one, you can quickly tweak your query to get your results, then look at your code and see why your input wasn't what you expected.

"Cannot access ___ property of undefined"
This is your favorite javascript error.  The debugging trick with these is to console.log() the main object, then look around in that object in the console. Firebug will print out the object in a nice neat cascading way in order traverse the object and its properties.  I use this a ton.  This will allow you to see what properties actually exist on that object, and where you might have messed up.

The best tip I can give for debugging is this PHP function.

function debug($data,$die=0) {
echo "<pre>";
echo "</pre>";
if($die) die();

I use it everywhere.  Basically you call debug($myVar); and it prints it out nice and neat for you to read. You can even pass debug($myArray,true); and it will print then kill the script.  If your are using and MVC - put this function outside in your base controller and then you can use this without having to do $this->debug().

Wednesday, June 15, 2011

OpenJS Grid

Why did I make my own jQuery grid?
So any decent developer will go and look for something before making their own.  So throughout the years I've used several jQuery grid tools.  And these really aren't grids but data tables.  Anyway, I tried jqGrid, flexGrid, and even slickGrid.  We even made our own simple one once upon a time.

Why aren't these good?
It's not that they aren't good.  It's that they aren't easy.  Easy to use, easy to implement, easy to modify.  Here is the code to use jqGrid.

Note: This is copy and pasted from their site for their "simple" example.

Java Scrpt code ... jQuery("#list2").jqGrid({ url:'server.php?q=2', datatype: "json", colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], colModel:[ {name:'id',index:'id', width:55}, {name:'invdate',index:'invdate', width:90}, {name:'name',index:'name asc, invdate', width:100}, {name:'amount',index:'amount', width:80, align:"right"}, {name:'tax',index:'tax', width:80, align:"right"}, {name:'total',index:'total', width:80,align:"right"}, {name:'note',index:'note', width:150, sortable:false} ], rowNum:10, rowList:[10,20,30], pager: '#pager2', sortname: 'id', viewrecords: true, sortorder: "desc", caption:"JSON Example" }); jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
PHP with MySQL

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

if( $count >0 ) {
 $total_pages = ceil($count/$limit);
} else {
 $total_pages = 0;
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT, a.invdate,, a.amount,,,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());

$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo json_encode($responce);
Now that is a lot of code right?  And that is just their simple example.  This isn't even going into say row editing or anything.

So ok, lets look at flex grid

        url: 'post2.php',
        dataType: 'json',
        colModel : [
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'},
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'},
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'},
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true},
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'}
        searchitems : [
                {display: 'ISO', name : 'iso'},
                {display: 'Name', name : 'name', isdefault: true}
        sortname: "iso",
        sortorder: "asc",
        usepager: true,
        title: 'Countries',
        useRp: true,
        rp: 15,
        showTableToggleBtn: true,
        width: 700,
        onSubmit: addFormData,
        height: 200

So much better right? This is much shorter. But really who wants all that javascript config when you just want a table? And... This is just the javascript. Here is the required PHP you need to write everytime.

PHP with Mysql

< ?php
$page = isset($_POST['page']) ? $_POST['page'] : 1;
$rp = isset($_POST['rp']) ? $_POST['rp'] : 10;
$sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'name';
$sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';
$query = isset($_POST['query']) ? $_POST['query'] : false;
$qtype = isset($_POST['qtype']) ? $_POST['qtype'] : false;

$usingSQL = true;
function runSQL($rsql) {

        $db['default']['hostname'] = "localhost";
        $db['default']['username'] = '';
        $db['default']['password'] = "";
        $db['default']['database'] = "";

        $db['live']['hostname'] = 'localhost';
        $db['live']['username'] = '';
        $db['live']['password'] = '';
        $db['live']['database'] = '';

        $active_group = 'default';

        $base_url = "http://".$_SERVER['HTTP_HOST'];
        $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

        $connect = mysql_connect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']) or die ("Error: could not connect to database");
        $db = mysql_select_db($db[$active_group]['database']);

        $result = mysql_query($rsql) or die ($rsql);
        return $result;

function countRec($fname,$tname) {
        $sql = "SELECT count($fname) FROM $tname ";
        $result = runSQL($sql);
        while ($row = mysql_fetch_array($result)) {
                return $row[0];

$sort = "ORDER BY $sortname $sortorder";
$start = (($page-1) * $rp);

$limit = "LIMIT $start, $rp";

$where = "";
if ($query) $where = " WHERE $qtype LIKE '%".mysql_real_escape_string($query)."%' ";

$sql = "SELECT iso,name,printable_name,iso3,numcode FROM country $where $sort $limit";
$result = runSQL($sql);

$total = countRec("iso","country $where");

        include dirname(__FILE__).'/';
        if($qtype && $query){
                $query = strtolower(trim($query));
                foreach($rows AS $key => $row){
                        if(strpos(strtolower($row[$qtype]),$query) === false){
        //Make PHP handle the sorting
        $sortArray = array();
        foreach($rows AS $key => $row){
                $sortArray[$key] = $row[$sortname];
        $sortMethod = SORT_ASC;
        if($sortorder == 'desc'){
                $sortMethod = SORT_DESC;
        array_multisort($sortArray, $sortMethod, $rows);
        $total = count($rows);
        $rows = array_slice($rows,($page-1)*$rp,$rp);
header("Content-type: application/json");
$jsonData = array('page'=>$page,'total'=>$total,'rows'=>array());
foreach($rows AS $row){
        //If cell's elements have named keys, they must match column names
        //Only cell's with named keys and matching columns are order independent.
        $entry = array('id'=>$row['iso'],
        $jsonData['rows'][] = $entry;
echo json_encode($jsonData);

My Solution

Now Flex grid seems just as bad as jqGrid.
Before, I get too far ahead. YES you could wrap this all in some file and replace all the variables, and do a database config, and then god forbid you want searching. Oy.  And I know it looks messy here, but it looks just as messy in their source.

So now you should understand why these grid solutions are not ideal for most people.  Here is my solution

<!DOCTYPE html>
  <link rel="stylesheet" type="text/css" href="grid.css">
  <script src="jquery.js"></script>
  <script src="grid.js"></script>
   $(function() {
  <table class="grid" title="Grid" action="ajax.php">
    <th col="feature">Feature</th>
    <th col="version">Version</th>

< ?php
   $grid = new Grid("orders");
   echo json_encode($grid->data);
? >

And to note - This is nearly the FULL page code, not just a chunk like I pulled for the other guys.

How am I able to do this?
Classes and the power of object oriented programming.  Seriously, all I did was make 2 classes. 1 to handle all the mysql + database stuff.  And 1 in jQuery to handle all the client side behavior.  Thats all.  This code is all open source, spaced perfected, well commented, and free to use and play with.

Feel free to download it from  Over 2000 people already have. (Thanks for all those who support OpenJS Grid)

Brewing Ideas

Day to day I often have to figure one thing out or another.  If you ever see one of my desks, you'll notice strange objects all over them.  I have a logarithmic potentiometer (dual channel of course) here at home.  A piece of tek flex sits here as well.  At work I have a rubber band and a momentary switch button.


All of these things keep my hands busy.  I never really thought about it that much before, but I have a lot of trouble thinking if I don't have something in my hands.  When I'm typing, I feel really productive, as if I'm getting a lot done.  But when I'm planning or thinking, I'm not so productive in terms of work output.  I think subconsciously my brain starts to get upset and lose track if I'm not feeling productive.  So while I'm thinking, I have to be messing with something in my hands to keep my brain happy.

Walking away is an amazing way to regenerate.  I can't tell you how many times that just walking away fixed the problem.  And not just walking around the hallway, but doing something else, non programming related.  I'm sure there is some psychological thing going on here where you're able to think more clearly because those thoughts are the back of your mind.  Like when your sleeping - you can solve many more problems.  I think my best ideas, and most complicated problems are solved while sleeping.  This is why you should always have something to write with and write on near your bed. Something that isn't a 9.7 inch LCD screen.  I prefer a whiteboard.  I have one above my bed.

Currently on my whiteboard are some scribbles of how to translate a 2d square in 3D space using css3 transformations.  I plan to incorporate that into openJS Grid sometime.  So... Look for that lol.

Tuesday, June 14, 2011

My Philosophy on Web Development

I think web development really has 4 layers.  And really when I talk about web development, I'm talking about web applications, like backends, not just plain websites.  Who has a plain html website anymore?

Layer 1 - Business and Finance.  This really can be ignored if your a freelancer, but not if your a company. This is the layer that you figure out the future of the company,  your goals as a programmer, the quality of work you want to provide, and handling all the money and charging and tax stuff.  This layer should not be done by a programmer, leave this to the guys that like to write proposals.

Layer 2 - Client Management.  Its difficult to talk to clients. Clients are stupid. (No offense to any of my clients whom might be reading this.  You're not stupid we love you :).  But basically in customer service you go by the rule of "the customer is always right". Well that doesn't apply in web development.  They are hiring you for your expertise, and expect you to know what is best.  They only know a little bit of what they want, and you have to sift through all of their gorgeous thoughts and really figure out what will make them happy, in the most efficient and cost effective way. We can take a minute here to thank tools like Pivotal tracker, Fresh-books, drop box and any other client management tools you might use. They really do make a huge difference.  Programmers can be client account managers, but generally should not be, you should stick to coding.

Layer 3 - Core Design.  I don't mean the photoshop skills here. This is really the functional design and implementation architecture of the project.  A lot of freelancers do this but they call it "sketching on a whiteboard".  You can get really complex with this step.  But more or less, this phase you are figuring you the entire project, solving all the problems, and building the foundation so that you can outsource the rest of the work.  This is really the most fun phase, and its also the most challenging.  You really have to understand every facet of the project, from what coding languages to use, to math, to what the client wants.  This phase is the heart of the project.  A great tool here is Omnigraffle, it really helps spec out projects.

Layer 4 - Work.  This is where the meat is.  This layer is all the html, css, photoshop files, images, php files, database files etc..  Basically you are building the project here.  This is different from the core because everything from this layer is built to work with the system that you created in layer 3.  When you get started, this is the main phase you focus on, and the phase that costs the most money.  Over time - in a business, you will do less of this and more of layer 3. As your company grows, you will find your self being able to outsource this part to your employees, and focus on designing more layer 3's for other projects.

So yea - that is just  my philosophy on web development, and what I think is involved from being just a freelance to growing into a web company.

Ok Now what is Square Bracket?

So Square Bracket is the company that I started in order to teach and do all the programming videos that you seen youtube.  Its also where I plan to release all my open source software and even some paid software coming up.

What about Connect Ai?
Connect Ai is a company I started with Stephen Jensen in order to provide paid consulting services, and awesome web application projects.  Basically people will ask me for help, but some will ask me to just do the project, those people get to be a client of Connect Ai.

Introduction to Me

I figure I should start a blog. So this is just a copy and paste from my about section on my website so you know who I am at the start of writing this.

Hi, My name is Sean. I am a web software engineer. I have been programming for the web for about 8 years now. I started learning HTML and the slowly worked into PHP. I started a huge project that was written completely in raw javascript, thus began my javascript career. Aftwards, I went to school to learn C and some newer programming techniques. During this time I picked up mySQL and got back in PHP.
I consider myself an expert in PHP, Javascript, mySQL and jQuery. With a strong emphasis on AJAX and HTML5 applications. I'm really interested in cutting edge web technologies such as HTML5, basically anything that Internet Explorer can't do, I like.
I'm also rather versed in many programming techniques such as writing API's, building MVC frameworks, PayPal payment systems, creating full database structures, and complicated event based planning.

As you may have noticed, I like to teach. Or I just like to hear myself talk, haven't figured that out yet. Either way this life of programming is causing me to learn so much about so many topics. I started my youtube channel in 2007 with the intent to just share some programming thoughts. I now have almost 1000 views a day and over 200 videos online. The best way for me to learn, is to explain back to myself so that I understand. Thefore, it becomes easy to make these training videos. As soon as I figure out something awesome, I make a video about it and hope that someone else needed to learn the same thing. My goal in the future is to keep making videos, but for more advanced users. As I continue to learn more, I find the amount of documentation and training material decreases. This is really tough because advanced programmers still need to research how to do something. For example, If you look up how to jQuery slide, you get 1.5 million results. If you look up PayPal adaptive payment api quirks, you get maybe 2.

Life is fun. When I'm not destroying my eyes in front of 3 monitors I like to go camping, hiking, skiing, ice skating and exercising. I really want to sky dive some day, and I also want to go into space one day. I've secretly always wanted to be an astronaut, but after working on some NASA projects I'm not so inclined to anymore.

I enjoy business. Not going to school for it, but the art of business. I started my first company when I was 17 with my buddy Dan Schepleng. He's a locally famous movie composer now. We built 4Ten Technologies from the ground up. We started by fixing windows computers, and then moved onto creating Annex, our first software project. We had moved [up] into our 3rd office in baltimore, and had 2 amazing employees. I'll miss those guys.

After 4 Ten I went to work for 
mp3Car where I do forum maintenance, built their website, and became an on air personality I get to interview some really interesting people and see some awesome tech. I also get to do some funny videos once in a while.

While at mp3Car I made a lot of headway on my youtube videos. I was found by Vantage Systems LLC to work on a bunch of NASA database applications. That really launched me ahead in what enterprise companies need. A few months ago, I started Square Bracket LLC, which is where I consult on various web application projects, and will continue to peruse this video training career, in hopes to start providing full length advanced training videos.