Browse by Month RSS Feed
  • September 2010
  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010

  • Function: Array.customJoin()January 28, 2008
    Filed under: Code, JavaScript, Life @ 3:17 pm
    /**
     * Simple function that acts like String.join(), except it allows for a custom final joiner. This
     * is helpful in situations where you want to join an array in human readable form, e.g.
     *   var arr = ["one", "two", "three"];
     *   alert(arr.customJoin(", ", " and ")); // alerts "one, two and three"
     */

    Array.prototype.customJoin = function(glue, finalGlue)
    {
      // if there's at least one element, pop off the LAST item
      var lastItem = null;
      if (this.length> 0)
        lastItem = this.pop();

      // now, if there's still 1 or more items left, join them with the glue
      if (this.length> 0)
      {
        var str = this.join(glue);
        str += finalGlue + lastItem;
      }
      // otherwise there was only one item: just return the string
      else
        str = lastItem;

      return str;
    }

    Comments (0)


    Filed under: Code, JavaScript, Life @ 2:04 pm
    String.prototype.ucFirstLetter = function()
    {
      return this.substr(0,1).toUpperCase() + this.substr(1);
    }

    Comments (0)


    Two Great Ajax ToolsJanuary 16, 2008
    Filed under: Life, Software @ 1:04 pm

    I've come across oodles of handy online tools, but these two take the cake. I've lost count of the number of times I've used them - invaluable!

    Stripe Generator - generates tiled, background images for your web apps; highly customizable. Saves hours of fiddling around in Photoshop.

    Ajaxload.info - generates "loading" icons in whatever custom designs and colours you need for your Ajax apps.

    Comments (2)


    Filed under: Tech News @ 2:15 pm

    Last month, Brian Dillard released an updated version of RSH. Apparently I had my head in the sand because I'm only just learning about it now.

    RSH is a uber-lightweight JS library (9KB!) commonly used in Ajax applications. It provides a very simple mechanism for bookmarking Ajax-generated pages and preserving the functionality of the browser's Back button. I've used it on a number of sites including generatedata.com and blacksheepsoft.com.

    The one drawback to the earlier version was its lack of support for Safari, Opera & IE7. This new version supports all three. So a big thanks for Brian for taking over the project - and, of course, to Brad Neuberg for writing it in the first place.

    You can learn more about RSH at the Google Code project homepage.

    On a entirely different subject, I added this blog post via the rather nifty Bee AIR application. I'm currently taking a breather from working on Form Tools 2 and swatting up on Adobe AIR. Terrific fun! I'm midway through porting generatedata.com over to a desktop application and across Bee while looking for sample AIR-compatible JS code. Neat stuff!

    Comments (0)


    Function: String.prototype.padJanuary 1, 2008
    Filed under: Code, JavaScript, Life @ 9:20 pm

    Handy little function for padding a javascript string, written by Jonas Raoni Soares Silva.

    /**
     * Returns a padded string, left, right or both sides.
     *
     * @author Jonas Raoni Soares Silva
     * @link http://jsfromhell.com/string/pad [v1.0]
     * @param integer l amount of characters that the string must have
     * @param string s string that will be concatenated
     * @param integer t specifies the side where the concatenation will happen: 0 = left, 1 = right and 2 = both sides
     */

    String.prototype.pad = function(l, s, t){
        return s || (s = " "), (l -= this.length)> 0 ? (s = new Array(Math.ceil(l / s.length)
            + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
            + this + s.substr(0, l - t) : this;
    };

    Comments (2)