<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en">
<title>heatxsink.com - stay hungry, stay foolish</title>
<link rel="alternate" href="http://www.heatxsink.com/" title="" type="text/html" />
<id>http://www.heatxsink.com/</id>
<icon>http://www.heatxsink.com/favicon.ico</icon>
<updated>2010-09-09T02:21:57Z</updated>
<author><name>Nick Granado</name></author>

<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.heatxsink.com/heatxsink/atom" /><feedburner:info uri="heatxsink/atom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
<title>This is Life</title>
<id>http://www.heatxsink.com/entry/this-is-life</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/ujAjo_y4SHk/this-is-life" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-09-09T02:21:57Z</updated>
<published>2010-09-09T01:55:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<iframe class="youtube-player" type="text/html" width="480" height="385" src="http://www.youtube.com/embed/8cfeTZNcA3g" frameborder="0" />

<blockquote>they don't call it the amazing race for nothin'</blockquote>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/ujAjo_y4SHk" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/this-is-life</feedburner:origLink></entry>

<entry>
<title>Arduino Knight Rider Project</title>
<id>http://www.heatxsink.com/entry/arduino-knight-rider-project</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/oBx7VRvUoWk/arduino-knight-rider-project" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-08-29T09:51:12Z</updated>
<published>2010-08-29T03:25:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
I've always wanted to build a Knight Rider style LED array (minus the swoosh sound). It just so happens that a few months ago I ordered an <a href="http://en.wikipedia.org/wiki/Arduino">arduino</a>. I finally assembled the "<a href="http://www.ladyada.net/make/pshield/">proto shield</a>" for it, and one of the first things I wanted to test out is if I can make something like this. I'm pleased to report it took about an hour of hacking and it works. Check out the <a href="http://www.youtube.com/watch?v=WTA-hcalpMQ">video</a>. 
</p>

<a href="http://snapp.me/pic/4e2" target="_blank"><img src="http://pics.snapp.me/9ff975326c4a37a4_e1848a76f9d86a55_d.jpg" alt="posted using snapp.me" /></a>

<div style="padding-bottom: 14px;">
<iframe class="youtube-player" type="text/html" width="480" height="385" src="http://www.youtube.com/embed/WTA-hcalpMQ" frameborder="0" />
</div>

<h3>Schematic</h3>
<img src="http://share.heatxsink.com/temp/arduino_knight_rider.png" alt="" />

<h3>Parts List</h3>
<ul>
<li>1 x Arduino</li>
<li>5 x Red LED's</li>
<li>5 x 1k ohm (1/4 watt) Resistors</li>
<li>16 guage insolated solid copper wire (about 6 inches will do, you'll also probably need some wire strippers and side cutters)</li>
</ul>
<h3>Code</h3>
<p>
I think the following code could be optimized a lot. However the whole purpose of this experiment was to test if something like this is quick and relatively easy to hack up.
</p>

<pre class="snippet">
/*
 *  Knight Rider
 * 
 *  Ever watch Knight Rider? Yes that 80's show with that awesome car named Kit?
 *
 *  Want that same effect for your car?
 *
 *  Here it is.
 *
 *  created 28 August 2010
 *  by Nicholas Granado
 *  
 */

int DELAY = 100;
int LONG_DELAY = 500;
int MODE = 0;
int START = 9;
int LENGTH = 14;
//       PINS: 0 1 2 3 4 5 6 7 8 9 0 1 2 3
int state[] = {0,0,0,0,0,0,0,0,0,1,0,0,0,0};
int pin;

void setup()   {                
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void load_pin_state() {
  for(pin = START; pin &lt; LENGTH; pin++) {
    if(state[pin] == 0) {
      digitalWrite(pin, LOW);
    }
    else if(state[pin] == 1) {
      digitalWrite(pin, HIGH);    
    }
  }
  
  if(state[START] == 1 || state[LENGTH - 1] == 1) {
    delay(LONG_DELAY);
  } else {
    delay(DELAY);
  }
}

void loop()                     
{
  load_pin_state();

  if(MODE == 0) {
    
    for(pin = START; pin &lt; LENGTH; pin++) {
      if(state[pin] == 1) {
        state[pin] = 0;
        state[pin + 1] = 1;
        
        if((pin + 1) == (LENGTH - 1)) {
          MODE = 1;
        }
        
        break;
      }
    } // end for loop
    
  } else {
    
    for(pin = LENGTH - 1; pin &gt;= START; pin--) {
      if(state[pin] == 1) {
        state[pin] = 0;
        state[pin - 1] = 1;
        
        if((pin - 1) == START){
          MODE = 0;
        }
        
        break;
      }
    } // end for loop
    
  }// end mode  
}
</pre>

<h3>Summary</h3>
<p>
The <a href="http://en.wikipedia.org/wiki/Arduino">arduino</a> hardware platform makes building circuits and interfacing them with a micro-controller fun. My next goal is to build something a bit more complicated and useful.
</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/oBx7VRvUoWk" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/arduino-knight-rider-project</feedburner:origLink></entry>

<entry>
<title>Javascript Templates in jQuery </title>
<id>http://www.heatxsink.com/entry/javascript-templates-in-jquery</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/kAaiAAul0aQ/javascript-templates-in-jquery" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-30T07:41:04Z</updated>
<published>2010-04-25T23:32:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>As writing web applications becomes increasingly more popular, so has the ability for an application to be "almost" completely rendered via javascript. A great example of this is Gmail. Unfortunately as a product is built it's difficult to keep from making sweeping changes in your source code. This obviously becomes painful. Especially if part of your view rendering is in javascript.
</p>
<p>
In jQuery I see alot of code like the following:
</p>
<pre class="snippet">
$.each(data, function(i,item) {
    $("&lt;img/&gt;").attr("src", item.picture_url).attr("width", "480").appendTo("#my-images").wrap("&lt;a href='" + item.picture_page_url + "'&gt;&lt;/a&gt;");
});
</pre>

<p>
With jQuery templates it now turns into a script tag with your markup and a single line of code:
</p>
<pre class="snippet">
&lt;script id="image_template" type="text/html"&gt;
	&lt;a href="${ picture_page_url }"&gt;
		&lt;img width="480" src="${ picture_url }" /&gt;
	&lt;/a&gt;
&lt;/script&gt;

...

$("#image_template").render(data).appendTo("#my-images");
</pre>
<p>
You can also put your template into a string:
</p>
<pre class="snippet">
var template = '&lt;a href="${ picture_page_url }"&gt;&lt;img width="480" src="${ picture_url }" /&gt;&lt;/a&gt;';

$("#my-images").append(template, data);
</pre>

<p>Until jquery-tmpl is included into jquery-core there's a script include up on github at <a href="http://github.com/jquery/jquery-tmpl">http://github.com/jquery/jquery-tmpl</a>.</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/kAaiAAul0aQ" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/javascript-templates-in-jquery</feedburner:origLink></entry>

<entry>
<title>How To Uniquely Identify An Android Device</title>
<id>http://www.heatxsink.com/entry/how-to-uniquely-identify-an-android-device</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/Y3TvXt6fE2E/how-to-uniquely-identify-an-android-device" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-20T21:13:15Z</updated>
<published>2010-04-20T09:13:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>After doing a little bit of native iPhone application development it's pretty nifty to be able to get the unique identifier for an iPhone. When porting an iPhone application to Android I was running into a similar scenario. Is there a unique identifier for each Android device? The answer is Yes. Unfortunately there isn't just one way to do it, there's two. The first way requires the user to approve an application permission. The second way is completely open, and requires no application permission.</p>

<h3>The Way With An Application Permission</h3>
<p>Add this <code>uses-permission</code> in your applications <code>AndroidManifest.xml</code></p>
<pre class="snippet">
&lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
</pre>
<pre class="snippet">
Context context = getApplicationContext();
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String device_id = manager.getDeviceId();
</pre>
<p><em>Update:</em> This will only work if the Android device is a phone! Big thanks to <a href="http://twitter.com/tberman/status/12534159539">Todd Berman</a> for the catch.</p>


<h3>The Way Without An Application Permission</h3>
<pre class="snippet">
String android_id = System.getString(this.getContentResolver(), System.ANDROID_ID);
</pre>

<p><em>Update:</em> This will only work if the device is associated with a google account! Again thanks to <a href="http://twitter.com/tberman/status/12534159539">Todd Berman</a> for the catch.</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/Y3TvXt6fE2E" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/how-to-uniquely-identify-an-android-device</feedburner:origLink></entry>

<entry>
<title>Storing A Url To A File In C# .NET</title>
<id>http://www.heatxsink.com/entry/storing-a-url-to-a-file-in-csharp-dotnet</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/eRuJ26-CcZM/storing-a-url-to-a-file-in-csharp-dotnet" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-20T09:31:31Z</updated>
<published>2010-04-18T10:59:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
This is for all of you C# .NET web developers out there. Been having todo a lot of ridiculous clean up lately which normally includes lots of offline batch processes. I found this method to be uber useful, I'm sure most of you will too.
</p>

<pre class="snippet">
public void StoreUrlToFile(string url, string destination, int timeout)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Timeout = timeout;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    if (HttpStatusCode.OK == response.StatusCode)
    {
        using (Stream stream = response.GetResponseStream())
        {
            using (FileStream fileStream = new FileStream(destination, FileMode.OpenOrCreate, FileAccess.Write))
            { 
                byte[] buffer = new byte[4096];
                int bytesRead;
                while (0 &lt; (bytesRead = stream.Read(buffer, 0, buffer.Length)))
                {
                    fileStream.Write(buffer, 0, bytesRead);
                }
            }
        }
    }
}
</pre>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/eRuJ26-CcZM" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/storing-a-url-to-a-file-in-csharp-dotnet</feedburner:origLink></entry>

<entry>
<title>My First 24 Hours with iPad</title>
<id>http://www.heatxsink.com/entry/my-first-24-hours-with-ipad</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/z1JrI2-uUcY/my-first-24-hours-with-ipad" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-11T05:46:36Z</updated>
<published>2010-04-05T07:48:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
<h3>To buy or not to buy</h3>
I did not pre-order the iPad. I own a lot of Apple gear. My intentions were not to buy this device because I didn't quite get the device. That's even after watching every video and keynote. The night before it hit stores I did what any other fanboy would do; I was thinking about the device. I thought long and hard about it, I decided that in "Steve I trust." I started reading about how pre-orders were sold out and rumor had it that it would be "slim pickings" on trying to get one at the store with out pre-ordering. My next move was to hit craigslist and see if anyone was selling theirs. I found a couple of sellers, sent them emails, and anxiously waited. I got no response. 
</p>
<p>
<h3>Next day</h3>
The next day, still no response. It was 1:00PM, I called the Apple store a  sales rep. said, "there's no line, I don't know how long that will last, and we have units available in every size, again I don't know how long that will last." I immediately got to the store, as I walked up there was no line! I was thinking, "ha ha ha, I knew this thing was gonna flop." There's no way a company as awesome as Apple could pull this many wins. I enter the Apple store, and it was packed! I wanted to hold the device in my hands, unfortunately looking at the station with the display models that wasn't going to happen. I thought about it as I approached a sales rep. and bought one.
</p>
<p>
<h3>There is no spoon</h3>
After syncing my iPad for the first time (which was exactly like iPhone) I found myself in the web browser a lot. Browsing the internet on this device is insane. Yes, this thing is really just a larger version of an iPod Touch. However I think that statement doesn't help potential first time buyers. My iPhone now feels like this very small and dated device. I think it's because, before iPhone/iPad a computer was composed of separate devices that have a single purpose. The outputs were not connected to the inputs. There was a screen, a keyboard, and a mouse or pen. This is where Tablet PC's failed, you still needed a stylus to do input, and using your finger didn't work well at all. Now with these newer devices everything is folded into a single sleek device. The difference between an iPod Touch and an iPad that everyone might be overlooking is the input, more screen real estate equals a larger soft keyboard. This is where some people are saying it's "natural". Tangible interfaces on a much larger scale are finally here.
</p>
<p>
<h3>Goodbye other devices</h3>
I did not put my iPad down till around 11:30PM. The battery had not even dipped below 50% and I had been hitting the device hard by watching videos, browsing the web, playing with apps. I was flipping out! I started thinking about how this device competes with existing products and what I would make for this device. Ever heard of a netbook? I spent a long time trying to figure out which netbook to get, turns out they all sucked. How about those annoying portable DVD players? Gone. The Kindle/e-book reader? This is an interesting one. About one year ago I had the opportunity to use a Kindle for 30 days. I read two books, and even the Wall Street Journal. It was a sweet device, but it was lacking something and I couldn't put my finger on it. I finally figured it out. It's all of the buttons on the device! When I read a book in the analog, do I have a QWERTY keyboard on my book? FAIL.
</p>
<p>
<h3>The future</h3>
We are entering the era where devices I flipped out about seeing on Star Trek are becoming common place. Remember when the Motorola Razr came out? The entire reason why I bought that phone was because it reminded me of the "communicator" on Star Trek. The projector for my living room, Star Trek. Bluetooth headset, Star Trek. Tom tom GPS unit, Star Trek. And now the iPad, Star Trek. This is an amazing time, but I really want a replicator asap!
</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/z1JrI2-uUcY" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/my-first-24-hours-with-ipad</feedburner:origLink></entry>

<entry>
<title>How Many Ads Does It Take To Get To The Content?</title>
<id>http://www.heatxsink.com/entry/how-many-ads-does-it-take-to-get-to-the-content</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/mWOBzDestBM/how-many-ads-does-it-take-to-get-to-the-content" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-02T21:10:41Z</updated>
<published>2010-04-01T16:48:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
<a href="http://www.flickr.com/photos/heatxsink/4482132964/" title="Picture 26 by heatxsink, on Flickr"><img src="http://farm5.static.flickr.com/4033/4482132964_7c6b303278.jpg" width="500" height="426" alt="Picture 26" /></a>
</p>
<p>
I'm all about making money. However, this is straight up greed. Four ads? Really?
</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/mWOBzDestBM" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/how-many-ads-does-it-take-to-get-to-the-content</feedburner:origLink></entry>

<entry>
<title>Rest in Peace Ben Mok</title>
<id>http://www.heatxsink.com/entry/rest-in-peace-ben-mok</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/z65u0FWLGyw/rest-in-peace-ben-mok" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-04-14T10:10:11Z</updated>
<published>2010-03-24T02:11:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
<a href="http://www.flickr.com/photos/heatxsink/4459016722/" title="Ben Mok (Current) by heatxsink, on Flickr"><img src="http://farm3.static.flickr.com/2704/4459016722_38ab191981.jpg" width="500" height="376" alt="Ben Mok (Current)" /></a>
<br />
On March 23rd, 2010 at approximately 4:00PM Ben Mok passed away. He had just turned 35. He was a really good friend. He was hit by a drunk driver while riding his bicycle (his passion) in his homeland of Singapore on Sunday. [<a href="http://www.straitstimes.com/BreakingNews/Singapore/Story/STIStory_506151.html">link</a>]
</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/z65u0FWLGyw" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/rest-in-peace-ben-mok</feedburner:origLink></entry>

<entry>
<title>Ben Folds Does Chatroulette Live</title>
<id>http://www.heatxsink.com/entry/ben-folds-does-chatroulette-live</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/zB4iSZqYYD0/ben-folds-does-chatroulette-live" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-03-22T01:38:28Z</updated>
<published>2010-03-22T00:34:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/LfamTmY5REw&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://www.youtube.com/v/LfamTmY5REw&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="385" /></object>
<br /><br />
All I can say is I love <a href="http://www.benfolds.com/">Ben Folds</a>!
</p>
<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/zB4iSZqYYD0" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/ben-folds-does-chatroulette-live</feedburner:origLink></entry>

<entry>
<title>Backup and Restore with MySQL</title>
<id>http://www.heatxsink.com/entry/backup-and-restore-with-mysql</id>
<link href="http://feeds.heatxsink.com/~r/heatxsink/atom/~3/pBeQIR2BbpA/backup-and-restore-with-mysql" rel="alternate" />
<author><name>Nick Granado</name></author>
<updated>2010-02-24T08:53:02Z</updated>
<published>2010-02-25T06:32:00Z</published>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<p>There's a lot of ways to backup a MySQL database. I've had to look this up from time to time. And I have not found anyone take these scenarios and boil them down into a short concise guide. Enjoy.</p>

<h3>Backup</h3>

<p>The simple way of backing up a MySQL database.</p>
<pre class="snippet">
$ mysqldump -u [username] -p [password] [database_name] &gt; [backup_filename.sql]
</pre>

<p>What if you want to restore an existing database? You can add 'drop table' statements to your backup like so...</p>
<pre class="snippet">
$ mysqldump --add-drop-table -u [username] -p [password] [database_name] &gt; [backup_filename.sql]
</pre>

<p>What if you just wanted a table and not the whole database? Yes, you can do that too...</p>
<pre class="snippet">
$ mysqldump --add-drop-table -u [username] -p [password] [database_name] [table1 table2 ...] &gt; [backup_filename.sql]
</pre>

<p>More than one database to backup?</p>
<pre class="snippet">
$ mysqldump -u [username] -p [password] --databases [database1 database2 ...] &gt; [backup_filename.sql]
</pre>

<p>Need to backup all databases in a MySQL instance?</p>
<pre class="snippet">
$ mysqldump --all-databases &gt; [backup_filename.sql]
</pre>

<p>How about the database, but no data please. Coming right up!</p>
<pre class="snippet">
$ mysqldump --no-data --all-databases &gt; [backup_filename.sql]
</pre>

<h3>Automating Backups</h3>

<p>Need to automate your MySQL backup? There's a script for that...</p>
<pre class="snippet">
#!/bin/sh
date=`date -I`
mysqldump --all-databases | gzip &gt; /some/path/backup-db-name-$date.sql.gz 
</pre>

<h3>Restore</h3>

<p>The way to restore a MySQL database.</p>
<pre class="snippet">
$ mysql -u [username] -p [password] [database_name_to_restore] &lt; [backup_filename.sql]
</pre>



<xhtml:img xmlns:xhtml="http://www.w3.org/1999/xhtml" src="http://feeds.feedburner.com/~r/heatxsink/atom/~4/pBeQIR2BbpA" height="1" width="1" /></div></content>
<feedburner:origLink>http://www.heatxsink.com/entry/backup-and-restore-with-mysql</feedburner:origLink></entry>

</feed>
