<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Nerdlife</title>
	
	<link>http://nerdlife.net</link>
	<description>*Insert Witty Subtitle Here*</description>
	<lastBuildDate>Sun, 01 Aug 2010 21:25:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/nerdlife" /><feedburner:info uri="nerdlife" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>GazeHawk Launches!</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/uHJ5XspjugY/</link>
		<comments>http://nerdlife.net/gazehawk-launches/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 22:06:39 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=325</guid>
		<description><![CDATA[At least now I have a publicly know excuse for being busy!
http://techcrunch.com/2010/07/29/y-combinator-backed-gazehawk-heatmaps-with-web-cams/
Keep an eye on our blog at http://gazehawk.com/blog/ for some interesting technology/startup posts.
Time to go deal with my ever-growing inbox  .
]]></description>
			<content:encoded><![CDATA[<p>At least now I have a publicly know excuse for being busy!</p>
<p><a href="http://techcrunch.com/2010/07/29/y-combinator-backed-gazehawk-heatmaps-with-web-cams/">http://techcrunch.com/2010/07/29/y-combinator-backed-gazehawk-heatmaps-with-web-cams/</a></p>
<p>Keep an eye on our blog at <a href="http://gazehawk.com/blog/">http://gazehawk.com/blog/</a> for some interesting technology/startup posts.</p>
<p>Time to go deal with my ever-growing inbox <img src='http://nerdlife.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/uHJ5XspjugY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/gazehawk-launches/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://nerdlife.net/gazehawk-launches/</feedburner:origLink></item>
		<item>
		<title>The Worst Paragraph Ever Written</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/kuNYMADUeOo/</link>
		<comments>http://nerdlife.net/the-worst-paragraph-ever-written/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 11:31:15 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=323</guid>
		<description><![CDATA[Context: There&#8217;s an organization that sponsors Shabbat dinners.  It&#8217;s really awesome: they basically pay you to feed your friends.  That being said, they need a copywriter.  Here&#8217;s a paragraph in the email they sent confirming my sponsored dinner:
As of Monday, July 19th, the new NEXT Shabbat program will begin providing new NEXT [...]]]></description>
			<content:encoded><![CDATA[<p>Context: There&#8217;s an organization that sponsors Shabbat dinners.  It&#8217;s really awesome: they basically pay you to feed your friends.  That being said, they need a copywriter.  Here&#8217;s a paragraph in the email they sent confirming my sponsored dinner:</p>
<blockquote><p>As of Monday, July 19th, the new NEXT Shabbat program will begin providing new NEXT Shabbat&#8217;s with up to $14 per guest (maximum of 16 guests) for the first three meals a host registers after that date. After those three meals, hosts will receive up to $10 dollars per guest. As a returning NEXT Shabbat host, your meal-payment will be based on the number of meals you’ve held already. However, since you have a meal scheduled to take place between July 19th and August 19th, you will still receive $18 per-guest for that meal. Following that meal, if you’ve already held at least three meals, any meal registered after July 19th will only be eligible for a payment of $10 per guest. By joining with us as we make these changes to the program you will give many more people the opportunity to host and will enable thousands to participate in home-based Shabbat meals for the first time. If you’ve held less than three meals, any meal registered after July 19th will be eligible for a payment of up to $14 through your third meal. You can also see how many meals you have already hosted.</p></blockquote>
<p>As always apologies for the lack of updates: I promise there&#8217;s a short (but major) update coming very soon, followed by more frequent posting (there&#8217;s a reason I&#8217;ve been so quiet lately).</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/kuNYMADUeOo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/the-worst-paragraph-ever-written/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://nerdlife.net/the-worst-paragraph-ever-written/</feedburner:origLink></item>
		<item>
		<title>How to Dispose of a Hard Drive</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/SQa2ZK0ki-4/</link>
		<comments>http://nerdlife.net/how-to-dispose-of-a-hard-drive/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 01:50:40 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=319</guid>
		<description><![CDATA[In 5 easy steps:

Find hammer
Give up on finding hammer&#8230;grab pliers
Attack drive with pliers, destorying circuitry but leaving platters untouched
Cut finger, swear and bleed profusely on drive
Repeat steps 3 &#038; 4 until you realize that nobody cares enough about your data to read it directly from platters.  Toss drive in trash, go grab a band-aid

Tada!
]]></description>
			<content:encoded><![CDATA[<p>In 5 easy steps:</p>
<ol>
<li>Find hammer</li>
<li>Give up on finding hammer&#8230;grab pliers</li>
<li>Attack drive with pliers, destorying circuitry but leaving platters untouched</li>
<li>Cut finger, swear and bleed profusely on drive</li>
<li>Repeat steps 3 &#038; 4 until you realize that nobody cares enough about your data to read it directly from platters.  Toss drive in trash, go grab a band-aid</li>
</ol>
<p>Tada!</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/SQa2ZK0ki-4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/how-to-dispose-of-a-hard-drive/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://nerdlife.net/how-to-dispose-of-a-hard-drive/</feedburner:origLink></item>
		<item>
		<title>Diaspora’s Upfront Costs</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/XeOGKUWsGoE/</link>
		<comments>http://nerdlife.net/diasporas-upfront-costs/#comments</comments>
		<pubDate>Thu, 27 May 2010 03:08:55 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=307</guid>
		<description><![CDATA[This post on Hacker News got me thinking about the costs Dispora&#8217;s going to have receiving all of their money and fulfilling their promises, so I did a little digging.  The numbers below are estimates, but they should be fairly close to actual costs for these services (assuming no huge burst in donations over [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://news.ycombinator.com/item?id=1380942">This post on Hacker News</a> got me thinking about the costs <a href="http://www.kickstarter.com/projects/196017994/diaspora-the-personally-controlled-do-it-all-distr">Dispora</a>&#8217;s going to have receiving all of their money and fulfilling their promises, so I did a little digging.  The numbers below are estimates, but they should be fairly close to actual costs for these services (assuming no huge burst in donations over the next 6 days):</p>
<pre>
$ 5510 = $190k * 2.9% Amazon fees[1]
  1800 = 6k donations * $0.30 Amazon fees
  9500 = $190k * 5% for Kickstarter
  4150 = 5000 cds with jewel cases * $0.83 (random googling, I assume the "note from our team" will be on the jewel case insert)
  1380 = 400 sheets of stickers * $3.45 (zazzle, 20 sheet of stickers, 2 stickers per person)
 10200 = 3000 shirts * $3.40 (customink, Gildan 50/50 1 color on white front only)
  9000 = 3000 postage &#038; packaging for shirts + stickers * $3
  2000 = 2000 postage &#038; packaging for just stickers * $1
  1200 = "Turnkey hosting" for 600 people[2]
  2800 = 4 new computers*$700
======
$47540</pre>
<p><small>[1] I&#8217;m not sure if Kickstarter gets a bulk discount here, or if it&#8217;s Dispora&#8217;s account history, so a volume discount may apply.  I also assume all transactions are billed at the $10+ rate (2.9%) rather than the < $10 rate (5%) for simplicity.<br />
[2] Turnkey hosting and phone support are hard to estimate...it may be more if they need to pay for phone support, but I think this is a reasonable number.  I'm also including project hosting costs.  I know they say plenty of hosting companies have offered their services, but you can't guarantee that will be there.</small></p>
<p>Keep in mind that this misses three big points:</p>
<ol>
<li>Declined credit cards &#038; canceled/fraudulent donations &#8211; I have no clue what the expected amount of these is</li>
<li>People who requested a gift for donating who never give their contact info</li>
<li>The huge overhead for packing/sending all of these items, though I imagine a day of pizza and soda for volunteers can get all of them packed (the con I used to help run had similar &#8220;mailing parties&#8221; that were fairly effective)</li>
</ol>
<p>With that in mind you&#8217;re looking at about 25% of the funding going toward transaction fees and fulfilling the rewards.  This leaves around $142,000 left for them, which is still plenty of money.  Though I don&#8217;t want to think about what an accountant would say about this money and how much he would charge to make it legitimate.</p>
<p>Don&#8217;t get me wrong: I think Diaspora is a great idea and I&#8217;d love to see it succeed, but I wonder if the founders considered the logistical overhead to this whole thing.  Granted, this would have been smaller had they only raised $10k, but it&#8217;s still a big task to undertake.  I hope they&#8217;re ready for it and they don&#8217;t let us down.</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/XeOGKUWsGoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/diasporas-upfront-costs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://nerdlife.net/diasporas-upfront-costs/</feedburner:origLink></item>
		<item>
		<title>Boston WordPress Meetup Example Code</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/Y_hlFuRIQYc/</link>
		<comments>http://nerdlife.net/boston-wordpress-meetup-example-code/#comments</comments>
		<pubDate>Thu, 27 May 2010 02:01:50 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=289</guid>
		<description><![CDATA[As promised here&#8217;s the example code from the meetup I gave last Monday.  It&#8217;s fairly small, so I only describe what it does briefly in the top comment.  Feel free to use it how you wish (though if you make a lot of money off of it you owe me a t-shirt):

Example 1: [...]]]></description>
			<content:encoded><![CDATA[<p>As promised here&#8217;s the example code from the meetup I gave last Monday.  It&#8217;s fairly small, so I only describe what it does briefly in the top comment.  Feel free to use it how you wish (though if you make a lot of money off of it you owe me a t-shirt):</p>
<p><span id="more-289"></span></p>
<h5>Example 1: Erroring out on install</h5>
<pre><code>register_activation_hook(__FILE__, 'bostonwp_install_error');

if('error_scrape' == $_GET['action'] &#038;&#038; basename($_SERVER['PHP_SELF']) == 'plugins.php') {
    echo '&lt;pre>' . get_option('bostonwp_activate_error') . '&lt;/pre>';
    delete_option('bostonwp_activate_error');
    deactivate_plugins($_GET['plugin']);
    die();
}

function bostonwp_install_error($error = false) {
    if(!$error) {
        $error = 'Generic Error Occurred';
    }
    add_option('bostonwp_activate_error', $error);
    //trigger a fatal error
    trigger_error('', E_USER_ERROR);
}</code></pre>
<p></p>
<h5>Example 2: Updating your DB structure</h5>
<pre><code>// http://codex.wordpress.org/Creating_Tables_with_Plugins

define('BOSTONWP_DB_VERSION', '1.0');

register_activation_hook(__FILE__, 'bostonwp_install');

$wpdb->bostonwp = $wpdb->prefix . 'bostonwp';

function bostonwp_install() {
    global $wpdb;

    $installed_ver = get_option( 'bostonwp_db_version' );

    $sql = 'CREATE TABLE ' . $wpdb->bostonwp . ' (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        time bigint(11) DEFAULT 0 NOT NULL,
        name tinytext NOT NULL,
        text text NOT NULL,
        url VARCHAR(55) NOT NULL,
        UNIQUE KEY id (id)
        );';

    if($wpdb->get_var('show tables like "' . $wpdb->bostonwp . '"') != $wpdb->bostonwp) {
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);

        $welcome_name = 'Mr. Wordpress';
        $welcome_text = 'Congratulations, you just completed the installation!';

        $insert = 'INSERT INTO ' . $wpdb->bostonwp .
            ' (time, name, text) ' .
            'VALUES (' . time() . ',"' . $wpdb->escape($welcome_name) . '","' . $wpdb->escape($welcome_text) . '")"';

        $results = $wpdb->query( $insert );

        add_option("bostonwp_db_version", BOSTONWP_DB_VERSION);
    }
    elseif( $installed_ver != BOSTONWP_DB_VERSION ) {
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);

        update_option( "bostonwp_db_version", BOSTONWP_DB_VERSION );
    }
}</code></pre>
<p></p>
<h5>Example 3: Adding admin menus</h5>
<pre><code>// http://codex.wordpress.org/Adding_Administration_Menus

add_action('admin_menu', 'bostonwp_menu');
function bostonwp_menu() {
    add_posts_page('My Page', 'My Page', 'manage_categories', 'bostonwp_page', 'bostonwp_dostuff');
}

function bostonwp_dostuff() {
?>
    &lt;div class="wrap">
        &lt;?php if(function_exists('screen_icon')) screen_icon(); ?>
        &lt;h2>My Boston WP Page&lt;/h2>
    &lt;/div>
&lt;?php
}</code></pre>
<p></p>
<h5>Example 4: Adding meta boxes to posts</h5>
<pre><code>// http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html

add_action('add_meta_boxes_post', 'bostonwp_box');
add_action('save_post', 'bostonwp_save');
add_action('delete_post', 'bostonwp_delete');

function bostonwp_box($post) {
    // http://codex.wordpress.org/Function_Reference/add_meta_box
    add_meta_box('bostonwp', __('Boston WP'), 'bostonwp_meta_box', 'post', 'side');
}

function bostonwp_meta_box() {
    global $post;
    $val = get_post_meta($post->ID, 'bostonwp', true);

    // Use nonce for verification
    echo '&lt;input type="hidden" name="bostonwp_nonce" id="bostonwp_nonce" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

    // The actual fields for data entry
    echo '&lt;input type="checkbox" name="bostonwp" value="1" ' . ($val ? ' checked="checked" ' : '') . ' />';
    echo '&lt;label for="bostonwp">' . __('There Is Cake!') . '&lt;/label> ';
}

function bostonwp_save($id) {
    // verify nonce
    if ($_POST['action'] != 'inline-save' &#038;&#038; !wp_verify_nonce($_POST['bostonwp_nonce'], plugin_basename(__FILE__))) {
        return $id;
    }

    // check autosave
    if (defined('DOING_AUTOSAVE') &#038;&#038; DOING_AUTOSAVE) {
        return $id;
    }

    update_post_meta($id, 'bostonwp', $_POST['bostonwp']);
}

function bostonwp_delete($id) {
    delete_post_meta($id, 'bostonwp');
}</code></pre>
<p></p>
<h5>Example 5: Adding columns to post list</h5>
<pre><code>add_filter('manage_posts_columns', 'bostonwp_posts_column');
add_action('manage_posts_custom_column', 'bostonwp_manage_column', 10, 2);

function bostonwp_posts_column($cols) {
    $cols['bostonwp'] = __('Boston WP');
    return $cols;
}

function bostonwp_manage_column($name, $id) {
    if($name != 'bostonwp') {
        return;
    }
    $cake = get_post_meta($id, 'bostonwp', true);
    if($cake) {
        echo 'There is cake!';
        $cake = 1;
    }
    else {
        echo 'The cake is a lie!';
        $cake = 0;
    }
    echo '&lt;div id="inline_' . $id . '_bostonwp" class="hidden">' . $cake . '&lt;/div>';
}</code></pre>
<p></p>
<h5>Example 6: Expanding Quick Edit</h5>
<pre><code>add_action('quick_edit_custom_box', 'bostonwp_posts_custom_box', 10, 2);
add_action('admin_head-edit.php', 'bostonwp_add_script');

function bostonwp_posts_custom_box($col, $type) {
    if($col != 'bostonwp' || $type != 'post') {
        return;
    }
?>
&lt;fieldset class="inline-edit-col-right">&lt;div class="inline-edit-col">
    &lt;div class="inline-edit-group">
        &lt;label class="alignleft">
            &lt;input type="checkbox" value="1" name="bostonwp" id="bostonwp_check">
            &lt;span class="checkbox-title">This Post Has Cake&lt;/span>
        &lt;/label>
    &lt;/div>
&lt;/fieldset>
&lt;?php
}

function bostonwp_add_script() {
?>
&lt;script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('a.editinline').live('click', function() {
        var id = inlineEditPost.getId(this);
        var val = parseInt(jQuery('#inline_' + id + '_bostonwp').text());
        jQuery('#bostonwp_check').attr('checked', !!val);
    });
});
&lt;/script>
&lt;?php
}
</code></pre>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/Y_hlFuRIQYc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/boston-wordpress-meetup-example-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nerdlife.net/boston-wordpress-meetup-example-code/</feedburner:origLink></item>
		<item>
		<title>On To Bigger Things</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/w25IothUmLI/</link>
		<comments>http://nerdlife.net/on-to-bigger-things/#comments</comments>
		<pubDate>Tue, 04 May 2010 01:20:56 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=282</guid>
		<description><![CDATA[Alternative title: OMGWTF I just quit my job!
Alternative alternative title: A better way to resign from a company
That&#8217;s right.  I just gave notice that I&#8217;m leaving a great job with awesome coworkers and interesting problems.  I&#8217;m trading all of that for the privilege of moving across the country, not taking a salary, and [...]]]></description>
			<content:encoded><![CDATA[<p>Alternative title: OMGWTF I just quit my job!<br />
Alternative alternative title: <a href="http://techcrunch.com/2010/04/24/how-not-to-handle-a-resignation-gracefully/">A better way to resign from a company</a></p>
<p>That&#8217;s right.  I just gave notice that I&#8217;m leaving a great job with awesome coworkers and interesting problems.  I&#8217;m trading all of that for the privilege of moving across the country, not taking a salary, and working 80 hours a week.  If I&#8217;m lucky, I&#8217;ll get to continue doing this for a long time, rather than finding another job that pays actual money.</p>
<p>Shorter explanation: I&#8217;m moving to Silicon Valley to start a business.</p>
<p>Not too much to say right now about the startup.  I got a funding offer I couldn&#8217;t turn down for an idea I really believe in.  Expect more posts in the future, since they valley always does inspire more blogging in me.  For now I don&#8217;t want to say too much about the idea itself, since we&#8217;re still fleshing a lot of things out, but I promise there will be some awesome posts about it in the future.</p>
<p>However, there is something to say about my current employer, TripAdvisor.  Shortly put, they&#8217;ve been amazing.  I got to work on awesome features (like mobile flight search, which just launched today&#8230;tripadvisor.com from a mobile phone).  And not just work on them but have a major say in their direction.  My coworkers were a lot of fun, and my boss was flexible and understanding.</p>
<p>I knew before I graduated that I would eventually leave my first employer to start a business (though I didn&#8217;t think it would be so soon).  TripAdvisor made that an incredibly hard thing to do, which I commend them for.  Hopefully I&#8217;ll be hiring soon, but until I open a Boston office, definitely <a href="http://www.tripadvisor.com/careers/jobs">apply for a position with them</a>.  If you&#8217;d like a contact within the company (not necessary, the engineering HR manager is a solid guy and will get your resume to the right place), <a href="http://nerdlife.net/about/">just ask</a>.</p>
<p>I&#8217;ll be out in Mountain View in early June.  See you on TechCrunch <img src='http://nerdlife.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/w25IothUmLI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/on-to-bigger-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nerdlife.net/on-to-bigger-things/</feedburner:origLink></item>
		<item>
		<title>Building a C++ XPCOM Component in Windows</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/zSfl4cRKwKc/</link>
		<comments>http://nerdlife.net/building-a-c-xpcom-component-in-windows/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 20:47:58 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[XPCOM]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=259</guid>
		<description><![CDATA[I&#8217;ve been teaching myself to write Firefox extensions for the last few weeks, and became interested in XPCOM components.  Unfortunately, I couldn&#8217;t find a good (and recent) summary of them, and had to spend 3 or 4 days cobbling together various tutorials, so I figured it&#8217;s time to write one.
What is XPCOM?
XPCOM is a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been teaching myself to write Firefox extensions for the last few weeks, and became interested in XPCOM components.  Unfortunately, I couldn&#8217;t find a good (and recent) summary of them, and had to spend 3 or 4 days cobbling together various tutorials, so I figured it&#8217;s time to write one.</p>
<h4>What is XPCOM?</h4>
<p>XPCOM is a language-agnostic communication platform used in Mozilla products (and some other random pieces of software) to allow code (specifically extensions) to be written in a wide variety of languages.</p>
<h4>Why would I want to use XPCOM?</h4>
<p>There are two ways to &#8220;use&#8221; XPCOM.  First, you can call functions through XPCOM.  For example, the Firefox bookmarks service uses an XPCOM interface.  So in order to interact with this service from Javascript you would do something like:</p>
<pre>var bmarks = Components.classes["@mozilla.org/browser/bookmarks-service;1"].getService();
bmarks.QueryInterface(Components.interfaces.nsIBookmarksService);
bmarks.addBookmarkImmediately("http://www.mozilla.org","Mozilla",0,null);</pre>
<p>There are plenty of tutorials on doing this as it is the more common use for XPCOM, so I won&#8217;t go into any detail on it here.</p>
<p>The second way is to write an XPCOM service.  That is what this tutorial covers. Sometimes you need extra functionality, speed, or just want to tie into some library that requires a different language.  Most commonly this is C++, but there is also <a href="https://developer.mozilla.org/en/JavaXPCOM">JavaXPCOM</a> and <a href="https://developer.mozilla.org/en/PyXPCOM">PyXPCOM</a> (and probably a few others).  I&#8217;ll be talking about C++, since it&#8217;s what I needed for my project.</p>
<h4>Warnings</h4>
<ol>
<li>Before you trudge through this: <b>you most likely are in the wrong place</b>.  Firefox extensions are usually all Javascript.  If you can use JS to do what you want, <b>stop now</b>.  There is no need to go through the complexity of an XPCOM component when you can just use JS.  Go read <a href="https://developer.mozilla.org/en/Extensions">a tutorial about writing extensions</a> and get to work.</li>
<li>There is something called <a href="https://developer.mozilla.org/en/JavaScript_code_modules/ctypes.jsm">ctypes</a> coming to FF 3.7 that may make doing this a lot easier.  I haven&#8217;t touched this at all, but it may be worth considering if you can wait for the functionality and only need to tie into a particular DLL for some functionality.  Long story short, XPCOM may become the more difficult way to call C++ functions from FF extensions.</li>
</ol>
<h4>My Setup</h4>
<ul>
<li>Windows 7</li>
<li>Visual C++ Express 2008 (free from <a href="http://www.microsoft.com/express/Downloads/#2008-Visual-CPP">Microsoft&#8217;s website</a>)</li>
<li>Firefox 3.6 (Gecko 1.9.2)</li>
<li>A UUID or GUID generator.  This is a unique (read: random) ID that identifies your app to the world.  Windows and Linux have tools to generate this (guidgen &#038; uuidgen, respectively), or you can find various online generators (<a href="https://developer.mozilla.org/en/Generating_GUIDs">Mozilla links to several</a>).  I recommend <a href="http://mozilla.pettay.fi/cgi-bin/mozuuid.pl">this one</a> since it gives you the C++ encoded form too, which you will need.  You need two different UUIDs: one for your interface and one for your component.</li>
<li>Ability to read and understand C++</li>
</ul>
<h4>Sample Code</h4>
<p>If you don&#8217;t want to go through the tutorial and just want everything to work, then download <a href="http://nerdlife.net/wp-content/uploads/2010/02/mycomponent.zip">this sample code</a>.  Just follow step #1 of the tutorial, then make sure your Gecko SDK directory is set right in the build step, and you can breeze on by most of this article.</p>
<h4>The Tutorial</h4>
<p>This is mostly paraphrased from <a href="http://www.iosart.com/firefox/xpcom/">Alex Sirota&#8217;s great tutorial</a>, but it hasn&#8217;t been updated since 2005 and is a bit outdated.  This new one should work out of the box for FF 3.6.</p>
<p>This tutorial will create a component called <code>MyComponent</code> with one function: <code>Add</code>, which will take 2 numbers and, surprisingly, return the sum.</p>
<ol>
<li><a href="https://developer.mozilla.org/en/Gecko_SDK">Download the Gecko SDK</a> for your version of Firefox.  I used 1.9.2 for FF 3.6.</li>
<li>Create an idl file &#8211; <code>IMyComponent.idl</code>, with the following (replacing <code>***IUID***</code> with your interface UUID):
<pre>#include "nsISupports.idl"

[scriptable, uuid(***IUID***)]
interface IMyComponent : nsISupports
{
  long Add(in long a, in long b);
};
</pre>
<p>This file is a language-agnostic interface definition which you can read more about <a href="http://www.mozilla.org/scriptable/xpidl/idl-authors-guide/index.html">here</a>.</li>
<li>Generate the interface header and typelib files out of the interface definition file.  Assuming you extracted the Gecko SDK to <code>C:\xulrunner-sdk\</code>, run the following commands (from the directory you saved <code>IMyComponent.idl</code> to):
<pre>
C:\xulrunner-sdk\sdk\bin\xpidl.exe -m header -I C:\xulrunner-sdk\idl .\IMyComponent.idl
C:\xulrunner-sdk\sdk\bin\xpidl.exe -m typelib -I C:\xulrunner-sdk\idl .\IMyComponent.idl
</pre>
<p>These will create <code>IMyComponent.h</code> and <code>IMyComponent.xpt,</code> respectively.</li>
<li><code>IMyComponent.h</code> has two snippits of code that you can use for the next two files.  Everything between <code>/* Header file */</code> and <code>/* Implementation file */</code> can be used for <code>MyComponent.h</code>:
<ol>
<li>Start by inserting double inclusion protection code and the right include:
<pre>#ifndef _MY_COMPONENT_H_
#define _MY_COMPONENT_H_

#include "IMyComponent.h"</pre>
</li>
<li>Add the following lines, which define your component name, contract ID, and CUID (where ***CUID*** is the C++-style component UUID, of the form { 0&#215;12345678, 0&#215;9abc, 0xdef0, { 0&#215;12, 0&#215;34, 0&#215;56, 0&#215;78, 0&#215;9a, 0xbc, 0xde, 0xf0 } }):
<pre>#define MY_COMPONENT_CONTRACTID "@example.com/XPCOMSample/MyComponent;1"
#define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"
#define MY_COMPONENT_CID ***CUID***</pre>
</li>
<li>Copy in the snippet from <code>IMyComponent.h</code>, replacing all the instances of <code>_MYCLASS_</code> with the name of your component (<code>MyComponent</code>).</li>
<li>Finish off the double inclusion protection code with <code>#endif //_MY_COMPONENT_H_</code></li>
</ol>
</li>
<li>Everything between <code>/* Implementation file */</code> and <code>/* End of implementation class template. */</code> can be used for <code>MyComponent.cpp</code>:
<ol>
<li>Start by inserting the right include:
<pre>#include "MyComponent.h"</pre>
</li>
<li>Copy in the snippet from <code>IMyComponent.h</code>, replacing all the instances of <code>_MYCLASS_</code> with the name of your component (<code>MyComponent</code>).</li>
<li>Add some implementation to the <code>Add</code> method.  I replaced <code>return NS_ERROR_NOT_IMPLEMENTED;</code> with
<pre>	*_retval = a + b;
return NS_OK;</pre>
</li>
</ol>
</li>
<li>Create your module definitions files:
<pre>#include "nsIGenericFactory.h"
#include "MyComponent.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)

static nsModuleComponentInfo components[] =
{
    {
       MY_COMPONENT_CLASSNAME,
       MY_COMPONENT_CID,
       MY_COMPONENT_CONTRACTID,
       MyComponentConstructor,
    }
};

NS_IMPL_NSGETMODULE("MyComponentsModule", components) </pre>
</ol>
<p>You now have all of the files needed to build an XPCOM component:</p>
<pre>IMyComponent.h
IMyComponent.idl
IMyComponent.xpt
MyComponent.cpp
MyComponent.h
MyComponentModule.cpp</pre>
<p>Now comes the hard part: getting the damn thing to build.</p>
<h4>Building the code</h4>
<p>Ok, it&#8217;s actually not hard since I&#8217;ve done most of the legwork for you.  Assuming you&#8217;re using Visual C++ 2008 here are the settings you need (again assuming <code>C:\xulrunner-sdk</code> is where your Gecko SDK is).  In <code>Project->Properties</code>:</p>
<pre>Configuration Properties
  General
    Configuration Type: .dll
  C/C++
    General
      Additional Include Directories: C:\xulrunner-sdk\include
    Preprocessor
      Preprocessor Definitions: XP_WIN;XP_WIN32;XPCOM_GLUE_USE_NSPR
  Linker
    General
      Additional Library Directories: C:\xulrunner-sdk\lib
    Input
      Additional Dependencies: nspr4.lib xpcom.lib xpcomglue_s.lib</pre>
<p>If you put the idl file into your project, be sure to mark it &#8220;Excluded from Build&#8221; in its properties&#8230;we don&#8217;t want VS touching it.</p>
<p>Cross your fingers, pray to whatever deity you believe in, and hit the build button.  If it didn&#8217;t work let me know why in the comments and I&#8217;ll try to build a troubleshooting section.</p>
<h4>Installing/Testing the Code</h4>
<ol>
<li>Copy two files to <code>C:\Program Files\Mozilla Firefox\components</code>:
<ul>
<li>The DLL the build generated</li>
<li><code>IMyComponent.xpt</code></li>
</ul>
</li>
<li>Normally, if this was installed as part of an extension, it would automatically search this directory and find these files.  But now we have to force a refresh.  Delete <code>xpti.dat.</code> and <code>compreg.dat</code> from your <a href="http://support.mozilla.com/en-US/kb/Profiles#Where_is_my_profile_stored_">profile directory</a> (FF will regenerate them on next restart)</li>
<li>Close Firefox and open it with this test file (<code>MyComponentTest.html</code> in the sample code):
<pre>&lt;html>
&lt;script type="text/javascript">
function MyComponentTestGo() {
	try {
		// normally Firefox extensions implicitly have XPCOM privileges, but since this is a file we have to request it.
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		const cid = "@example.com/XPCOMSample/MyComponent;1";
		obj = Components.classes[cid].createInstance();
		// bind the instance we just created to our interface
		obj = obj.QueryInterface(Components.interfaces.IMyComponent);
	} catch (err) {
		alert(err);
		return;
	}
	var res = obj.Add(3, 4);
	alert('Performing 3+4. Returned ' + res + '.');
}
&lt;/script>
&lt;body>
&lt;button onclick="MyComponentTestGo();">Go&lt;/button>
&lt;/body>
&lt;/html></pre>
<li>One last time: cross your fingers, pray to whatever deity you believe in, and hit the Go button.  If it didn&#8217;t work let me know why in the comments and I&#8217;ll try to build a troubleshooting section.</p>
</ol>
<p>Hopefully this clears up what looked like a lot of confusion to me.  I will keep this updated to the best of my abilities and hopefully it will continue to be useful for a long time.</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/zSfl4cRKwKc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/building-a-c-xpcom-component-in-windows/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		<feedburner:origLink>http://nerdlife.net/building-a-c-xpcom-component-in-windows/</feedburner:origLink></item>
		<item>
		<title>Yet Another Reason Not to Use GoDaddy</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/z1MLJ758UCk/</link>
		<comments>http://nerdlife.net/yet-another-reason-not-to-use-godaddy/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 17:50:08 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=253</guid>
		<description><![CDATA[Update: It seems GoDaddy fixed this issue.  Glad they fixed it, though I still can&#8217;t say I recommend them.  Thanks Sean for pointing that out to me.
I recently gave a talk on WordPress plugins at the Boston WordPress Meetup (slides are online on their meetup.com page).  During this talk the question came [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update:</b> It seems GoDaddy <a href="http://help.godaddy.com/article/4764">fixed this issue</a>.  Glad they fixed it, though I still can&#8217;t say I recommend them.  Thanks Sean for pointing that out to me.</p>
<p>I recently gave a talk on WordPress plugins at the Boston WordPress Meetup (slides are online on <a href="http://www.meetup.com/boston-wordpress-meetup/files/">their meetup.com page</a>).  During this talk the question came up of which webhost to use.  Everyone has their own recommendation of webhost, but the one host that was universally panned is GoDaddy.</p>
<p>I&#8217;ve long since moved on from shared webhosts on to VPSes (I&#8217;ve been using VPSLink since they started.  Use <a href="http://vpslink.com/?ref=D2NF81">this link</a> to get 10% off for life and snag me a nice referral bonus <img src='http://nerdlife.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ), but GoDaddy was my first web host, and since then I have heard nothing but terrible things about their marketing practices, upsells, and other sketchiness.  But they will show you videos of women taking their clothes off on their website, which is great if you&#8217;re into that sort of stuff, but not what I need from a webhost.</p>
<p>But until recently I never discovered anything actually wrong with their hosting service&#8230;it worked, and while it was cheap, they at least delivered what you paid for (though granted, you&#8217;re not paying or getting a lot).  Yesterday, while looking through some code for a GoDaddy site, I discovered something painfully bad with their service that makes them a terrible idea for any ecommerce site.</p>
<p>It seems GoDaddy doesn&#8217;t allow outgoing connections from their shared hosting packages.  So, for example, you can&#8217;t connect to authorize.net or paypal.com from your server.  How do they recommend you accept payments?  Send it through some unsecured proxy they have.</p>
<p>That&#8217;s right, GoDaddy is actually telling people to send credit card information to another server in unsecured plaintext.  They then forward it along and send you the response.  There are 2 things wrong with this.</p>
<ol>
<li>Man in the middle attacks up the wazoo.  Not only can someone possible get in between the proxy and your server, but who knows whether or not the proxy requires valid certificates.  If not then the entire workflow is vulnerable.</li>
<li>There&#8217;s a now a single point of failure for all of that hosting.  If that server is compromised, all those sites get compromised too.  This is a huge risk.</li>
</ol>
<p>If I were issuing merchant accounts and knew about this, I wouldn&#8217;t accept accounts from anyone hosted with GoDaddy.  There are very few reasons for GoDaddy to be doing this.  The only one I can think of is preventing the spread of website worms that use holes in website scripts.  This is a pretty lame reason to lock websites into their own box, and there are much better ways to stop this.</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/z1MLJ758UCk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/yet-another-reason-not-to-use-godaddy/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://nerdlife.net/yet-another-reason-not-to-use-godaddy/</feedburner:origLink></item>
		<item>
		<title>Speaking at Boston WordPress Meetup Tonight</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/O45CMLa4-3Y/</link>
		<comments>http://nerdlife.net/speaking-at-boston-wordpress-meetup-tonight/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 04:20:30 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=251</guid>
		<description><![CDATA[Totally forgot to post this, but I&#8217;ll be the speaker at tonight&#8217;s (Monday July 27) Boston WordPress Meetup at Microsoft&#8217;s New England R&#038;D Center (1 Memorial Dr in Cambridge).  If you&#8217;re interested in hearing about WordPress plugins, or WordPress in general, feel free to show up.  Should be a blast!
I&#8217;ll post my slide [...]]]></description>
			<content:encoded><![CDATA[<p>Totally forgot to post this, but I&#8217;ll be the speaker at tonight&#8217;s (Monday July 27) <a href="http://www.meetup.com/boston-wordpress-meetup/">Boston WordPress Meetup</a> at Microsoft&#8217;s New England R&#038;D Center (1 Memorial Dr in Cambridge).  If you&#8217;re interested in hearing about WordPress plugins, or WordPress in general, feel free to show up.  Should be a blast!</p>
<p>I&#8217;ll post my slide deck after the presentation.</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/O45CMLa4-3Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/speaking-at-boston-wordpress-meetup-tonight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nerdlife.net/speaking-at-boston-wordpress-meetup-tonight/</feedburner:origLink></item>
		<item>
		<title>On Spriting and Website Build Processes</title>
		<link>http://feedproxy.google.com/~r/nerdlife/~3/gSGuj2OEOME/</link>
		<comments>http://nerdlife.net/on-spriting-and-website-build-processes/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 06:11:06 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://nerdlife.net/?p=243</guid>
		<description><![CDATA[Ryan, my mentor from when I was at MoCo, wrote an excellent article on spriting a few days ago.  Man, I miss all the good conversations&#8230;that&#8217;s what I get for not subscribing to the webdev feed.  That&#8217;s all changed now.
I have an interesting history with spriting.  For both of my internships (Mozilla [...]]]></description>
			<content:encoded><![CDATA[<p>Ryan, my mentor from when I was at MoCo, wrote an excellent article on <a href="http://blog.mozilla.com/webdev/2009/03/27/css-spriting-tips/">spriting</a> a few days ago.  Man, I miss all the good conversations&#8230;that&#8217;s what I get for not subscribing to the webdev feed.  That&#8217;s all changed now.</p>
<p>I have an interesting history with spriting.  For both of my internships (Mozilla and Yahoo), one of my first projects was to sprite sites (<a href="http://addons.mozilla.org">AMO</a> &#038; <a href="http://realestate.yahoo.com">Yahoo! Real Estate</a>, respectively).  AMO is still using my work (for now), and YRE long ago gave up on rounded corners, and have few icons now, so spriting is more or less useless for them now.</p>
<p>I guess that qualifies me to weigh in a bit.  I&#8217;m not going to talk about the memory usage or anything on the client-side past delivery for two reasons.  First: size in RAM has a tiny impact on page-loads compared to downloading for most users.  Second: I&#8217;m horrible unqualified to talk about how web browsers load and store images in ram.  Not my field.</p>
<p>There are some issues (many fixable) with spriting:</p>
<ul>
<li>In both instances of spriting I got an email a few months after I left the company asking me where my source sprite file was located.  Once it was due to me not putting the file in the right place, but the fact still remains that a source sprite file is one more thing to lose, and losing it is pretty annoying.</li>
<li>Not everyone knows how to compress images properly.  If you do it wrong, you&#8217;ll end up with a huge PNG file that is worse than a bunch of small files.</li>
<li>Spriting removes any connection between CSS styles and the images they are associated with.  If I want to know what a class with a background image looks like, I have to either find a reference to it on the site, or figure out where the hell -123px -72px is.  It&#8217;s more or less obfuscating your CSS.</li>
<li>repeat-x or repeat-y images need to span the whole width/height of the sprite&#8230;they should have their own sprite files (if you have enough of them)</li>
<li>Like Ryan said, images that are supposed to be near the left of an element (i.e. they need an arbitrary amount of space to the right of them) should be at the right side of the sprite.  This makes an internationalized site that supports right-to-left text (an insanely difficult thing to achieve, and something which many MoCo sites do impressively well) much more difficult.  It&#8217;s very frustrating to discover halfway through that your sprites show up wrong in RTL.  Not many sites need to worry about this, but it&#8217;s annoying if you do.</li>
</ul>
<p>With that being said, spriting can be useful when done properly.  A very good example is how Yahoo Mail sprites.  They group similarly-size things in a file.  They have an <a href="http://mail.yimg.com/a/i/us/pim/pimstrip_22.png">icon file</a>, a <a href="http://mail.yimg.com/a/i/us/pim/th/el/shared/rcstrip_blue_05.png">rounded corners file</a>, etc.  This makes things easier to manage, but still suffers from some of the above issues.</p>
<p>I don&#8217;t know how Yahoo&#8217;s build process works, but to make sprites worth it I would propose some kind of CSS build step.  Ideally all the developer would have to do is specify which images are displayed which ways (whether there needs to be whitespace to the left, right, top, or bottom), and the system will build the sprite and generate a complied CSS file that is minimized and concatenated.</p>
<p>AMO&#8217;s <a href="http://svn.mozilla.org/addons/trunk/bin/build.py">build process</a> got halfway there.  It was originally a shell script written by yours truly, converted to python by <a href="http://fredericiana.com/">FWenzel</a>.  The shell script is described <a href="https://wiki.mozilla.org/Update:Build_Process">here</a> (the python script is essentially the same).  It concatenates a bunch of files, compresses them with <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>, and creates a PHP file with the current revision numbers (to append to the URL for <a href="http://developer.yahoo.net/blog/archives/2007/05/high_performanc_2.html">long expires headers</a>).  Pretty standard web build system.</p>
<p>I&#8217;d really love to see a system that also parses out background*: rows with comments at the end (identifying what type of spriting should be done), places them, replaces the URL, and adds a background-position.  That, combined with AMO&#8217;s build process, would allow an algorithm to determine what&#8217;s best for download times vs. memory usage.</p>
<p>The best part: an automated system would easily allow bucket tests on load times based on different sprite files.  Now wouldn&#8217;t that be useful?</p>
<img src="http://feeds.feedburner.com/~r/nerdlife/~4/gSGuj2OEOME" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nerdlife.net/on-spriting-and-website-build-processes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://nerdlife.net/on-spriting-and-website-build-processes/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.256 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-08-31 15:02:31 -->
