Getting into jQuery

Swiss Army Knife Cadet 1

I have a friend that is wanting to get into learning and using jQuery so I thought that I would throw some information together to help them get started.

Documentation

Love jQuery’s documentation! I love being able to go to http://api.jquery.com/ and being able to quickly search for what I am looking for. This is great for when I know roughly what I want and just need a bit of information on how to do it. When I was starting out, the documentation main page was the place to be http://docs.jquery.com/

Including jQuery into projects

So you can download the jQuery code from the site and put it up on S3 or your own hosting service and include it into your projects that you are working on but why not let Google do it for you if it makes life easier? Google has a bunch of script libraries that they host for free that are used commonly. To include jQuery in your project stress free try this

Document Ready

One thing that can be frustrating when just starting out using jQuery is finding out the hard way of why you have to wait for the page to load before your functions can work. What??!! jQuery is a JavaScript library that extends native functionality of JavaScript and just plain makes JavaScript easier to work with. Problem is, none of your jQuery functions will work until the library is completely loaded and the structure of the html is in the browser. You can make sure your jQuery functions don’t try to do anything until the page is ready by putting your code in a document read wrapper that jQuery makes easy.

$(document).ready(function() {
  // Your jQuery code goes here
});

Shortcut

Because using jQuery is soo awesome and you are going to be using it soo much, the shortcut ‘$’ was used to reference jQuery. So the following two jQuery functions are the same.

jQuery("#ajax img").hide();
$("#ajax img").hide();

Help

Just remember when you get frustrated or you need help understanding something with jQuery do a Google search for what your having trouble with. If that doesn’t get you what you are looking for, ask a friend! There are many who have loved using jQuery and would love to help a friend out. Also, don’t forget the ever awesome http://stackoverflow.com/ which is a great place to find, ask, and answer programming related stuff! jQuery included.

Example

Here is a full and simple working example that I created just to show off a bit of the fun power of jQuery. Again, jQuery documentation rocks and has many examples but I thought this would be nice to pull together everything I had talked about here.

https://mikegrace.s3.amazonaws.com/geek-blog/jquery-example-1/jquery-example-1.html

photo by Quality & Style

TextMate Bundle For Committing KRL

TextMate KRL Commit Bundle

TextMate KRL Commit Bundle

I created a simple TextMate bundle that maps cmd + k to saving the app code and then committing the app to the Kynetx servers.

You can view and download the bundle on my github at http://gist.github.com/437379

Growl Notifications for Kynetx KRL Command Line Tool

KRL Commit Growl Notification

KRL Commit Growl Notification

I have been using the Kynetx KRL command line tool for several weeks now and it has made my development of Kynetx apps much easier. The only problem that I have had as I have been using the command line tool is that once I commit my app I have to wait a few seconds before being able to run the new version in my browser. Until now I have been doing a lot of command + tab switching between windows to check to see if it has finished saving.

I have now created a clean solution that allows me to know when the version has finished being committed to the Kynetx servers and had one unexpected benefit.

I started out by creating a simple bash alias that would pipe the output from the ‘krl commit’ command to a growl notification

# Growl notify after krl commit is done
alias krlc="krl commit | growlnotify -t "KRL" --image /Users/mikegrace/src/kynetx-x.png;"

I quickly realized that this wouldn’t work for me because piping the console to the growl notification means that the commit output wouldn’t be visible on the console.  I need to be able to see on the console what the output was in case there were errors or the latest saved version so I started looking for a better solution and came up with this

# Use growlnotify to alert user of commit status
krl() {
 if [[ $@ == "commit" ]]; then
  command krl commit | tee status.txt | growlnotify -t "KRL" --image /kynetx-x.png;
  cat status.txt;
 else
  command krl $@
 fi;
}

I created a function in my bash profile that runs when I run the krl command. When it sees me using the commit parameter it will do a krl commit and then tee that output to a status.txt file and pipe it to the growl notification. To have the output also show up on the console I cat the status.txt file back to the console. The unforeseen benefit here is that it is now really easy to share error output with others because it can be found in the status.txt file in the app folder.

I also created a bash script, available on my github, that takes care of the installation for you. I created this script purely for fun and I had a blast doing it!

I had a really great time doing all of this and learned a lot. There is a lot of power in being able to manipulate command line tools to make tasks easier.

As Bigweld would say, “See a need, fill a need”

How Long Does Google Latitude Keep My Location History?

Hard Drive

From http://www.google.com/support/mobile/bin/answer.py?hl=en&answer=163845

Once you enable Location History, it stores your location history for as long as it’s enabled. You may disable Location History at any time to stop storing your locations moving forward. You can also delete your past history entirely, by date range, or by individual location.