jQuery each function

jQuery has done it again with a very succinct function to iterate over the values of a set and perform an action for each one. The each function is easy to use and keeps your code from being cluttered with many for loops.

var allAlts = new Array();
$('img').each(function(){
allAlts.push(this.alt);
});
These few lines of code will get the alt attribute of every image tag in your document and store it in an array.

More vi Commands

Here are some more vi Commands that I have learned recently:

j - move down one line
k - move up one line
ndd - delete n number of characters

And apparently there are many, many more. To be continued...

Creating and Using Branches in Git

Here are some basic work flows for working with the Git repository, especially the power of the branching features that Git offers.

To create a new branch and switch to that branch use:
$git checkout -b my_branch
Any changes that are done now will be reflected in the new branch and not the master.

To see what branch you are working on use:
$git branch
You should see an * beside the name of the branch that is current

To go back to our master branch use:
$git checkout master
Now any changes that are made will be reflected in the master branch but are not automatically populated to your new branch.

To merge our new branch into our master branch use:
$git merge my_branch
We do not need to specify where we are going to do the merge because we are already in the master branch.

To delete our new branch now that we have done a merge use:
$git branch -d my_branch

Another option for merging our branch into the master branch is the following:
$git checkout my_branch
$git rebase master
Fix any conflicts and do:
$git add
$git rebase --continue
$git checkout master
$git merge my_branch
This will make the history much cleaner.

Passing HashMap as POST parameter

If you would like to pass a hashmap as a parameter to a POST call in JavaScript, you need to use the dot notation and it will be interpreted as belonging to a hashmap. The code below loops through the properties of an object called 'options' and adds each one except for the toString() method to the POST parameter hashmap.
===================================================
Declaration of options variable

var options = {
foo: 'blah',
boo: 'muah',
toString: function() {
return this.foo + ', ' + this.boo;
}
};

===================================================
Inside AJAX call function

if (options != null) {
for (property in options) {
if (property != 'toString')
post_data['options.' + property] = options[property];
}
}

Using this code when you access the POST parameters on the server side, you can reference the 'options' POST parameter as a hashmap, i.e. options['foo'].

Basic vi Commands

Here are a few basic vi commands that I have found helpful in adding and deleting information in a file from the command line.

dd - delete a line
i - change to insert mode
/ - perform a search query
n - move to the next result in the search
:wq - save the file and exit

Javascript Object declared within another Object

In order to declare a Javascript object inside another one you would need to enter code similar to what is below.

var book = {
title: 'Nothing new!',
author: {name: 'Annyce', email:'annyce@gmail.com'}
};


You could then reference the author's name via:
book.author.name


and if you wanted to update the name of the author, you would use
book.author.name = 'Sarah';

This feature of Javascript becomes very useful when you attempt to create an object with default settings and so forth.