<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>I Prefer Jim</title>
	
	<link>http://www.ipreferjim.com</link>
	<description>Developer James Schubert shares his code and his thoughts.</description>
	<lastBuildDate>Sat, 04 Feb 2012 00:20:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ipreferjim" /><feedburner:info uri="ipreferjim" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nd/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nd/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/ipreferjim" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fipreferjim" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>words.pl: slogan word generator</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/zQ0CWLeoz4s/</link>
		<comments>http://www.ipreferjim.com/2012/02/words-pl-slogan-word-generator/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 00:20:04 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=762</guid>
		<description><![CDATA[About a year ago, I was really into playing this game online where you were given a single sentence and you had to use the letters in that sentence to make up as many words as possible. The longer the word, the higher the points. Creating a script may be considered cheating if you're in [...]]]></description>
			<content:encoded><![CDATA[<p>About a year ago, I was really into playing this game online where you were given a single sentence and you had to use the letters in that sentence to make up as many words as possible.  The longer the word, the higher the points.</p>
<p>Creating a script <em>may</em> be considered cheating if you're in it for money.  If you're in it for fun, script away.  That's what I always say.</p>
<p>Here's the gist of it:<br />
<script src="https://gist.github.com/1733871.js"> </script></p>
<pre class="brush: perl; collapse: true; light: false; title: ; toolbar: true; notranslate">
#!/usr/bin/env perl
# words.pl: Find all possible slogan words from a single sentence.
use strict; $|++;

@ARGV == 2 or die &quot;usage: $0 input_file output_file 'sentence'\n&quot;;
my ($infile, $outfile, $sentence) = @ARGV;
$sentence = $sentence || 'how much wood could a woodchuck chuck';

open INPUT, &quot;&lt; $infile&quot; or die $!;
open OUTPUT, &quot;&gt; $outfile&quot; or die $!;

my $stdout = select STDOUT;
$| = 1;
select $stdout;

my %sentence_letters;
my $stmp = $sentence;
$sentence_letters{$&amp;}++ while($stmp =~ s/[a-z]//);

print &quot;Using the sentence '$sentence'\n&quot;;
print &quot;Found the following letters:\n&quot;;
print &quot;\t$_ - &quot;. $sentence_letters{$_} .&quot;\n&quot; foreach(sort(keys %sentence_letters));
print &quot;Processing $infile for slogan words\n&quot;;

my $count = 0;
my @indicators = qw{\ / | .};
LINE: while(&lt;INPUT&gt;) {
    my $word = $_;
    my $tmp = $word;
    next LINE if($word =~ /['\&amp;\d]/);
    my %word_letters;
    $word_letters{$&amp;}++ while($tmp =~ s/[a-z]//);

    foreach(keys %word_letters) {
        next LINE if ($word_letters{$_} &gt; $sentence_letters{$_});
    }
    print OUTPUT $word;

    my $word_len = length($word);
    open WORD_LEN_OUTPUT, &quot;&gt;&gt; $outfile.$word_len&quot;;
    print WORD_LEN_OUTPUT $word;

    print $indicators[++$count % 4], &quot;\r&quot;;
}

print &quot;\nDone.\nView $outfile.* for words\n&quot;;
</pre>
<p>When I wrote this, I had only recently started using Perl.  Please go easy on me if it's poorly written.</p>
<p>The script takes an input file, an output file format (e.g. words.txt will be words.txt.20 for words of 20 characters), and an optional sentence to parse.</p>
<p>It gets a set of letters in the sentence, then runs through the list of words to see if the word can be made from any combination of letters.</p>
<p>For instance, if your 'sentence' is "baby cakes", the script will create a hash of those letters and their counts.  Conceptually, this looks like:</p>
<pre class="brush: jscript; title: ; notranslate">
// hash is an array
hash['a'] = 2
hash['b'] = 2
hash['c'] = 1
hash['e'] = 1
hash['k'] = 1
hash['s'] = 1
hash['y'] = 1
</pre>
<p>If, while walking line-by-line through your list of words, the script sees 'abracadabra', the loop will return false because (conceptually):</p>
<pre class="brush: jscript; title: ; notranslate">
word['a'] = 5
word['a'] &lt;= hash['a'] == false
</pre>
<p>The script also employs some interesting stdout manipulation. This allows the script to output "spinner text" and update the current line when the terminating character is a line-feed.</p>
<p>To run the script in a linux-based environment, you may do:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir ~/projects &amp;&amp; cd ~/projects
git clone git://gist.github.com/1733871.git gist-1733871
cd gist-gist-1733871
perl words.pl /usr/share/dict/words generated.txt 'Good goly, Miss Molly'
</pre>
<p>You should see output similar to:</p>
<pre class="brush: bash; title: ; notranslate">

jim at schubert in ~/projects/gist-1733871 on master*
$ tree .
.
├── generated.txt
├── generated.txt.1
├── generated.txt.2
├── generated.txt.3
├── generated.txt.4
├── generated.txt.5
├── generated.txt.6
├── generated.txt.7
├── generated.txt.8
└── words.pl

0 directories, 10 files
</pre>
<p>If you look at <em>generated.txt.7</em>, you will probably see something similar to:</p>
<pre class="brush: plain; title: ; notranslate">
Hollis
Osgood
glossy
goodly
idylls
igloos
solids
</pre>
<p class="wp-flattr-button"></p> <p><a href="http://www.ipreferjim.com/site/?flattrss_redirect&amp;id=762&amp;md5=004f7808b9b18c95cc015966463f0ca1" title="Flattr" target="_blank"><img src="http://www.ipreferjim.com/site/wp-content/plugins/flattr/img/flattr-badge-large.png?84cd58" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/MoCQNDn4fN1RpevPq6RdHB3c-PU/0/da"><img src="http://feedads.g.doubleclick.net/~a/MoCQNDn4fN1RpevPq6RdHB3c-PU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MoCQNDn4fN1RpevPq6RdHB3c-PU/1/da"><img src="http://feedads.g.doubleclick.net/~a/MoCQNDn4fN1RpevPq6RdHB3c-PU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/zQ0CWLeoz4s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2012/02/words-pl-slogan-word-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2012/02/words-pl-slogan-word-generator/</feedburner:origLink></item>
		<item>
		<title>My Review of Android Open Conference 2011: Complete Video Compilation</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/sZwZYxVM1v0/</link>
		<comments>http://www.ipreferjim.com/2012/01/my-review-of-android-open-conference-2011-complete-video-compilation/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 03:20:20 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=760</guid>
		<description><![CDATA[Originally submitted at O'Reilly Android Open Conference 2011: Complete Video Compilation Android Open Conference 2011: Complete Video Compilation Hours of Android enjoyment By Jim Schubert from Richmond, VA on 1/31/2012 &#160; 5out of 5 Pros: Helpful examples, Easy to understand, Accurate, Concise Best Uses: Intermediate, Student, Expert Describe Yourself: Developer There are a lot of [...]]]></description>
			<content:encoded><![CDATA[<div class="hreview">
<div class="item">
<p><a href="http://oreilly.com/product/0636920023838.do">Originally submitted at O'Reilly</a></p>
<div><img src="http://images.powerreviews.com/images_products/01/18/14846224_100.jpg" class="photo" align="left" style="margin: 0 0.5em 0 0">
<p style="margin-top:0">Android Open Conference 2011: Complete Video Compilation</p>
</div>
<p><a href="http://shop.oreilly.com/product/0636920023838.do" style="display: none;" class="url fn"><span class="fn">Android Open Conference 2011: Complete Video Compilation</span></a></div>
<p><br clear="left">
<p><strong class="summary">Hours of Android enjoyment</strong></p>
<div>By <strong>Jim Schubert</strong> from <strong>Richmond, VA</strong> on <strong><abbr title="2012131T1200-0800" class="dtreviewed" style="border: none; text-decoration: none;">1/31/2012</abbr></strong></div>
<p>
<div style="margin: 0.5em 0; height: 15px; width: 83px; background-image: url(http://images.powerreviews.com/images/stars_small.gif); background-position: 0px -180px;" class="prStars prStarsSmall">&nbsp;</div>
</p>
<div style="display: none"><span class="rating">5</span>out of 5</div>
<p><strong>Pros: </strong>Helpful examples, Easy to understand, Accurate, Concise</p>
<p><strong>Best Uses: </strong>Intermediate, Student, Expert</p>
<p><strong>Describe Yourself: </strong>Developer</p>
<p style="margin-top:1em" class="description">There are a lot of videos here. If you're only planning to write apps for the market, you'll most likely not be interested in the Embedded Android talk or Scala as a Java replacement.  If you don't work on iOS and never plan to, you can probably scan through Nick Farina's talk (sorry, Nick). I found many of the videos worthwhile, whether they related to actual app development or the business of apps.<br xmlns:pr="xalan://com.pufferfish.core.beans.xmlbuilders.xsl.Functions"><br />I also really enjoyed the keynotes.  Tim O'Reilly's talk is probably my favorite because I've been saying the same things about many of Tim's comparisons since I bought my first DROID a couple of years ago.</p>
<p>Even if you're familiar with Android development, you should definitely watch the videos by Ken Jones.  He shows the start of a Twitter client.  Although he didn't get very far in the actual coding, he will point you to the finished code. One aspect I loved about his talks is that he discusses a lot of best practices.  Many tutorials you find online either don't discuss best practices or don't incorporate them.</p>
<p>Be sure to watch the Arduino videos.  I hadn't heard about Arduino before this video and I was very impressed. In fact, I watched the keynote video twice.</p>
<p>Honestly, there are some videos here that I'm not that interested in. That doesn't detract from the overall usefulness of this video collection.  If you're 25% of the way through a video and it hasn't hooked you yet, move onto the next because there is a plethora of information.</p>
<p style="margin-top:0.5em">(<a href="http://www.powerreviews.com/legal/terms_of_use.html" rel="license">legalese</a>)</p>
</div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/J8Rk6q2BaltyFZH9DUlqnUpdJEs/0/da"><img src="http://feedads.g.doubleclick.net/~a/J8Rk6q2BaltyFZH9DUlqnUpdJEs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/J8Rk6q2BaltyFZH9DUlqnUpdJEs/1/da"><img src="http://feedads.g.doubleclick.net/~a/J8Rk6q2BaltyFZH9DUlqnUpdJEs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/sZwZYxVM1v0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2012/01/my-review-of-android-open-conference-2011-complete-video-compilation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2012/01/my-review-of-android-open-conference-2011-complete-video-compilation/</feedburner:origLink></item>
		<item>
		<title>dotfiles backup using GitHub</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/pJFx_E85SMY/</link>
		<comments>http://www.ipreferjim.com/2012/01/dotfiles-backup-using-github/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 01:58:12 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=753</guid>
		<description><![CDATA[I was recently looking for a solution to backup my configuration files (bash, vim, etc) using GitHub. After some looking around, I've compiled a pretty nice project for myself. github:jimschubert/dotfiles First, this script checks dependencies. My dependencies are git, ruby, vim, tree, rake, gem, bundle, and trash. You could check out the code and add [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently looking for a solution to backup my configuration files (bash, vim, etc) using GitHub.  After some looking around, I've compiled a pretty nice project for myself.</p>
<p><a href="http://github.com/jimschubert/dotfiles" title="click to check out the project" target="_blank">github:jimschubert/dotfiles</a></p>
<p>First, this script <a href="https://github.com/jimschubert/dotfiles/blob/v1.0/bootstrap.sh#L36" title="click to see where this code checks dependencies." target="_blank">checks dependencies</a>.  My dependencies are git, ruby, vim, tree, rake, gem, bundle, and trash.  You could check out the code and add any number of dependencies here.  Rubygems and bundler are required because the script later installs all gems listed in <strong>Gemfile</strong>. </p>
<p>Next, the script copies ~/.bashrc to ~/.bashrc.local.  This allows you to keep your current bash configuration as a 'local-only' config that doesn't get copied or committed to github.</p>
<p>The script, as I copied most of bootstrap.sh and the rakefile from <a href="http://github.com/gf3" title="click to view Ryan B's profile" target="_blank">@gf3</a>, expects the repository to be cloned to ~/.dotfiles.  From there, it calls rake.</p>
<p>Rake looks at every file in ~/.dotfiles and copies the corresponding file relatively from ~/ to, essentially, ~/dotfiles-backup/`date`.  I recommend first running the backup to make sure your files are properly backed up.</p>
<pre class="brush: bash; title: ; notranslate">
rake backup
</pre>
<p>The script then calls 'bundle install' to install all gems.  It then copies all files from ~/.dotfiles to replace those relative files that were previously backed up from ~/.</p>
<p>The post-install displays a message to remind you to edit .gitconfig and .hgrc.</p>
<p>Because I've done some copying and compiling, these are relative close to the three projects in the <a href="https://github.com/jimschubert/dotfiles/blob/v1.0/README.md" title="click to view README.md" target="_blank">README</a> for right now.</p>
<p>Here is an excerpt from the README:</p>
<h1>Bash</h1>
<pre><code>$ tree ~/.bash
/home/jim/.bash
├── aliases
├── completions
├── completion_scripts
│   └── git_completion
├── config
├── functions
├── paths
└── prompt
</code></pre>
<p>The above files are loaded by <code>.bashrc</code>. The files are pretty self-explanatory, other than <code>prompt</code> which colorizes the bash prompt with tweaks for git.</p>
<h2>Cool Aliases</h2>
<ul>
<li>cd : pushd</li>
<li>bd : popd</li>
<li>cd..  | ..   : back one directory</li>
<li>cd... | ...  : back two directories</li>
<li>^ up to five directories</li>
<li>rm : trash</li>
<li>undopush</li>
<li>ip</li>
<li>GET | HEAD | POST | PUT | DELETE | TRACE | OPTIONS</li>
</ul>
<h2>Config</h2>
<ul>
<li>sets editor to vim</li>
<li>sets English/UTF-8</li>
<li>sets manpager</li>
<li>sets commands to ignore in history</li>
<li>sets noclobber (e.g. prevents <code>cat &gt; IMPORTANT_FILE</code> mistakes )</li>
<li>sets nocaseglob (e.g. <code>ls ~/.B*</code> will list contents of <code>~/.bash</code>)</li>
</ul>
<h2>Functions</h2>
<p>The two functions, <code>md</code> and <code>c</code> may not seem like much, but they simplify some commands. For example:</p>
<pre><code>$ md projects; git clone git@github.com:jimschubert/dotfiles.git &amp;&amp; cd dotfiles
</code></pre>
<p>In the above line, <code>md</code> will create the projects directory and <code>cd</code> into it.</p>
<p><code>c</code> stands for 'code' and  works like this:</p>
<pre><code>jim at computer in ~
$ pwd
/home/jim
jim at computer in ~
$ c dotfiles
~/projects/dotfiles ~
jim at computer in ~/projects/dotfiles on master
$
</code></pre>
<p>You can change it to whatever shortcut and issue <code>reload</code>, which is also an alias from this setup.</p>
<h2>Screenshot</h2>
<p>Notice the color scheme and github branch notifications created by ~/.bash/prompt.</p>
<p><a href="http://www.ipreferjim.com/site/wp-content/uploads/2012/01/bash.png?84cd58"><img src="http://www.ipreferjim.com/site/wp-content/uploads/2012/01/bash.png?84cd58" alt="" title="bash" width="724" height="648" class="aligncenter size-full wp-image-756" /></a></p>
<p class="wp-flattr-button"></p> <p><a href="http://www.ipreferjim.com/site/?flattrss_redirect&amp;id=753&amp;md5=bbd3491d9b4c8ce812b54bf244012f13" title="Flattr" target="_blank"><img src="http://www.ipreferjim.com/site/wp-content/plugins/flattr/img/flattr-badge-large.png?84cd58" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/tkbi98MweaOsIYcWQomUgK58NSg/0/da"><img src="http://feedads.g.doubleclick.net/~a/tkbi98MweaOsIYcWQomUgK58NSg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tkbi98MweaOsIYcWQomUgK58NSg/1/da"><img src="http://feedads.g.doubleclick.net/~a/tkbi98MweaOsIYcWQomUgK58NSg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/pJFx_E85SMY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2012/01/dotfiles-backup-using-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2012/01/dotfiles-backup-using-github/</feedburner:origLink></item>
		<item>
		<title>Install nodejs under ChromeOS (CR-48)</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/ZBwhaWESeiM/</link>
		<comments>http://www.ipreferjim.com/2011/12/install-nodejs-under-chromeos-cr-48/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 04:35:53 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=741</guid>
		<description><![CDATA[Why would I want to do this? I'm a software developer. I love javascript. I love node.js. I love the direction Google is taking web development, user interaction, and the web in general. Installing node.js opens up a lot of possibilities for me on my CR-48. I don't know if this will work on anything [...]]]></description>
			<content:encoded><![CDATA[<p>Why would I want to do this?</p>
<p>I'm a software developer. I love javascript. I love node.js. I love the direction Google is taking web development, user interaction, and the web in general. Installing node.js opens up a lot of possibilities for me on my CR-48.  I don't know if this will work on anything other than the CR-48, considering the machine has to be in developer mode for these instructions.</p>
<p>If you don't have a chromebook yet, or you don't know what they are... where have you been? But seriously, visit <a href="http://www.google.com/chromebook/" title="Google Chromebooks" target="_blank">http://www.google.com/chromebook/</a> and check them out.</p>
<p>Before I start, let me first say that following these instructions may void your warranty if you have one, open your machine up to vulnerabilities, or replace existing files and cause instability.  If you don't know how to revert or fix any issues that may occur, don't continue. I offer no sort of warranty, support, or anything else. Consider this a 'hack' of sorts.</p>
<p>I found <a href="http://kalinchuk.com/?tag=install-packages-on-chrome-os" title="blog post about installing packages on chrome os" target="_blank">a blog post</a> detailing how to install an archive package and ruby on rails in ChromeOS.  I followed part of these instructions and I have modified them to fit my needs.</p>
<h2>Prerequisites</h2>
<ul>
<li>You must have a Chromebook, possibly only the CR-48</li>
<li>You must be in '<a href="http://www.chromium.org/chromium-os/poking-around-your-chrome-os-device" title="Instructions for entering developer mode" target="_blank">developer mode</a>'</li>
<li>You must have a writable rootfs (see above link for developer mode)</li>
</ul>
<h2>Instructions</h2>
<p>Downloading and installing xz</p>
<ol>
<li>Download the <a href="http://www.archlinux.org/packages/core/i686/xz/" title="download the xz package" target="_blank">xz package</a></li>
<li>Enter crosh or VT-2 (CTRL+ALT+T or CTRL+ALT+&rarr;)</li>
<li>If VT-2, login to the shell</li>
<li>Run on the terminal: cd /home/chronos/user/Downloads</li>
<li>Run on the terminal: tar -zxf xz-*.tar.gz</li>
<li>Run on the terminal: cd usr</li>
<li>Run on the terminal: cp * /usr/</li>
</ol>
<p>Now that xz is installed in /usr/bin (verify by running on the command line: which xz), you will be able to extract certain files that are necessary for nodejs and possibly any other package you'd like.</p>
<p>Download and install nodejs and openssl.<br />
<em>The site claims openssl is optional, but node wouldn't open without it</em></p>
<ol>
<li>Download <a href="http://www.archlinux.org/packages/community/i686/nodejs/" title="download nodejs" target="_blank">nodejs</a></li>
<li>Download <a href="http://www.archlinux.org/packages/core/i686/openssl/" title="download openssl" target="_blank">openssl</a></li>
<li>Enter the terminal again and navigate to /home/chronos/user/Downloads</li>
<li>Run on the terminal: xz -d node*.xz</li>
<li>Run on the terminal: tar -zxfv openssl*.tar.gz</li>
<li>Run on the terminal: cd usr</li>
<li>Run on the terminal: cp * /usr/</li>
</ol>
<p>Now you should have a working install of nodejs.  You can use npm, for instance, to install express and jade.<br />
<a href="http://www.ipreferjim.com/site/wp-content/uploads/2011/12/screenshot-20111222-233213.png?84cd58"><img src="http://www.ipreferjim.com/site/wp-content/uploads/2011/12/screenshot-20111222-233213-1024x640.png?84cd58" alt="node.js and express running on ChromeOS" title="node.js and express running on ChromeOS" width="550" height="343" class="aligncenter size-large wp-image-744" /></a></p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/vzvO3w-MPA39x4iarcwx5586puc/0/da"><img src="http://feedads.g.doubleclick.net/~a/vzvO3w-MPA39x4iarcwx5586puc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/vzvO3w-MPA39x4iarcwx5586puc/1/da"><img src="http://feedads.g.doubleclick.net/~a/vzvO3w-MPA39x4iarcwx5586puc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/ZBwhaWESeiM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/12/install-nodejs-under-chromeos-cr-48/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/12/install-nodejs-under-chromeos-cr-48/</feedburner:origLink></item>
		<item>
		<title>Visual Studio and Interface property stubs</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/mxfS5Sy1WS0/</link>
		<comments>http://www.ipreferjim.com/2011/11/visual-studio-and-interface-property-stubs/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 23:53:38 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=720</guid>
		<description><![CDATA[Last year, I posted a question on StackOverflow asking if it was possible to replace the property stubs for interface refactoring Is it possible to change the stub used to implement interfaces in Visual Studio 2008? For instance, when I choose either Implement interface 'IMyInterface' or Explicitly implement interface 'IMyInterface' Instead of a number of [...]]]></description>
			<content:encoded><![CDATA[<p>Last year, I <a href="http://stackoverflow.com/q/2608966/151445" title="my question on StackOverflow" target="_blank">posted a question</a> on StackOverflow asking if it was possible to replace the property stubs for interface refactoring</p>
<pre>Is it possible to change the stub used to implement interfaces in Visual Studio 2008?

For instance, when I choose either
Implement interface 'IMyInterface'
or
Explicitly implement interface 'IMyInterface'

Instead of a number of properties that look like this:

    public string Comment
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }
I'd like my properties to use the C# 3.0 auto-implemented properties and look like this:

    public string Comment {get;set;}
I want to do this to avoid forcing this interface to be an abstract class.

I've looked through the snippets in the Visual Studio folder, but I didn't see any that would be appropriate. I've also googled and searched SO, and found nothing.

If this isn't possible, does anyone have a macro I can steal?

Thanks.</pre>
<p>I then discovered that you can edit the file at:</p>
<pre class="brush: plain; title: ; notranslate">
[program files]\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring\PropertyStub.snippet
</pre>
<p>and modify the xml node 'Code' to contain the following:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Code Language=&quot;csharp&quot;&gt;
    &lt;![CDATA[ $signature$ { $GetterAccessibility$ get; $SetterAccessibility$ set;} $end$]]&gt;
&lt;/Code&gt;
</pre>
<p>I really wish this was the default for .NET 3.0 and higher (since auto-implemented properties have been around).</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/VcJKB3bzx6xdC6iPv2sEPQyOSrY/0/da"><img src="http://feedads.g.doubleclick.net/~a/VcJKB3bzx6xdC6iPv2sEPQyOSrY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/VcJKB3bzx6xdC6iPv2sEPQyOSrY/1/da"><img src="http://feedads.g.doubleclick.net/~a/VcJKB3bzx6xdC6iPv2sEPQyOSrY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/mxfS5Sy1WS0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/11/visual-studio-and-interface-property-stubs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/11/visual-studio-and-interface-property-stubs/</feedburner:origLink></item>
		<item>
		<title>My Review of JavaScript: The Definitive Guide, 6th Edition</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/O8Y2502lPSo/</link>
		<comments>http://www.ipreferjim.com/2011/11/my-review-of-javascript-the-definitive-guide-6th-edition/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 23:26:47 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/2011/11/my-review-of-javascript-the-definitive-guide-6th-edition/</guid>
		<description><![CDATA[Originally submitted at O'Reilly Activate Your Web Pages JavaScript: The Definitive Guide, 6th Edition A tome of knowledge By Jim from Herndon, VA on 11/8/2011 &#160; 4out of 5 Pros: Well-written, Accurate, Concise, Easy to understand Cons: Huge Best Uses: Student, Expert, Novice, Intermediate Describe Yourself: Developer This is an unbelievably thorough JavaScript book. It's [...]]]></description>
			<content:encoded><![CDATA[<div class="hreview">
<div class="item">
<p><a href="http://oreilly.com/product/9780596805531.do">Originally submitted at O'Reilly</a></p>
<div><img src="http://images.powerreviews.com/images_products/04/72/13514433_100.jpg" class="photo" align="left" style="margin: 0 0.5em 0 0">
<p style="margin-top:0">Activate Your Web Pages</p>
</div>
<p><a href="http://shop.oreilly.com/product/9780596805531.do" style="display: none;" class="url fn"><span class="fn">JavaScript: The Definitive Guide, 6th Edition</span></a></div>
<p><br clear="left">
<p><strong class="summary">A tome of knowledge</strong></p>
<div>By <strong>Jim</strong> from <strong>Herndon, VA</strong> on <strong><abbr title="2011118T1200-0800" class="dtreviewed" style="border: none; text-decoration: none;">11/8/2011</abbr></strong></div>
<p>
<div style="margin: 0.5em 0; height: 15px; width: 83px; background-image: url(http://images.powerreviews.com/images/stars_small.gif); background-position: 0px -144px;" class="prStars prStarsSmall">&nbsp;</div>
</p>
<div style="display: none"><span class="rating">4</span>out of 5</div>
<p><strong>Pros: </strong>Well-written, Accurate, Concise, Easy to understand</p>
<p><strong>Cons: </strong>Huge</p>
<p><strong>Best Uses: </strong>Student, Expert, Novice, Intermediate</p>
<p><strong>Describe Yourself: </strong>Developer</p>
<p style="margin-top:1em" class="description">This is an unbelievably thorough JavaScript book.  It's definitely more of a reference book than a front-to-back read.<br xmlns:pr="xalan://com.pufferfish.core.beans.xmlbuilders.xsl.Functions"><br />The first 12 chapters are an excellent introduction into the history of JavaScript and the core functionality of the language.  There is a lot of information in these chapters that really shouldn't be overlooked-- especially Chapter 8: "Functions".</p>
<p>I especially appreciate the structure and the approach of the client-side section of the book.  Flanagan makes it a point to avoid pushing JavaScript frameworks by explaining the features of the language first, followed by an explanation of the cross-browser simplification of using jQuery. </p>
<p>Later chapters cover additions to more recent browsers like client storage and HTML5 features.  Those chapters unfortunately go by really fast.  They're definitely not as in-depth as the JavaScript history part of the book.</p>
<p>The last two parts of the book are purely reference. This is pretty helpful, but it makes the book a lot thicker than most "guide" references.</p>
<p>I do agree with others that this book could use a few more examples, especially near the end when discussing JavaScript usage with new HTML5 APIs.  If you're looking for an in-depth understanding of the core functionality of JavaScript, this is the book.  It has helped me in numerous job interviews!</p>
<p style="margin-top:0.5em">(<a href="http://www.powerreviews.com/legal/terms_of_use.html" rel="license">legalese</a>)</p>
</div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/A9q23OXftovAaazNLOMRDvjb5tc/0/da"><img src="http://feedads.g.doubleclick.net/~a/A9q23OXftovAaazNLOMRDvjb5tc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/A9q23OXftovAaazNLOMRDvjb5tc/1/da"><img src="http://feedads.g.doubleclick.net/~a/A9q23OXftovAaazNLOMRDvjb5tc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/O8Y2502lPSo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/11/my-review-of-javascript-the-definitive-guide-6th-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/11/my-review-of-javascript-the-definitive-guide-6th-edition/</feedburner:origLink></item>
		<item>
		<title>jQuery plugin: fixed table header</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/Y58DdgKV4do/</link>
		<comments>http://www.ipreferjim.com/2011/10/jquery-plugin-fixed-table-header/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 12:27:57 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=714</guid>
		<description><![CDATA[Here's a plugin that I wrote a while ago for fixing a table's header row on scroll. This code is also available as a gist. Fork it and contribute. A demo:]]></description>
			<content:encoded><![CDATA[<p>Here's a plugin that I wrote a while ago for fixing a table's header row on scroll.</p>
<p>This code is also available <a href="https://gist.github.com/1047086" title="gist.github.com">as a gist</a>. Fork it and contribute.</p>
<pre class="brush: jscript; title: ; notranslate">
(function($) {
	$.fn.fixedHeader = function(options) {
		var settings = {
			selector: 'thead:first',
			cssClass: 'fixed',
			fixTo: 0
		};

		var _fixHeader = function(obj) {
			var header = $(obj.selector, obj.elem);
			if(header) {
				var parent =  header.parents('table:first') || header.parent();
				(parent &amp;&amp; parent.css({ borderCollapse: 'collapse'}) );

				var data = header.data('fixedHeader') || header.data('fixedHeader', {
						top: header.offset().top,
						width: parent.find('tr:eq(1)').width(),
						cells: parent.find('tr:eq(1) &gt; td'),
						processed: false
					});
				var top = data.top - $(document).scrollTop();
				if( top &lt; 0 ) {
					header.addClass(obj.css);
					if(!data.processed){
						header.width(data.width);
						for(var i = 0; i&lt;data.cells.length;i++) {
							$('th:eq('+i+')', header).width($(data.cells[i]).width());
						}
					}

				} else {
					header.removeClass(obj.css);
				}
			}
		};
		return this.each(function() {
			var self = this;
			if(&quot;object&quot; === typeof options) {
				$.extend(settings, options);
			}
			if($(self).parents('table:first')){
				$(window).bind('scroll.fixedHeader', function() {
					_fixHeader({
						elem: self,
						selector: settings.selector,
						css: settings.cssClass,
						top: settings.fixTo
					});
				});
			}
		});
	};
})(jQuery);
</pre>
<p>A demo:<br />
<iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/jimschubert/RMsqJ/1/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe></p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/MzOCc52zFe76JG_1OOUuTiGudUM/0/da"><img src="http://feedads.g.doubleclick.net/~a/MzOCc52zFe76JG_1OOUuTiGudUM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MzOCc52zFe76JG_1OOUuTiGudUM/1/da"><img src="http://feedads.g.doubleclick.net/~a/MzOCc52zFe76JG_1OOUuTiGudUM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/Y58DdgKV4do" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/10/jquery-plugin-fixed-table-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/10/jquery-plugin-fixed-table-header/</feedburner:origLink></item>
		<item>
		<title>Mercurial and Git in one repository</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/-DS7liaBkII/</link>
		<comments>http://www.ipreferjim.com/2011/10/mercurial-and-git-in-one-repository/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 22:07:53 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=704</guid>
		<description><![CDATA[I have a personal project hosted at bitbucket using Mercurial as the version control system. Since I started that project, I've been using GitHub for everything. I just found hg-git instructions on github.com. It is pretty awesome. For my purposes, it allows me to maintain the project on two remote servers, one running Mercurial, the [...]]]></description>
			<content:encoded><![CDATA[<p>I have a personal project hosted at bitbucket using Mercurial as the version control system.  Since I started that project, I've been using GitHub for everything.  I just found <a href="http://hg-git.github.com/" title="hg-git instructions on GitHub">hg-git</a> instructions on github.com.  It is pretty awesome.</p>
<p>For my purposes, it allows me to maintain the project on two remote servers, one running Mercurial, the other running Git.</p>
<p>To see how it works, first install hg-git:</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo easy_install hg-git
</pre>
<p>Then, edit your <em>~/.hgrc</em> settings, adding to the [extensions] section:</p>
<pre class="brush: plain; title: ; notranslate">
[extensions]
hgext.bookmarks =
hggit =
</pre>
<p>Also, be sure your <em>~/.hgrc</em> contains a valid email address:</p>
<pre class="brush: plain; title: ; notranslate">
[ui]
username = Jim Schubert &lt;james.schubert@gmail.com&gt;
</pre>
<p>Now, you can create a repository on github.com and push your Mercurial commits:</p>
<pre class="brush: bash; title: ; notranslate">
$ cd ~/projects/project_name
$ hg bookmark -r default master
$ hg push git+ssh://git@github.com/username/project_name.git
$ hg push
</pre>
<p>If you're only planning on using Mercurial to push changes to github or some other Git host, you can add that path to <em>~/.hgrc</em>:</p>
<pre class="brush: plain; title: ; notranslate">
[paths]
default-push = git+ssh://git@github.com/username/project_name.git
</pre>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/hAfK8GbLcdNXQUAS3e1WIKG8sZk/0/da"><img src="http://feedads.g.doubleclick.net/~a/hAfK8GbLcdNXQUAS3e1WIKG8sZk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hAfK8GbLcdNXQUAS3e1WIKG8sZk/1/da"><img src="http://feedads.g.doubleclick.net/~a/hAfK8GbLcdNXQUAS3e1WIKG8sZk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/-DS7liaBkII" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/10/mercurial-and-git-in-one-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/10/mercurial-and-git-in-one-repository/</feedburner:origLink></item>
		<item>
		<title>Makefile setup for minifying .js files in an expressjs application</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/wFKlQa8pMKE/</link>
		<comments>http://www.ipreferjim.com/2011/09/makefile-setup-for-minifying-js-files-in-an-expressjs-application/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 02:17:44 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=699</guid>
		<description><![CDATA[There's not really any reason to uglify or minify your JavaScript files on a per-request basis or on a pre-cache basis. This should be done at deployment time only. This can be achieved by adding uglify-js to your package.json file. Make sure the dependencies are installed with Then, add the following make file and minify [...]]]></description>
			<content:encoded><![CDATA[<p>There's not really any reason to uglify or minify your JavaScript files on a per-request basis or on a pre-cache basis.  This should be done at deployment time only.  This can be achieved by adding uglify-js to your package.json file.</p>
<pre class="brush: jscript; title: ; notranslate">
// default package.js for an expressjs app using ejs and uglify-js
{
    &quot;name&quot;: &quot;application-name&quot;
  , &quot;version&quot;: &quot;0.0.1&quot;
  , &quot;private&quot;: true
  , &quot;dependencies&quot;: {
      &quot;express&quot;: &quot;2.4.6&quot;
    , &quot;ejs&quot;: &quot;&gt;=0.4.3&quot;
    , &quot;uglify-js&quot;: &quot;&gt;=1.1.0&quot;
  }
}
</pre>
<p>Make sure the dependencies are installed with
<pre class="brush: plain; title: ; notranslate">npm install -d</pre>
<p>Then, add the following make file and minify your JavaScripts as part of your make process!</p>
<p><script src="https://gist.github.com/1249824.js"> </script></p>
<pre class="brush: bash; collapse: true; light: false; title: ; toolbar: true; notranslate">
JS = $(shell find public/javascripts/*.js)
MINIFY = $(JS:.js=.min.js)

all: clean $(MINIFY)

clean:
	rm -f ./public/javascripts/*.min.js

%.min.js: %.js
	node ./node_modules/uglify-js/bin/uglifyjs -o $@ $&lt;

.PHONY: clean js minify
</pre>
<p>(expandable source is the same as the gist. It is doubled here to show in RSS feed readers.)</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/Iw9FlP5J_iHaixfEqwnERabJCTs/0/da"><img src="http://feedads.g.doubleclick.net/~a/Iw9FlP5J_iHaixfEqwnERabJCTs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Iw9FlP5J_iHaixfEqwnERabJCTs/1/da"><img src="http://feedads.g.doubleclick.net/~a/Iw9FlP5J_iHaixfEqwnERabJCTs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/wFKlQa8pMKE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/09/makefile-setup-for-minifying-js-files-in-an-expressjs-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/09/makefile-setup-for-minifying-js-files-in-an-expressjs-application/</feedburner:origLink></item>
		<item>
		<title>propv.snippet for creating Automatic virtual properties in C#</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/EeHJQTW_vF8/</link>
		<comments>http://www.ipreferjim.com/2011/09/propv-snippet/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 13:21:34 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=694</guid>
		<description><![CDATA[I'm all about saving time. I have a huge collection of helpful snippets. Here's one that automatically creates a virtual property, which is really helpful if you use Castle's DynamicProxy (NHibernate uses this). Instead of embedding the code directly, I'm using http://gist.github.com so changes to the file will show immediately in the post.]]></description>
			<content:encoded><![CDATA[<p>I'm all about saving time.  I have a huge collection of helpful snippets. Here's one that automatically creates a virtual property, which is really helpful if you use Castle's DynamicProxy (NHibernate uses this).</p>
<p>Instead of embedding the code directly, I'm using http://gist.github.com so changes to the file will show immediately in the post.</p>
<p><script src="https://gist.github.com/1237291.js"> </script></p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/AC34O3Q4nPC_0SDKU41jYvnYxf0/0/da"><img src="http://feedads.g.doubleclick.net/~a/AC34O3Q4nPC_0SDKU41jYvnYxf0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/AC34O3Q4nPC_0SDKU41jYvnYxf0/1/da"><img src="http://feedads.g.doubleclick.net/~a/AC34O3Q4nPC_0SDKU41jYvnYxf0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/EeHJQTW_vF8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/09/propv-snippet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/09/propv-snippet/</feedburner:origLink></item>
		<item>
		<title>Editing JavaScript in vim</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/gv4E-hLFIcI/</link>
		<comments>http://www.ipreferjim.com/2011/09/editing-javascript-in-vim/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 04:02:50 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=689</guid>
		<description><![CDATA[I primarily use vim as my editor of choice for JavaScript. I have a fairly simple .vimrc: I also use the JavaScript syntax/indents found here: https://github.com/pangloss/vim-javascript You can access the completion by typing CTRL+X,CTRL+O. If you have any other suggestions for using vim as a JavaScript editor, let me know!]]></description>
			<content:encoded><![CDATA[<p>I primarily use vim as my editor of choice for JavaScript.</p>
<p>I have a fairly simple .vimrc:</p>
<pre class="brush: bash; title: ; notranslate">
syntax on &quot; enabled syntax highlighting
:set number &quot; line numbers
:set ai &quot; autoindent
:set tabstop=4 &quot; sets tabs to 4 characters
:set shiftwidth=4
:set expandtab
:set softtabstop=4 &quot; makes the spaces feel like real tabs
&quot; CSS (tabs = 2, lines = 79)
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType css set sw=2
autocmd FileType css set ts=2
autocmd FileType css set sts=2
&quot; JavaScript (tabs = 4, lines = 79)
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType javascript set sw=4
autocmd FileType javascript set ts=4
autocmd FileType javascript set sts=4
&quot; autocmd FileType javascript set tw=79

autocmd FileType jade set omnifunc=jadecomplete#CompleteJade
autocmd FileType jade set sw=2
autocmd FileType jade set ts=2
autocmd FileType jade set sts=2

&quot; Highlight current line only in insert mode
autocmd InsertLeave * set nocursorline
autocmd InsertEnter * set cursorline

&quot; Makefiles require TAB instead of whitespace
autocmd FileType make setlocal noexpandtab

&quot; Highlight cursor
highlight CursorLine ctermbg=8 cterm=NONE
</pre>
<p>I also use the JavaScript syntax/indents found here:<br />
<a href="https://github.com/pangloss/vim-javascript">https://github.com/pangloss/vim-javascript</a></p>
<p>You can access the completion by typing CTRL+X,CTRL+O.</p>
<p>If you have any other suggestions for using vim as a JavaScript editor, let me know!</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/CN3Kk9EHvuf3V4h9pcjGXPgMHgc/0/da"><img src="http://feedads.g.doubleclick.net/~a/CN3Kk9EHvuf3V4h9pcjGXPgMHgc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/CN3Kk9EHvuf3V4h9pcjGXPgMHgc/1/da"><img src="http://feedads.g.doubleclick.net/~a/CN3Kk9EHvuf3V4h9pcjGXPgMHgc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/gv4E-hLFIcI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/09/editing-javascript-in-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/09/editing-javascript-in-vim/</feedburner:origLink></item>
		<item>
		<title>testy C# Test Method Snippet</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/zuMTpdqnFNY/</link>
		<comments>http://www.ipreferjim.com/2011/08/testy-c-test-method-snippet/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 13:06:47 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=686</guid>
		<description><![CDATA[This is a pretty trivial snippet, but I use it quite a lot. Save this file as testy.snippet in your [Visual Studio]\VC#\Snippets\1033\Test directory. Then, in the code editor, type testy, TAB+TAB to expand the snippet.]]></description>
			<content:encoded><![CDATA[<p>This is a pretty trivial snippet, but I use it quite a lot.</p>
<p>Save this file as testy.snippet in your [Visual Studio]\VC#\Snippets\1033\Test directory.</p>
<p>Then, in the code editor, type <strong>testy</strong>, TAB+TAB to expand the snippet. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;CodeSnippets  xmlns=&quot;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&quot;&gt;
	&lt;CodeSnippet Format=&quot;1.0.0&quot;&gt;
		&lt;Header&gt;
			&lt;Title&gt;testy&lt;/Title&gt;
			&lt;Shortcut&gt;testy&lt;/Shortcut&gt;
			&lt;Description&gt;Code snippet for creating an NUnit unit test in C#&lt;/Description&gt;
			&lt;Author&gt;James Schubert&lt;/Author&gt;
			&lt;SnippetTypes&gt;
				&lt;SnippetType&gt;Expansion&lt;/SnippetType&gt;
			&lt;/SnippetTypes&gt;
		&lt;/Header&gt;
		&lt;Snippet&gt;
			&lt;Declarations&gt;
				&lt;Literal&gt;
					&lt;ID&gt;summary&lt;/ID&gt;
					&lt;ToolTip&gt;Summary&lt;/ToolTip&gt;
					&lt;Default&gt;Summary&lt;/Default&gt;
				&lt;/Literal&gt;
				&lt;Literal&gt;
					&lt;ID&gt;name&lt;/ID&gt;
					&lt;ToolTip&gt;Test name&lt;/ToolTip&gt;
					&lt;Default&gt;TestName&lt;/Default&gt;
				&lt;/Literal&gt;
                &lt;Literal&gt;
                    &lt;ID&gt;description&lt;/ID&gt;
                    &lt;ToolTip&gt;Test Case&lt;/ToolTip&gt;
                    &lt;Default&gt;Assumption_Does_Expectation&lt;/Default&gt;
                &lt;/Literal&gt;
			&lt;/Declarations&gt;
			&lt;Code Language=&quot;csharp&quot;&gt;&lt;![CDATA[ ///&lt;summary&gt;
/// $summary$
///&lt;/summary&gt;
[Test]
public void $name$_When_$description$()
{
	// Arrange

	// Act

	// Assert
}
$end$]]&gt;
			&lt;/Code&gt;
		&lt;/Snippet&gt;
	&lt;/CodeSnippet&gt;
&lt;/CodeSnippets&gt;
</pre>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/7c-kfgFW8eshtOBQ0YRgXgnn_W4/0/da"><img src="http://feedads.g.doubleclick.net/~a/7c-kfgFW8eshtOBQ0YRgXgnn_W4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7c-kfgFW8eshtOBQ0YRgXgnn_W4/1/da"><img src="http://feedads.g.doubleclick.net/~a/7c-kfgFW8eshtOBQ0YRgXgnn_W4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/zuMTpdqnFNY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/08/testy-c-test-method-snippet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/08/testy-c-test-method-snippet/</feedburner:origLink></item>
		<item>
		<title>Origin of the term “bug”</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/A0HBegVSPXE/</link>
		<comments>http://www.ipreferjim.com/2011/08/origin-of-the-term-bug/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 19:23:45 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=667</guid>
		<description><![CDATA[Grace Murray Hopper was a Navy officer who was instrumental in the development of COBOL, one of the first programming languages to use the English language to write code instead of assembly or machine language. In 1947, computers used relays instead of transistors as they are today (or vacuum tubes some time between). Relays are [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Wikipedia: Grace Hopper" href="http://en.wikipedia.org/wiki/Grace_Hopper" target="_blank">Grace Murray Hopper</a> was a Navy officer who was instrumental in the development of COBOL, one of the first programming languages to use the English language to write code instead of assembly or machine language.</p>
<p>In 1947, computers used relays instead of transistors as they are today (or vacuum tubes some time between). Relays are little (usually magnetic) switches which are essentially a mechanical representation of binary (on or off).</p>
<div id="attachment_669" class="wp-caption alignright" style="width: 135px"><a href="http://www.ipreferjim.com/site/wp-content/uploads/2011/08/Relay.jpg?84cd58"><img class="size-full wp-image-669  " title="Relay" src="http://www.ipreferjim.com/site/wp-content/uploads/2011/08/Relay.jpg?84cd58" alt="A relay" width="125" height="163" /></a><p class="wp-caption-text">A relay</p></div>
<div id="attachment_668" class="wp-caption alignright" style="width: 190px"><a href="http://www.ipreferjim.com/site/wp-content/uploads/2011/08/h96566k.jpg?84cd58"><img class="size-medium wp-image-668 " style="margin-top: 3px; margin-bottom: 3px; margin-left: 8px; margin-right: 8px; border-width: 1px; border-color: black; border-style: solid;" title="The first computer &quot;bug&quot;" src="http://www.ipreferjim.com/site/wp-content/uploads/2011/08/h96566k-300x249.jpg?84cd58" alt="U.S. Naval Historical Center Online Library Photograph NH 96566-KN" width="180" height="149" /></a><p class="wp-caption-text">U.S. Naval Historical Center Online Library Photograph NH 96566-KN</p></div>
<p>When relays encountered foreign objects, they would no longer switch optimally, if at all. In 1947, a moth got caught on a relay and died. The team recorded the incident:</p>
<blockquote><p>Relay #70 Panel F<br />
(moth) in relay.</p>
<p>First actual case of bug being found.</p></blockquote>
<p>They announced that they had "debugged" the system.</p>
<p>From that moment on, anything preventing a program from performing optimally or failing altogether has been referred to as a "bug". On the other hand, "debugging" has strayed somewhat to not only mean removing bugs from a program but is also used to mean a programmer is stepping through code to ensure it works as planned (whether or not bugs exist).</p>
<p>The history of computers is very interesting. Sometimes slang terms like "bug" are easily adopted by the community. Sometimes terms like "core" are used to refer to things which have evolved away from the original implementation.</p>
<p>For more information about Grace Hopper and "bugs", check out these resources:</p>
<ul>
<li><a href="http://www.history.navy.mil/photos/pers-us/uspers-h/g-hoppr.htm" target="_blank">http://www.history.navy.mil/photos/pers-us/uspers-h/g-hoppr.htm</a></li>
<li><a href="http://en.wikipedia.org/wiki/Grace_Hopper" target="_blank">http://en.wikipedia.org/wiki/Grace_Hopper</a></li>
<li><a href="http://en.wikipedia.org/wiki/Relay" target="_blank">http://en.wikipedia.org/wiki/Relay</a></li>
</ul>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/WQqWI9vxjPkv0fAUo02yrBnmGvQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/WQqWI9vxjPkv0fAUo02yrBnmGvQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WQqWI9vxjPkv0fAUo02yrBnmGvQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/WQqWI9vxjPkv0fAUo02yrBnmGvQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/A0HBegVSPXE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/08/origin-of-the-term-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/08/origin-of-the-term-bug/</feedburner:origLink></item>
		<item>
		<title>[c#] Instantiating an object with a private constructor</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/kVZFbCIyI4k/</link>
		<comments>http://www.ipreferjim.com/2011/08/c-instantiating-an-object-with-a-private-constructor/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 18:26:43 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=661</guid>
		<description><![CDATA[Not too long ago, I needed to modify a type available in the the BCL which didn't have a public constructor or any method for creating an instance of the object. The solution was to use reflection to invoke the type's private constructor. Caveat! Most times, these types are designed with private methods for a [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago, I needed to modify a type available in the the BCL which didn't have a public constructor or any method for creating an instance of the object.  The solution was to use reflection to invoke the type's private constructor.</p>
<p><strong>Caveat!</strong><br />
Most times, these types are designed with private methods for a reason.  There may be internal dependencies which can cause all kinds of problems if they're not met. Only do something like this if you're writing tests against the constructor or exploring the capabilities of Reflection.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.reflection.constructorinfo.aspx">ConstructorInfo Class</a> is the one we'll use.  If your constructor is parameterless and non-public, you can instead do:</p>
<pre class="brush: csharp; title: ; notranslate">
var myType = (MyType)Activator.CreateInstance(typeof(MyType), true /*nonPublic*/);
</pre>
<p>To instantiate an object from a non-public constructor with parameters, you'll need three things:</p>
<ul>
<li>the target type</li>
<li>an array of parameter types (same order as signature)</li>
<li>a reference to the constructor</li>
</ul>
<p>Suppose your target type is defined as:</p>
<pre class="brush: csharp; title: ; notranslate">
  class Example
    {
        public string Display { get; private set; }
        private Example(string msg)
        {
            Display = msg;
        }
    }
</pre>
<p>To instantiate this object, you can do the following:</p>
<pre class="brush: csharp; title: ; notranslate">
      // 1. the target type
      var exampleType = typeof(Example);

      // 2. an array of parameter types (same order as signature)
      var argTypes = new Type[] { typeof(string) };

      // 3. a reference to the constructor
      // Because method signatures must be unique in parameters and return type,
      // this will return the matching constructor, or ctor will be null.
      ConstructorInfo ctor = exampleType.GetConstructor(
          BindingFlags.Instance | BindingFlags.NonPublic,
          null, argTypes, null);

      // similar to var example = new Example(&quot;You've set me privately!&quot;)
      var example = (Example)ctor.Invoke(new []{ &quot;You've set me privately!&quot; });

      Console.WriteLine(&quot;Example's display: {0}&quot;, example.Display);
</pre>
<p>Note:<br />
<strong>ConstructorInfo</strong> requires FullTrust.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/nQeUQfqEFWEYUkXT73-FQUqIPCM/0/da"><img src="http://feedads.g.doubleclick.net/~a/nQeUQfqEFWEYUkXT73-FQUqIPCM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/nQeUQfqEFWEYUkXT73-FQUqIPCM/1/da"><img src="http://feedads.g.doubleclick.net/~a/nQeUQfqEFWEYUkXT73-FQUqIPCM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/kVZFbCIyI4k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/08/c-instantiating-an-object-with-a-private-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/08/c-instantiating-an-object-with-a-private-constructor/</feedburner:origLink></item>
		<item>
		<title>[js] Closures versus Functional Scoping</title>
		<link>http://feedproxy.google.com/~r/ipreferjim/~3/P4q-T-QEvn0/</link>
		<comments>http://www.ipreferjim.com/2011/08/js-closures-versus-functional-scoping/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 03:47:40 +0000</pubDate>
		<dc:creator>jimschubert</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ipreferjim.com/?p=652</guid>
		<description><![CDATA[I was recently asked a very simple JavaScript question: what is a closure? Of course, I answered it (correctly, might I add) as "it means capturing a variable inside a function". I was asked for an example, so I said, "Well, first I'd like to show a common mistake of closures when using loops." I [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently asked a very simple JavaScript question: <strong>what is a closure?</strong></p>
<p>Of course, I answered it (correctly, might I add) as "it means capturing a variable inside a function". I was asked for an example, so I said, "Well, first I'd like to show a common mistake of closures when using loops." I gave the common <em><a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures#Creating_closures_in_loops.3a_A_common_mistake" title="MDN : A common mistake with closures" target="_blank">looping mistake</a></em> example:</p>
<pre class="brush: jscript; title: ; notranslate">
var someArrayOfThings = /* [blah blah blah objects blah blah] */;
for (var i = 0, len = someArrayOfThings.length; i &lt; len; i++) {
   var item = someArrayOfThings[i];
   // some function here to access item
}
</pre>
<p>There was some huffing about this.  Maybe the developer didn't understand where I was going, or didn't care. Unfortunately, I wasn't asked to explain why it would cause an error. I should have given the <a href="http://jsfiddle.net/v7gjv/" title="jsfiddle example from MDN" target="_blank">example from MDN</a> verbatim.</p>
<p>So, this guy gave me the following 'example':</p>
<pre class="brush: jscript; title: ; notranslate">
var a = 1;
function a() {
  var a = 0;
  test = function() { alert(a); }
  test();
}
a();
</pre>
<blockquote><p>
Him: What does this do?<br />
Me: Uh... nothing.<br />
Him: No, you're wrong.<br />
Me: Uh... I'm pretty sure I'm right.<br />
Him: No, I'm sure you're wrong. This will alert 0. Always.
</p></blockquote>
<p>So sure?  <a href="http://jsfiddle.net/G8ydD/" title="Am I so wrong?" target="_blank">Try it yourself</a>.</p>
<p><strong>Why I was right.</strong></p>
<ul>
<li>"Functional scoping" !== "closure"</li>
<li>Hoisting redefines '<strong>a</strong>' from function to number, not the other way around.</li>
<li>Did he mean to define '<strong>test</strong>' as a global?</li>
</ul>
<p>This guy wasn't even talking about a 'closure', he was displaying <em>functional scoping</em>.  I can understand the misconception between the two. A 'closure' occurs when a function <em>closes</em> the functional chain over some variable available at a greater scope, making that variable look like part of the function.</p>
<p>For instance:</p>
<pre class="brush: jscript; title: ; notranslate">
var message = &quot;outside&quot;;
var first = function() {
    var message = &quot;inside&quot;;
    var second = function() { alert(message); }
    return second();
};

first(); // alerts &quot;inside&quot;
</pre>
<p><a href="http://jsfiddle.net/G8ydD/1/" target="_blank">View on jsfiddle.net</a></p>
<p>In this example, the <em>functional scope</em> of the second function <em>has access to</em> the message which holds "inside".  This is exactly the same concept as the developer was getting at. However, just calling the function, as in his example, doesn't close the outer function chain. Yes, variables captured inside functions will hold the value of the variable at the level of scope of when the function was declared. However, in his example he's just calling (or he thinks he is, I'll get to that later) one function to another: </p>
<pre class="brush: plain; title: ; notranslate">
call a -&gt;
  set local a to zero -&gt;
    define 'inner function' -&gt;
      call inner function -&gt;
        alert a from outer scope
</pre>
<p>As you can see, there is no 'capturing' of any variables.  You could just as easily write this up without the added complexity of an inner function.</p>
<p>In my example, the execution goes more like this:</p>
<pre class="brush: plain; title: ; notranslate">
parse first -&gt;
  create second function -&gt;
    capture message &quot;inside&quot; -&gt;
      compile second function to alert(&quot;inside&quot;) -&gt;
        call newly compiled function
</pre>
<p>If you're familiar with C++, this is similar to a function pointer. In C#, it's almost like a compiled expression. Your function is actually encapsulating the data created by the closure.</p>
<p>Then again, I consider this all common sense about JavaScript.</p>
<p><strong>On to the fundamental incorrectness of the not-mine example</strong><br />
So, I asked, "Both variables and the function are <strong>a</strong>?" "Yes" "Then, I'm sure it won't do anything!" (Ok, I just want to drive that home!) Then I said, "If you rename the function, then yes... it will alert 0."</p>
<p><a href="http://jsfiddle.net/G8ydD/2/" target="_blank">See for yourself!</a></p>
<p><strong>Function definition versus function declaration.</strong><br />
Here is an obviously very little known fact about JavaScript. You can declare a function in two general ways in JavaScript:</p>
<pre class="brush: jscript; title: ; notranslate">
// function definition
var myFunction = function() { alert(&quot;My function!&quot;); }

// function declaration
function myFunction() { alert(&quot;My function!&quot;); }
</pre>
<p>I <em>rarely</em> ever use the second form of declaring a function. </p>
<p>In the function definition (first) example, only the variable is hoisted to the top of the current scope. 'myFunction' will always refer to your function.  If you reassign myFunction to an integer, it's an integer.  If you've previously defined it as an integer and reassign to a function, it's a function. This is the commonly expected behavior and is why you should declare all of your variables at the top of every function.</p>
<p>In the function declaration example, the <em>entire</em> function is hoisted!! This is done because JavaScript allows you to call methods which haven't physically been defined yet. So, the code the developer wrote for me and insisted was correct is actually parsed like this by JavaScript standards:</p>
<pre class="brush: jscript; title: ; notranslate">
function a() {
  var a = 0;
  test = function() { alert(&quot;a&quot;);}
  test();
}
var a = 1;
a();
</pre>
<p>If you don't believe me, run <a href="http://jsfiddle.net/G8ydD/" target="_blank">the first example</a> on jsfiddle and <a href="http://jsfiddle.net/G8ydD/3/" target="_blank">this example</a>. If you look in your browser's console, you should see the same error for both bits of code. e.g. in Chrome 15:</p>
<pre class="brush: plain; title: ; notranslate">
Uncaught TypeError: number is not a function
</pre>
<p>As you can see, JavaScript implicitly raises all function declarations to the top of your scope!  <strong>BE CAREFUL WITH THIS.</strong></p>
<p>In contrast, had this developer written the function in my preferred way, I would have said, "It will alert 0, but you shouldn't be assigning the function to a global variable!" So, in the future, it's <a href="http://jsfiddle.net/G8ydD/4/" target="_blank">my way or the highway</a>.</p>
<p>I highly recommend that every developer who writes JavaScript code read <a href="http://oreilly.com/catalog/9780596805531" title="JavaScript: The Definitive Guide by David Flanagan" target="_blank">JavaScript: The Definitive Guide by David Flanagan</a>. You will learn everything about the language you'll ever need to know.  You'll learn quirks like the function-hoisting I've described here.</p>
<p>Even if you're like me, and you've been using JavaScript since 1998 or 1999, you'll learn a LOT.  I'll admit, I used to hate JavaScript with a fiery passion.  It wasn't until 2006 or so when jQuery appeared and made JavaScript cool again that I started to really dig into it. Anyway, read the book!</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/MLqzvy4-9Swoy2zCGtwBlcdmMkc/0/da"><img src="http://feedads.g.doubleclick.net/~a/MLqzvy4-9Swoy2zCGtwBlcdmMkc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MLqzvy4-9Swoy2zCGtwBlcdmMkc/1/da"><img src="http://feedads.g.doubleclick.net/~a/MLqzvy4-9Swoy2zCGtwBlcdmMkc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ipreferjim/~4/P4q-T-QEvn0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ipreferjim.com/2011/08/js-closures-versus-functional-scoping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ipreferjim.com/2011/08/js-closures-versus-functional-scoping/</feedburner:origLink></item>
	</channel>
</rss><!-- Served from: www.ipreferjim.com @ 2012-02-03 19:48:29 by W3 Total Cache -->

