Updates from January, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • wade 13:02 on Friday, 1 January 2010 Permalink | Log in to leave a Comment  

    Read boolean HTML attributes with jQuery 

    After much testing, I have concluded that in order to use jQuery with boolean attributes (and have it work in the big four browsers), the following markup must be used: checked=”checked”.

    While browsers except any of the following…


    …only the last option works with jQuery in all browsers.

  • wade 17:47 on Wednesday, 30 December 2009 Permalink | Log in to leave a Comment  

    Display 12, read/write 24 TimePicker jQuery plugin 

    Jason Huck’s jQuery TimePicker plugin didn’t work for me as-is since it reads and writes in 12-hour format. While most people (strangely) prefer 12 hour format for interacting with, database time fields are 24 hour. I could have converted the format with scripting on the back-end but decided I would prefer to have the picker display 12-hour but read/write 24-hour. So, I took Jason’s great design and rewrote it to suite my needs.

    Other changes I made were adding a colon between the hour and the minute select lists, adding a space between the minute and the am/pm list, and changed the hours and minutes arrays such that the hours no longer have leading zeros and the minutes are every five instead of every fifteen.

    I have intergrated tomsalfield (issue 3) and jasonalanharris’ (issue 5) changes as well.

    My version of the script can be found in the issue tracker on the Google Code project for the plugin. Here’s a screenshot of it in use next to a date field:

  • wade 10:46 on Saturday, 13 December 2008 Permalink | Log in to leave a Comment  

    zebra striping across rowspans with jQuery 

    On one of my current projects, I am adding alternating shading (“zebra striping”) to rows in a table with javascript. This last week I encountered a scenario where I needed this to work on a table that had some cells that spanned multiple rows.

    My current script could not handle this as it was using jQuery’s :odd selector and I now needed to stripe all of the spanned rows together instead of just every other one. The additional shading that I was applying when hovering over the row was also broken as it too needed to shade all of the spanned rows instead of just the one the mouse was over.

    So, I enhanced my script to work with both scenarios. I hope it can be of use to someone.

    // check for rowspans
    rows = $('.datatable > tbody > tr:first > td:first').attr('rowspan');
    var rows_count = rows * 1;
    // if, shade spanned rows; else, shade for every other row
    if(rows_count > 1) {
       // find the row group leader
       function rgl(who) {
          var current = who;
          for(i = 0; i < rows_count; i++) {
             if($(current).find('td:first').attr('rowspan') > 1) {
                var rgl = current;
             current = $(current).prev('tr');
          return rgl;
       // row shading
       for(r = 1; r <= rows_count; r++) {
          var nth = (rows_count * 2) + 'n+' + (rows_count + r);
          $('.datatable > tbody > tr:nth-child(' + nth + ')').addClass('odd');
       // row hover shading
       $('.datatable > tbody > tr').hover(
          function() {
             var who = rgl(this);
             for(i = 0; i < rows_count; i++) {
                who = $(who).next('tr');
          function() {
             var who = rgl(this);
             for(i = 0; i < rows_count; i++) {
                who = $(who).next('tr');
    } else {
       $('.datatable > tbody > tr:odd').addClass('odd');
  • wade 21:02 on Sunday, 12 October 2008 Permalink | Log in to leave a Comment  

    Chainlove alerts 

    Any other cyclists out there? You a chainlove junkie too? After finding myself spending too much time refreshing and refreshing, I wrote the following script to watch the site for things I was interested in and send me a text message when they come up. I put it on my machine that’s always on and scheduled it to run every ten minutes with launchd. Hopefully it will save you a little time and sanity as well. (Note the wrapped lines.)

     * This script scrapes chainlove.com and sends an email when words in 
     * the "watch list" are included in the current product offering.
    // list of words to watch for
    $watch_list = array('sunglasses', 'warmers', 'jersey', 'giordana');
    // cache file (including path)
    $cache_file = '/tmp/chainlove_alerts.cache';
    // scrape page
    $ch = curl_init() or die(curl_error()); 
    curl_setopt($ch, CURLOPT_URL, "http://www.chainlove.com"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $page = curl_exec($ch) or die(curl_error()); 
    // pull out the product details
    preg_match('/<h1 id="item_title">([^<]+)<\/h1>.*<h3 class="price"> ¬
       ([^<]+)<\/h3>.*<div id="regular_price">\n*\t*\s*([^<]+)<br \/> ¬
       \n\t*\s*([^<]+)<\/div>/sm', $page, $matches);
    // compare current product against cache product... if same, exit
    if(!file_exists($cache_file)) {
       file_put_contents($cache_file, trim($matches[1]));
    } else {
       $cache_product = file_get_contents($cache_file);
       if($cache_product == trim($matches[1])) {
       } else {
          file_put_contents($cache_file, trim($matches[1]));
    // search current product title with "watch list"
    $send_mail = 0;
    foreach($watch_list as $watch_item) {
       if(stripos($matches[1], $watch_item)) {
    // send email
    if($send_mail > 0) {
       $mail['to'] = '8015551212@txt.att.net';
       $mail['subject'] = trim($matches[1]);
       $mail['message'] = trim($matches[2]) . ' (' . trim($matches[3]) .
          ', ' . trim($matches[4]) . ')';
       $mail['from'] = 'Chainlove Alerts <user@example.com>';
       $mail['additional_headers'] = 'From: ' . $mail['from'];
       mail($mail['to'], $mail['subject'], $mail['message'], ¬
    • thebigdog 17:38 on Sunday, 19 October 2008 Permalink | Log in to Reply

      nice job wade. have you thought about storing the data in a sqlite db so you can do some data analysis on it? like how often they actually change the data.

    • wade 18:08 on Sunday, 19 October 2008 Permalink | Log in to Reply

      I hadn’t thought of storing the data anything longer than the cache file. Tossing it in a SQLite database is a cool idea though. It would be very interesting to learn more about their system. For example, they do not always run a product until it is sold out; they appear to run it only as long as it’s hot. As soon as units stop moving at a certain pace, they swap it out with something else. Although I don’t know how automated it is. These products will often appear again later. I wonder if you would be able to start predicting patterns with enough data.

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top
go to login
show/hide help
shift + esc