Author Archives for Jared Mellentine
JAVASCRIPT: Simple date conversion from SQL to readable
I needed a simple date converter function from SQL dates (YYYY-MM-DD) to something readable (M/D/YYYY). So I wrote this little function. Maybe someone else will have some use for it.
1
2
3
var makeSQLDatePretty = function(d) {
return d.replace(/([0-9]{4})-0?([0-9]{1,2})-0?([0-9]{1,2})/, ‘$2/$3/$1′);
};
Pass in a SQL date and the function trims leading zeros and returns a reformatted date.
1
2
var sqlDate = [...]
JAVASCRIPT: Smart, unobtrusive AJAX form submission with jQuery
A former coworker was telling me recently about MooTools and how the AJAX functions are so easy to use. He sent me the following example:
JAVASCRIPT: Iterating through objects, the easy way
Objects in any ECMAScript language (Javascript, Actionscript, Jscript, etc) are very powerful for - among other things - storing data. However, getting some information out of these objects can be a hassle sometimes.
I ran into this issue recently and wrote some cool little handlers for objects. The following methods can be used to [...]
JAVASCRIPT: onerror image magic
HTML has a little-known event handler for <img> and <body> tags. I’m going to focus on <img> tags and how you can use this to clean up some 404s.
JAVASCRIPT: Internet Explorer’s attachEvent breaks ‘this’
First of all, let me just say that I love jQuery. It makes Javascript development so much faster. I’m sure that Prototype is just as easy for those that use that daily, but I prefer jQuery. And before you ask… Yes, I learned both.
That having been said, there are some applications where [...]
LEARNING: 2008 monthly plan updated
The learning plan has been canceled for now. Between work, side work and a new baby, I really don’t have time to learn as a separate task. I guess I’ll just have to learn as I go along.
LEARNING: 2008 monthly plan
Since it is the new year already, I’ve decided to plan my learning schedule for the next 12 months. Here’s the plan so far (subject to change):
January: JavaServer Pages
February: Java
March: Java (continued)
April: MySQL 5
May: MySQL 5 (continued)
June: SQLite
July: Python
August: Python (continued)
September: Perl
October: Perl (continued)
November: Ext
December: Ruby
These should really push me out of my comfort [...]
JAVASCRIPT: Method overloading
John Resig, one of my heroes and creator of the jQuery JavaScript library, wrote a great piece about overloading methods. He created a dead simple function that shoulders most of the work. Check it out:
1
2
3
4
5
6
7
8
9
function addMethod(object, name, fn){
var old = object[ name ];
object[ name ] = function(){
[...]
JAVASCRIPT: Creating objects and methods
That’s right, object-oriented Javascript. Let’s get to it. We’re going to make an object for storing and retrieving user information.
Let’s start with the base object:
1
2
var User = function(firstName, lastName, emailAddress) {
}
We have to initialize the variables so that they’re available to the rest of the methods of this object:
1
2
3
4
5
var User = function(firstName, lastName, [...]
FLASH: Recursively parse XML into an array
Flash does not make it easy to handle XML. I’ve used some really bad code to help me parse arrays until I came up with this. It doesn’t handle elements of the same name at the same level, but it can probably be modified to do so.
var myParsedXML = new Array();
var myXML = [...]