Sunday, November 29, 2009

DIY: Replacing Nike Plus iPod Sensor Battery

I fell in love on the very first time I used my Nike+ Sport Kit. Great device, simple, easy to use, very cool web portal.



The only thing that annoys me is the fact Apple made replacing its battery an almost impossible task. It is not a big deal if you live in the US where a new kit or just the sensor are fairly cheap. But, if you live abroad like I do, it might cost a lot of money. For instance, in Brazil, a new Nike+ iPod Kit costs a lot more, due importing taxes and currency exchange rate. Steel, a battery costs much less than the kit itself.

Luckily, I found this post explaining how to open and replace sensor's battery. My post is solely to endorse those instructions and share my personal experience while doing so.

1. Opening: by far the hardest step. The instructions I mentioned above does not emphasize how hard and tricky this step is. I used a very sharp knife and after half an hour and a lot of patient, I was able to open it up.This guy used a very hand sawing tool. Either way, you've got to be careful. If you go too deep, you may ruin its internals circuit.

2. Removing the battery. At very first moment, I thought it was some sort of special battery as I could see 4 wires coming out. But it is not - the thing on the top of the battery is just a component you have to take off of the battery's surface. Using a sharp knife, I removed some the plastic protection. As the instructions I mentioned above says, a plier might be handy in order to remove terminals from the battery (they are soldered):



Sensor uses a regular watch's battery (model ref. is CR2032) which provides 3v. I didn't have one sitting around and I would have to drive to the nearest store. I ended up wiring up two piles together so I could test whether the battery was actually the reason why the sensor was not working anymore.



And it worked like a charm.

UPDATE

3. Placing a new battery and closing sensor up: I just bought a new battery. I removed old metal terminals and soldered directly to the battery:





4. Closing the cover: Just place everything in nicely and carefully. I used some electric tape in order to avoid accidental short circuits.



Instead of glueing it together again, I used some electric tape to put the closer caps together. That makes my life a lot easier next time I need to replace the battery.

Sunday, October 4, 2009

Viewing lyrics while playing songs with iTunes on OS X

I've tried iClipLyrics and found it really nice until they've push an update which sadly changed the overall experience. Anyways, I've found couple of really nice apps which replaces iClipLyrics pretty well:

  • GimmeSomeTune iTunes plugin shows lyrics in a window plus, more importantly IMO, fetches lyrics for you.

  • DesktopLyrics shows lyrics on the Desktop, as its name suggests.

Sunday, September 27, 2009

Using JQuery in Chrome user scripts

It's been a while since Chrome supports user scripts. Chrome's user scripts runtime works pretty similar to Firefox + Greasemonkey's, but it is still not (and may will never be) fully compatible to FF+GM's runtime.

While writing user scripts, you may find JQuery a very powerful tool. It is a javascript library with many handy functions for extracting and manipulating HTML code in runtime.

In order to use JQuery within a user script, you may either download JQuery and embed it (being Minified version particularly insteresting in this case), or you may add some code to load JQuery with the actual page being fetched. I like the last better since it keeps my scripts smaller and cleaner, and linked to the latest version of JQuery. Unfortunately, this piece of code if incompatible with Chrome user scripts API.

Here is the modified version which works in Chrome:

// ==UserScript==
// @match http://*
// @run-at document-start
// ==/UserScript==

var jq_script = document.createElement("script");
jq_script.src = "http://jquery.com/src/jquery-latest.js";
jq_script.type = "text/javascript";
document.getElementsByTagName("html")[0].appendChild(jq_script);

function wait_for_jquery(attempts) {
try {
$ = window.jQuery || this.jQuery;
} catch(err) { alert(err); }
if ($ == null || typeof $ == "undefined") {
if (attempts > 0) {
window.setTimeout(wait_for_jquery, 250, attempts-1);
}
} else { letsJQuery(); }
}
wait_for_jquery(20);

function letsJQuery() {
alert($);
}


Core changes are:
  • Added instruction // @run-at document-start

  • Using "html" node rather than "head" in document.getElementsByTagName("html")[0].appendChild(jq_script);

  • Using window.JQuery rather than windowUnsafe.JQuery
  • Wednesday, July 29, 2009

    Get notified when a command finishes

    I tried for quite a while (I'm not really a bash expert) unsuccessfully building up a mechanism to notify me when a command has finished. I wanted more than a simple notification. I wanted it to tell me which command it was and its exit status. So I tried the following script:

    $ cat saydone

    #!/bin/bash
    if [ "$1" != "" ]; then
    $*;
    fi
    if [ $? = 0 ]; then
    notify-send "Done: $*";
    else
    notify-send -urgency=critical "Failed: $*";
    fi


    Now I could type $ saydone command or $ command ; saydone where the last one would miss the command typed. That worked well until I found out it does not handle aliases. I've tried outputting the command to a temporary script file preceded by shopt -s expand_aliases (as pointed here) which didn't work for some reason I don't know.

    Then I started playing around with history which (apparently) does not work inside bash scripts. Then I ran across this post which inspired me to create my final version:

    alias saydone="notify-send \"\`history 1\`\""

    Which gets you a nice simple notification:




    And if you are looking for something fancier, you can add the following to your .bashrc:

    alias saydone='if [ $? = 0 ]; then
    notify-send Successed "`history 1 | cut -d\; -f1 | cut -b8-`" ;
    else
    notify-send --urgency=critical Failed "`history 1 | cut -d\; -f1 | cut -b8-`" ;
    fi'


    And type $ ls /bogus ; saydone to get: