IE and its broken substr() (show)  

substr() is a very simple function for working with strings. It's been around forever, and is well documented. I recently had need to find the last character of a string in javascript. Everything was working fine in Firefox and Chrome, but IE was breaking.

'abcdef'.substr(-1,1)

That is, start at 1 character from the end (-1) and return 1 character. In all other browsers this returns 'f' but in IE it returns 'a'.

Leave A Reply

Ruminating on the new iPad (show)  

  • Isn't this just a big expensive iPod touch now?
    • It's more than just an iPod touch that won't fit in your pocket...it's also an underpowered netbook with no keyboard. It's the worst of both worlds!
      • It actually has a robust power source; it is powered almost entirely by the user's sense of self-importance.

Slashdot.org comments

Leave A Reply

Microsoft has two malware tools (show)  

Malicious Software Removal Tool scans your system on demand for malware, and Microsoft Security Essentials is a real time anti-virus tool. Both are tools are free.

Leave A Reply

GMail and IMAP (show)  

I use Thunderbird as an IMAP client on my GMail account. There are a couple of idiosyncrasies that require some settings changes. Google has a detailed page about setting up various IMAP Clients to work properly with GMail.

Leave A Reply

Caching results in a PHP function (show)  

If you have a function that will get called lots of times, and you'd like to cache the results so as not to incur a performance penalty for hitting the disk/DB again use static variables.

function get_user($id) {
  // Sanitize the input
  $id = intval($id);

  // Declaring as static prevents the variable from dying when the function exits
  static $cache;

  // If the data is already in the cache just return that
  if ($cache[$id]) { return $cache[$id]; }

  // Get the data from the DB/Disk/Slow Source
  $rs = mysql_query("SELECT * FROM UserTable WHERE ID = $id");
  $ret = mysql_fetch_assoc($rs);

  // Store the results in the cache so it will be there next time
  $cache[$id] = $ret;

  return $ret;
}

This will store the results in cache (memory), speeding up subsequent requests. This cache will last until your script ends. To store across multiple script executions you'll want to look at something like memcache.

Leave A Reply - 1 Reply

pgrep where have you been all my life? (show)  

Ever need to find the PID of a specific process, or if a process is running? Pgrep to the rescue!

pgrep pigdin

This allows you to do cool things like:

#!/usr/bin/perl

if (`pgrep speedcrunch`) {
    print "is running\n";
} else {
    print "It's not running\n";
    # do some other stuff
}
Leave A Reply

Fridge Filter (show)  

I changed the water filter in my fridge. This is strictly a tracking entry for that.

The filter is a Kenmore 469010

Leave A Reply

AnonymousPro is my font of choice for coding (show)  

AnonymousPro is a great free (as in beer, and speech) monospace font. I've been using it for a couple of months now for all my console/coding needs. It's very readable and functional. I can't recommend it enough!

Leave A Reply

Extended the javascript string operator (show)  

If you want to extend a javascript object:

// Define the function to do what you want
function first3char() {
    return this.substr(0,3); // 'this' will be the variable that's passed in
}

// Extend the javascript string operator
String.prototype.first3=first3char;

// Call your extension using the string 'abc123'
"abc123".first3();
Leave A Reply

Books of 2010 (show)  

Also see the list of 2009. The date indicated denotes the date I started reading the book.

2010-01-08 - Women are Crazy, Men are Stupid - 243 pages
2010-01-13 - Relentless - 354 pages
2010-01-19 - Google Speaks - 287 pages
2010-01-24 - Under the Dome - 1072 pages

2010-xx-xx - A Widow for One Year - 534 pages
2010-xx-xx - Why Architecture Matters - 261 pages
2010-xx-xx - I Drink For a Reason - 238 pages
2010-xx-xx - Next - 423 pages
2010-xx-xx - Year's Best Fantasy 6 - 355 pages
Leave A Reply

Testing PHP Markdown (show)  

I found this interesting PHP library called Markdown. I'm looking at implementing it on this site.

  • Makes formatting text much easier
  • No need to know HTML tags
  • Text version is still very readable

Here's a link to the syntax documentation.

This is a test of some blockquoted text! - Scott Baker

Leave A Reply

Save an MP3 stream with Curl (show)  

Use the following code to save a MP3 stream to disk. Useful with cron to record a show for later time shifting.

curl -sS -o /tmp/output.mp3 --max-time 1800 http://stream1.opb.org/radio.mp3 Courtesy of comandlinefu.com
Leave A Reply

Firebug is great but... (show)  

I use FireBug all the time, it's an amazing tool for web developers. Leaving it enabled all the time causes Firefox to slow down considerably:

I need to be clear here: If you have Firebug installed you are probably not getting fast Javascript. Firebug doesn’t have to be active on your current page. If you have the grey icon on your status bar, you have probably disabled the JIT. This is true if you have ever enabled the Console and consequently the Script panels and left them on. This is likely true for most recent versions of Firebug. The quick fix is to disable the Script and Console panels via the mini menu on their respective tabs. - robcee It's pretty easy to disable and speed things up. Now I only enable it for sites I need to debug.

See previous

Leave A Reply

Amazon + Firebug = Slow (show)  

Item pages on Amazon were slowing to crawl, and locking up my browser for 15 seconds. It was making Amazon almost unusable, and I couldn't figure out what was causing the problem. Looking down at the status bar in Firefox I saw that Firebug was enabled and reporting errors. I disabled Firebug and now Amazon is fast again!
Leave A Reply

wToolTip: finally a good jQuery tooltip (show)  

I finally found a good (and more importantly simple) jQuery tooltip plugin. wToolTip is small, simple, and very effective.
Leave A Reply