web based gantt charts
here’s a cool web tool for creating gantt charts. its got a hand full of features and it can export to a few various document types. there are levels of product use but the free level has a lot of the necessary features to get a decent gantt chart create (albeit with a brand watermark in the background).
hash tables
hash tables are a great way to sore associated lists of information and also maintain a very low retrieval time (O(1)). a hash table is basically an associative array where the keys can be anything (typically strings) that points to a value. lets say you have a list of people and their addresses. you might want to associate the people with there addresses so that when you look up “jesse mazur” you get “555-1212″. rather than having to traverse the entire array to find the value you simply query the hash table for the key “jesse mazur” and get the value “555-1212″ returned. an easy way to create this type of relationship in php is to simply use an array:
$hashTable = array('my' => 'some data',
'hash' => 'some more data',
'table' => 'even more data');
retrieval from the hash table would be as simple as saying:
echo $hasTable['hash'];
which would display 'some more data' to the screen.
in javascript you would use a json object to do something every similar:
var hashTable = new Array(); hashTable['my'] = 'some data'; hashTable['hash'] = 'some more data'; hashTable['table'] = 'even more data';
and retrieval is as easy as:
document.write(hashTable.table);
which would display 'even more data' to the screen.
recursion
this is something that programmers deal with on a regular basis when faced with a problem were some set of tasks needs to be performed repeatedly on a set of data as well as that data’s subsets. many recursive functions can also be carried out with cunning use of loops, which is often better in the long run (as far as big-o-notation is concerned) but when the only way to do something (or the most efficient way) is to do it recursively, then writing a recursive function is the way to go. consider this: you have an array that contains either integers or other arrays, who contain integers or other arrays, and so on. you need to find the highest integer contained by the parent array, regardless of how deep the internal arrays may go. a loop would be a rather difficult way to achieve this considering you have no idea how many tiers to traverse. so recursion is a great way to do it. first write a function that just returns the highest value in the array (for the purposes of this article ill use php but this applies to almost all languages):
function highestVal ($array) {
$curHigh = 0;
if (is_array($array)) {
foreach($array as $val) {
if ($val > $curHigh) {
$curHigh = $val;
}
}
} else
// return some error for incorrect data type
}
return $curHigh;
}
passing an array that contains only integers such as array(3,4,8,12,9,8,1) would return 12 in this case. but what if the array was array(3,2,8,9,4,array(12,3),1)? this function might return an error or at the very least not catch the 12 inside the internal array. so modifying the function to check if the $val is an array and recursively calling itself would then return the highest value of the inner array (and if that contained any inner arrays, they would also be assessed):
function highestVal ($array) {
$curHigh = 0;
if (is_array($array)) {
foreach($array as $val) {
if (is_array($val)) {
$val = highestVal($val);
}
if ($val > $curHigh) {
$curHigh = $val;
}
}
} else {
// return some error for incorrect data type
}
return $curHigh;
}
there you have it, a function that would return the highest value if an array containing any number of integers or arrays. recursion can have a high cost as far as resources are concerned but this function still maintainss a big-o value of O(n) because it only evaluates each member of each array one time.
javascript location based applications
mobile application development seems to be the new craze and everyone is getting in on it. with so many different platforms its difficult to decide which platform to code for. there are a few frameworks out there like Appcelerator and PhoneGap that enable you to write the application in JavaScript, HTML5 and CSS3 and then wrap the application in a ‘native’ shell to run on multiple platforms but you still need all the SDKs to do so. since all major phones have modern browsers you can create any web application using the 3 web languages instead. since geolocation seems to be the hip thing that all mobile apps have you need a way to make location based software. luckily the w3c has a new standard for doing so that is part of javascript and functions in most modern browsers:
navigator.geolocation
to make sure that the browser supports it wrapping the line in an if() statement will make sure that the application wont try to do something its incapable of doing. then once you know geolocation works, write your code:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
alert('You are at' + position.coords.latitude + ' x ' + position.coords.longitude);
}
}
once you know the coordinates you can do all sorts of things: look up near by restaurants, get directions, find the closest gas station. now all you need to do is create a css that looks good on mobile devices and make the website itself the app. on an iphone its easy to save a website as a book mark on the home screen, so effectively you have created a location based application using only javascript, html5, and css3!
regular expressions
i had to work with regular expressions today and i realized i have never posed about them but i used them often. a regular expression is a way of matching patterns in a string. most programming languages have a way to work with them. in php the method i prefer to use is preg_match() and in javascript its match(). ill just show some very very basic regular expressions to describe how they work. first, a few of the basic special characters that i use rather often:
- . – any character
- ^ – when at the beginning of the expression it means the very first character in the expression, however when inside of a pair square brackets it denotes the NOT logical operator
- $ – when at the end of the expression it means the end of the entire expression, otherwise it means an actual dollar sign
- * – 0 or more of the preceding character
- ? – 0 or 1 of the preceding character
- {n} – n number of the preceding character
- {n,m} – between n and m instances of the preceding character
- | – OR logical operator
- () – used to group things together, can also be used for back references as
$nwherenrepresents the n’th set of parenthesis (starting at 0) - \s – white space
- \d – a digit
- ‘-’ – a dash implies a range between the two characters on either site (they must match in type)
- \ – this escapes the following character in the event that the character would otherwise be a reserved character in regular expressions
there are many more, in fact regular expressions can get so complex that some even consider it to be a pseudo-language of its own. in any result i’ll try to think of a situation where i can use at least a few of these characters and then write out the expression in plain English.
^[A-Z]([^.]\s)*hello?(\s[^.])*\.$
this would mean any grammatically correct sentence that begins with a capital letter followed by any number of characters and spaces that are not periods, followed by zero or one instance of the word ‘hello’, followed by any number of characters and spaces other than a period, and finally ending with a period




