Programming


9
Nov 11

jQuery .keyup() vs .change() vs .bind()

I’ve found that using .keyup() in jQuery doesn’t always work like I want. For example, if I want to ensure that a user can’t put a special character into an input field I want to check for that character every time the input changes. Only using .keyup() allows someone to right-click and paste a bad value in.

Instead I use .bind(“change keyup input”) to catch all changes on an input field, regardless of how they are done.

For example:

// detect the change
$('input#myId').bind("change keyup input",function() {
    // if there's a bad value
    if (this.value.match(/[^a-zA-Z0-9\-_\s]/g)) {
        // replace it with nothing
        this.value = this.value.replace(/[^a-zA-Z0-9\-_\s]/g, '');
    }
});

Pretty simple, eh?

If you liked this you should follow me on Twitter where I tweet about startups, code, and other useful things.


24
Sep 11

Piwik and jqPlot

This took me waaaaaay longer than I wanted it to, so I’m making a point of posting it.

In order to take an API call to Piwik and use the returned JSON to generate a custom graph with jqPlot, do this:

    $.getJSON(url, function(data) {
        var i = 0;
        var line1 = new Array();
        $.each(dates, function(x, y) {
            line1[i] = [x,y];
            i++;
        });

        $.jqplot("chartdiv", [line1],
        {
        // the rest of your jqPlot options
        });
    });

The part that took me a while to wrap my head around was that jqPlot requires an array of arrays for the data points. Hopefully this is helpful to whomever finds it.


2
Feb 09

CSS Frameworks

I’m going to start developing sites using a CSS framework. I’ve read lots of arguments for and against and I feel like I won’t be delving into super complicated content anytime soon and therefore a prebuilt framework should speed things up a lot.

That’s really the goal that myself and Rob and going for, speed. We’re aiming to create inexpensive, customized, and well designed websites for small businesses and organizations. In order to keep prices down and profits up that means we need to be fast. I think that using a CSS framework will help me out.

I watched Yahoo’s YUI introduction video by Nate Koechley and it taught me a lot. Yes I have to submit to their div names and whatnot but I think it’ll speed things up.


27
Jul 08

Open-Mesh Update

Open-Mesh.com is slowly but surely improving. Just recently I noticed their homepage changed slogans. It went from something like “WiFi for the developing world” to “WiFi Where You Need It”. I like the latter, myself.

New firmware updates have also happened and beta 1.21 has been released. There was a glitch upgrading to the c953 firmware because of the technique used to upgrade. This required a lot of people to manually reset their routers if they were using the test firmware. They fixed the problem by using the “normal” way to upgrade and version c955 went off without a hitch.

According to Antonio Anselmi, author of the ROBIN mesh network software which powers Open-Mesh, says that the latest kernel is about a week away. Yay!


25
May 08

PHP Gallery Directory Image Reader

I wrote a neat little script to simply read a directory, search for thumbnails, then print a list with links to the larger images. I look for the thumbnails so it doesn’t get images that don’t have small versions.

There are limitations, for example if you put a PDF with ‘.thumb’ in the directory it will try to link it as an image. This is ok for me because I’m controlling what goes in the directories. I suppose I could add a check for it later if I need to.

<?php

/* This little snippet takes the directory and looks for any files with ‘.thumb’. Then it takes out the ‘.thumb’ to link to the big image. Then it makes a nice little list. */

$dir = ‘gallery/gallery2/’; /* Point to the right gallery directory */

echo “<ul>”;

if ($handle = opendir($dir)) {

while (false !== ($file = readdir($handle))) { /* Loop over directory */

if (strpos($file, ‘.thumb’)) { /* Look for the .thumb */

$filebig = str_replace(‘.thumb’,”,$file); /* Remove .thumb for our big files */

echo “<li><a href=\”$dir$filebig\” rel=\”lightbox[1]\”><img src=\”$dir$file\” border=\”0\”/></a></li>\n”; /* Make the list with both file names */

}

}

closedir($handle); /* Finish */

}

echo “</ul>”

?>


Edmonton Computer Repair