Josh Davis' Personal Site2023-05-01T01:33:48+00:00https://joshldavis.comJosh Davishello@joshldavis.comAmazon's Culture of Discomfort2018-07-22T00:00:00+00:00https://joshldavis.com/2018/07/22/amazons-culture-of-discontent<h1 id="amazons-culture-of-discomfort">Amazon’s Culture of Discomfort</h1>
<blockquote>
<p>The unknown Leadership Principle.</p>
</blockquote>
<p>It’s well known that Amazon gives every new employee a door as a desk on their
first day. As Ben Horowitz says in <a href="https://www.amazon.com/dp/0062273205//ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=jld07-20&linkId=49551e190963fada0fc8f31a210d93c1">The Hard Thing About Hard
Things</a>, this is a way to set the tone of the culture.</p>
<p>It reminds employees the tenants of the culture and breaks previous habits. It
is a physical symbol of <a href="https://www.amazon.jobs/principles">one of the Leadership Principles</a>: Frugality.</p>
<p>He writes in the chapter of Programming Culture:</p>
<blockquote>
<p>… when a shocked new employee asks why she must work on a makeshift desk
constructed out of random Home Depot parts, the answer comes back with
withering consistency: “We look for every opportunity to save money so that we
can deliver the best products for the lowest cost.” If you don’t like sitting
at a door, then you won’t last long at Amazon.</p>
</blockquote>
<p>The door desk is very well known and for good reason. However there is a more
fundamental part of their culture that has a larger influence but no one talks
about.</p>
<h2 id="the-moving-door-desk">The Moving Door Desk</h2>
<p>Ask any Amazon employee that has worked there for more than a few years and they
will be able to tell you the number of times they have moved their desk.</p>
<p>More than likely the number of times their door desk has been moved will be
comparable to their tenure or in some cases close to the number of years they’ve
worked there.</p>
<p>Amazon has grown so rapidly that it went from <a href="https://www.seattletimes.com/business/real-estate/watch-amazons-seattle-campus-quadruple-in-size-in-a-decade/">11 buildings in 2007 to over 40
in late 2017</a>. Below is a gif from that article to visualize the
growth. It has also made <a href="https://www.seattletimes.com/business/amazon/thanks-to-amazon-seattle-is-now-americas-biggest-company-town/">Seattle the largest company town</a> with
8.1 million square feet of office space which is more than the next 43 largest
companies in Seattle.</p>
<p>Both articles were written by <a href="https://twitter.com/ByRosenberg">Mike Rosenberg</a>.</p>
<div>
<img src="/img/amazon-culture/footprint.gif" alt="Amazon's growing footprint" />
</div>
<p>Desks move for various reasons. It was common in AWS due to the rapid expansion
of hiring for service teams. As teams grow, in order to keep organizations close
to each other, it would be necessary to move them around to make space.</p>
<p>It seemed like a monthly struggle of resources of trying to get more space
without engineers having to sit on top of each other. It often involved lots of
coordination because it very quickly becomes a resource constraint problem as
other teams would also be vying for more space.</p>
<p>It also was common for your desk to be moved when a team or product was moved
into another organization or when a leader changed. Due to the urban campus, the
odds were high that the new organization would be in another building.</p>
<p>To move an employee’s stuff, large orange crates would be given out and it was
not uncommon for an employee to just leave their stuff in it for the next year
rather than unpacking it because they knew it was only a matter of time until
the next inevitable move.</p>
<p>I was there for 3.5 years and moved 3 times between buildings and 3 times within
those buildings for a total of 6. These were mini-moves where I would move my
desk across the floor or to another part of the team area. Although far easier
of a move, it has a similar impact on the culture.</p>
<p>I used to keep my area decorated with nice pictures or things to occupy space on
my desk but eventually stopped putting them back up after the first few moves.</p>
<h2 id="cultural-impact">Cultural Impact</h2>
<p>Unlike the door desk, there is no Leadership Principle that matches it. Instead,
it’s an unwritten rule of the culture that says: Don’t Get Comfortable.</p>
<p>Don’t get comfortable and stop improving the product or driving towards
operational excellence. Don’t get comfortable and not obsess over what your
customers want. Don’t get comfortable and not push your team and yourself to get
better.</p>
<p>It’s a small overlooked part of the culture that I’d argue is more impactful
than the door desk.</p>
Splootysplotty: Open Source Alternative to Lewis Carroll's Jabberwocky2018-03-25T00:00:00+00:00https://joshldavis.com/2018/03/25/splootysplotty-open-source-alternative-to-jabberwocky<div class="sploot-logo">
<img src="/img/splootysplotty/logo.png" alt="Logo of Splootysplotty" />
</div>
<h2 id="splootysplotty-open-source-alternative-to-lewis-carrolls-jabberwocky">Splootysplotty: Open Source Alternative to Lewis Carroll’s Jabberwocky</h2>
<p>(This is a satire article that is critiquing the common naming
scheme in some open source projects. See <a href="#lets-have-a-talk-open-source">this section below</a> for more details.)</p>
<p>Welcome to my fantastic open source project named Splootysplotty. It is easier
now than ever to Sploot the Splott.</p>
<p>It is an open source improvement on the legacy software of <a href="https://www.poetryfoundation.org/poems/42916/jabberwocky">Jabberwocky
1.0</a> written long ago. It is comparable to any of these projects:
Dalo, Jotts, or Lablem.</p>
<p>I’m very excited for you to use Splootysplotty. Below is my guide on the
problem it solves as well as the why and how to use it.</p>
<p>Splootysplotty has a few core concepts and ideas that you need to understand. I
decided to take these common concepts and instead give them new names to make it
easier to understand my fantastic open source project.</p>
<p>You’ll have to memorize what these terms are but that’s okay because they are
related to the theme of Splootysplotty and it makes it so much more fun. I’m
sure you will appreciate it when you start to learn this fantastic open source
project.</p>
<h2 id="splootysplotty-guide">Splootysplotty Guide</h2>
<div class="poem">
<p>
'Twas haplex and kuffle problem.
<br />
<span>Projects Dalo and Jotts voluck.</span>
<br />
It's not folazy as Lablem,
<br />
<span>But merely fosts toontruck.</span>
</p>
<p>
"Just Sploot and Splott!” I say ageel.
<br />
<span>Frispy code, interface that’s sweeze.</span>
<br />
Need not go and retrend the wheel,
<br />
<span>Chornings ne'er zolter than these.</span>
</p>
<p>
To Sploot the Splott, use a Sorzer,
<br />
<span>Contigged to process jobaley.</span>
<br />
Sorzers are but many Vorder,
<br />
<span>So bostruct it gosalee.</span>
</p>
<p>
We soload it from the Koltam,
<br />
<span>Where all the cakedent Codelets be.</span>
<br />
Run a Doclot with Luds param,
<br />
<span>But not with the Bapaley.</span>
</p>
<p>
Beep, boop! Beep, boop! And loop and loop
<br />
<span>The sussy data is contruced.</span>
<br />
And with the code, that's on the node
<br />
<span>The Malicon is produced.</span>
</p>
<p>
Sploot of the Splott, solmedds the lot,
<br />
<span>Zassy, acey, all the features.</span>
<br />
O gosly devs! Happy! Jubsot!
<br />
<span>Heed the ease procedures.</span>
</p>
<p>
'Twas haplex and kuffle problem.
<br />
<span>Projects Dalo and Jotts voluck.</span>
<br />
It's not folazy as Lablem,
<br />
<span>But merely fosts toontruck.</span>
</p>
</div>
<hr />
<h3 id="lets-have-a-talk-open-source">Let’s Have a Talk, Open Source</h3>
<p>But for real, if you create a new project just name things what they are.</p>
<p>We already know what a dependency is. We know what a template is. We know what a
function is. We know what things are, so just name them accordingly.</p>
<p>Choosing names that obscure the concepts and constructs just increases the
barrier to entry of understanding a project.</p>
<p>Coding is the easier part of technology but working with people and
communicating is the hard part. Let’s not make it worse by using <em>Jabberwocky
Terminology</em>.</p>
<h3 id="wall-of-shame">Wall of Shame</h3>
<p>Let’s collect various examples of this in current open source projects.</p>
<p>If you think of any more, please check out and contribute to the:</p>
<div class="buttons">
<a class="button" href="/jabberwocky-terminology">Jabberwocky Terminology Wall of Shame</a>
</div>
<h3 id="thank-you">Thank You!</h3>
<p>For more brillig insight and chortling joy, <a href="https://twitter.com/jldavis">folound me on Twitter</a>.</p>
<p><strong>Note:</strong> Credit to <a href="https://twitter.com/ballpointcarrot">Chris Kruse</a>, <a href="https://twitter.com/cmueller">Chris Mueller</a>, and <a href="https://twitter.com/conorgil">Conor
Gilsenan</a> for critiques and criticism. Their compelling commentary on the
concepts cemented the couplets convincingness.</p>
An Email from Edsger Dijkstra's Son2017-10-11T00:00:00+00:00https://joshldavis.com/2017/10/11/an-email-from-edsger-dijkstras-son<h1 id="an-email-from-edsger-dijkstras-son">An Email from Edsger Dijkstra’s Son</h1>
<p>Over four years ago I wrote about how I learned to <a href="/2013/05/20/the-path-to-dijkstras-handwriting/">write like
Dijkstra</a>. Since then it has become one of my most visited blog
posts.</p>
<p>The last person I ever expected to read it though was one of Dijkstra’s family
members.</p>
<p>In January 2016, I received an email from Marcus Dijkstra, Edsger’s son. It was
a surreal moment and an one of my favorite emails to date.</p>
<p>I want to share it with everyone because of the extra details it has about how
Dijkstra improved upon his handwriting.</p>
<h2 id="the-email">The Email</h2>
<blockquote>
<p>Hi Josh,</p>
<p>a friend pointed me to your blog post on handwriting improvement.</p>
<p>Edsger used always a clipboard, where he would use a page with horizontal
lines under the white A4. I suspect that that (as long as one can be
self-disciplined enough to keep paying attention) does contribute to the
groundedness of the script.</p>
<p>He spend quite some time finding the right spacing, and experimented with
double lines, so as to have a top and bottom for the aceimnorsuvwxz letters,
as well as length indicators for bdhklf and gjpqy sticks. In the end this was
discarded in favour of a fairly wide spaced lined one.</p>
<p>The script itself was carefully designed (and subsequently trained on, always
carefully drawing the individual letters one by one, albeit faster in time) to
avoid ambiguity like between x and multiplication, one and the letter l, seven
and one, zero and the letter o etc. after he found sometimes not being sure
about what he actually wrote the day before and seeing students ending up in
real messes.</p>
<p>From the party trick department: After having trouble with his right wrist
(arm?) caused by too many hours of writing he decided to learn to do it left
handed too. After a few months he could, and kept writing left handed
alternate days, also after his right arm was back in business.</p>
<p>Enjoy your script,</p>
<p>Marcus</p>
</blockquote>
Iowa, Pigs, Microchips, and Founding Silicon Valley2016-06-20T00:00:00+00:00https://joshldavis.com/2016/06/20/iowa-pigs-microchips-and-founding-silicon-valley<h1 id="iowa-pigs-microchips-and-founding-silicon-valley">Iowa, Pigs, Microchips, and Founding Silicon Valley</h1>
<p>Last night I was reading the <a href="https://www.amazon.com/gp/product/019531199X/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=019531199X&linkCode=as2&tag=jld07-20&linkId=f44ab354e414f1b773327dcac792931c">The Man Behind the Microchip</a> by Leslie
Berlin which tells the story of <a href="noyce">Robert Noyce</a>.</p>
<p>Noyce, also known as “The Mayor of Silicon Valley”, was credited with the
invention of the microchip, cofounding Fairchild
Semiconductor and Intel. Together with Andy Grove and Gordon Moore,
<a href="https://stratechery.com/2016/andy-grove-and-the-iphone-se/">they created</a> the culture and economic force that Silicon Valley
became.</p>
<h2 id="personal-significance">Personal Significance</h2>
<p>Besides the obvious reason of wanting to read more about Noyce because he set
the foundation for my career of choice, I was also interested because he was
born in Iowa like myself.</p>
<p>It may seem insignificant but there’s something fantastic when reading about an
incredible figure that came from a similar upbringing. We both lived in small
towns that were separated by only a three hour drive and half a century in time.</p>
<h2 id="the-story">The Story</h2>
<p>To set the stage, this story took place when Robert Noyce was still an undergrad
living in Iowa attending <a href="https://en.wikipedia.org/wiki/Grinnell_College">Grinnell College</a>.</p>
<p>Here’s the story which starts on page 21:</p>
<blockquote>
<p>Every spring and fall, each hall hosted a party. In their zeal to create the
most spectacular party – the better the celebration, the larger the pool of
potential dates – residents often enhanced the décor with a few bales of hay
or a stack of lumber “borrowed” from unsuspecting farmers or townfolk.</p>
<p>Noyce lived in Clark Hall, which decided upon a Hawaiian luau theme for its
spring house party a few weeks before the end of his junior year. Since Noyce
knew the town of Grinnell especially well, he was assigned the task of
liberating a young pig to be roasted upon a realistic looking <a href="https://en.wiktionary.org/wiki/spit_roast">spit</a>.</p>
<p>[Noyce and his partner in crime] walked across the golf course behind the
campus, grabbed a suckling pig, and ran with it back to Clark Hall. His
housemates decided to butcher the piglet in a third-floor shower. A
frantically squealing animal, intoxicated young men with knives – the ruckus
was such that students all over campus immediately knew something untoward was
happening in Clark Hall. The administration, however, did not hear about it
until the next day, when Noyce and his housemate repented and returned to the
farm with an offer to pay for the pig, whose absence had not yet been noticed.</p>
<p>It quickly became apparent that Noyce had not chosen a good farm to target.
The farmer was the mayor of Grinnell, a no-nonsense man given to motivating
his constituents through mild intimidation.</p>
<p>Noyce’s previous exploits […] had been dismissed as boys-will-be-boys
tomfoolery. Stealing a pig was a different matter entirely. It crossed the
line Noyce had skirted throughout his high school years, for as the letter the
dean sent home to Ralph and Harriet Noyce explained, “In the agricultural
state of Iowa, stealing a domestic animal is a felony which carries a minimum
penalty of a year in prison and a fine of one thousand dollars.” A prize pig
could easily sell for $1,000, nearly three times Noyce’s annual college
tuition.</p>
<p>Grant Gale [Noyce’s physics professor] and Grinnell College president Stevens
were in a frenzy. Even without a criminal conviction, expulsion alone would
have meant the end of the boys’ education. In 1948 no school would have
accepted a student expelled from another, and Gale in particular could not
bear the prospect of “losing Bob.” The two college representatives, both
longtime residents of Grinnell and friends of the Noyces, brokered a
compromise in which the college would compensate the farmer for his pig, and
no charges would be pressed. The boys would be allowed to finish the few
remaining days of their junior year but were suspended for the first semester
of their senior year.</p>
</blockquote>
<h2 id="a-sound-of-thunder">A Sound of Thunder</h2>
<p>There are an infinite number of butterflies that can change history. This one
stuck out at me because it is so Iowan, yet ties together two completely
different parts of American history: the agrarian one and the current
technological one.</p>
<p>It’s probably safe to say that if Robert Noyce hadn’t graduated from Grinnell
College, went to graduate school at MIT, then to work with <a href="https://en.wikipedia.org/wiki/William_Shockley">William
Shockley</a> with the knowledge and expertise that he had in transistors,
that Silicon Valley either would have been delayed or at least it would look
different than it does today.</p>
<p>I loved this story and the implication it could have had on the future if a grumpy
mayor had gotten his way. It’s a quirky little part of history that reminded me
of technology, Silicon Valley, and the state that I never felt apart of yet
still love.</p>
The Bram Moole-Laaw: There Will be Attempts to Rewrite Vim in Nearly Every New Language2015-11-29T00:00:00+00:00https://joshldavis.com/2015/11/29/the-bram-moole-laaw-vim-re-write<h1 id="the-bram-moole-laaw-there-will-be-attempts-to-rewrite-vim-in-nearly-every-new-language">The Bram Moole-Laaw: There Will be Attempts to Rewrite Vim in Nearly Every New Language</h1>
<p>It started out as a tongue-in-cheek <a href="https://twitter.com/HopefulJosh/status/639179394309685248">Tweet</a> but I’ve decided to write a
blog post on it so it can reach a wider audience. Plus it’s always fun to come
up with new software laws and Jeff Atwood <a href="http://blog.codinghorror.com/the-principle-of-least-power/">would agree</a>.</p>
<p>Before we get to the law though, let’s look at why this law exists.</p>
<h2 id="a-very-short-history">A Very Short History</h2>
<p>Vim is one of the most popular text editors of all time and has been around for
<a href="http://moolenaar.net/vimstory.pdf">nearly 30 years (pdf)</a> since version 1.0.</p>
<p>It has perhaps the most imitated and desired key bindings (possibly second only
to <a href="https://en.wikipedia.org/wiki/GNU_Readline#Keyboard_shortcuts">GNU readline’s</a>) when it comes to editing. Somehow these
key bindings make their way into nearly every mainstream editor that comes
along.</p>
<p>Here are some of the latest and greatest editors (as well as <a href="https://en.wikipedia.org/wiki/Editor_war">one of the
worst</a>) with their accompanying Vim plugins:</p>
<ol>
<li><a href="https://atom.io/">Atom</a> with <a href="https://github.com/atom/vim-mode">Vim Mode</a></li>
<li><a href="https://www.sublimetext.com/">Sublime Text</a> with <a href="https://www.sublimetext.com/docs/2/vintage.html">Vintage Mode</a></li>
<li><a href="http://brackets.io/">Brackets</a> with <a href="https://github.com/daveosborne/brackets-vimderbar">Vimderbar</a></li>
<li><a href="https://www.jetbrains.com/">All of Jetbrain’s IDEs</a> with <a href="https://github.com/JetBrains/ideavim">IntelliVim</a></li>
<li><a href="https://www.gnu.org/software/emacs/">Emacs</a> with <a href="http://www.emacswiki.org/emacs/Evil">Evil</a> (the worst, <em>obviously</em>)</li>
</ol>
<p>The list goes on and on. The most salient point is that Vim quite clearly has
hit a sweet spot in developer’s hearts with the ability to edit text fast, with
its modal editing, and overall power without ever requring a mouse.</p>
<h2 id="the-first-rewrite">The First Rewrite</h2>
<p>There are a lot of people that know that Vim stands for Vi iMproved but this
wasn’t true until its 2.0 release in 1993. Before being called Vi iMproved, it
was called Vi iMitation. Do you see a pattern?</p>
<p>The reason for this is because <a href="https://en.wikipedia.org/wiki/Bram_Moolenaar">Bram Moolenaar</a>, the original creator
of Vim (and apparently a big fan of German beer as dictated by his Wikipedia
picture?), had an Amiga computer at the time but Vi wasn’t available for it. So
he started out with a different text editor and eventually built it up to add Vi
functionality. In fact, Vim still has Amiga code and might still work with
<a href="http://www.vim.org/download.php#amiga">some versions</a>.</p>
<p>This was the first Vi rewrite (albeit in the same language, C) and a very large
success by Bram. To this day, if you run <code class="language-plaintext highlighter-rouge">vi</code> on most systems, it is just
symlinked to <code class="language-plaintext highlighter-rouge">vim</code> as you can see from El Capitan’s <code class="language-plaintext highlighter-rouge">/usr/bin/</code>.</p>
<div class="gallery medium">
<a href="/img/bram/symlink.png">
<img src="/img/bram/symlink.png" alt="OS X 10.11 /usr/bin" />
<span>OS X 10.11's /usr/bin</span>
</a>
</div>
<h2 id="the-law">The Law</h2>
<p>This finally brings me to The Law which will from now on will be called <strong>The Bram
Moole-Laaw</strong>. This is because Bram is currently the <a href="https://en.wikipedia.org/wiki/Benevolent_dictator_for_life">BDFL</a> of Vim and
was the first (and so far the last?) person to ever successfully rewrite
Vi/Vim.</p>
<p>Here is The Law:</p>
<blockquote>
<p>With any new language that is sufficiently popular, it will be used to
re-write Vim from <em>within</em> Vim as long as Vim is still around.</p>
</blockquote>
<p>The first quantifier is there because anyone can create a little language. But
this law won’t hold if enough people don’t use the language.</p>
<p>The second quantifier is mainly a joke in that most of the people writing these
rewrites are probably using Vim to code in.</p>
<h2 id="a-refactoring">A Refactoring?</h2>
<p>Now I know what you are all thinking, what about <a href="https://neovim.io/">Neovim</a>? Well,
Neovim has never wanted to rewrite Vim from scratch. It is just a refactoring.</p>
<p>In <a href="https://youtu.be/R7z2GQr9-tg?t=38m20s">an interview</a>, Justin Keyes, one of the project managers for Neovim, was asked
what he thought about porting Neovim (or Vim for that matter) to another
language or rewriting it.</p>
<p>Here was his reply:</p>
<blockquote>
<p>Crazy idea. Many have tried and they all have pretty much failed. And there
still are new projects coming out.</p>
</blockquote>
<p>When given an example of a <a href="https://github.com/mathall/rim">latest Rust rewrite of Vim</a>, Justin
continues:</p>
<blockquote>
<p>The thing is, it sounds like a fun project. But the problem is, people always
get past the first few steps and have an interface that feels like Vim,
mostly. At least for the way the commands work together.</p>
<p>But then there are all these dark, dusty, unsexy corners that never get
implemented because they are boring. They are full of corner cases that were
already figured out in Vim. Like the way that it handles shell commands and
redirects. That has all been figured out already. That’s not going to exist in
the Vim port that someone wrote for fun because it’s not a fun thing to
implement. It’s actually a mess.</p>
<p>Things like cscope and tags. The ctags support in Vim is pretty good and
useful but if you are going to write a new editor, you’re going to be like
“this is dumb, I’m going to do it a different way” but then that’s going to be
yet another feature that someone that is used to Vim is not going to be there
and they are going to miss it because it works in a very specific way.</p>
</blockquote>
<p>Justin then goes on to discuss some other features of Vim that might be lost in
such ports.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Vim is a great editor and will forever be remembered if its end ever comes. I
don’t fault anyone for wanting to rewrite it.</p>
<p>However, now when the next rewrite comes along, we can use common vocabulary to
discuss such an event.</p>
<p>Also, this article was written in pure jest and I meant nothing malicious to all
those that have tried. I think all of the rewrites are great because it is a
great way to learn new concepts and a new language. Plus like I mentioned, Vim
was just an iMitation at the start as well.</p>
Self Documenting Vim Key Mappings2015-08-22T00:00:00+00:00https://joshldavis.com/2015/08/22/self-documenting-vim-mappings<h1 id="self-documenting-vim-key-mappings">Self Documenting Vim Key Mappings</h1>
<p>When configuring Vim with plugins, one of the common things that I like to do is
to dedicate a letter to a single Vim plugin (or a group of similar tasks).</p>
<p>An example of this is below where I have some key mappings for @tpope’s <a href="https://github.com/tpope/vim-fugitive">Fugitive
plugin</a>:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Fugitive mapping</span>
nmap <span class="p"><</span>leader<span class="p">></span>gb <span class="p">:</span>Gblame<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>gc <span class="p">:</span>Gcommit<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="nb">gd</span> <span class="p">:</span>Gdiff<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>gg <span class="p">:</span>Ggrep
nmap <span class="p"><</span>leader<span class="p">></span>gl <span class="p">:</span>Glog<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="nb">gp</span> <span class="p">:</span>Git pull<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>gP <span class="p">:</span>Git push<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>gs <span class="p">:</span>Gstatus<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>gw <span class="p">:</span>Gbrowse<span class="p"><</span><span class="k">cr</span><span class="p">></span></code></pre></figure>
<h2 id="the-problem">The Problem</h2>
<p>Most of the mappings and plugin functions are pretty straight forward and they
aren’t hard to remember. Unfortunately I have some other key mappings that are a
bit harder to remember.</p>
<p>Take for example these <a href="http://cscope.sourceforge.net/">cscope</a> mappings:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim">nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span>s <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> s <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">g</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">g</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">c</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">c</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">t</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">t</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">e</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">e</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">f</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">f</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cfile>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">i</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">i</span> ^<span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cfile>"</span><span class="p">)<</span>CR<span class="p">></span>$<span class="p"><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">d</span> <span class="p">:</span><span class="k">cs</span> <span class="k">find</span> <span class="k">d</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span></code></pre></figure>
<p>What the hell do all of these mean? I took these from <a href="http://cscope.sourceforge.net/cscope_maps.vim">cscope’s Vim
mappings</a> and unless I’m using them very, very regularly, it is
going to take some time to learn them all.</p>
<p>At first I wanted to make a plugin that would be able to help with this but I
was able to come up with a simpler solution even if it is a bit hacky.</p>
<h2 id="solution">Solution</h2>
<p>The first part is just to be able to view all of these similar mappings easily.
The best way I found to do this is just to run <code class="language-plaintext highlighter-rouge">:map binding_start</code> where you
substitute in what you want to look up.</p>
<p>In the case of Fugitive, we just run <code class="language-plaintext highlighter-rouge">:map <leader>g</code>. The output looks like the
following:</p>
<div class="gallery large">
<a href="/img/documenting/map.png" rel="lightbox[map]">
<img src="/img/documenting/map.png" alt="Map output" />
<span>Output of `:map <leader>g`</span>
</a>
</div>
<p>As you can see, the output clearly shows the key mapping as well as the command
that is ran. For plugins like these, it is very easy to use it as a reference
for when you forget a mapping.</p>
<h2 id="easy-access">Easy Access</h2>
<p>The next part of the solution is to make that command easier to run. I like to
map it to <code class="language-plaintext highlighter-rouge">?</code> and match it with the previous mappings.</p>
<p>This means the mapping for Fugitive becomes:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Fugitive reference</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">g</span>? <span class="p">:</span><span class="nb">map</span> <span class="p"><</span>leader<span class="p">></span><span class="k">g</span><span class="p"><</span><span class="k">cr</span><span class="p">></span></code></pre></figure>
<h2 id="self-documenting">Self Documenting</h2>
<p>Now what can we do about those cryptic mappings that don’t make a lot of sense
like the cscope example?</p>
<p>Well since <a href="http://vimdoc.sourceforge.net/htmldoc/map.html"><code class="language-plaintext highlighter-rouge">nmap</code></a> just runs a set of commands. We could just put
some superfluous text that won’t affect the mapping yet show up when <code class="language-plaintext highlighter-rouge">:map
binding</code> is ran.</p>
<p>I gave it a try and it turns out it works pretty well. It makes the command a
bit messier (this can be tidied up by using whitespace) but this is what it
looks like:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim">nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">c</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find all calls to function'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">c</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">d</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find functions that call this function'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">d</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">e</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'egrep search for the word under cursor'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">e</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">f</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Open filename under cursor'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">f</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cfile>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">g</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find all global definitions'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">g</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">i</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find files that include the filename'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">i</span> ^<span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cfile>"</span><span class="p">)<</span>CR<span class="p">></span>$<span class="p"><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span>s <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find all references'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> s <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span><span class="k">t</span> <span class="p">:</span><span class="k">ec</span> <span class="s1">'Find all instances to text'</span> <span class="p"><</span>bar<span class="p">></span> <span class="k">cs</span> <span class="k">find</span> <span class="k">t</span> <span class="p"><</span>C<span class="p">-</span>R<span class="p">>=</span><span class="nb">expand</span><span class="p">(</span><span class="s2">"<cword>"</span><span class="p">)<</span>CR<span class="p">><</span>CR<span class="p">></span></code></pre></figure>
<p>All we do is just <a href="http://vimdoc.sourceforge.net/htmldoc/eval.html#:echo"><code class="language-plaintext highlighter-rouge">echo</code></a> out what the mapping actually does in
English. Then by using <code class="language-plaintext highlighter-rouge"><bar></code>, it tells Vim to run the commands
together.</p>
<p>The end result is below:</p>
<div class="gallery large">
<a href="/img/documenting/map2.png" rel="lightbox[map]">
<img src="/img/documenting/map2.png" alt="Final map output" />
<span>Cscope reference</span>
</a>
</div>
<p>Then the mapping to be able to run this command quickly is:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Cscope reference</span>
nmap <span class="p"><</span>C<span class="p">-</span>\<span class="p">></span>? <span class="p">:</span><span class="nb">map</span> <span class="p"><</span>C<span class="p">-</span>\<span class="p">><</span><span class="k">cr</span><span class="p">></span></code></pre></figure>
<h2 id="conclusion">Conclusion</h2>
<p>That’s it! I have a few other examples of this in my <a href="https://github.com/jdavis/dotfiles/blob/master/.vimrc"><code class="language-plaintext highlighter-rouge">.vimrc</code></a>, be sure
to give it a look to see other examples.</p>
<p>Hopefully you get some use out of this. It has made it a lot easier for me to
remember some of my more arcane key mappings.</p>
<p>Also, if there’s a better way to do it, feel free to get in contact with me on
<a href="https://twitter.com/jldavis">Twitter</a>.</p>
Everything I Needed to Know, I Learned in my High School Calculus Class2015-03-07T00:00:00+00:00https://joshldavis.com/2015/03/07/calculus<h1 id="everything-i-needed-to-know-i-learned-in-my-high-school-calculus-class">Everything I Needed to Know, I Learned in my High School Calculus Class</h1>
<p>During my last two years of high school, I had to take Precalculus and
subsequently Calculus with a teacher named Mr. Bormann. Those two years
assuredly prepared me for college and instilled the discipline and drive to
learn outside of school which has carried me to where I am today.</p>
<p>I owe a lot to those two years and to Mr. Bormann. The unfortunate thing is that
during those years, I didn’t see it like I do now. I disliked Mr. Bormann from
the very first day just because he replaced one of my favorite teachers which
wasn’t fair to him.</p>
<p>I wanted to write about what caused me to dislike him and how his class ended up
preparing me for the rest of my life.</p>
<h2 id="a-small-town">A Small Town</h2>
<p>I grew up in a little town of Iowa called <a href="http://en.wikipedia.org/wiki/Algona,_Iowa">Algona</a>. The population was
5,741 at the 2000 census.</p>
<p>The <a href="http://www.algona.k12.ia.us/">Algona School District</a> is the home of the bulldogs and
small like the town it inhabits. My graduating class from Algona High School
(AHS) of 2009 consisted of 86 students.</p>
<p>The town and school were small enough that it meant the population was more
homogeneous than it should have been. There was a lack of diversity in interests
as well as many other aspects; it was nearly impossible for me to find someone
that had a similar passion for computers and programming.</p>
<p>It was this reason that finding someone that had similar interests and
understood me was such an important thing in my life.</p>
<h2 id="high-school">High School</h2>
<p>My freshman year at AHS I got to meet the physics and precalculus teacher at the
time. His name was Mr. Hines and he was known as not only a brilliant teacher
but as someone that made class really fun.</p>
<p>My first two years were filled with “Mr Hines did this…”, “In Hines’s
class…” types of stories about classes with Hines and the funny and great
things that happened in them.</p>
<p>In addition to teaching those classes, he also was in charge of the Computer
Club for AHS. You wouldn’t have doubted this if you had to step into his
classroom. It had computer towers and monitors stacked all over. There was a box
full of hard drives and various other parts. He loved computers but I think he
loved using them for pedagogical purposes more than anything.</p>
<p>It wasn’t uncommon to be talking about a subject only for him to relate it back
to computers with an analogy. Every discussion was an opportunity to learn
something new with Mr. Hines.</p>
<p>I heard about computer club from a sophomore friend at the time so I decided to
go to the first one to see what it was like in the hopes of learning and meeting
some people.</p>
<h3 id="computer-club">Computer Club</h3>
<p>It was a great little club that had a lot of upperclassman that I looked up to.
We’d spend a few hours after 3:30pm every Thursday to discuss the tech news,
build some computers, talk about a Linux distro, or even things vaguely related
to computers.</p>
<p>The community and <a href="http://en.wikipedia.org/wiki/Belongingness">belongingness</a> was what was important. It was
the closest thing I could find to being around similar people at least in that
small town that I was stuck in.</p>
<p>The first year was definitely the best. While the senior class my freshman year
had a lot of people that attended, the junior class had only a few that showed
up. This meant that by my sophomore year, the Computer Club attendance dropped
pretty dramatically but it didn’t hinder me from going and hanging out with Mr.
Hines.</p>
<p>It was the days where not many people showed up that I really got to know him
and talk with him.</p>
<h3 id="mr-hines">Mr. Hines</h3>
<p>I got to know Mr. Hines really well and really looked up to him. He was a very
smart guy that had a ton of curiosity about the world.</p>
<p>I couldn’t wait for the following year where I could have him for two classes as
I was going to take Physics with him as well. It was going to be the first time
that I had a teacher that I felt “understood” me and what I hoped to do.</p>
<p>However, during the second half of my sophomore year, Mr. Hines mentioned that
he was going to be leaving the school district and moving to Mason City to
pursue teaching there instead.</p>
<p>When he mentioned that, I was absolutely crushed. I felt that I got along with
him the most out of all of the teachers that I had met yet. It wasn’t fair for
him to move to a different school district like that.</p>
<h2 id="junior--senior-years">Junior & Senior Years</h2>
<p>As my junior year approached, I wondered a lot about who would take over
teaching for Mr. Hines. There was a bit of hope that it would be someone with
similar interests that I could learn from. I assumed that the more like me that
the teacher was, the better it would be for me.</p>
<p>On the first day of school, I finally got to find out who would be taking over
teaching Precalculus.</p>
<p>His name was Mr. Bormann and he was quite a bit different than Mr. Hines.</p>
<h2 id="precalculus--calculus-class">Precalculus & Calculus Class</h2>
<p>Mr. Bormann’s classes (as far as I could tell) were very different than how it
was in Mr. Hines’s classroom. Since Mr. Hines’s classroom was so full of
computers, there wasn’t much room for other things to be organized. So his desk
was always full of various papers, pop bottles, and other things to compensate
for the lack of space. When you walked into Hines’s class, it just felt like a
carefree environment.</p>
<p>This carried over to the students attitude because when Hines wasn’t talking,
the students usually were. There was always a buzz of chatter that occasionally
got too loud.</p>
<p>Mr. Bormann’s classroom had a much different feel. It was always tidy and
nothing was ever a mess. His books were lined up and things were put away.</p>
<p>In addition to the classroom differences, Mr. Bormann carried himself
differently. He had a lot discipline and was more serious. As I came to learn,
he was this way through high school and college when it came to football so it
was only natural that it carried over into his teaching.</p>
<p>I came to learn later on that he was softer than his exterior but that
definitely didn’t show in the classroom.</p>
<p>When you walked in, if there was any discussion going on, it was always just
a handful of people. It was never loud and rowdy.</p>
<p>Classtime was even quieter once Mr. Bormann started talking. You would have
to be slightly nuts to risk talking to your friend because it wouldn’t be wise
to disrupt class.</p>
<p>Mr. Hines was one of the most laid back guys I had met. He just let everything
fly unless someone was being hurt or something was being damaged.</p>
<p>Mr. Bormann was the opposite. He had a tight reign on everything happening and
never let things get out of control.</p>
<p>Despite these differences, it was a good place (at least for me) to learn.</p>
<h2 id="learning-everything-i-needed">Learning Everything I Needed</h2>
<p>One of the most important things I learned from his class was (ironically) how
to learn on my own as well as how to study.</p>
<p>Studying in high school was a rare occurrence and something I just didn’t have
to do much of. I paid attention in class, I turned my homework in on time
(albeit after much procrastination), and never missed school. Surprisingly,
those 3 things took care of most of the worry and made high school incredibly
easy.</p>
<p>Precalculus was a bit of the same. I could tell quite soon that it wasn’t going
to be that challenging since I liked math so much.</p>
<p>Even though it was just as easy, I wanted to make it a bit more difficult for
myself.</p>
<h3 id="learning">Learning</h3>
<p>I was a spiteful teenager at the time and disliked that Mr. Hines was gone and
that a teacher that I didn’t see eye-to-eye with was teaching.</p>
<p>I made a pretty immature and naive decision to channel this spite by doing as
little of in class activities as possible. This included not taking notes and
not doing anything that wasn’t absolutely required.</p>
<p>This irked Mr. Bormann because it went against his nature of hard work and
discipline. A number of times he would recommend that we all write a particular
equation down or a helpful pointer for a topic down. A few times when he saw
that I never did, he’d ask why I wasn’t doing so.</p>
<p>However, unbeknownst to him, I would actually go home and every other day devote
an hour or so to reading about the same topics from <a href="http://amzn.com/053439339X">Stewart’s 5th edition
Calculus</a> book.</p>
<p>I saw this as an opportunity to learn more about a topic on my own yet have
pretty low risk if I wasn’t good at learning without an instructor.</p>
<p>This attitude and practice made it easier to pick up other math and programming
ideas later on. I was a big fan of <a href="https://projecteuler.net/">Project Euler</a> and liked to explore
the problems on the site. The problems usually had a relatively easy brute
force method of solving them, but they also had a more optimized way of solving
it which usually involved math.</p>
<p>It was fun to delve into these topics which we didn’t have time to look at
in depth at school. This also was a great way to improve my programming as that
was something I was working a lot on at the time.</p>
<h3 id="math">Math</h3>
<p>I had always liked math but Precalculus and Calculus cemented the fact that I
wanted to continue to learn more about it.</p>
<p>One of Mr. Bormann’s big goals beyond learning the material was college
preparation. In anticipation for this, he decided that there wouldn’t be a
mandatory end of the year exam given in the class.</p>
<p>Instead, we were given the choice to either take his exam or take the Calculus
AB Advanced Placement exam offered by College Board and inturn, receive an
automatic A on the final. This was because it took months for the results to be
returned and it would be the middle of the summer before we knew how well we
did.</p>
<p>Beyond the obvious incentive of the automatic A, the additional perk was that if
we did well on it, it had the potential to eliminate the need to take Calculus I
at university. Nearly everyone took the AP test.</p>
<p>The weeks prior to the test, I was pouring over the various preparation material
that Mr. Bormann had given us. In fact, the picture at the top of this blog post
that shows up (on desktop) when you hover your mouse over my picture is of my
cat when I was studying for the test.</p>
<p>It was the first time that I truly had to study for an exam. It set the
foundation for my study habits in college.</p>
<p>The whole test, preparation, and waiting for the results reminded me of Harry
Potter and of his <a href="http://harrypotter.wikia.com/wiki/Ordinary_Wizarding_Level">O.W.L.s</a>.</p>
<p>When the day came to see the results, I was pretty nervous but for the most part
excited to finally see that my hard work had paid off that last month of school.
I got to skip Calculus I and went straight to Calculus II in college. Plus based
on getting to know the other students, I had a stronger base than most when it
came to the basics of Calculus.</p>
<h3 id="programming">Programming</h3>
<p>In addition to not taking notes, I also spent my in-class time learning as much
as I could about my <a href="http://en.wikipedia.org/wiki/TI-84_Plus_series">TI-84 Plus Silver Edition</a> which was my calculator at
the time. By the time I graduated, it was a well known trope that I spent a lot
of time on that thing and that the manual for my calculator never left my side
and was heavily worn.</p>
<p>The calculators had a rather primitive language called <a href="http://en.wikipedia.org/wiki/TI-BASIC">TI-BASIC</a> that
you could write programs in. The programs that I wrote started off simple like
the classic number guessing game to more advanced things like a program that got
passed around from student to student called “ULTIQUAD” because it would ask for
<code class="language-plaintext highlighter-rouge">A, B, C</code> and then use the <a href="http://en.wikipedia.org/wiki/Quadratic_equation">quadratic equation</a> and it would either
spit out the values if they were rational, or show the simplification if they
were irrational or complex.</p>
<p>Eventually I went onto more advanced things like my own version of Pong, Snake,
and a fun little (naive) interpreter that made it easy to manipulate
mathematical functions as values.</p>
<p>TI-BASIC was just a convenient way to program when I didn’t have a computer
around. At home, I spent my time learning how to program on OS X with the
de facto <a href="http://amzn.com/0321967607">Objective-C book</a> by Steven Kochan and followed it up with
<a href="http://amzn.com/0321774086">Hillegass’s book</a> on Cocoa.</p>
<p>By my senior year, I had written a few different OS X applications for myself
and even made one for one of my other favorite teachers.</p>
<p>Objective-C was the first language that I learned but it made it easier to learn
others. I spent time to read the classic <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language">K&R book on C programming</a>,
learned Python from the <a href="http://amzn.com/1449355730">Lutz book</a>, and picked up Perl when I had
downtime at my high school job.</p>
<p>All of this extra work learning various languages lightened the load when I got
to college and decided to major in Computer Science. While the students that
hadn’t programmed before were struggling with the syntax and semantics of
languages, I got to ease past that and focus on the problem solving.</p>
<h3 id="discipline">Discipline</h3>
<p>Mr. Bormann had a phrase that he used to remind us of (especially during the
later Calculus class) and it went something like this:</p>
<blockquote>
<p>This isn’t supposed to be easy.</p>
</blockquote>
<p>He’d say it when people were trying to grok a harder topic and just couldn’t
wrap their heads around it. He also said it whenever anyone complained.</p>
<p>It was a phrase that stuck in my head when I would be stuck on a hard problem at
university or trying to implement something while working.</p>
<h2 id="summary">Summary</h2>
<p>It’s weird to think about what might have happened if Hines had stayed to teach.
I might have still went on to learn a lot, but maybe I wouldn’t have had a
similar drive with the discipline.</p>
<p>Or maybe I wouldn’t have gained the ever-necessary study habits that helped me
succeed in college.</p>
<p>Either way I do know that I’m ever grateful for Mr. Hines helping me those first
two years when I was an awkward teen without much aim in life.</p>
<p>But I’m ever more grateful for Mr. Bormann for stirring up the desire to want to
prove something to myself, to him, and to others. It instilled the skills and
knowledge that I needed to succeed after high school when things got so much
more tough.</p>
<p>It’s just a shame that I did all of this without explaining it all to Mr.
Bormann or showing him that I really appreciated what he did.</p>
Why I Blog2015-02-13T00:00:00+00:00https://joshldavis.com/2015/02/13/why-i-blog<h1 id="why-i-blog">Why I Blog</h1>
<p>It has been four months since my last blog post. I haven’t been any busier than
I have been in the past. I have just become a bit complacent with my blog. This
blog post is just a reminder to myself Why I Blog and why I should continue.</p>
<p>You probably won’t find this as interesting because it is intended only for me.
If you continue reading, keep that in mind.</p>
<h2 id="timeline">Timeline</h2>
<p>I wrote my <a href="/2013/05/11/beginning-of-a-beautiful-blogship/">first blog post</a> back in May of 2013. I had a lot of
drive and discipline and wrote nearly every week up until August when things
started to spread out a bit.</p>
<p>This was expected as school had just started. After the New Years, I was able to
go on a nice run which lasted up until June.</p>
<p>Compared to my earlier posts, the span from January to June contains some of my
most linked to blog posts. The average quality of each blog post was also the
highest it had been. Even a year after writing them, I am still receiving tweets
and emails regarding them. I think this is because the topics I chose were
more interesting than before and primarily because I devoted a lot of time to
writing each post.</p>
<p>In July, I made a move across the country and started a new job. Since I
started, I’ve only had 3 blog posts (two of which are of debatable quality).</p>
<h2 id="why-i-started">Why I Started</h2>
<p>This was mentioned in that <a href="/2013/05/11/beginning-of-a-beautiful-blogship/">first blog post</a> that I linked a few
paragraphs up, but here they are in condensed form:</p>
<ol>
<li>I started because I wanted to overcome my fear and <a href="/2014/06/13/put-yourself-out-there/">put myself out
there</a>.</li>
<li>I wanted to show case myself and abilities instead of hiding behind a
curtain of anonymity on the internet.</li>
<li>I wanted to “write for myself” like <a href="http://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Dijkstra</a> decided to do to
overcome his writer’s block that he suffered from.</li>
</ol>
<h2 id="why-ive-stopped">Why I’ve Stopped</h2>
<p>I can come up with a few different excuses as to why I haven’t blogged as much
as I could.</p>
<h3 id="excuse-1-ive-been-too-busy-like-with-work">Excuse #1: I’ve been too busy (like with work).</h3>
<p>This is a silly one because I still have plenty of time outside of work. It
isn’t like I’m working 18 hours a day. Once I come home, I have plenty of time
to do what I want at night. Most of the problem is that the time just disappears
into non-quantifiable areas; many of which are expectedly unproductive.</p>
<h3 id="excuse-2-i-dont-know-what-to-write-about">Excuse #2: I don’t know what to write about.</h3>
<p>This is a funny one; I have a huge Trello board filled with ideas that I can
pick from (pictured below the text whited out for various reasons):</p>
<div class="gallery medium">
<a href="/img/why-blog/trello.png" rel="lightbox[trello]" title="Blogging board on Trello">
<img src="/img/why-blog/trello.png" alt="Blogging board on Trello" />
<span>One of my Trello boards dedicated to blogging ideas.</span>
</a>
</div>
<p>There definitely isn’t a shortage of things to write about there.</p>
<h3 id="excuse-3-there-isnt-much-of-a-need-anymore">Excuse #3: There isn’t much of a need anymore.</h3>
<p>This is definitely the lamest of the excuses. The root of the idea is that I
have a job now and I’m not actively seeking new employment like I was when I was
in college (and blogging the most). Surely I don’t need to blog, right?</p>
<p>This is bogus because the “need” should be intrinsically motivated instead of
externally. I should have a “need” to write to articulate my thoughts, to learn
new things, and to explore topics that I normally wouldn’t.</p>
<h2 id="why-i-continued-to-blog">Why I Continued to Blog</h2>
<p>Even though I haven’t been as prolific as I could hope; I still get a steady
stream of emails regarding my blog posts.</p>
<p>Each of them is as humbling as the first. With emails from people saying that I
inspired them, or that they came across a blog post and they learned a lot, or
even just from people just saying thanks for <a href="https://twofactorauth.org">twofactorauth.org</a>.</p>
<p>Each time a new email comes through or I meet a person that has read my blog
since I’ve dropped off, I feel guilty.</p>
<p>It’s like this little feeling of having let down a person that you have never
met before if you don’t continue to blog.</p>
<p>If you <em>had</em> continued to blog about some ideas that you’ve had, who knows what
they might have learned from it. Who knows how it might have made them a better
engineer or a better human.</p>
<h2 id="how-ill-start-blogging-again">How I’ll Start Blogging Again</h2>
<p>It isn’t a question of if I’ll start blogging again; I <em>need</em> to. I journal
daily for private thoughts but there are other thoughts that I want to make
public.</p>
<h3 id="stay-disciplined">Stay Disciplined</h3>
<p>The amount of discipline I have varies (at least lately) depending on the task.
I have a lot when it comes to exercise, eating right and various tasks at work.
Yet ever since I’ve graduated, I haven’t been disciplined with learning in my
free time and blogging is a big part of that.</p>
<p>I have been a <a href="http://www.reddit.com/r/getdisciplined/">big fan of discipline</a> for a few years now. The
reason for caring more about discipline rather than motivation is explained well
in <a href="http://www.wisdomination.com/screw-motivation-what-you-need-is-discipline/">this recent blog</a> post that went around the internet a
month ago.</p>
<h3 id="stay-hungry-stay-foolish">Stay Hungry, Stay Foolish</h3>
<p>This idea comes from <a href="http://en.wikipedia.org/wiki/Steve_Jobs">Steve Job’s</a> excellent Stanford commencement
speech which is a classic by now.</p>
<p>In terms of my life, I haven’t been either of
them. I haven’t been hungry to learn new things and to continue to do things
just to learn.</p>
<p>I think the speech is a great reminder of why it is important and how it helped
Steve:</p>
<div class="gallery medium">
<iframe width="640" height="425" src="https://www.youtube.com/embed/D1R-jKKp3NA?rel=0&start=769&autoplay=0" frameborder="0" allowfullscreen=""></iframe>
</div>
<h3 id="the-end">The End</h3>
<p>If you made it this far, hopefully it wasn’t too terrible and generic. Like I
said, this is for myself to get back into the habit.</p>
<p>Be looking for my next post!</p>
The Similarity of the World in Gattaca and the World Elon Musk Envisions2014-10-11T00:00:00+00:00https://joshldavis.com/2014/10/11/the-similarity-of-the-world-in-gattaca-and-the-world-elon-musk-envisions<h1 id="the-similarity-of-the-world-in-gattaca-and-the-world-elon-musk-envisions">The Similarity of the World in Gattaca and the World Elon Musk Envisions</h1>
<p>This dawned on me a year ago when I was watching Gattaca for the 800th time; the
world that <a href="http://www.imdb.com/title/tt0119177/">Gattaca (1997)</a> takes place in has striking similarity to
<a href="http://en.wikipedia.org/wiki/Elon_Musk">Elon Musk’s</a> current dream for our present world.</p>
<p>I’ve written about <a href="/2013/08/11/my-favorite-elon-musk-quote/">Elon Musk before</a> as well as <a href="/2013/08/31/never-save-anything-for-the-swim-back/">why Gattaca means
so much to me</a>. If you can’t tell, I’m a big fan of both =]</p>
<p>Even though genetics is a big part of the movie, there isn’t a direct analogy to
today thus I won’t address it. And as the movie illustrates, let’s hope there
never is a time when that is the case.</p>
<p>Let’s take a look at the world that Elon Musk dreams of. This world will be
based on what he has said and what he spends his time working on.</p>
<h2 id="elons-world">Elon’s World</h2>
<p>Elon has talked about his vision for the world in many different interviews. He
said that when he was in college, he wanted to start businesses that would “most
affect the future of humanity.” He identified these sectors that would be most
influential as these three:</p>
<ol>
<li>Space</li>
<li>Renewable energy</li>
<li>The Internet</li>
</ol>
<p>As we know, Elon has been quite lucky in that he has been able to start very
successful businesses in all three.</p>
<p>If we were to look these three categories a bit closer, break them down, and
then map them to the current businesses that he currently has a part in, we get
the following list:</p>
<ol>
<li>Being a space faring civilization: <a href="http://www.spacex.com/">SpaceX</a></li>
<li>Sustainable transport: <a href="http://www.teslamotors.com/">Tesla Motors</a></li>
<li>Renewable energy: <a href="http://www.solarcity.com/">SolarCity</a></li>
</ol>
<p>These are the three companies that he currently has a role in. He is the CEO of
Tesla, the CTO of SpaceX, and a chairman of SolarCity (the CEO, <a href="http://en.wikipedia.org/wiki/Lyndon_Rive">Lyndon
Rive</a>, is a cousin to Elon).</p>
<p>Based off of this, how does the world of Gattaca compare? Let’s see.</p>
<h2 id="gattacas-world">Gattaca’s World</h2>
<h3 id="space-faring-civilization">Space Faring Civilization</h3>
<p>As we learn within the first few minutes, Vincent (<a href="http://www.imdb.com/name/nm0000160/">Ethan Hawke</a>) is
working at an elite institution, Gattaca, that has 12 or so spaceship launches
every day. Vincent, the main character, is an engineer at Gattaca. Gattaca
selects only the very, very best to work there and to travel into space.</p>
<p>We learn early on that Vincent’s project is still on schedule. He is one of the
astronauts that is taking a trip to Titan, the largest of Saturn’s moons.</p>
<p>Learning about space and traveling into the final frontier is Vincent’s passion
ever since he could read.</p>
<div class="gallery medium">
<a href="/img/gattaca/spaceship.png" rel="lightbox[spaceship]">
<img src="/img/gattaca/spaceship.png" alt="Rocket launch in Gattaca" />
<span>One of the 12 daily rocket launches in Gattaca.</span>
</a>
</div>
<p>The civilization in Gattaca has daily rocket launches and is traveling all over
the solar system exploring planets and moons.</p>
<p>I can only imagine that many of the daily launches are for sending supplies to
various bases that are spread across the planets. Much in the way that Elon
imagines a civilization on Mars would be supported.</p>
<h3 id="sustainable-transport">Sustainable Transport</h3>
<p>The next area of similarity is that all of the cars that are in Gattaca are
electric. It is never explicitly mentioned but it is very obvious in all of the
scenes as the cars are given an electric “zipping” sound whenever they are being
driven.</p>
<p>The look of the cars are quite a departure from the sleek look of the Model S
that we have now. The film definitely went for a more timeless look by modeling
the cars after classics from the 1960’s such as the <a href="http://en.wikipedia.org/wiki/Rover_P6">Rover P6</a> and
<a href="http://en.wikipedia.org/wiki/Studebaker_Avanti">Studebaker Avanti</a> instead of trying to make them look futuristic.</p>
<div class="gallery medium">
<a href="/img/gattaca/electric-car.png" rel="lightbox[car]">
<img src="/img/gattaca/electric-car.png" alt="Electric car in Gattaca" />
<span>An electric car from Gattaca.</span>
</a>
</div>
<p>At no point in the film do we have any evidence that the cars run on fossil
fuels or anything besides electricity.</p>
<h3 id="renewable-energy">Renewable Energy</h3>
<p>The last area that shows an awful amount of similarity to the world Elon is
trying to create is how the world of Gattaca gets its energy.</p>
<p>At one point in the film, Vincent and Irene (<a href="http://www.imdb.com/name/nm0000235/">Uma Thurman</a>) visit a
<a href="http://en.wikipedia.org/wiki/Concentrated_solar_power">concentrated solar power (CSP)</a> plant. As you can read on Wikipedia, the
way those solar power plants work is by focusing all the light through mirrors
to a single location where a generator then converts the heat to electricity.</p>
<p>This technology of CSP is one way of generating electricity from the sun with
the other being <a href="http://en.wikipedia.org/wiki/Photovoltaics">photovoltaics</a> which is what SolarCity uses for
their panel installation.</p>
<div class="gallery medium">
<a href="/img/gattaca/solar-farm.png" rel="lightbox[solar]">
<img src="/img/gattaca/solar-farm.png" alt="CSP in Gattaca" />
<span>Concentrated solar complex from Gattaca</span>
</a>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>Gattaca was a sci-fi film that came out in 1997 yet there aren’t many things in
the film that are too far out of reach. If Elon Musk can continue at the pace he
is, it is only years away as opposed to decades or centuries.</p>
<p>If you haven’t seen Gattaca, I highly recommend that you do. If you haven’t
taken a test drive in a Model S, I would probably recommend that more.</p>
<p>Thanks for reading. Let’s hope that Elon can continue to make the world he sees
a part of reality.</p>
Heavy-handed HackerNews: Mods are Unnecessarily Editing Titles and Swapping URLs2014-10-03T00:00:00+00:00https://joshldavis.com/2014/10/03/heavy-handed-hackernews<h1 id="heavy-handed-hackernews-mods-are-unnecessarily-editing-titles-and-swapping-urls">Heavy-handed HackerNews: Mods are Unnecessarily Editing Titles and Swapping URLs</h1>
<h6 id="note">Note</h6>
<blockquote>
<p>This post didn’t make the frontpage thus the experiment didn’t work. Still,
the content is still valid.</p>
</blockquote>
<p>I have been less than thrilled about the increase in administrative “duties”
that have been going on with HackerNews since pg stepped down administrating the
site.</p>
<h2 id="experiment">Experiment</h2>
<p>As an experiment, I’ve changed the title of my post to see if it happens first
hand.</p>
<p>The title of the submission should be <em>Heavy-handed HackerNews: This Title
Should Differ from the Article</em>.</p>
<p>Here is the submission: <a href="https://news.ycombinator.com/item?id=8405771">https://news.ycombinator.com/item?id=8405771</a></p>
<h2 id="url-hot-swapping">URL Hot Swapping</h2>
<p>In particular, <a href="https://news.ycombinator.com/user?id=dang">dang</a> has a habit of hot swapping out URL submissions from
underneath the comments.</p>
<p>Just last night an article was posted linking to <a href="http://blog.erratasec.com/2014/10/reading-silk-road-configuration.html">Errata Security’s</a>
post on <a href="http://blog.erratasec.com/2014/10/reading-silk-road-configuration.html">Reading the Silk Road configuration</a>.</p>
<p>The <a href="https://news.ycombinator.com/item?id=8404511">comment section</a> for the submission started off discussing
the original posting. Yet at some point, the submission was changed to point to
<a href="http://krebsonsecurity.com/2014/10/silk-road-lawyers-poke-holes-in-fbis-story/">Brian Kreb’s post</a> which had a less technical take and more general.</p>
<p>This hot swapping was noticed in <a href="https://news.ycombinator.com/item?id=8404723">the comments</a> as well.</p>
<p>Doing this is unfair for a variety of reasons:</p>
<ol>
<li>The original submission could be from the author.</li>
<li>The comments can cease to be relevant (like the previous example).</li>
<li>The submitted article might add on to a more “credible” article that it
refers to (like the previous example).</li>
</ol>
<h2 id="title-changing">Title Changing</h2>
<p>There is some rule that says submissions should have the original title of the
web page. This is quite inane in various circumstances.</p>
<p>I have actually been the victim of this title changing as being an author of
something linked to.</p>
<p>I wrote the <a href="http://neovim.org/news/2014/sept/">September newsletter</a> for Neovim. Within the hour, the
newsletter was <a href="https://news.ycombinator.com/item?id=8290283">posted to HackerNews</a> with a title that mentioned the
new newsletter as well as mentioning the word Neovim.</p>
<p>This makes sense as the title of the article doesn’t include Neovim. That’s
because “Neovim” is <a href="https://github.com/neovim/neovim.github.io/blob/master/_layouts/default.html#L9">prepended to the Jekyll template</a> that is used for
rendering the page. The final <code class="language-plaintext highlighter-rouge"><title></code> tag in the HTML becomes `<title>Issue #3</title></p>
<ul>
<li>Better Late than Never - Neovim</title>`</li>
</ul>
<p>It was then changed to “Issue #3 – Better Late Than Never” which makes
absolutely no sense without seeing the URL. I wasn’t the only one to notice
either as <a href="https://news.ycombinator.com/item?id=8292175">this comment</a> points out.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I understand that moderation is a necessity for spam, insults, sensational
titles and the like. However this micro-moderating of submissions that degrade
and <em>change</em> the original submissions needs to stop.</p>
Oh-my-zsh is the Disease and Antigen is the Vaccine2014-07-26T00:00:00+00:00https://joshldavis.com/2014/07/26/oh-my-zsh-is-a-disease-antigen-is-the-vaccine<h1 id="oh-my-zsh-is-the-disease-and-antigen-is-the-vaccine">Oh-my-zsh is the Disease and Antigen is the Vaccine</h1>
<p><a href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a> is one of the <a href="https://github.com/search?q=stars%3a%3E1&s=stars&type=Repositories">most popular repositories</a> on GitHub with
17,500+ stars. If you use zsh as your main shell, you likely have heard of
oh-my-zsh or even use it.</p>
<p>It features “120+ optional plugins” and just as many themes for your beloved
shell. It has a great <a href="https://github.com/robbyrussell/oh-my-zsh/tree/master/lib">default library</a> that turns on a lot of great
zsh features that make it better for new users.</p>
<p>However, I think that oh-my-zsh has actually become a bit harmful to the goal
that it is trying to achieve.</p>
<h2 id="the-problem">The Problem</h2>
<p>oh-my-zsh is a great idea but it has evolved quite a bit past its <a href="https://github.com/robbyrussell/oh-my-zsh/tree/5da20b9dddb1f7a9110675ded5df59c4c3ed1b83">initial
import into Git</a>.</p>
<p>It was never “designed” to support the plugin directory that it is trying to be.
The intention of providing plugins has grown beyond manageability. Let’s take a
better look at the issues that oh-my-zsh has.</p>
<h3 id="gitgithub">Git/GitHub</h3>
<p>Using version control for something as volatile as plugins is a bit strange.
While it has been working for <a href="https://github.com/Homebrew/homebrew">Homebrew</a>, Homebrew only maintains
instructions on how to install each package; it obviously doesn’t contain the
source of the package which is far more volatile.</p>
<p>Using a massive repository for this just isn’t the greatest idea for maintaining
a list of plugins. Why should I have to download EVERY single plugin when I just
want to use a few. Even though most plugins are a single or a few files, it just
doesn’t scale and is unnecessary.</p>
<p>To make an analogy, it would be like having one large repository for every
single Vim plugin. The thought is just absurd.</p>
<h3 id="inactivity">Inactivity</h3>
<p>The other problem is that <a href="https://github.com/robbyrussell/oh-my-zsh/commits/master?author=robbyrussell">Robby Russell</a> appears to be the only
collaborator that handles pull requests and issues. Every single change must go
through him and be approved. The effort just seems outrageous. The <a href="http://en.wikipedia.org/wiki/Bus_factor">Bus
factor</a> should definitely not be that low.</p>
<p>At one point, there was a span of 45 days from May to nearly July in which
nothing happened.</p>
<p>As of right now, there are nearly <a href="https://github.com/robbyrussell/oh-my-zsh/issues">~400 issues</a> open on the
oh-my-zsh repository with 70% of them being pull requests.</p>
<p>This isn’t a knock against Robby in anyway either. We all get busy and I know
first hand that managing issues is sometimes the last thing you want to do.
However it is a reason to look into alternative solutions that don’t have this
dependency on a single person.</p>
<h3 id="adding-customizations">Adding Customizations</h3>
<p>oh-my-zsh gives some pointers on adding your <a href="https://github.com/robbyrussell/oh-my-zsh#customization">own customizations</a>.
What does it suggest?</p>
<p>It says to add your own files into the <code class="language-plaintext highlighter-rouge">custom/</code> directory. That sounds easy.
But what do you do if you want to hold those in version control as well? You
either have to use something like a Git submodule or you have to maintain your
own Fork of oh-my-zsh. I already have a few submodules in <a href="https://github.com/jdavis/dotfiles">my
dotfiles</a>, but it isn’t a very fun thing to manage. Each change
becomes two commits (one for the change, one for the submodule reference), and
it is very easy to forget to push a submodule change while updating the
reference in the main repository.</p>
<p>I had <a href="https://github.com/jdavis/oh-my-zsh">my own fork</a> that I kept my customizations in for a couple
years but if I wanted new updates, I would have to merge in the new changes from
upstream. It isn’t that bad of a process but it is extra work and I’d argue
forks aren’t the best for this.</p>
<h3 id="where-do-we-go-from-here-then">Where do we go from here then?</h3>
<p>oh-my-zsh has done a lot for the community and has helped make zsh popular. This
is great but a solution is being developed that addresses these problems.</p>
<p>Let’s take a look at it.</p>
<h2 id="introduction-to-antigen">Introduction to Antigen</h2>
<p><a href="https://github.com/zsh-users/antigen">Antigen</a> cites that it is directly inspired by <a href="https://github.com/gmarik/Vundle.vim">Vundle</a>, which
is a great plugin manager for Vim. Vundle was inspired by <a href="https://github.com/tpope/vim-pathogen/">Pathogen</a>
which was the first plugin manager for Vim. Thus this is the reason Antigen is
named after an <a href="http://en.wikipedia.org/wiki/Immunology">Immunology</a> term.</p>
<p>Essentially what you do is list plugins in your <code class="language-plaintext highlighter-rouge">.zshrc</code> and it will
automatically download them. It allows you to run various commands such as
updating all the plugins, clean up unused plugins, and more.</p>
<p>The configuration is super simple and it addresses all of the issues with
oh-my-zsh. In fact, all of this is mentioned in the <a href="https://github.com/zsh-users/antigen#motivation">Motivation
section</a> of the README.</p>
<h2 id="antigen-features">Antigen Features</h2>
<p>Antigen has a great set of features as of right now.</p>
<h3 id="easy-setup--installation">Easy Setup & Installation</h3>
<p>If you are familiar with Vundle, then Antigen will make complete sense. Here’s
what I currently have in my <a href="https://github.com/jdavis/dotfiles/blob/master/.zshrc">.zshrc</a> for the plugins that I use:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c"># Load Antigen</span>
<span class="nb">source</span> ~/.antigen.zsh
<span class="c"># Load various lib files</span>
antigen bundle robbyrussell/oh-my-zsh lib/
<span class="c">#</span>
<span class="c"># Antigen Theme</span>
<span class="c">#</span>
antigen theme jdavis/zsh-files themes/jdavis
<span class="c">#</span>
<span class="c"># Antigen Bundles</span>
<span class="c">#</span>
antigen bundle git
antigen bundle tmuxinator
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle rupa/z
<span class="c"># For SSH, starting ssh-agent is annoying</span>
antigen bundle ssh-agent
<span class="c"># Node Plugins</span>
antigen bundle coffee
antigen bundle node
antigen bundle npm
<span class="c"># Python Plugins</span>
antigen bundle pip
antigen bundle python
antigen bundle virtualenv
<span class="c"># OS specific plugins</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$CURRENT_OS</span> <span class="o">==</span> <span class="s1">'OS X'</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then
</span>antigen bundle brew
antigen bundle brew-cask
antigen bundle gem
antigen bundle osx
<span class="k">elif</span> <span class="o">[[</span> <span class="nv">$CURRENT_OS</span> <span class="o">==</span> <span class="s1">'Linux'</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span>
<span class="c"># None so far...</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$DISTRO</span> <span class="o">==</span> <span class="s1">'CentOS'</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then
</span>antigen bundle centos
<span class="k">fi
elif</span> <span class="o">[[</span> <span class="nv">$CURRENT_OS</span> <span class="o">==</span> <span class="s1">'Cygwin'</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then
</span>antigen bundle cygwin
<span class="k">fi
</span>antigen bundle jdavis/zsh-files
<span class="c"># Secret info</span>
antigen bundle git@github.com:jdavis/secret.git</code></pre></figure>
<p>This setup makes it trivial to find new plugins and add them to your setup.
Heredocs can be used instead but I find this approach a bit nicer to read.</p>
<p>As an example, before to use <a href="https://github.com/rupa/z">z</a>, I had to add a <a href="https://github.com/jdavis/dotfiles/commit/36d72a26eb80b3a944d276fa0b32544e2eecf18c">submodule</a>, which
would have to be updated if there were any bug fixes/feature fixes. Then I had
to create a <a href="https://github.com/jdavis/oh-my-zsh/blob/master/custom/z.zsh"><code class="language-plaintext highlighter-rouge">custom/z.zsh</code></a> script that would load z.</p>
<p>In my new setup, it has become one line: <code class="language-plaintext highlighter-rouge">antigen bundle rupa/z</code> And retrieving
new updates is just a command away: <code class="language-plaintext highlighter-rouge">antigen update</code>.</p>
<h3 id="single-dependency">Single Dependency</h3>
<p>Instead of having to manage an entire fork or submodule, the entirety of Antigen
lives in a file called <a href="https://github.com/zsh-users/antigen/blob/master/antigen.zsh"><code class="language-plaintext highlighter-rouge">antigen.zsh</code></a> which can be added to
your dotfiles.</p>
<p>In the event that there is a bug fix or feature added, all that is required to
do is to run <code class="language-plaintext highlighter-rouge">antigen selfupdate</code> and then commit the changes. No longer must
must you fetch and merge upstream changes.</p>
<h3 id="autoloading">Autoloading</h3>
<p>Antigen has tries to automatically load various files in a plugin. It has a few
mechanisms that it uses to do this. If you are interested in writing a plugin,
there is a <a href="http://zsh-users.github.io/antigen/#notes-on-writing-plugins">section on what rules it follows</a>.</p>
<h2 id="antigen-drawbacks">Antigen Drawbacks</h2>
<p>Antigen isn’t perfect however. There are a few idiosyncrasies that are a bit
annoying. Here’s what I think could be improved based off of the current
version.</p>
<h3 id="dependency-errors">Dependency Errors</h3>
<p>Antigen relies on Git and when Git isn’t installed, you are greeted with some
pretty errors every single time a shell is opened.</p>
<p>Obviously the fix would be to check if all the required tools are installed
before blindly proceeding. It is a simple fix but would make the user experience
a bit nicer.</p>
<h3 id="automatic-downloading-is-a-mess">Automatic Downloading is a Mess</h3>
<p>In addition to the errors that you get when Git isn’t installed, every time you
open a new shell, it will automatically try to download any missing plugins.</p>
<p>This goes with the above point but it would be great to turn this off. I’d argue
it should be off by default as well.</p>
<p>Also, if a repository is private, which is what I do to manage sensitive
information like IP’s of my servers and other private things, it will try to
download it every time a shell is opened up.</p>
<p>This happens on new machines until I get a SSH key in place. The constant errors
popping up is quite frustrating.</p>
<p>A more sane alternative is to check if permissions are required and instead of
trying to download it every single time, just keep a list of ones that aren’t
accessible due to permission. Then the user can download them when they are
ready (say after they have setup their GitHub private keys and loaded
ssh-agent) instead of the constant errors.</p>
<h3 id="version-locking">Version Locking</h3>
<p>This actually is something missing from Vundle but in some other Vim plugin
managers. But there is no way to lock to a specific tag or version (a release in
GitHub-lingo).</p>
<p>This would prevent issues where the master is used for development and potential
broken changes might slip through.</p>
<h2 id="conclusion">Conclusion</h2>
<p>oh-my-zsh has always had noble intentions, yet it has fallen short as it has
grown. I feel that a better, more sustainable solution is required for managing
plugins in zsh.</p>
<p>Antigen so far has been a great attempt at that and my chosen tool to remedy
these shortcomings of oh-my-zsh. As mentioned, it isn’t without its flaws but
that is expected of projects; the base features are there which is far more
important.</p>
GitHub + University: A Follow Up2014-06-30T00:00:00+00:00https://joshldavis.com/2014/06/30/github-university-follow-up<h1 id="github--university-a-follow-up">GitHub + University: A Follow Up</h1>
<h6 id="follow-up">Follow Up</h6>
<blockquote>
<p>This is a follow up post to my original post:
<a href="/2014/01/19/github-university-how-college-assignments-should-work/">GitHub + University: How College Coding Assignments Should
Work</a></p>
</blockquote>
<p>At the beginning of the year, I wrote <a href="/2014/01/19/github-university-how-college-assignments-should-work/">a post</a> that detailed
how myself and another TA were going to experiment with using GitHub for all of
the course assignments.</p>
<p>I promised a follow-up with some source code plus how it went. I’ve had many,
many people email me saying they were looking forward to the follow up, so here
it is.</p>
<p>If you want to jump straight to the few scripts that I wrote, check out the
source here:</p>
<div class="buttons">
<a class="button" href="https://github.com/jdavis/github-plus-university"><i class="icon-github"></i> View on GitHub</a>
</div>
<h2 id="learning-curve">Learning Curve</h2>
<p>For a lot of the students, this was the first time that they had any experience
with any sort of version control system.</p>
<p>We all know what that feels like and have our own stories about either the pain
or triumph in learning it.</p>
<p>To counter this, I wrote up a <a href="https://github.com/ComS342-ISU/course-info/blob/master/guides/course-setup.md">Git/GitHub guide</a> that explained
how to set things up as well as how we intended to use the repositories.</p>
<h3 id="homework-zero">Homework Zero</h3>
<p>To cut down on issues that might occur close to the deadline of homeworks that
matter, we had a required yet ungraded Homework 0. We used this to get all of
the Git issues out of the way and to ensure that all the students had it
properly setup.</p>
<p>The homework just contained some simple questions regarding the syllabus.</p>
<h3 id="student-issues">Student Issues</h3>
<p>There were 50 people in the class and I’d estimate (based on the people I talked
to) that a fifth or so had issues with Git/GitHub.</p>
<p>I thought this number was completely reasonable for a class of this size. While
most of the issues that I came across could have been solved by a quick
Google search, I think the students just wanted a personal touch in solving the
issue.</p>
<p>The great thing is that while the questions were plentiful during Homework 0, by
the time of the first real homework a small percentage of students still had
issues.</p>
<h2 id="a-course-setup-app">A Course Setup App</h2>
<p>As I mentioned in the previous post, I created a little app to help in creating
all the repositories for the students. The app is written in NodeJS and has a
few different dependencies: <a href="https://github.com/jdavis/github-plus-university/blob/master/app/package.json">package.json</a></p>
<p>The problem was that we knew the student’s University ID but we didn’t know
their GitHub info.</p>
<p>This app does a few things, each thing with a link to specific lines of code in
the source where this happens:</p>
<ol>
<li>
<p>It uses OAuth to request a token for the student’s GitHub account. This
ensures that the account is valid. <a href="https://github.com/jdavis/github-plus-university/blob/master/app/server.js#L159-L215">(link to source)</a>.</p>
<p>It also adds this token to a SQLite database just in case you need to use it
again. <a href="https://github.com/jdavis/github-plus-university/blob/master/app/server.js#L230-L233">(link to source)</a></p>
</li>
<li>It asks the student for a University ID and validates it against a list of
students in the course. <a href="https://github.com/jdavis/github-plus-university/blob/master/app/server.js#L240-L278">(link to source)</a></li>
<li>It then creates a repository in the Organization according to a predetermined
format. <a href="https://github.com/jdavis/github-plus-university/blob/master/app/server.js#L350-L369">(link to source)</a></li>
<li>It adds the student to the organization and gives them permission to view the
newly created repository. The repository is also only visible to the student
(and instructors/TAs). <a href="https://github.com/jdavis/github-plus-university/blob/master/app/server.js#L280-L348">(link to source)</a></li>
</ol>
<p>View the <a href="https://github.com/jdavis/github-plus-university/blob/master/README.md">README</a> for more details on using the code.</p>
<h3 id="helper-scripts">Helper Scripts</h3>
<p>I also have three helper scripts for the app.</p>
<ol>
<li><a href="https://github.com/jdavis/github-plus-university/blob/master/app/scripts/createTable.js">createTable.js</a> creates a new SQLite database with two columns:
a place for the username and one for the GitHub OAuth token.</li>
<li><a href="https://github.com/jdavis/github-plus-university/blob/master/app/scripts/dumpTable.js">dumpTable.js</a> just outputs the entire table; it’s pretty simple.</li>
<li><a href="https://github.com/jdavis/github-plus-university/blob/master/app/scripts/unenrolled.js">unenrolled.js</a> goes through the entire list of students given in
the CSV file and then queries GitHub to see if the student has already been
added to the organization. If not, it prints the list and formats so you can
easily see which students have been slacking and haven’t signed up yet.</li>
</ol>
<h2 id="administering-the-course">Administering the Course</h2>
<p>In addition to GitHub, we also used the University standard for courses,
Blackboard. We used it for posting lecture notes as well as announcements as it
was still tied into the University side emailing system.</p>
<p>Using GitHub, it let us to the following really easily: troubleshooting
student’s code, releasing new homeworks, and grading homework.</p>
<p>Before I look at each of these, first let me refresh how we had the repositories
setup.</p>
<h3 id="repo-setup">Repo Setup</h3>
<ol>
<li>(Public) <a href="https://github.com/ComS342-ISU/course-info">Course-Info</a> was the repo that was publicly available and it
contained the syllabus as well as other useful information.</li>
<li>(Public) <a href="https://github.com/ComS342-ISU/recitations">Recitations</a> was the repo that I put test code and other things
that we worked on in my recitation section.</li>
<li>(Private) Main Homework Repo: this was a private repository that was the repository
that we we put newly released homework in as well as solutions to previous
homeworks.</li>
<li>(Private) Student Repos: there was a student repo for every student in the class. Each
was private to that student which means that only the instructor, the TAs and
that student could see the contents. This is where the student would keep
their homework submissions and answer sheets.</li>
</ol>
<h4 id="manual-fork">Manual Fork</h4>
<p>GitHub has the idea of a Fork within its interface. The idea is that you can
<a href="https://help.github.com/articles/fork-a-repo">Fork</a> a repo and then contribute to the upstream with your changes. It
might seem a bit magical but this mechanism is easy to understand.</p>
<p>The term fork doesn’t exist in Git; it only exists in GitHub. This is important
because we couldn’t use Forks within GitHub because if each student Forked the
Main Homework Repo, it would have the same permissions and every other student
would be able to see the repository.</p>
<p>A fork actually is just a convenient way to manage branches and remotes within
Git with a bit of cleverness on top.</p>
<p>To mimic a Fork but keep the repo private, it was pretty straight forward. We
told the students to use their repository as the <code class="language-plaintext highlighter-rouge">origin</code> and the Main Homework
Repo as the <code class="language-plaintext highlighter-rouge">upstream</code>.</p>
<p>Here is what a correct repo would look like:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>git remote <span class="nt">-v</span>
upstream git@github.com:ComS342-ISU/homework.git <span class="o">(</span>fetch<span class="o">)</span>
upstream git@github.com:ComS342-ISU/homework.git <span class="o">(</span>push<span class="o">)</span>
origin git@github.com:ComS342-ISU/hw-answers-joshuad.git <span class="o">(</span>fetch<span class="o">)</span>
origin git@github.com:ComS342-ISU/hw-answers-joshuad.git <span class="o">(</span>push<span class="o">)</span></code></pre></figure>
<p>As you can see that the “Main Homework Repo” is set to be the upstream and my
own repository is set to be the origin.</p>
<p>This allowed the student to “pull” in new changes just by checking the
<code class="language-plaintext highlighter-rouge">upstream</code> remote and the <code class="language-plaintext highlighter-rouge">master</code> branch. The section on new homeworks will
provide the exact command in case remotes and branches are unfamiliar to you.</p>
<p>To see more about how to do this, check out the guide that we provided:
<a href="https://github.com/ComS342-ISU/course-info/blob/master/guides/course-setup.md">Git/GitHub Guide</a>.</p>
<h3 id="troubleshooting-code">Troubleshooting Code</h3>
<p>One of the best things about using GitHub to host code was that it made it
trivial to troubleshoot a student’s code. There were a handful of occasions when
a student was having a strange error that I couldn’t debug over email.</p>
<p>I’d email the student back, telling them to commit what they have so far and I
would be able to debug it then. I’d then either pull the repository locally
and run it, or I would just debug by looking at it in GitHub.</p>
<h3 id="new-homeworks--solutions">New Homeworks & Solutions</h3>
<p>Releasing new homeworks was dead simple. One of the TA’s or the instructor would
just add a new folder containing the homework files to the main repo.</p>
<p>Then we’d release an announcement on Blackboard with the reminder to run the
following:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>git pull upstream master</code></pre></figure>
<p>This tells Git to look at the <code class="language-plaintext highlighter-rouge">master</code> branch of the Main Homework Repo (which
we’ve configured to be called <code class="language-plaintext highlighter-rouge">upstream</code>), then to pull in all the changes.</p>
<p>This also allowed us to add solutions as we wished and by keeping things in
separate folders, it allowed us to eliminate merge conflicts.</p>
<h3 id="submitting-homeworks">Submitting Homeworks</h3>
<p>In the <a href="/2014/01/19/github-university-how-college-assignments-should-work/">original post</a>, I mentioned that there are various
ways to improve the setup. The first was the issue of submitting homeworks.</p>
<p>The solution that we ended up using was the simple solution proposed by Lorand.
He said that instead of worrying about any of the repo history, he could just
run the grading bot 15 minutes after the homework deadline.</p>
<p>This gave enough time for people that had strange issues to get things resolved,
yet close enough to the deadline that it effectively solved the “submission”
process.</p>
<h3 id="grading-homework">Grading Homework</h3>
<p>The other TA, <a href="http://lorandszakacs.com/">Lorand</a>, wrote up a wicked cool bot in Scala that would
download all of the repositories, run a suite of unit tests on them, then upload
the text output with a rough grade.</p>
<p>Then depending on which one of us was going to grade the homework, we’d manually
review the results and inspect each student’s code. Then we’d assign the final
grade based on the unit test results as well as the code inspection.</p>
<p>Since Lorand was the one that wrote the grading bot, you’d have to ask him for
the source code if you’d like to see it.</p>
<h2 id="students-response">Student’s Response</h2>
<p>In the class there were a handful of advanced engineers that already knew Git.
The great thing is that I heard from a few in that they really enjoyed the
setup.</p>
<p>Here’s one student’s response in particular that I liked:</p>
<div class="gallery medium">
<a href="/img/cs342/git.png" rel="lightbox[git]" title="One student's response.">
<img src="/img/cs342/git.png" alt="A student's git love." />
</a>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>If I had to be a TA again, I would pick to use GitHub in a heartbeat. It saved
us a ton of time in not only releasing homeworks but grading them.</p>
<p>Hopefully if you are coming here to learn more about how to use GitHub for your
course this will help.</p>
<p>Let me know if there’s anything that’s vague or missing from this post.
Thanks again for reading!</p>
<h2 id="after-thought">After Thought</h2>
<p>I am really interested in creating an actual software solution to this. I think
it has the potential to be a great help in classrooms and bring some much needed
innovation to the coding + teaching front.</p>
<p>If you are interested in helping or just want to sign up for the beta (if it
ever is completed), please do <a href="/about/#contact">contact me</a>. I’d love to hear about your
suggestions and your story.</p>
Put Yourself Out There: The Myth of the Genius Programmer2014-06-13T00:00:00+00:00https://joshldavis.com/2014/06/13/put-yourself-out-there<h1 id="put-yourself-out-there-the-myth-of-the-genius-programmer">Put Yourself Out There: The Myth of the Genius Programmer</h1>
<p>Just barely over a year ago, I started my blog with my very <a href="/2013/05/11/beginning-of-a-beautiful-blogship/">first
post</a>. In it, I talked about how I was afraid to put myself out there and
how I slowly overcame it.</p>
<p>In this post, I want to discuss how the past year has gone as well as some of
the amazing things that have happened. I have met some really great people and
I’ve changed how I think of things because of it.</p>
<h2 id="the-myth-of-the-genius-programmer">The Myth of the Genius Programmer</h2>
<p>Before I jump into that, let’s take a look at the myth I was believing. The
video below is one of my favorite talks. It caused a paradigm shift in my
thinking when I first watched it. I very much believed in the myth. I was lucky
in that I watched it the summer before I started college.</p>
<p>If you have time, I recommend watching it. If you don’t just continue on and
I’ll summarize it.</p>
<div class="gallery medium">
<iframe width="640" height="450" src="//www.youtube.com/embed/0SARbwvhupQ?rel=0" frameborder="0" allowfullscreen=""></iframe>
</div>
<h3 id="the-myth">The Myth</h3>
<p>The gist of the video is that it is a myth that to create software, you need to
isolate yourself in a room and code a ton. Then when you emerge from your
asylum, your project and code is so incredible that you are forever enshrined in
the annals of Computer Programming and you are hailed as a genius.</p>
<p>Beyond the obvious implications it has for being a programmer, the myth extends
to other professions as well. The idea is that it is bad to seek help and to
show your insecurities. If you have to seek help, then you are obviously
incompetent which will be looked down upon by your peers.</p>
<h3 id="new-guidelines">New Guidelines</h3>
<p>Instead the speakers, <a href="https://twitter.com/therealfitz/">Brian Fitzpatrick</a> and <a href="https://twitter.com/sussman/">Ben
Collins-Sussman</a>, discuss how software should be developed with other
people and with as open as communication as possible. These “geniuses” that can
do it alone are actually incredibly rare and often their stories are over
exaggerated. Code that is written should be reviewed often and by other
people; your mistakes, vulnerabilities, and inner self should be completely
exposed.</p>
<p>This is hard because it goes against human nature; it isn’t normal to show your
vulnerabilities. They encourage the following:</p>
<ol>
<li>Make yourself vulnerable.</li>
<li>Be open.</li>
<li>Communicate well.</li>
<li>Embrace criticism.</li>
</ol>
<h3 id="the-takeaway">The Takeaway</h3>
<p>The ending of the video they share the secret in what often happens if you don’t
believe in the myth. They say that if you follow the guidelines above:</p>
<blockquote>
<p>…people will think you’re a genius.</p>
</blockquote>
<p>This was completely revolutionary to me. I understood it the second they
explained it in the video. I knew people that hid nothing and were vulnerable in
every way; I just hadn’t realized that this was why I revered them as such.</p>
<h2 id="overcoming-the-myth">Overcoming the Myth</h2>
<p>I detailed how I was able to gradually do this in my <a href="/2013/05/11/beginning-of-a-beautiful-blogship/">first post</a>.
Essentially I just started small until I realized that nothing bad had happened
yet.</p>
<p>This is the classic idea of <a href="https://en.wikipedia.org/wiki/Desensitization_(psychology)">desensitization</a>. After the fear
of being vulnerable and exposed went away, I never even gave it a second
thought.</p>
<h3 id="little-steps">Little Steps</h3>
<p>I started putting some things on GitHub like my dotfiles. I started to do more
interviews for internships.</p>
<p>I started to talk to people about what I didn’t know in addition to what I did
know.</p>
<p>I let people into the protective little bubble that I had created for myself
because I thought the bubble was for the best.</p>
<h2 id="be-vulnerable">Be Vulnerable</h2>
<p>My favorite blog post that I’ve written in the past year is without a doubt the
post about my favorite quote from the movie Gattaca: <a href="/2013/08/31/never-save-anything-for-the-swim-back">Never Save Anything for
the Swim Back. Ever</a>.</p>
<p>One of my friends, Kien Nguyen, came across that blog post and read it. He sent
me one of the best messages that I’ve received. This is what he said:</p>
<blockquote>
<p>man, you are awesome :). just scanned over your personal website, and I was
inspired and impressed with what you’ve done :). It makes me want to try
harder to find and achieve what I really wanna do in my life. You are great
Josh. I am glad I had a chance to meet you :)</p>
</blockquote>
<p>Kien then decided to stay up late and watched the entire movie of Gattaca. I
know this because after 2am, he sent me a message saying that he just finished
watching it.</p>
<p>I wrote that blog post because it was something that I hold very near to the
core of who I am. I’ve drawn a lot of inspiration from the film over the years.
As such, it was something that only a few people knew.</p>
<p>By writing that, I made it known that I compare myself to other people a lot. I
told how I struggle with feelings of inferiority and the fear of being “stupid”.</p>
<p>Yet to have someone read about your vulnerabilities and draw inspiration from it
rather than to judge you is so incredibly meaningful & exquisite.</p>
<h3 id="a-tale-of-many-tales">A Tale of Many Tales</h3>
<p>That is just one example but there have been many others. From people teaching
college classes that have stumbled upon my post about <a href="/2014/01/19/github-university-how-college-assignments-should-work/">using GitHub for
university assignments</a>, to people that are now <a href="/2014/02/12/doing-your-homework-in-latex/">using LaTeX for
homework</a>.</p>
<p>Changing someone’s heart and their mind to want to become better and to learn
more is an incredible feeling.</p>
<h3 id="open-source-opportunities">Open Source Opportunities</h3>
<p>This past March I made a website called <a href="http://twofactorauth.org/">TwoFactorAuth.org</a>. It was
something that I would never have done if I hadn’t overcome the myth and had
still been afraid.</p>
<p>The idea would have entered my mind only to be met with an endless stream of
reasons why it wouldn’t be perfect and how I’d look like a fool. The motivation
for doing it would be drowned in the torrent. I would go on my way looking for
the idea where I would be finally hailed as a “genius”.</p>
<p>I’ve also been getting involved with <a href="http://neovim.org">Neovim</a>, the project that hopes to
refactor Vim and bring it into the 21st century.</p>
<p>These are just two opportunities that I never would have seized a couple of
years ago.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I completely understand the inert fear and discomfort that comes when thinking
about “putting yourself out there”. It is completely natural and normal. But I
also understand what it takes to break free from that myth and that fear.</p>
<p>I certainly don’t think that everyone has to “put themselves out there”. But I
do think that if you do seek it out and challenge yourself to, that you will
have meaningful experiences.</p>
<p>Don’t let the myth hold you back. Follow the words of Michael Scott:</p>
<div class="gallery small">
<a href="/img/put/michael-scott.png" rel="lightbox[michael]" title="Michael Scott">
<img src="/img/put/michael-scott.png" alt="Wise Michael Scott quote" width="350" />
<span>Michael Scott and his infinite wisdom.</span>
</a>
</div>
Josh Uses This2014-05-15T00:00:00+00:00https://joshldavis.com/2014/05/15/uses-this<h1 id="josh-uses-this">Josh Uses This</h1>
<p>I’m a big fan of <a href="http://usesthis.com/">UsesThis.com</a> and love reading about people that I
admire and how they work. It may seem a bit corny, but I want to do a UsesThis
of my own because I’m incredibly picky when it comes to what I use. Here goes.</p>
<div class="gallery small">
<a href="/img/uses/me.png">
<img src="/img/uses/me.png" alt="Me!" width="350" />
</a>
</div>
<h2 id="who-are-you-and-what-do-you-do">Who are you, and what do you do?</h2>
<p>If I had written this a week ago, I’d have said that I’m a Computer Science
undergraduate major, but I just graduated this past Saturday with my Bachelor’s.</p>
<p>I will start working at Amazon on <a href="http://aws.amazon.com/">AWS</a> in exactly two months as a Software
Engineer on the Dev Productivity & Tools team.</p>
<h2 id="what-hardware-do-you-use">What hardware do you use?</h2>
<p>I am a lover of Apple’s hardware & software. I’ve only owned 2 different iMacs
starting with the first one that I bought in 2006. They are my favorite machine
to use as long as I have a nice <a href="http://www.daskeyboard.com/">mechanical keyboard</a> and a
<a href="http://www.logitech.com/en-us/product/wireless-trackball-m570">Trackball</a>.</p>
<p>When I’m not at home, I have a generic Dell laptop that used to run <a href="https://www.archlinux.org/">Arch
Linux</a> but now runs <a href="http://www.linuxmint.com/">Linux Mint</a>. I can’t wait to get rid of it to
get a <a href="https://www.apple.com/macbook-air/">Macbook Air</a>. I love Linux but I get a bit tired of <a href="https://github.com/jdavis/dotfiles">configuring
it</a> endlessly to work exactly how I want.</p>
<h2 id="and-what-software">And what software?</h2>
<p>I can’t do any coding or text editing without <a href="http://www.vim.org/">Vim</a>. I love <a href="https://github.com/jdavis/dotfiles/blob/master/.vimrc">tweaking
it</a> to work perfectly with my workflow. I’m pretty obsessed with
productivity and getting things done. I also have high hopes for
<a href="http://neovim.org/">Neovim</a> and want to do all I can to see it come to fruition.</p>
<p>I can’t use OS X without a sane window manager. I was too spoiled by
<a href="http://xmonad.org/">xmonad</a> when using Linux. I’ve settled with <a href="https://github.com/jigish/slate">Slate</a> (<a href="https://github.com/jdavis/dotfiles/blob/9881858b3f306bf55e53186a56b7a7f69dfc3bea/.slate">my slate
config</a>) on OS X although I don’t use it to its full potential (yet).</p>
<p>I have a handful of Gmail accounts that I manage with <a href="http://mailplaneapp.com/">Mailplane</a>. It
is a great way to manage multiple accounts.</p>
<p>The app that I use the most is probably <a href="https://www.google.com/intl/en_us/chrome/browser/">Chrome</a> for obvious reasons.</p>
<p>As long as I have a terminal (either iTerm or Terminal.app) with <a href="http://tmux.sourceforge.net/">tmux</a>
installed to <a href="https://github.com/jdavis/dotfiles/blob/master/.tmux.conf">my liking</a>, I can pretty much get by with only the apps
from above and don’t have to install much else.</p>
<p>On the command line, there are a few necessities like Git, Homebrew, LaTeX and
the like. With those, a software engineer can just about conquer anything.</p>
<h2 id="what-would-be-your-dream-setup">What would be your dream setup?</h2>
<p>My dream setup would be finished as long as I had a Macbook Air. It would be the
perfect addition and allow me to work on things anywhere. Plus the size and
portability make it awesome.</p>
<p>And maybe if I could move the mouse and click on things with my vision. That way
I’d never have to use a mouse again. I’d never have to move my hands from the
homerow – you know, like Vim style.</p>
A Beginner's Tutorial for knitr2014-04-12T00:00:00+00:00https://joshldavis.com/2014/04/12/beginners-tutorial-for-knitr<h1 id="a-beginners-tutorial-for-knitr">A Beginner’s Tutorial for knitr</h1>
<p>My first homework assignment for my Machine Learning class was a mess. I was
copying and pasting code into my LaTeX file, I was manually running and saving
graphs in R as PNGs and PDFs.</p>
<p>There has to be an easier way of doing this, I thought. A search or two later
and I learned about knitr. I have never looked back and completely love it.</p>
<p>If this sounds like you or if you are upset with <a href="http://www.stat.uni-muenchen.de/~leisch/Sweave/">Sweave</a>, then you
really need to check out <a href="http://yihui.name/knitr/">knitr</a> (GitHub <a href="https://github.com/yihui/knitr">Source</a>).</p>
<p>Also, if you don’t <a href="http://joshldavis.com/2014/02/12/doing-your-homework-in-latex/">do your homework in LaTeX</a>, you’re really
missing out.</p>
<h2 id="foreword">Foreword</h2>
<div class="figure right">
<img src="/img/knitr/book.png" alt="knitr book" />
<span>Yihui's book</span>
</div>
<p>This is meant to be a short intro to knitr; it isn’t meant to be comprehensive.</p>
<p>If you wish to learn more about knitr in depth, check out <a href="http://yihui.name/">Yihui Xie’s</a>
book, <a href="https://www.amazon.com/gp/product/B00F2MPD9O/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B00F2MPD9O&linkCode=as2&tag=jld07-20&linkId=7c4c4862760278bd1051cc45224aaf2b">Dynamic Documents with R and knitr</a>. He’s the creator of knitr and
has written a really, really excellent book on it.</p>
<p>On a sidenote, he got his PhD in Statistics from Iowa State University where I
am finishing up my Bachelor’s degree.</p>
<p>Together he and <a href="http://had.co.nz/">Hadley Wickham</a> both graduated from ISU and both have
contributed a whole lot to the R community.</p>
<h2 id="getting-started">Getting Started</h2>
<p>First you’ll need to install <a href="http://cran.r-project.org/web/packages/knitr/index.html">knitr from CRAN</a> if you don’t already have
it. This can be done by launching R and running:</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">install.packages</span><span class="p">(</span><span class="s1">'knitr'</span><span class="p">,</span><span class="w"> </span><span class="n">dependencies</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span></code></pre></figure>
<p>You can verify that it has been installed by running:</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">library</span><span class="p">(</span><span class="s1">'knitr'</span><span class="p">)</span></code></pre></figure>
<p>If you don’t get any errors, you’re good to go! If you do get errors, check out
the <a href="https://github.com/yihui/knitr/blob/master/FAQ.md">knitr FAQ</a> to see if there are any solutions.</p>
<h2 id="adding-r-code">Adding R Code</h2>
<p>Adding R code to a LaTeX document is as easy as adding a chunk. A chunk is just
what knitr calls a section of R code. Each chunk can have its own options to
configure how it is rendered.</p>
<p>A simple example chunk in LaTeX looks like this:</p>
<figure class="highlight"><pre><code class="language-tex" data-lang="tex">From ISLR: Chapter 3, Problem 14.
Using a created simulated data, answer the questions regarding simple
linear regression.
<<>>=
# Ensure consistent values
set.seed(1)
# Create uniform distribution for first input
x1 <- runif(100)
# Normal distribution for second input
x2 <- 0.5 * x1 + rnorm(100) / 10
# Our Linear Model
y <- 2 + (2 * x1) + (.3 * x2) + rnorm(100)
@
<span class="k">\part</span>
Write out the form of the linear model. What are the regression
coefficients?</code></pre></figure>
<p>Which will end up being rendered like this:</p>
<div class="gallery medium">
<a href="/img/knitr/knitr1.png" rel="lightbox[knitr]">
<img src="/img/knitr/knitr1.png" alt="Basic chunk in knitr" />
<span>Basic chunk example</span>
</a>
</div>
<h3 id="basic-chunk-options">Basic Chunk Options</h3>
<p>If we want to just show code without seeing the results, we can do that by
adding <code class="language-plaintext highlighter-rouge">eval=FALSE</code> to the chunk options. Like so:</p>
<figure class="highlight"><pre><code class="language-tex" data-lang="tex"><<eval=FALSE>>=
# This code is just shown, it isn't ran
x1 <- runif(100)
@</code></pre></figure>
<p>As you can see, all the options go within the angle brackets.</p>
<p>Another common one that I use for things such as imports is to set <code class="language-plaintext highlighter-rouge">echo=FALSE</code>.
This will hide the code but still evaluate it.</p>
<p>There are a ton of other <a href="http://yihui.name/knitr/options#chunk_options">chunk options</a> that allow you to completely
fine tune how to handle the R code in your documents.</p>
<h3 id="referencing-r-variables">Referencing R Variables</h3>
<p>Since the R code is evaluated as you compile your document, you can include
variables in your normal LaTeX.</p>
<p>Let’s say you wanted to compute the <code class="language-plaintext highlighter-rouge">mean()</code> of <code class="language-plaintext highlighter-rouge">y</code>, store it in a variable and
then include it in output below it. It would look like this:</p>
<figure class="highlight"><pre><code class="language-tex" data-lang="tex"><<>>=
# Our Linear Model from before
y <- 2 + (2 * x1) + (.3 * x2) + rnorm(100)
# Calculate the mean
mean.y <- mean(y)
@
The mean of <span class="p">\(</span><span class="nb">Y</span><span class="p">\)</span> is <span class="p">\(</span><span class="nv">\Sexpr</span><span class="p">{</span><span class="nb">mean.y</span><span class="p">}\)</span>.</code></pre></figure>
<p>The output is in the image below. This makes it really, really easy to keep
info up to date and not have to worry about re-computing values.</p>
<p>You can put any R code in the <code class="language-plaintext highlighter-rouge">\Sexpr{}</code>. More info about that can be found
under the <strong>Inline output</strong> section on the <a href="http://yihui.name/knitr/demo/output/">knitr Output</a> page.</p>
<div class="gallery medium">
<a href="/img/knitr/knitr3.png" rel="lightbox[knitr]">
<img src="/img/knitr/knitr3.png" alt="Values in knitr" />
<span>Values from R in LaTeX</span>
</a>
</div>
<h3 id="figures">Figures</h3>
<p>This is the most indespensible feature of knitr. It is capable of automatically
evaluating the R code and including any graphs that are output.</p>
<p>Let’s go back to our simple linear model. If we add this to our LaTeX document:</p>
<figure class="highlight"><pre><code class="language-tex" data-lang="tex">Which checks out with our value. This suggests that <span class="p">\(</span><span class="nb">X</span><span class="p">_</span><span class="m">1</span><span class="p">\)</span> and <span class="p">\(</span><span class="nb">X</span><span class="p">_</span><span class="m">2</span><span class="p">\)</span> are
pretty colinear. Let's visualize this by using a scatter plot:
<<p1b, fig.pos="H", fig.height=4, fig.cap="Correlation of given predictors.">>=
plot(x1, x2,
main = 'Correlation of X1 and X2',
xlab = 'X1',
ylab = 'X2')
@</code></pre></figure>
<p>Then we get this as the output:</p>
<div class="gallery medium">
<a href="/img/knitr/knitr2.png" rel="lightbox[knitr]">
<img src="/img/knitr/knitr2.png" alt="Figures in knitr" />
<span>Simple figure</span>
</a>
</div>
<p>We don’t have to worry about outputting our image, saving it, then adding it to
LaTeX. Instead, knitr handles all of that for us.</p>
<p>We are using a few more chunk options as well. The first, <code class="language-plaintext highlighter-rouge">p1b</code>, is just a label
that allows us to refer to it by name.</p>
<p>Next we are using the option <code class="language-plaintext highlighter-rouge">fig.pos="H"</code>, this tells knitr to include it with
a certain position. These options are given by LaTeX’s <a href="http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Figures"><code class="language-plaintext highlighter-rouge">figure</code>
environment</a>.</p>
<p>Then we set a height for the figure as well as giving it a caption. As you can
see, the caption ends up at the bottom of the figure.</p>
<p>Once again, these figure chunk options can be found on the same <a href="http://yihui.name/knitr/options#chunk_options">chunk
options</a> page.</p>
<h2 id="running-knitr">Running knitr</h2>
<p>Before typesetting the LaTeX code, you need to first run it through knitr. My
preferred way to do this is by running the following:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>Rscript <span class="nt">-e</span> <span class="s2">"library(knitr); knit('./file-here.Rnw')"</span></code></pre></figure>
<p>Where <code class="language-plaintext highlighter-rouge">file-here.Rnw</code> points to your knitr file. This will automatically output
the accompanying formatted output. So for this example, we will then get a file
called <code class="language-plaintext highlighter-rouge">file-here.tex</code> which will be all ready to typeset.</p>
<p>You can then run this through LaTeX anyway you wish. However, I like to automate
things because it allows me to seamlessly edit files. I’ll talk about that next.</p>
<h2 id="seamless-editing">Seamless Editing</h2>
<p>I do all of my editing in Vim so one of the things that I like is automatic
typesetting of LaTeX when I save.</p>
<p>I have the following saved in my <a href="https://github.com/jdavis/dotfiles/blob/master/.latexmkrc"><code class="language-plaintext highlighter-rouge">~/.latexmkrc</code></a> file:</p>
<figure class="highlight"><pre><code class="language-perl" data-lang="perl"><span class="k">if</span> <span class="p">(</span><span class="vg">$^O</span> <span class="ow">eq</span> <span class="p">'</span><span class="s1">darwin</span><span class="p">')</span> <span class="p">{</span>
<span class="c1"># Open Skim when using OS X</span>
<span class="nv">$pdf_previewer</span> <span class="o">=</span> <span class="p">"</span><span class="s2">open -a Skim.app</span><span class="p">";</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="c1"># Open Mint's default pdf viewers</span>
<span class="nv">$pdf_previewer</span> <span class="o">=</span> <span class="p">"</span><span class="s2">mate-open</span><span class="p">";</span>
<span class="p">}</span></code></pre></figure>
<p>This launches my preferred PDF viewer depending on the system that I’m on. All I
need to run this is to run:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>latexmk <span class="nt">-pdf</span> <span class="nt">-pvc</span> solution.tex</code></pre></figure>
<p>The <code class="language-plaintext highlighter-rouge">-pvc</code> is a special option for <code class="language-plaintext highlighter-rouge">latexmk</code>. It tells the system to run a file
previewer and continously update the output whenever changes are made to the
source file, <code class="language-plaintext highlighter-rouge">solution.tex</code>.</p>
<h3 id="watching-a-knitr-file">Watching a knitr File</h3>
<p>Since <code class="language-plaintext highlighter-rouge">latexmk</code> works great for watching tex files, I wrote up a little script
that I’ve called <code class="language-plaintext highlighter-rouge">knitr</code> that I place on my $PATH. It allows me to run:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>knitr file-here.Rnw</code></pre></figure>
<p>And will automatically run knitr whenever the source file updates. It uses
Ruby’s <a href="https://github.com/alloy/kicker">kicker</a> to watch for a file change and run a specific command.</p>
<p>The entire source can be found <a href="https://github.com/jdavis/dotfiles/blob/d4551c015b1ac4c8438b5e590661ed3dddf63928/bin/knitr">here</a> but here is the basic idea:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">FILE</span><span class="o">=</span><span class="s2">"</span><span class="k">${</span><span class="nv">1</span><span class="k">}</span><span class="s2">"</span>
<span class="nv">KNITR</span><span class="o">=</span><span class="s2">"echo </span><span class="se">\"</span><span class="s2">Rerunning knitr...</span><span class="se">\"</span><span class="s2">; Rscript -e </span><span class="se">\"</span><span class="s2">library(knitr); knit('./</span><span class="k">${</span><span class="nv">FILE</span><span class="k">}</span><span class="s2">')</span><span class="se">\"</span><span class="s2">"</span>
<span class="nb">echo</span> <span class="s2">"Watching </span><span class="k">${</span><span class="nv">FILE</span><span class="k">}</span><span class="s2">..."</span>
kicker <span class="nt">-e</span> <span class="s2">"</span><span class="k">${</span><span class="nv">KNITR</span><span class="k">}</span><span class="s2">"</span> <span class="k">${</span><span class="nv">FILE</span><span class="k">}</span></code></pre></figure>
<h2 id="conclusion">Conclusion</h2>
<p>Together with these scripts and knitr, I’m able to edit a LaTeX + R file and
have it constantly updated and formatted. When I keep my PDF viewer open, I can
see my document evolve right in front of me.</p>
<p>knitr makes working on Statistics and Machine Learning a breeze. I can’t imagine
trying to work without it.</p>
<p>Do you use knitr and have some feedback? Feel free to <a href="/about/#contact">send me an
email</a> me or Tweet at me on Twitter: <a href="https://twitter.com/">@HopefulJosh</a>. I’d love
to learn more or talk.</p>
Vim Tab Madness. Buffers vs Tabs2014-04-05T00:00:00+00:00https://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs<h1 id="vim-tab-madness-buffers-vs-tabs">Vim Tab Madness. Buffers vs Tabs</h1>
<p>First I have to admit, I was a heavy user of tabs in Vim.</p>
<p>I was using tabs in Vim as you’d use tabs in most other programs (Chrome,
Terminal, Adium, etc.). I was used to the idea of a tab being the place where a
document lives.</p>
<p>When you want to edit a document, you open a new tab and edit away! That’s how
tabs work so that must be how they work in Vim right?</p>
<p>Nope.</p>
<h2 id="stop-the-tab-madness">Stop the Tab Madness</h2>
<p>If you are using tabs like this then you are really limiting yourself and using
a feature of Vim that wasn’t meant to work like this.</p>
<p>Vim’s tabs are named very badly, as <a href="http://stackoverflow.com/a/103590">others note</a>, they would make
more sense if they were called <em>layouts</em>.</p>
<p>Before I explain that, let’s be sure we understand what a <em>buffer</em> is in Vim as
well as a few other basic things.</p>
<p>After that, I’ll explain the <em>correct</em> way to use tabs within Vim.</p>
<h2 id="buffers">Buffers</h2>
<p>A buffer is nothing more than text that you are editing. For example, when you open a
file, the content of the file is loaded into a buffer. So when you issue this
command:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>vim .vimrc</code></pre></figure>
<p>You are actually launching Vim with a single buffer that is filled with the
contents of the <code class="language-plaintext highlighter-rouge">.vimrc</code> file. Easy peasy!</p>
<p>Now let’s look at what happens when you try to edit multiple files. Let’s issue
this command:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>vim .vimrc .zshrc
<span class="c"># In Vim run this:</span>
<span class="c"># :bnext</span></code></pre></figure>
<p>Vim does what it did before, but instead of just 1 buffer, it opens another
buffer that is filled with .zshrc. So now we have two buffers open.</p>
<p>If you want to pause editing .vimrc and move to .zshrc, you could run this
command in Vim <code class="language-plaintext highlighter-rouge">:bnext</code> which will show the .zshrc buffer. There are various
other commands to manipulate buffers which you can see if you type <code class="language-plaintext highlighter-rouge">:h
buffer-list</code>.</p>
<p>Here’s a gif of what that looks like:</p>
<div class="gallery medium">
<figure>
<img src="/img/vim/buffers.gif" alt="Editing two buffers" width="600" />
<figcaption>Editing two buffers</figcaption>
</figure>
</div>
<h2 id="windows">Windows</h2>
<p>A window in Vim is just a way to view a buffer. Whenever you create a new
vertical or horizontal split, that is a window. For example, if you were to type
in <code class="language-plaintext highlighter-rouge">:help window</code>, it would launch a new window that shows the help
documentation.</p>
<p>The important thing to note is that a window can view any buffer it wishes; it
isn’t forced to look at the same buffer. And we’ve all noticed this. When
editing a file, if we type <code class="language-plaintext highlighter-rouge">:vsplit</code>, we will get a vertical split and in the
other window, we will see the current buffer we are editing!</p>
<p>That should no longer be confusing because a window lets us look at <em>any</em>
buffer. It just so happens that when creating a new split: <code class="language-plaintext highlighter-rouge">:split</code> or
<code class="language-plaintext highlighter-rouge">:vsplit</code>, the buffer that we view is just the current one.</p>
<p>By running any of the buffer commands from <code class="language-plaintext highlighter-rouge">:h buffer-list</code>, we can modify which
buffer a window is <em>viewing</em>.</p>
<p>For an example of this, by running the following commands, we will start
editing two files in Vim, open a new window by horizontally splitting, and then
view the second buffer in the original window.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>vim .vimrc .zshrc
<span class="c"># In Vim run these:</span>
<span class="c"># :split</span>
<span class="c"># :bnext</span></code></pre></figure>
<p>Here’s a gif of these commands:</p>
<div class="gallery medium">
<figure>
<img src="/img/vim/windows.gif" alt="Editing two buffers with windows" width="600" />
<figcaption>Editing two buffers with windows</figcaption>
</figure>
</div>
<h2 id="so-a-tab-is">So a Tab is…?</h2>
<p>So now that we know what a buffer is and what a window is. Here is what Vim says
in the Vim documentation regarding a buffer/window/tab:</p>
<figure class="highlight"><pre><code class="language-rst" data-lang="rst">Summary:
A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.</code></pre></figure>
<p>According to the documentation, a tab is just a collection of windows. This goes
back to our earlier definition in that a tab is really just a layout.</p>
<p>A tab is only designed to give you a different layout of windows.</p>
<p>Here’s the exact same setup as last time (two files, horizontally split) with a
new tab with a different <strong>layout</strong> of windows:</p>
<div class="gallery medium">
<figure>
<img src="/img/vim/tabs.gif" alt="Two tabs with window layouts" width="600" />
<figcaption>Two tabs, both with different window layouts</figcaption>
</figure>
</div>
<p>The first tab is just split horizontally while the second tab is split
horizontally and vertically.</p>
<p>As you can see, the first and second tabs have different layouts yet they
are only <em>viewing</em> the same two buffers: <code class="language-plaintext highlighter-rouge">.vimrc</code> and <code class="language-plaintext highlighter-rouge">.zshrc</code>.</p>
<p>This brings us to the basic problem of tabs within Vim.</p>
<h2 id="the-tab-problem">The Tab Problem</h2>
<p>Tabs were only designed to let us have different layouts of windows. They aren’t
intended to be where an open file lives; an open file is instead loaded into a
buffer.</p>
<p>The previous gif illustrates this problem. If you can view the same buffer
across all tabs, how is this like a normal tab in most other editors?</p>
<p>If you try to force a single tab to point to a single buffer, that is just
futile. Vim just wasn’t meant to work like this.</p>
<h2 id="the-buffer-solution">The Buffer Solution</h2>
<p>To reconcile all of this and learn how to use Vim’s buffers/windows effectively,
it might be useful to stop using tabs altogether until you understand how to
edit with just using buffers/windows.</p>
<p>I’m going to present two different ways to use buffers. The first is to
use buffers to replicate how tabs work in other editors.</p>
<p>The second is a more natural way to the Vim editor that yields a lot of
power.</p>
<h3 id="solution-1-replicating-tabs-with-buffers">Solution #1: Replicating Tabs with Buffers</h3>
<p>The first thing I did was install a plugin that allows me to visualize all the
buffers open across the top. There are multiple different <a href="http://vim.wikia.com/wiki/Easier_buffer_switching#Scripts">plugins</a>
for this.</p>
<p>I was already using <a href="https://github.com/bling/vim-airline">vim-airline</a>, so I just turned on its feature to
<a href="https://github.com/bling/vim-airline#smarter-tab-line">list buffers</a> across the top. To add airline and the buffer
list, <a href="https://github.com/bling/vim-airline#installation">install airline</a>, and then just add this to your
<code class="language-plaintext highlighter-rouge">.vimrc</code>:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Enable the list of buffers</span>
<span class="k">let</span> <span class="nv">g:airline</span>#extensions#<span class="nb">tabline</span>#enabled <span class="p">=</span> <span class="m">1</span>
<span class="c">" Show just the filename</span>
<span class="k">let</span> <span class="nv">g:airline</span>#extensions#<span class="nb">tabline</span>#fnamemod <span class="p">=</span> <span class="s1">':t'</span></code></pre></figure>
<p>This is the result:</p>
<div class="gallery medium">
<figure>
<img src="/img/vim/airline.gif" alt="All open buffers" width="600" />
<figcaption>A plugin that shows all open buffers</figcaption>
</figure>
</div>
<p>Next I needed to replace the tab shortcuts that I’d no longer be using. I did
this by adding these to my <a href="https://github.com/jdavis/dotfiles/blob/master/.vimrc">.vimrc</a> as well:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" This allows buffers to be hidden if you've modified a buffer.</span>
<span class="c">" This is almost a must if you wish to use buffers in this way.</span>
<span class="k">set</span> <span class="nb">hidden</span>
<span class="c">" To open a new empty buffer</span>
<span class="c">" This replaces :tabnew which I used to bind to this mapping</span>
nmap <span class="p"><</span>leader<span class="p">></span>T <span class="p">:</span><span class="k">enew</span><span class="p"><</span><span class="k">cr</span><span class="p">></span>
<span class="c">" Move to the next buffer</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">l</span> <span class="p">:</span><span class="k">bnext</span><span class="p"><</span>CR<span class="p">></span>
<span class="c">" Move to the previous buffer</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">h</span> <span class="p">:</span><span class="k">bprevious</span><span class="p"><</span>CR<span class="p">></span>
<span class="c">" Close the current buffer and move to the previous one</span>
<span class="c">" This replicates the idea of closing a tab</span>
nmap <span class="p"><</span>leader<span class="p">></span>bq <span class="p">:</span><span class="k">bp</span> <span class="p"><</span>BAR<span class="p">></span> <span class="k">bd</span> #<span class="p"><</span>CR<span class="p">></span>
<span class="c">" Show all open buffers and their status</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">bl</span> <span class="p">:</span><span class="k">ls</span><span class="p"><</span>CR<span class="p">></span></code></pre></figure>
<p>These settings gave me a hybrid approach to how I expected tabs to
work in Vim yet it still gave me the same power that comes from
understanding and using buffers.</p>
<h3 id="solution-2-crouching-tiger-hidden-buffer">Solution #2: Crouching Tiger, Hidden Buffer</h3>
<p>Instead of replicating tabs across the top like we did in the previous solution,
we are instead going to use the power of being able to open many buffers
simultaneously without worrying about which ones are open.</p>
<p>In my experience, there are two plugins that I like that help a lot with this.
The first is <a href="https://github.com/jeetsukumaran/vim-buffergator">Buffergator</a> which gives a great way to manage
buffers. The second is <a href="https://github.com/kien/ctrlp.vim">CtrlP</a> which is a favorite among many Vim users.
It gives a powerful fuzzy finder within Vim for files.</p>
<p>Instead of worrying about closing buffers and managing your pseudo-tabs that was
mentioned in the previous solution, you just open files that you want to edit
using CtrlP and don’t worry about closing buffers or how many you have opened.</p>
<p>When you are done editing a file, you just save it and then open CtrlP and
continue onto the next file.</p>
<p>CtrlP offers a few different ways to fuzzy find. You can use the following
fuzziness:</p>
<ol>
<li>Find in your current directory.</li>
<li>Find within all your open buffers.</li>
<li>Find within all your open buffers sorted by Most Recently Used (MRU).</li>
<li>Find with a mix of all the above.</li>
</ol>
<p>Here are the settings that I use for working well with CtrlP:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Setup some default ignores</span>
<span class="k">let</span> <span class="nv">g:ctrlp_custom_ignore</span> <span class="p">=</span> <span class="p">{</span>
<span class="se"> \</span> <span class="s1">'dir'</span><span class="p">:</span> <span class="s1">'\v[\/](\.(git|hg|svn)|\_site)$'</span><span class="p">,</span>
<span class="se"> \</span> <span class="s1">'file'</span><span class="p">:</span> <span class="s1">'\v\.(exe|so|dll|class|png|jpg|jpeg)$'</span><span class="p">,</span>
<span class="se">\</span><span class="p">}</span>
<span class="c">" Use the nearest .git directory as the cwd</span>
<span class="c">" This makes a lot of sense if you are working on a project that is in version</span>
<span class="c">" control. It also supports works with .svn, .hg, .bzr.</span>
<span class="k">let</span> <span class="nv">g:ctrlp_working_path_mode</span> <span class="p">=</span> <span class="s1">'r'</span>
<span class="c">" Use a leader instead of the actual named binding</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">p</span> <span class="p">:</span>CtrlP<span class="p"><</span><span class="k">cr</span><span class="p">></span>
<span class="c">" Easy bindings for its various modes</span>
nmap <span class="p"><</span>leader<span class="p">></span>bb <span class="p">:</span>CtrlPBuffer<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">bm</span> <span class="p">:</span>CtrlPMixed<span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="nb">bs</span> <span class="p">:</span>CtrlPMRU<span class="p"><</span><span class="k">cr</span><span class="p">></span></code></pre></figure>
<p>The way I use Buffergator is to clean up buffers when I need them and to easily
view what files I have edited in case I have edited one and forgot to save it.</p>
<p>Here are the settings and the keybindings I use for Buffergator:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim"><span class="c">" Use the right side of the screen</span>
<span class="k">let</span> <span class="nv">g:buffergator_viewport_split_policy</span> <span class="p">=</span> <span class="s1">'R'</span>
<span class="c">" I want my own keymappings...</span>
<span class="k">let</span> <span class="nv">g:buffergator_suppress_keymaps</span> <span class="p">=</span> <span class="m">1</span>
<span class="c">" Looper buffers</span>
<span class="c">"let g:buffergator_mru_cycle_loop = 1</span>
<span class="c">" Go to the previous buffer open</span>
nmap <span class="p"><</span>leader<span class="p">></span>jj <span class="p">:</span>BuffergatorMruCyclePrev<span class="p"><</span><span class="k">cr</span><span class="p">></span>
<span class="c">" Go to the next buffer open</span>
nmap <span class="p"><</span>leader<span class="p">></span>kk <span class="p">:</span>BuffergatorMruCycleNext<span class="p"><</span><span class="k">cr</span><span class="p">></span>
<span class="c">" View the entire list of buffers open</span>
nmap <span class="p"><</span>leader<span class="p">></span><span class="k">bl</span> <span class="p">:</span>BuffergatorOpen<span class="p"><</span><span class="k">cr</span><span class="p">></span>
<span class="c">" Shared bindings from Solution #1 from earlier</span>
nmap <span class="p"><</span>leader<span class="p">></span>T <span class="p">:</span><span class="k">enew</span><span class="p"><</span><span class="k">cr</span><span class="p">></span>
nmap <span class="p"><</span>leader<span class="p">></span>bq <span class="p">:</span><span class="k">bp</span> <span class="p"><</span>BAR<span class="p">></span> <span class="k">bd</span> #<span class="p"><</span><span class="k">cr</span><span class="p">></span></code></pre></figure>
<h3 id="using-tabs-correctly">Using Tabs Correctly</h3>
<p>This doesn’t mean you should stop using tabs altogether. You should
just use them how Vim intended you to use them.</p>
<p>Instead you should use them to change the layout among windows. Imagine
you are working on a C project. It might be helpful to have one tab dedicated
to normal editing, but another tab for using a vertical split for the <code class="language-plaintext highlighter-rouge">file.h</code>
and <code class="language-plaintext highlighter-rouge">file.c</code> files to make editing between them easier.</p>
<p>Tabs also work really well to divide up what you are working on. You could
be working on one part of the project in one tab and another part of the project
in another tab.</p>
<p>Just remember though, if you are using a single tab for each file, that isn’t
how tabs in Vim were designed to be used.</p>
<h2 id="example-of-using-buffers">Example of Using Buffers</h2>
<p>As I claimed at the beginning of the article, using buffers is far more powerful
than trying to use tabs in the way mentioned above.</p>
<p>To illustrate this let’s use an example. Here’s what you do as you edit:</p>
<ol>
<li>
<p>Let’s imagine you are editing your blog and writing a new blog post. In one
split, you have your CSS, <code class="language-plaintext highlighter-rouge">base.css</code>, as a reference and above it, you have
the post that you are actually editing.</p>
</li>
<li>
<p>Then let’s say you have to make a change to your homepage, instead of opening
up a new tab (which is the old way of thinking), you just open up a
different buffer, <code class="language-plaintext highlighter-rouge">index.html</code> using CtrlP.</p>
</li>
<li>
<p>This will just switch the buffer you are <em>viewing</em> in the window to point to
the <code class="language-plaintext highlighter-rouge">index.html</code>. All your other windows stay intact and you can still use
<code class="language-plaintext highlighter-rouge">base.css</code> as a reference below.</p>
</li>
<li>
<p>After you are done editing the layout, you can close it using <code class="language-plaintext highlighter-rouge"><leader>bq</code>,
switch back to your post and continue writing.</p>
</li>
</ol>
<p>Here’s what it looks like:</p>
<div class="gallery medium">
<figure>
<img src="/img/vim/example.gif" alt="Buffer benefits" width="600" />
<figcaption>An example of buffer benefits</figcaption>
</figure>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>Using tabs in Vim as you would in other programs isn’t the same. Then again,
when is anything in Vim like in any other program.</p>
<p>Learning how to use and embrace buffers and windows leads to a far more cohesive
editing experience in Vim and will help eliminate a lot of frustration when
trying to use tabs unnaturally.</p>
<p>If you have any suggestions on this article or using Vim in general, feel free
to <a href="/about/#contact">contact</a> me, I love talking with people =]</p>
<h4 id="updated-on-oct-25">Updated on Oct 25</h4>
<p>I’ve updated it to present my latest solution (called Solution #2) of managing
buffers in in addition to the pseudo-tab bar with buffers that now is called
“Solution #1”.</p>
My New Site to Demand Two Factor Auth Support2014-03-15T00:00:00+00:00https://joshldavis.com/2014/03/15/demand-two-factor-auth-support<h1 id="my-new-site-to-demand-two-factor-auth-support">My New Site to Demand Two Factor Auth Support</h1>
<p>About a month ago I was going through the process of looking for a new domain
registrar to transfer my domains to. My number one criteria was a secure
registrar.</p>
<p>Although I don’t own a <a href="https://medium.com/cyber-security/24eb09e026dd">rare Twitter handle</a>, it was scary to think about
how the extortion of Naoki Hiroshima was possible just because of a lost domain
name.</p>
<p>Although GoDaddy does support two factor auth, if Naoki hadn’t been using it for
PayPal, his PayPal account would have been compromised as well.</p>
<p>I did a Google search for a list of sites with two factor auth and the results
were pretty dissatisfying. The first result was a website with a huge list of
sites that was barely usable.</p>
<p>This gave me an idea for my next mini-project.</p>
<h2 id="a-quick-explanation">A Quick Explanation</h2>
<p>Now if you don’t know what <a href="http://en.wikipedia.org/wiki/Two-step_verification">two factor auth</a> is, basically the idea is that it
gives you a second way to verify that you are you. The key is that this value
doesn’t reside in your head or stored on a sticky note next to your monitor.</p>
<p>Instead the value is given to you (either through cryptographic means or through
a text/SMS). You then take this value and put it into whatever service you are
logging into.</p>
<p>Thus this gives a “second” factor to verify yourself by and giving you more
security.</p>
<h2 id="twofactorauthorg">TwoFactorAuth.org</h2>
<p>First, check it out here: <a href="http://twofactorauth.org">TwoFactorAuth.org</a></p>
<p>In the last 24 hours, I’ve spent the time creating a very simple website that
has a list of all the most common categories of websites like social media,
finance, email, etc. Then under each category there is a list of the most common
websites and whether or not they support two factor auth.</p>
<div class="gallery medium">
<a href="/img/2fa/twofactorauth.png" rel="lightbox[2fa]" title="TwoFactorAuth.org">
<img src="/img/2fa/twofactorauth.png" alt="TwoFactorAuth.org screenshot" width="640" />
<span>TwoFactorAuth.org</span>
</a>
</div>
<p>In addition to this, it provides a Twitter button that allows you to Tweet out
to the companies to demand that they support two factor auth. While it may be a
bit passive aggressive, it is a simplified version of the late Aaron Swartz’
idea for his website, <a href="http://www.demandprogress.org/">DemandProgress</a>.</p>
<h2 id="my-goal">My Goal</h2>
<p>I am a strong proponent for individual security and awareness. I hope that this
website will give a single place to go when determining alternative services
based on the care and engineering they have in place for their customers.</p>
<p>If every website that ends up on TwoFactorAuth.org ends up in the green and my
website becomes pointless, then that is only a success in my vision.</p>
<p>Here’s to hoping that more sites will put the security of their customers first
and invest in two factor auth.</p>
<h2 id="open-source-of-course">Open Source (of course)</h2>
<p>Oh and lastly, the best part is that it is open source so you can add any
website to it you want. Just head over to the <a href="https://github.com/jdavis/twofactorauth">GitHub repo</a> and make a
pull request.</p>
<div class="buttons">
<a class="button" href="http://www.github.com/jdavis/twofactorauth"><i class="icon-github"></i> View on GitHub</a>
</div>
Doing Your Homework in LaTeX2014-02-12T00:00:00+00:00https://joshldavis.com/2014/02/12/doing-your-homework-in-latex<h1 id="doing-your-homework-in-latex">Doing Your Homework in LaTeX</h1>
<p>It is a common occurrence for other students to comment on my homework whenever
I turn it in for one of my classes.</p>
<p>The complete
<a href="http://en.wikipedia.org/wiki/LaTeX">LaTeX</a> file (and the pdf output) can be found in my repository,
<a href="https://github.com/jdavis/latex-homework-template">latex-homework-template</a>.</p>
<div class="buttons">
<a class="button" href="http://www.github.com/jdavis/latex-homework-template"><i class="icon-github"></i> View on GitHub</a>
</div>
<p>Below are a few screenshots of problems that I’ve done in the past:</p>
<div class="gallery large">
<a href="/img/latex/latex1.png" rel="lightbox[latex]" title="Cover page">
<img src="/img/latex/latex1.png" alt="Cover page" width="180" />
<span>Cover page</span>
</a>
<a href="/img/latex/latex2.png" rel="lightbox[latex]" title="Example problem 2">
<img src="/img/latex/latex2.png" alt="Algorithm problem" width="180" />
<span>Algorithm problems</span>
</a>
<a href="/img/latex/latex3.png" rel="lightbox[latex]" title="Example problem 3">
<img src="/img/latex/latex3.png" alt="Complexity problem" width="180" />
<span>Complexity problems</span>
</a>
<a href="/img/latex/latex4.png" rel="lightbox[latex]" title="Example problem 4">
<img src="/img/latex/latex4.png" alt="Stats problem" width="180" />
<span>Statistics problem</span>
</a>
</div>
<p>If I didn’t know how easy it was and the benefits that I get from typesetting my
homework, I’d probably ask as well. However, I’d argue that using LaTeX to type
up homework has made me a far better student than when I used to handwrite my
homeworks.</p>
<p>And that is something that I care a lot about.</p>
<h2 id="the-benefits">The Benefits</h2>
<p>I can summarize the benefits like so:</p>
<ol>
<li>
<p><strong>It can be kept in Source Control.</strong>
Handwriting can’t be stored in a version control system; once you erase
something, it’s gone.</p>
</li>
<li>
<p><strong>You can see your homework materialize in front of you.</strong>
Seeing the results and the equations in their complete LaTeX-glory is a very
powerful way to conceptualize things. There’s just something different about
the way things look so perfect that makes the subject easier to understand.</p>
</li>
<li>
<p><strong>You’ll do better in your classes.</strong> This one goes with the previous point,
but having the ability to see your homework helps you understand it. By
understanding it well, you’ll do better on tests. You will maximize how much
you can learn as well as maximize your grade (if that matters to you).</p>
</li>
<li>
<p><strong>It’s <em>very</em> neat & tidy.</strong>
Although my <a href="http://joshldavis.com/2013/05/20/the-path-to-dijkstras-handwriting/">handwriting has improved</a> quite a bit, I still find
myself slipping back into a rushed, messy script from the past. LaTeX gives
zero doubt that the professor/TA will be able to read my solutions.</p>
</li>
</ol>
<h2 id="about-latex">About LaTeX</h2>
<h3 id="a-very-short-history">A Very Short History</h3>
<p><a href="http://en.wikipedia.org/wiki/Donald_Knuth">Donald Knuth</a>, a legendary Computer Scientist as well as one of my
favorites, is well known for the system that he created called just <a href="http://en.wikipedia.org/wiki/TeX">TeX</a>.</p>
<p>It is a piece of typesetting software that aids in writing documents and
formulas. The power comes from the fact that the document that you write is
plain source code.</p>
<p>The code that you write is then “typeset” into the final document in whatever
form you wish.</p>
<h3 id="example">Example</h3>
<p>Here’s an example of some basic LaTeX code:</p>
<figure class="highlight"><pre><code class="language-tex" data-lang="tex">This gives us:
<span class="p">\[</span><span class="nb">
</span><span class="nv">\begin</span><span class="p">{</span><span class="nb">split</span><span class="p">}</span><span class="nb">
</span><span class="nv">\sum</span><span class="p">_{</span><span class="nb">i </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="p">}^{</span><span class="nb">n</span><span class="p">}</span><span class="nb"> </span><span class="p">{</span><span class="nb">x</span><span class="p">_</span><span class="nb">i </span><span class="o">(</span><span class="nb">Y</span><span class="p">_</span><span class="nb">i </span><span class="o">-</span><span class="nb"> </span><span class="nv">\hat</span><span class="p">{</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">}</span><span class="nb"> x</span><span class="p">_</span><span class="nb">i</span><span class="o">)</span><span class="p">}</span><span class="nb">
</span><span class="p">&</span><span class="o">=</span><span class="nb"> </span><span class="nv">\sum</span><span class="p">_{</span><span class="nb">i </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="p">}^{</span><span class="nb">n</span><span class="p">}</span><span class="nb"> </span><span class="p">{</span><span class="nb">x</span><span class="p">_</span><span class="nb">i Y</span><span class="p">_</span><span class="nb">i</span><span class="p">}</span><span class="nb">
</span><span class="o">-</span><span class="nb"> </span><span class="nv">\sum</span><span class="p">_{</span><span class="nb">i </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="p">}^{</span><span class="nb">n</span><span class="p">}</span><span class="nb"> </span><span class="nv">\hat</span><span class="p">{</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">}</span><span class="nb"> x</span><span class="p">_</span><span class="nb">i</span><span class="p">^</span><span class="m">2</span><span class="nb">
</span><span class="nv">\\</span><span class="nb">
</span><span class="p">&</span><span class="o">=</span><span class="nb"> </span><span class="nv">\sum</span><span class="p">_{</span><span class="nb">i </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="p">}^{</span><span class="nb">n</span><span class="p">}</span><span class="nb"> </span><span class="p">{</span><span class="nb">x</span><span class="p">_</span><span class="nb">i Y</span><span class="p">_</span><span class="nb">i</span><span class="p">}</span><span class="nb">
</span><span class="o">-</span><span class="nb"> </span><span class="nv">\hat</span><span class="p">{</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">}</span><span class="nv">\sum</span><span class="p">_{</span><span class="nb">i </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="p">}^{</span><span class="nb">n</span><span class="p">}</span><span class="nb"> x</span><span class="p">_</span><span class="nb">i</span><span class="p">^</span><span class="m">2</span><span class="nb">
</span><span class="nv">\end</span><span class="p">{</span><span class="nb">split</span><span class="p">}</span><span class="nb">
</span><span class="p">\]</span>
Solving for <span class="p">\(</span><span class="nv">\hat</span><span class="p">{</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">}\)</span> gives the final estimator for <span class="p">\(</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">\)</span>:
<span class="p">\[</span><span class="nb">
</span><span class="nv">\begin</span><span class="p">{</span><span class="nb">split</span><span class="p">}</span><span class="nb">
</span><span class="nv">\hat</span><span class="p">{</span><span class="nv">\beta</span><span class="p">_</span><span class="m">1</span><span class="p">}</span><span class="nb">
</span><span class="p">&</span><span class="o">=</span><span class="nb"> </span><span class="nv">\frac</span><span class="p">{</span><span class="nb">
</span><span class="nv">\sum</span><span class="nb"> </span><span class="p">{</span><span class="nb">x</span><span class="p">_</span><span class="nb">i Y</span><span class="p">_</span><span class="nb">i</span><span class="p">}</span><span class="nb">
</span><span class="p">}{</span><span class="nb">
</span><span class="nv">\sum</span><span class="nb"> x</span><span class="p">_</span><span class="nb">i</span><span class="p">^</span><span class="m">2</span><span class="nb">
</span><span class="p">}</span><span class="nb">
</span><span class="nv">\end</span><span class="p">{</span><span class="nb">split</span><span class="p">}</span><span class="nb">
</span><span class="p">\]</span></code></pre></figure>
<p>With the output looking like below:</p>
<div class="gallery large">
<a href="/img/latex/example.png" rel="lightbox[latex]" title="Example output">
<img src="/img/latex/example.png" alt="Example output" width="480" />
<span>Result of above code</span>
</a>
</div>
<h2 id="using-the-template">Using the Template</h2>
<p>I’ve created a GitHub repository, <a href="https://github.com/jdavis/latex-homework-template">latex-homework-template</a>, just for my
homework template that I’ve been using ever since I started. I found it
<a href="http://www.latextemplates.com/template/programming-coding-assignment">online</a> and used it as a base to start my template.</p>
<p>To use it, just download the <a href="https://github.com/jdavis/latex-homework-template/blob/master/homework.tex">homework.tex</a> file and start
editing. Once you need to typeset it, you’ll need LaTeX <a href="http://latex-project.org/ftp.html">here</a>.</p>
<p>After that, you just need to compile it and you’ll get your output. There are
tons of different resources that I’ve found useful in learning LaTeX:</p>
<ol>
<li>
<p><a href="http://tex.stackexchange.com/">TeX StackExchange</a></p>
</li>
<li>
<p><a href="http://en.wikibooks.org/wiki/LaTeX">LaTeX Wikibook</a></p>
</li>
</ol>
<h2 id="effect-on-performance">Effect on Performance</h2>
<p>I have a solid set of anecdotal evidence in favor of using LaTeX for writing up
my homework.</p>
<p>In all the classes that I’ve used LaTeX, I’ve come out of the class with a very
strong understanding of the material as well as a good grade. Although I’m not a
big fan of grades (like at all), I know it matters to some people.</p>
<p>This might have to do with the fact that doing the homework in LaTeX takes
longer. It might have to do with the fact that I perfect the appearance and
spend a lot more time looking at the subject.</p>
<p>The most likely reason is a combination of all that I previously mentioned plus
other factors. I’m usually one to always want to quantify something, but in this
case, I know it helps; that’s all I need.</p>
<h2 id="learning-curve">Learning Curve</h2>
<p>There definitely is a learning curve when it comes to trying to use LaTeX for
homework. I felt that it was definitely worth the effort unlike how it might
seem to some students.</p>
<p>I reasoned that when I go to graduate school, I will want to use it there. I
also know how pervasive it is in textbooks. Since I love to <a href="https://www.goodreads.com/review/list/6593701?shelf=favorites-textbooks">read
textbooks</a> so much, I wanted to see what it took to write them so
elegantly. I may even want to write one in the future; we’ll have to see =]</p>
<p>To me it seemed like a small tradeoff for the great benefits that it provided.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I cannot recommend using LaTeX for your homework enough.</p>
<p>The benefits go a long way. It helps you learn the material and in a way that
isn’t as easily achieved when just using pencil and paper.</p>
<p>LaTeX is also widely used in academia and learning about the tool is almost
essential if you wish to go to graduate school.</p>
<p>Once I graduate from university, I plan on releasing all my code for the last
three semesters as open source. It includes all my LaTeX code which has really
accumulated over the last year. It should provide a nice resource for others.</p>
<p>In the meantime, hopefully if you start using LaTeX for your homework, you won’t
be able to resist doing it early because of how fun it is. Well, at least it was
fun for me =]</p>
GitHub + University: How College Coding Assignments Should Work2014-01-19T00:00:00+00:00https://joshldavis.com/2014/01/19/github-university-how-college-assignments-should-work<h1 id="github--university-how-college-coding-assignments-should-work">GitHub + University: How College Coding Assignments Should Work</h1>
<h6 id="update-on-june-30-2014">Update on June 30, 2014</h6>
<blockquote>
<p>You can find the follow up post here as well as source code:
<a href="/2014/06/30/github-university-follow-up/">GitHub + Univeristy: A Follow Up</a></p>
</blockquote>
<p>This semester (Spring 2014), I’m a Teaching Assistant (TA) for a course that I
took last semester called “Principles of Programming Languages.” It was a very
enjoyable class and I have always been interested in programming languages. I
felt that being a TA would be a great way to explore the learning process and
subject matter more deeply.</p>
<h2 id="an-idea">An Idea</h2>
<p>Through out my entire college career, all programming assignments have had to be
submitted through <a href="http://www.blackboard.com/">BlackBoard</a>. To be as diplomatic as possible, BlackBoard
does a lot of things to help students & teachers. Unfortunately it does not do a
single one of them well.</p>
<p>The normal way to submit coding assignments is to have homework assigned through
BlackBoard and to have to code up the solutions and then zip them up and submit
them using the web interface.</p>
<h3 id="blackboard-issues">BlackBoard Issues</h3>
<p>There are many different issues with this.</p>
<ol>
<li>
<p>The first and most obvious is that it is tedious for each party (TA & the
student) to zip and extract code.</p>
</li>
<li>
<p>It can’t be automated (painlessly). BlackBoard has a series of iframes that
make it incredibly hard to automate submission or retrieval of homework.</p>
</li>
<li>
<p>Code should not be stored in zip files anymore. Distributing code is a solved
problem by using version control systems.</p>
</li>
</ol>
<h2 id="github-to-the-rescue">GitHub to the Rescue</h2>
<p><a href="http://lorandszakacs.com/">Lorand</a>, one of the other TA’s, and I both came to the conclusion that
using <a href="https://github.com/">GitHub</a> would be an interesting experiment. We were both very
experienced with using Git as well as GitHub so we wanted to brainstorm how we
could get a class of considerable size to do this.</p>
<p>The great part is that GitHub provides plenty of opportunities for students and
teachers to get free access to normally pay-only features though the <a href="https://education.github.com/">GitHub
Education</a> section.</p>
<p>Using this, the professor reached out to GitHub and was able to setup an
Organization with 125 private repositories for free.</p>
<p>After typing up a little README with the course info, a guide to using Git +
GitHub, as well as shamelessly stealing the <a href="http://en.wikipedia.org/wiki/Half-Life_(video_game)">Half-Life</a> logo, we had an
organization that was ready for the semester: <a href="https://github.com/ComS342-ISU">ComS342-ISU</a>.</p>
<h2 id="setting-it-up">Setting It Up</h2>
<p>The first obstacle was that we wanted each student to have a private repository
that would contain all their solutions in individual folders. We wanted the
repositories to be only visible to the student it belonged to as well as the
TA’s and instructor.</p>
<p>I knew that I would never want to individually create 50+ repositories and setup
the correct push/pull access so I turned to <a href="http://developer.github.com/v3/">GitHub’s API</a> +
<a href="http://nodejs.org/">NodeJS</a>.</p>
<h3 id="automating-using-the-api">Automating Using the API</h3>
<p>It only took a few hours but within short time I had a very simple web
application that would allow the student to connect using their GitHub account
through GitHub’s OAuth.</p>
<div class="gallery xlarge">
<a href="/img/cs342/app0.png" rel="lightbox[bad]" title="Step one of the app">
<img src="/img/cs342/app0.png" alt="Signing in on the app" height="250" />
<span>Signing in with GitHub</span>
</a>
<a href="/img/cs342/app1.png" rel="lightbox[bad]" title="Step two of the app">
<img src="/img/cs342/app1.png" alt="Joining the class" height="250" />
<span>Joining the Class</span>
</a>
<a href="/img/cs342/app2.png" rel="lightbox[bad]" title="Step three of the app">
<img src="/img/cs342/app2.png" alt="Enrolling" height="250" />
<span>Successfully enrolling</span>
</a>
</div>
<p>The application would then ask for their University login, check that they are
actually registered for the class, and then automagically create a new private
repository for them in the form <code class="language-plaintext highlighter-rouge">hw-answers-<id></code> and add them to the Students
team.</p>
<p>In addition to the creating of the repositories, I also made a script to check
to see what students aren’t in the class that are currently registered and to
automatically remind them that they need to register as soon as possible.</p>
<h3 id="source-code">Source Code</h3>
<p>After the class is finished, I’ll make the code to this little bot available on
my <a href="https://github.com/jdavis">GitHub</a>.</p>
<h3 id="how-we-are-using-the-repos">How We Are Using the Repos</h3>
<p>We have a few different repositories that we are using. The first repo is the
only public one and it is the <a href="https://github.com/ComS342-ISU/course-info">course-info</a> repo. It contains the
syllabus information as well as some basic guides to help the students set
everything up.</p>
<p>The second repository is private but available for all the students to see. This
is where we will release homeworks and publish solutions as they become
available. This is also the repository that students are encouraged to discuss
within the repositories Issue Tracker. This is replacing the discussion boards
of the past.</p>
<p>The bulk of our repository usage (roughly 50) is each student’s repository to
contain their answer sheets. These are essentially manual <a href="https://help.github.com/articles/fork-a-repo">Forks</a> of the
main homework repository from the previous paragraph. The students are
responsible for <a href="https://help.github.com/articles/syncing-a-fork">syncing</a> their repositories with the official homework
repository to bring in new homeworks as they are released.</p>
<p>There are a few other repositories like one for the code that I’ve created for
the course and the grading infrastructure the other TA has created. We also have
an internal homework repository that we use to organize all the future homeworks
and to collaborate.</p>
<h2 id="grading--feedback">Grading & Feedback</h2>
<p>The best part about using GitHub for homework submissions is that it is
incredibly easy to give feedback and help the students through learning the
material.</p>
<p>In the past, most feedback/grading is provided back to the student in a little
.txt file that contains a few comments and the final grade.</p>
<p>With GitHub, we can comment on specific commits, specific lines of code, and see
how the student progressed through the homework.</p>
<p>It is far more valuable to the student for this kind of interaction. Without
using GitHub, it would be a lot more difficult because of the time it would
require to do this.</p>
<p>When it comes to grading, all of our homeworks come with a suite of unit tests
that test nearly every part of the homework. The students can get immediate
feedback on how well they are doing.</p>
<p>This also makes it incredibly easy to grade. The other TA has created a bot
written in Scala that grabs all of the homework repositories and runs the set of
unit tests. The results are then written to a text file and pushed back to the
repository.</p>
<p>We the TAs then can see the final status of their tests and then spend the rest
of the time looking at the code to see why any of the tests failed and how they
can improve their code.</p>
<p>This cuts out so much time that would be spent downloading zip files, extracting
them, manually running the tests and so on.</p>
<h2 id="ways-to-improve">Ways to Improve</h2>
<p>So far only a week has passed since the semester started so there are a lot of
unforeseen things that might happen. I’m sure I will think of other ways to
improve this little system but there are a few major ones that I can see right
now:</p>
<ol>
<li>
<p>Continuous integration would be nice. Like I mentioned, we have to instruct
the bot to grab the homeworks and test them. It would be great to use
something like <a href="https://travis-ci.org/">TravisCI</a> to test every commit as it is pushed.</p>
<p>The problem is that the homeworks need to be private but TravisCI is only
free for open source projects. It would be great if TravisCI provided an
Educational discount like GitHub.</p>
</li>
<li>
<p>A more formal submission process. Right now we are saying that the code just
needs to be pushed by the homework deadline. There is nothing that needs to
be done to actually “submit” their homework.</p>
<p>There are a few issues with this because if a student forges a commit time
stamp, they can set the date a to be before the deadline and still push the
code.</p>
<p>We are looking into ways to counter this in the short term. The first that
comes to my mind is to just run a bot shortly after the deadline to grab the
SHA-1 HEAD of the master branch and its parent commits for every student’s
repository. This would ensure that any tampering with the git log would be
noticeable and change the SHA-1s.</p>
</li>
</ol>
<h2 id="going-forward">Going Forward</h2>
<p>Once the semester is finished, I will revisit the topic to see how things turned
out. I really hope that things go well \^_\^.</p>
The Differences Between Imperative and Functional Programming. Part 1.2013-09-30T00:00:00+00:00https://joshldavis.com/2013/09/30/difference-between-imperative-and-functional-part-1<h1 id="the-differences-between-imperative-and-functional-programming-part-1">The Differences Between Imperative and Functional Programming. Part 1.</h1>
<p>This semester I’m taking a class called “Principles of Programming Languages.”
It is the class in at my university where people are first exposed to functional
programming (assuming they don’t have prior experience).</p>
<p>So far I am really enjoying it. The professor is really engaging and his
lectures are really interesting. We are using three books:</p>
<ol>
<li><a href="http://www.eopl3.com/">Essentials of Programming Languages</a></li>
<li>The classic: <a href="http://www.ccs.neu.edu/home/matthias/BTLS/">The Little Schemer</a></li>
<li>And even more of a classic: <a href="http://mitpress.mit.edu/sicp/">Structure and Interpretation of Computer
Programs</a></li>
</ol>
<p>I am having a lot of fun <em>finally</em> reading The Little Schemer. It has been on my
to-read list for awhile now. I’m also really enjoying reading SICP again. Back
in high school, I read the first few chapters while watching the
<a href="http://www.youtube.com/watch?v=2Op3QLzMgSY">lectures</a> given back in 1986.</p>
<p>Reading through it now, I’ve realized that a lot of it went over my head when I
was younger. I think I have a better appreciation for it now however.</p>
<p>Since this class uses a functional programming language, I have been programming
a lot in <a href="http://racket-lang.org/">Racket</a> lately. It has been a really eye opening experience.
I’ve written some <a href="http://en.wikipedia.org/wiki/Scheme_(programming_language)">Scheme</a> (Racket is a dialect of Scheme) in high
school and am quite use to closures/first class functions from JavaScript, but
not to the Racket extreme.</p>
<p>I wanted to learn a bit about what the differences between imperative languages
and functional languages are so I figured I’d write up what I learned. Let’s dig
in.</p>
<h2 id="programming-paradigms">Programming Paradigms</h2>
<p>A programming paradigm is a way of thinking and seeing the world when it comes
to programming. It borrows the Thomas Kuhn definition of paradigm and just
applies it to the practice of programming.</p>
<p>The four main programming paradigms (according to Wikipedia) are: imperative,
functional, object-oriented, and logic. Although object-oriented is pretty self
explanatory, I won’t go into it nor will I discuss logic programming.</p>
<h2 id="imperative-programming">Imperative Programming</h2>
<p>Imperative programming is the most dominant paradigm of all the others. It is
used in Assembly, Java, C, Python, Ruby, JavaScript, and many others. (Note:
Some programming languages have multiple paradigms)</p>
<p>It is characteristic of a sequence of steps/instructions that happen in order.
Common constructs to manipulate the flow of these instructions include <code class="language-plaintext highlighter-rouge">while</code>
statements, <code class="language-plaintext highlighter-rouge">for</code> loops, functions, and even the <a href="http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF">dreaded goto (pdf)</a>.</p>
<p>Since it is the most dominant programming paradigm, it’s what most people are
familiar with. Thus if you are anything like me, it just seems like the
“natural” way to program.</p>
<p>Since imperative programming is a list of steps that need to be executed, there
needs to be some way of keeping track of everything computed to that point.
That’s (obviously) where variables come in. They are keeping the “state” of
where the program is at which then can control where the program should go to
next which continues to modify the state.</p>
<p>This sequence of state changes is often called a <a href="http://en.wikipedia.org/wiki/Side_effect_(computer_science)">side effect</a>. The
reason it is called a side effect is because it has the potential to modify
the state, thus changing the flow of the program.</p>
<h2 id="functional-programming">Functional Programming</h2>
<p>Functional programming is used in languages like Lisp, Haskell, and Scala.</p>
<p>The main difference between imperative and functional languages is that
functions that are evaluated are the main way of gaining and transforming data,
functional programming is stateless. Rather than assigning values which can then
be mutated like what happens in imperative languages, the value returned by a
function is only dependent on its input.</p>
<p>The lack of state allows a functional language to be reasoned just by looking at
a function’s input and output.</p>
<p>Instead of <code class="language-plaintext highlighter-rouge">for</code> and <code class="language-plaintext highlighter-rouge">while</code> loops, <a href="http://en.wikipedia.org/wiki/Recursion_(computer_science)">recursion</a> is used instead. Most
people are exposed to recursion in imperative languages, but functional
languages can have special support for recursion (such as <a href="http://en.wikipedia.org/wiki/Tail_call">tail call</a>).
Recursion is just the idea of one’s own definition to define itself. It may seem
counterintuitive, but it actually is more prevalent than you might expect.</p>
<h2 id="coming-soon">Coming Soon…</h2>
<p>Now that you at least know the definitions of imperative and functional
programming, be watching for the second part to this article. It’ll include
pros and cons and examples of each to illustrate the difference.</p>
<p>When I finish it, I’ll link it here.</p>
Never Save Anything for the Swim Back. Ever.2013-08-31T00:00:00+00:00https://joshldavis.com/2013/08/31/never-save-anything-for-the-swim-back<h1 id="never-save-anything-for-the-swim-back-ever">Never Save Anything for the Swim Back. Ever.</h1>
<p>I put the quote “I never save anything for the swim back” everywhere. I have it
on almost every profile that I have on the internet. Some of you might have
heard it before but I’m finally going to explain where I got it from and why it
means so much to me.</p>
<h2 id="the-movie">The Movie</h2>
<p><a href="http://en.wikipedia.org/wiki/Gattaca">Gattaca</a> is a science fiction movie that came out in 1997. Although I
was 7 the year it was released, I didn’t watch it until ~10 years later when I
was in high school.</p>
<p>This post won’t spoil any of the plot. Almost everything that I say happens very
early on in the film. However, if you haven’t seen it, I really, <em>really</em>
suggest that you do so. It has been the single most influential thing that I
have experienced.</p>
<h3 id="the-plot">The Plot</h3>
<p><em>Gattaca</em> takes place in the future where genetics is completely understood and
rocket launches take place daily. Instead of discrimination based on social
status or the color of one’s skin, discrimination is based on genes. Those with
superior genes rule the world and get all the opportunities.</p>
<p>The main character, Vincent Freeman, is born the natural way to us but unnatural
to them. This isn’t common practice because of how advanced genetics has become.
Instead, parents select the best possible child of any desired gender based on
the genes of the parents.</p>
<p>Gone are the days of poor eyesight, baldness, mental problems, birth defects,
and anything else that doesn’t give the child the “best possible chance.” After
all, according to one of the doctor’s in the film, “humans have enough
imperfection built in.”</p>
<p>Vincent grows up in this near perfect world with an inferior set of genes. His
brother, Anton Freeman, unlike Vincent, was selected genetically. He overshadows
Vincent’s achievements in every way and their parents are always very proud of
Anton.</p>
<p>Vincent struggles to find jobs because of his inferior genes. His hopes and
dreams of becoming an astronaut can never be attained because of his low
intelligence and genetic heart condition.</p>
<h3 id="growing-up">Growing Up</h3>
<p>Vincent and Anton liked to compete in a swimming challenge. The two would start
swimming out to the ocean and keep going until the other one gave up. Although
Vincent was older than Anton, Vincent always lost.</p>
<p>When Vincent became old enough to live on his own, he realized that there wasn’t
much of a reason to stick around. Before he left he competed in their old swim
challenge one last time. This time things were different as Vincent describes:</p>
<blockquote>
<p>It was the last time we swam together and out into the open sea. Like always,
we knew each stroke to the horizon was one we’d have to make back to the
shore.</p>
<p>But something was very different about that day. Every time Anton tried to
pull away, he found me right beside him. Until finally, the impossible
happened.</p>
<p>It was the one moment in our lives that my brother was not as strong as he
believed I was not as weak. It was the moment that made everything else
possible.</p>
</blockquote>
<h2 id="the-quote">The Quote</h2>
<p>Near the end of the movie, Vincent is asked how he has done all that he has. His
answer is simple but profound:</p>
<blockquote>
<p>You want to know how I did it? This is how I did it: <strong>I never saved anything
for the swim back.</strong></p>
</blockquote>
<p>Vincent had hopes and dreams. He knew that if he wanted to achieve them, he
wasn’t going to be able to do it without giving it his all. Vincent knew that
the risk of giving everything meant that he might possibly fail and drown. When
something mattered to Vincent, he knew that hard work was the only thing that
separated him from everyone else. Intelligence, genetics, talent, were all
secondary to hard work and practice for Vincent.</p>
<h2 id="personal-significance">Personal Significance</h2>
<p>I watched <em>Gattaca</em> for the first time sometime during high school. At the time
I was struggling a lot with what the purpose of my life was and what I wanted to
do when I graduated high school. I was also struggling a lot with feeling
inferior to others intellectually.</p>
<p>I would read about someone’s achievements on the internet and compare them to my
own. I was just growing up in a small little town in Iowa. How could I ever
compete?</p>
<p>When I saw <em>Gattaca</em>, I realized that none of that mattered. It didn’t matter
what my purpose in life was. It didn’t matter how smart I was. All that mattered
was that I follow my heart and dreams and <strong>never save anything for the swim back.</strong></p>
<p>I have watched <em>Gattaca</em> every summer before school starts and many times in
between. It always reminds me of what my true aspirations are and what I stand
for: I have a dream and I’ll never give up in achieving it.</p>
My Favorite Elon Musk Quote2013-08-11T00:00:00+00:00https://joshldavis.com/2013/08/11/my-favorite-elon-musk-quote<h1 id="my-favorite-elon-musk-quote">My Favorite Elon Musk Quote</h1>
<p>Recently I’ve been going on an <a href="http://en.wikipedia.org/wiki/Elon_Musk">Elon Musk</a> video watching spree as you can see by
my <a href="http://www.youtube.com/playlist?list=PLa4Rb2NzNbLV6nyxCaY52Xi6CVHFMmD75">recent playlist</a> on YouTube.</p>
<p>Elon Musk, without a doubt, is the man I look up to most at the moment. With the
exception of <a href="http://en.wikipedia.org/wiki/Steve_Wozniak">Steve Wozniak</a>, most of the other people that I really admire
have all passed away. This includes people like <a href="http://en.wikipedia.org/wiki/Richard_Feynman">Richard Feynman</a>, <a href="http://en.wikipedia.org/wiki/Carl_Sagan">Carl Sagan</a>,
<a href="http://en.wikipedia.org/wiki/Benjamin_Franklin">Benjamin Franklin</a>, and <a href="http://en.wikipedia.org/wiki/Steve_Jobs">Steve Jobs</a>.</p>
<p>One of the <a href="http://youtu.be/1sumVEEAZ_w">interview videos</a> that I watched recently was a clip of Elon
at the 2013 SXSW. He was asked the following question:</p>
<blockquote>
<p>What’s the biggest mistake you’ve ever made and how did you move
forward? Looking back, was it really that big of a deal?</p>
</blockquote>
<p>I’ve linked to the point in the interview that it happens. If you have the time,
I’d definitely recommend watching the whole thing. It’s an excellent interview,
like always.</p>
<div class="gallery medium">
<iframe width="560" height="315" src="//www.youtube.com/embed/EORFe_zbZO8?rel=0&start=3131&end=&autoplay=0" frameborder="0" allowfullscreen=""></iframe>
</div>
<p>I figured he would mention something about building a business or possibly a
financial situation, but he didn’t. It was actually straight from Elon’s heart
which is why I really enjoyed it.</p>
<p>It took him awhile to come up with an answer for it but here is what he
answered:</p>
<blockquote>
<p>The biggest mistake, in general, that I’ve made and I’m trying to correct for
that is to put too much of a weighting on somebody’s talent and not enough on
their personality… It actually matters whether someone has a good heart, it
really does. I’ve made the mistake of thinking sometimes it’s just about the
brain.</p>
</blockquote>
<p>The reason why I love this quote so much is that it completely embodies the way
I approach the world. I have always argued that if one cares enough and works
hard enough, they will <strong>always</strong> outperform someone that somewhat cares and is
only riding on their natural ability.</p>
<p>This whole idea, I think, is best shown in the movie <a href="http://en.wikipedia.org/wiki/Gattaca">Gattaca</a>. It is
without a doubt my favorite movie. If you haven’t Googled it by now, my favorite
tag line: “I never save anything for the swim back” is from Gattaca.</p>
<p>The next post that I will write in the next week or so will talk about why I
love Gattaca so much. It is a long overdue post but I think it’ll be a good one.
Stay tuned.</p>
C: A Minute to Learn... A Lifetime to Master2013-07-24T00:00:00+00:00https://joshldavis.com/2013/07/24/c-a-minute-to-learn-a-lifetime-to-master<h1 id="c-a-minute-to-learn-a-lifetime-to-master">C: A Minute to Learn… A Lifetime to Master</h1>
<p>Last weekend I picked up the book <a href="http://amzn.to/28WuEEA">Expert C Programming: Deep C Secrets</a>
from a <a href="http://seattletechnicalbooks.com/">local bookstore</a> here in Seattle. The <a href="http://en.wikipedia.org/wiki/C_(programming_language)">C Programming language</a>
has arguably been the most influential programming language that I have learned.
It was the first language that I grew to love and <em>Expert C Programming</em>
inspired me to write up this short post chronicling my journey learning C, some
resources that I find valuable, as well as various other things.</p>
<h2 id="kr-know-your-roots">K&R: Know Your Roots</h2>
<p>I read the famous <a href="http://en.wikipedia.org/wiki/The_C_Programming_Language">K&R</a> book back in high school during a blissful week at
the beginning of spring one year. I fell in love with the C programming
language. My views match up pretty well with what most of the community
already knows: it is one of the most beautifully written introductions to a
programming language ever. The most striking part is that the first edition it
came in at only 228 pages.</p>
<h3 id="trivia-tidbits">Trivia Tidbits</h3>
<ul>
<li>The K&R book popularized the standard of having one’s <a href="http://en.wikipedia.org/wiki/Hello_world">first program</a>
write “Hello, world.</li>
<li>The K&R book also popularized its <a href="http://en.wikipedia.org/wiki/Indent_style#K.26R_style">own brace style</a>, which then influenced the
<a href="http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS">brace style</a> used in the Unix and Linux kernels.</li>
</ul>
<h3 id="what-made-it-so-great">What Made it so Great?</h3>
<p>Considering I read it so long ago, it’s hard for me to determine why it made
such an impact on me. It might possibly have been the succinctness of it. Being
able to learn a language after reading ~200 pages allows one to program more
which was how I learned the best back in high school.</p>
<p>I also think a big part of it had to do with the examples in the book. Some of
the examples included converting an <code class="language-plaintext highlighter-rouge">int</code> to a binary/hexadecimal string,
writing a function that takes in strings of numbers written in scientific
notation and returning a float. My personal favorite was one of the exercises
from the first chapter:</p>
<blockquote>
<p>Write a program to check a C program for rudimentary syntax errors like
unbalanced parentheses, brackets and braces. Don’t forget about quotes, both
single and double, escape sequences, and comments.</p>
</blockquote>
<p>A full list of the exercises by chapter (as well as the solutions) can be found
on the <a href="http://clc-wiki.net/wiki/K%26R2_solutions">clc-wiki</a>. If you actually want to try and solve them, don’t cheat
and look at the solutions!</p>
<h2 id="dive-deep">Dive Deep</h2>
<p>Now back to the book that inspired me to write this post. <em>Expert C Programming</em>
covered some of the less well-defined parts of C.</p>
<h3 id="declarations">Declarations</h3>
<p>It had a chapter just on C declarations and how to read them. If you spend any
amount of time programming C at all, you’ve more than likely come to realize
that sometimes determining what a variable is defined as is quite a difficulty.</p>
<p>The book has a short set of rules to follow to decipher a declaration yourself.
It also provides a small little program that will do the deciphering for you. If
you put in a declaration, it will output the English equivalent.</p>
<p>One of the best resources out there appears to be this <a href="http://cdecl.org/">online C declaration to
English parser</a> that will do the work for you. However, if you want to be
able to do this without relying on a website, definitely check out <a href="http://unixwiz.net/techtips/reading-cdecl.html">this
guide</a>.</p>
<h3 id="arrays-vs-pointers">Arrays vs Pointers</h3>
<p>Often a person will think that a pointer and an array are the same thing because
of the following:</p>
<figure class="highlight"><pre><code class="language-c" data-lang="c"><span class="kt">int</span> <span class="n">a</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">};</span>
<span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">;</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Equal</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>Running the above in a <code class="language-plaintext highlighter-rouge">main</code> function will print out <code class="language-plaintext highlighter-rouge">Equal</code> and stop. The
chapter goes more in depth on why they aren’t the same with more examples.</p>
<p>The general idea is that <code class="language-plaintext highlighter-rouge">a</code> actually holds the data while <code class="language-plaintext highlighter-rouge">p</code> is holding the
<em>location</em> of where <code class="language-plaintext highlighter-rouge">a</code> is at. This means that <code class="language-plaintext highlighter-rouge">p[2]</code> can’t just access it at
once, it must dereference the pointer to find out where <code class="language-plaintext highlighter-rouge">a</code> is stored, then
calculate the offset. While <code class="language-plaintext highlighter-rouge">a[2]</code> can calculate the offset immediately.</p>
<h3 id="history-lesson">History Lesson</h3>
<p>The book also has a ton of little stories about certain parts of the C language.
For example it discusses how C came to have so many different ways to increment
an integer. The <code class="language-plaintext highlighter-rouge">i++</code> and <code class="language-plaintext highlighter-rouge">++i</code> came about because it was a single machine
instruction for the PDP-11.</p>
<p>That’s just one example but the book was written in 1994 so it is packed with
other little history facts that make it really interesting.</p>
<h3 id="i-guess-im-an-expert-now">I Guess I’m an Expert Now</h3>
<p>There are 11 chapters all together and each one looks at a crucial aspect of C
that might be a bit fuzzy. I definitely recommend checking it out if you like C.
I think it also would make a great reference book for when you get stuck on a
certain feature, say like declarations or pointers.</p>
<h2 id="learning-by-doing">Learning by Doing</h2>
<p>It certainly goes without saying that writing a lot of code will help you to
learn the language. I certainly did this with C when I was learning it.</p>
<p>In addition to most of the exercises in K&R, I also did a lot of the <a href="http://projecteuler.net/">Project
Euler</a> problems in C. Project Euler is just a list of problems that
intersect math and programming. Most often the problems can be solved using
brute force, but designing a better algorithm or understanding the problem more
usually can lead to a better solution.</p>
<p>My favorite part about Project Euler is that the only thing that it is very easy
to check if you are right or wrong. All the problems have a single number as the
result. Take the first problem for example:</p>
<blockquote>
<p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we
get 3, 5, 6 and 9. The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below 1000.</p>
</blockquote>
<p>The end result is just the sum; it doesn’t matter how long it took to calculate
or what language you use. This makes it easy to experiment and work on solving
it first before optimizing a solution.</p>
<p>A <a href="https://github.com/thekarangoel/Projects">repository</a> that I came across recently has been <a href="https://github.com/explore">trending on
GitHub</a> for the last few days. The list of projects originally came
from <a href="http://www.dreamincode.net/forums/topic/78802-martyr2s-mega-project-ideas-list/">Martyr2 on dream-in-code</a>, but it is a repository of a guy that is
trying to implement most of the list in Python.</p>
<h2 id="learning-by-reading">Learning by Reading</h2>
<p>There’s a certain point where you can only learn so much from writing code. One
of the best ways to pick up new programming habits or techniques is best
achieved by reading other people’s code.</p>
<p>C is so ancient that there are a ton of projects out there that you can use to
read. Here are a few of my favorites:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs">Plan 9</a> <a href="http://plan9.bell-labs.com/sources/plan9/sys/src/">source code</a>. Plan 9 is an OS that was developed
back in the early 90s. It uses a dialect of ANSI C so it shouldn’t be too
foreign.</li>
<li><a href="http://g.oswego.edu/dl/html/malloc.html">dlmalloc</a>. <code class="language-plaintext highlighter-rouge">dlmalloc</code> stands for “Doug Lea malloc” and is a
reimplementation of <code class="language-plaintext highlighter-rouge">malloc</code>. It has a few benefits as well as a few
shortcomings.</li>
</ul>
<h2 id="conclusion">Conclusion</h2>
<p>Like the title says, the C programming language can be really simple to learn at
first. Yet like <a href="https://en.wikipedia.org/wiki/Reversi">Reversi</a>, the flexibility of the language allows for
complexity to manifest itself. Mastering the language can take a very long time.</p>
<p>Since the language is so low level, it is very tightly dependent on the
implementation and hardware it is running on. Although the C standards are
supposed to limit these edge cases, they still exist.</p>
<p>I just read <a href="http://prog21.dadgum.com/179.html">an article</a> earlier today about what happens when
<code class="language-plaintext highlighter-rouge">malloc(0)</code> is called. As it turns out, it depends on the system what
<code class="language-plaintext highlighter-rouge">malloc(0)</code> will return.</p>
<p>C might seem quite scary considering it has been out for so long yet people
still have a ton of issues with it. I don’t see it that way though.</p>
<p>Instead C is much like the game of chess, except the other player is the
computer. The more you master C the better you will get at countering the
computer and bending it to your will. It now becomes a game of mathematical
precision and a direct test of your knowledge of C and the computer.</p>
<p>It’s certainly more magical and beautiful this way.</p>
Where Do I Sign Up to Change the World?2013-07-17T00:00:00+00:00https://joshldavis.com/2013/07/17/where-do-i-sign-up-to-change-the-world<h1 id="where-do-i-sign-up-to-change-the-world">Where Do I Sign Up to Change the World?</h1>
<p>The title of this post was inspired by an idea that came to my head in the last
month or so about my future. I will be graduating from university in this
upcoming May of next year after taking 3 semesters off because of
internships/co-ops. I’m at the point where I need to start to make decisions
about my future.</p>
<p>The only thing that I’m certain of at this point is that I want to leave this
world having made it a better place than when I came into it.</p>
<p>You might think that it sounds incredibly cheesy, but I agree. Though the thing that
I’ve come to realize over the last year was described the best by
<a href="http://www.google.com">Google’s</a> current CEO, <a href="http://en.wikipedia.org/wiki/Larry_Page">Larry Page</a>, during this year’s Google
IO. Here’s the clip:</p>
<div class="gallery medium">
<iframe width="640" height="360" src="http://www.youtube.com/embed/h4CFhT4Mrcg?rel=0&start=432&end=&autoplay=0" frameborder="0" allowfullscreen=""></iframe>
</div>
<p>I cut out the quote just in case you don’t want to watch the video:</p>
<blockquote>
<p>Despite the faster change we have in the industry. We are still moving slow
relative to the opportunities that we have. And some of that, I think, is due
to the <strong>negativity</strong> … We should be building great things that don’t exist,
right?</p>
</blockquote>
<p>Although he’s just talking about the media and its negativism, I can’t help but
feel the same sentiment. I would much rather be hopelessly optimistic than
cynically pessimistic.</p>
<h2 id="so-where-do-i-sign-up">So, where do I sign up?</h2>
<p>I’ve come across another quote that is just a question that perfectly sums up
how I am feeling as I wonder about what I want to do after I graduate. This time
the quote is from <a href="http://en.wikipedia.org/wiki/Elon_Musk">Elon Musk</a>.</p>
<p>If you don’t know who Elon Musk is, you need to find out now. Go to
<a href="http://www.youtube.com">YouTube</a> and find some of his interviews. I’ve said it before, but I have a
feeling that a hundred years from now, he will be considered a modern prophet.</p>
<p>The quote is from his <a href="http://www.ted.com/talks/elon_musk_the_mind_behind_tesla_spacex_solarcity.html">TED Talk</a> that he gave. He was asked what caused him
to start an all-electric car company. Here’s what he said:</p>
<blockquote>
<p>Well, it goes back to when I was in university. I thought about, what are the
problems that are most likely to affect the future of the world or the future
of humanity?</p>
</blockquote>
<p>This was really profound when I heard him say this. I think it’s really rare to
hear about a person that starts a business to change the world. I feel that too
often we hear about people starting a business to make money, or to gain fame,
or to gain power. While it certainly isn’t true for all businesses, I feel that
it is true for more than what it should be.</p>
<h2 id="conclusion">Conclusion</h2>
<p>As I come upon these major life decisions in the next six months, I can only
try my best to keep these two things in mind:</p>
<ol>
<li><strong>I want to build things that don’t exist.</strong></li>
<li><strong>I want to work on problems that are most likely to affect the future of the
world and humanity.</strong></li>
</ol>
<p>I still don’t know yet where I need to go to sign up on this list. All I know is
that I’m searching for it. I’m just being hopelessly optimistic that my
preparation and an opportunity will come along to make some luck.</p>
Verification is Often Easier than Creation2013-07-07T00:00:00+00:00https://joshldavis.com/2013/07/07/verification-is-often-easier-than-creation<h1 id="verification-is-often-easier-than-creation">Verification is Often Easier than Creation</h1>
<p>This past Spring semester (Spring 2013), I took the best Computer Science class
(at least so far) that I’ve taken at University. The class was called “Theory of
Computing” and was taught by <a href="http://theory.stanford.edu/~tingz/index.html-">Ting Zhang</a>.</p>
<p>The textbook that we used was the classic Michael Sipser book, <a href="http://amzn.com/113318779X">Introduction to
the Theory of Computation</a>. I ended up absolutely loving the class so I
asked my professor for a recommendation for further reading on the subject. He
recommended <a href="http://amzn.com/0521424267">Computational Complexity: A Modern Approach</a> by Sanjeev
Arora and Boaz Barak. I’ve finally found a chance to dig into it this summer and
I came across a quote that struck me because it was a notion that I hadn’t given
much thought to.</p>
<p>Here’s the quote (emphasis mine):</p>
<blockquote>
<p>… the P versus NP question captures a widespread phenomenon of some
philosophical importance (and a source of great frustration): <strong>recognizing the
correctness of an answer is often much easier than coming up with the
answer</strong>. Appreciating a Beethoven sonata is far easier than composing the
sonata; verifying the solidity of a design for a suspension bridge is easier
(to a civil engineer anyway!) than coming up with a good design; verifying the
proof of a theorem is easier than coming up with a proof itself (a fact
referred to in Godel’s letter quoted at the start of the chapter), and so
forth.</p>
</blockquote>
<p>The idea that struck me was that the implications of the <code class="language-plaintext highlighter-rouge">P</code> vs <code class="language-plaintext highlighter-rouge">NP</code> problem
goes beyond mathematics into fields such as art and engineering.</p>
<p>There’s no way I could even count the number of times I’ve seen a great user
interface that works intuitively and well (verification) and have struggled to
design something for a similar project that I’m working on (creation).</p>
<p>It’s very easy to be using a service such as Google Maps, buying something
off of Amazon, or even just looking at my Twitter feed and seeing and verifying
that it works well but not being able to fathom how much time it took to create
such a service.</p>
<p>In a way, it is a very strong reminder that some great things take time. There’s
no way to fake that. While it is possible to create great things in a short
amount of time, some things might <strong>only</strong> take hard work and persistence.</p>
Program to an Interface, Fool2013-07-01T00:00:00+00:00https://joshldavis.com/2013/07/01/program-to-an-interface-fool<h1 id="program-to-an-interface-fool">Program to an Interface, Fool</h1>
<p>If you’ve read my post about how <a href="http://joshldavis.com/2013/06/16/the-rise-of-the-gang-of-four-with-rust/">the object-oriented paradigm is being
changed</a> by languages such as <a href="http://www.rust-lang.org/">Rust</a> and <a href="http://golang.org/">Go</a>, and if you’ve
seen my project of <a href="https://github.com/jdavis/rust-design-patterns">Rust Design Patterns</a>, then you’ve probably realized
that I’ve taken quite a liking to Rust.</p>
<p>In addition to this, over this past weekend, I finished reading the classic
<a href="http://amzn.to/28RLKFI">Design Patterns: Elements of Reusable Object-Oriented Software</a>. All of
this has caused me to think quite a bit about one of the core principles in the
book:</p>
<blockquote>
<p>Program to an ‘interface’, not an ‘implementation’.</p>
</blockquote>
<h2 id="what-does-it-mean">What does it mean?</h2>
<p>First you need to understand what interface and implementation mean. To put it
shortly, an <em>interface</em> is just what we call a set of methods that an object
responds to.</p>
<p>An <em>implementation</em> is where the code and logic for the interface resides.</p>
<p>In essence, the principle is advocating that when we write a function, or
method, that we choose to reference an interface instead of something more
concrete like a class.</p>
<h2 id="programming-to-an-implementation">Programming to an Implementation</h2>
<p>First let’s look at what happens when you don’t follow this principle.</p>
<p>Imagine you are Guy Montag from the book, <a href="http://en.wikipedia.org/wiki/Fahrenheit_451">Fahrenheit 451</a> (F451 from here
on out). As everyone knows, books in F451 are forbidden. It’s the job of
firefighters to set them on fire whenever they come across them. Therefore
thinking in terms of OOP, a book has a method called <code class="language-plaintext highlighter-rouge">burn()</code>.</p>
<p>Books aren’t the only things that can burn. If we have another object say a Log
of wood, it also has a method called <code class="language-plaintext highlighter-rouge">burn()</code>. So let’s write this code in Rust
to see how it turns out without “programming to an ‘interface’”:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">struct</span> <span class="n">Book</span> <span class="p">{</span>
<span class="n">title</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="n">author</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Log</span> <span class="p">{</span>
<span class="n">wood_type</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="p">}</span></code></pre></figure>
<p>So this pretty straight forward. We just create two different structs to
represent a Book and a Log. Now let’s implement the methods for our structs:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">impl</span> <span class="n">Log</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">burn</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="nd">fmt!</span><span class="p">(</span><span class="s">"The %s log is burning!"</span><span class="p">,</span> <span class="k">self</span><span class="py">.wood_type</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Book</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">burn</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="nd">fmt!</span><span class="p">(</span><span class="s">"The book %s by %s is burning!"</span><span class="p">,</span> <span class="k">self</span><span class="py">.title</span><span class="p">,</span> <span class="k">self</span><span class="py">.author</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></figure>
<p>Now that a <code class="language-plaintext highlighter-rouge">Log</code> and a <code class="language-plaintext highlighter-rouge">Book</code> both have <code class="language-plaintext highlighter-rouge">burn()</code> methods, let’s set them on
fire.</p>
<p>First let’s set the log on fire:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">fn</span> <span class="nf">start_fire</span><span class="p">(</span><span class="n">lg</span><span class="p">:</span> <span class="n">Log</span><span class="p">)</span> <span class="p">{</span>
<span class="n">lg</span><span class="nf">.burn</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
<span class="k">let</span> <span class="n">lg</span> <span class="o">=</span> <span class="n">Log</span> <span class="p">{</span>
<span class="n">wood_type</span><span class="p">:</span> <span class="o">~</span><span class="s">"Oak"</span><span class="p">,</span>
<span class="p">};</span>
<span class="c">// Burn the oak log!</span>
<span class="nf">start_fire</span><span class="p">(</span><span class="n">lg</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>Everything works great and we get the output “The Oak log is burning!”.</p>
<p>Now since we’ve already written the <code class="language-plaintext highlighter-rouge">start_fire</code> function, can we pass in a book
as well since they both have <code class="language-plaintext highlighter-rouge">burn()</code> methods? Let’s try:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
<span class="k">let</span> <span class="n">book</span> <span class="o">=</span> <span class="n">Book</span> <span class="p">{</span>
<span class="n">title</span><span class="p">:</span> <span class="o">~</span><span class="s">"The Brothers Karamazov"</span><span class="p">,</span>
<span class="n">author</span><span class="p">:</span> <span class="o">~</span><span class="s">"Fyodor Dostoevsky"</span><span class="p">,</span>
<span class="p">};</span>
<span class="c">// Let's try to burn the book...</span>
<span class="nf">start_fire</span><span class="p">(</span><span class="n">book</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>Does it work? <strong>Nope.</strong> Instead we get the error:</p>
<blockquote>
<p>mismatched types: expected <code class="language-plaintext highlighter-rouge">Log</code> but found <code class="language-plaintext highlighter-rouge">Book</code> (expected struct Log but
found struct Book)</p>
</blockquote>
<p>Which completely makes sense, because we wrote our function to expect a <code class="language-plaintext highlighter-rouge">Log</code>
struct but we passed it a <code class="language-plaintext highlighter-rouge">Book</code> struct. How can we fix this? Well we can write
the function again but this time take in a <code class="language-plaintext highlighter-rouge">Book</code> struct as an argument. That
isn’t a good solution at all, however. We now have the exact same function in
two places and if one changes, we need to manually change the other.</p>
<p>Let’s take a look at how “programming to an ‘interface’” can fix this.</p>
<h2 id="programming-to-an-interface">Programming to an Interface</h2>
<p>Let’s take the structs that we had previously, but this time let’s add an
interface. In Rust, interfaces are called <strong>traits</strong>:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">struct</span> <span class="n">Book</span> <span class="p">{</span>
<span class="n">title</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="n">author</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Log</span> <span class="p">{</span>
<span class="n">wood_type</span><span class="p">:</span> <span class="o">~</span><span class="nb">str</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">trait</span> <span class="n">Burns</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">burn</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>Now in addition to the two structs, we also have an interface called <code class="language-plaintext highlighter-rouge">Burns</code>.
This defines just a single method called <code class="language-plaintext highlighter-rouge">burn()</code>. Let’s implement the interface
for each struct now:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">impl</span> <span class="n">Burns</span> <span class="k">for</span> <span class="n">Log</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">burn</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="nd">fmt!</span><span class="p">(</span><span class="s">"The %s log is burning!"</span><span class="p">,</span> <span class="k">self</span><span class="py">.wood_type</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Burns</span> <span class="k">for</span> <span class="n">Book</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">burn</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="nd">fmt!</span><span class="p">(</span><span class="s">"The book </span><span class="se">\"</span><span class="s">%s</span><span class="se">\"</span><span class="s"> by %s is burning!"</span><span class="p">,</span> <span class="k">self</span><span class="py">.title</span><span class="p">,</span> <span class="k">self</span><span class="py">.author</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></figure>
<p>So far it doesn’t look that much different. This is where the power of
programming to an interface comes in:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">fn</span> <span class="n">start_fire</span><span class="o"><</span><span class="n">T</span><span class="p">:</span> <span class="n">Burns</span><span class="o">></span><span class="p">(</span><span class="n">item</span><span class="p">:</span> <span class="n">T</span><span class="p">)</span> <span class="p">{</span>
<span class="n">item</span><span class="nf">.burn</span><span class="p">();</span>
<span class="p">}</span></code></pre></figure>
<p>Rather than expecting a Book object or a Log object, we just take in any object
with any type (we call the type <code class="language-plaintext highlighter-rouge">T</code>) that implements the <code class="language-plaintext highlighter-rouge">Burns</code> interface.
This leaves us with the following main function:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
<span class="k">let</span> <span class="n">lg</span> <span class="o">=</span> <span class="n">Log</span> <span class="p">{</span>
<span class="n">wood_type</span><span class="p">:</span> <span class="o">~</span><span class="s">"Oak"</span><span class="p">,</span>
<span class="p">};</span>
<span class="k">let</span> <span class="n">book</span> <span class="o">=</span> <span class="n">Book</span> <span class="p">{</span>
<span class="n">title</span><span class="p">:</span> <span class="o">~</span><span class="s">"The Brothers Karamazov"</span><span class="p">,</span>
<span class="n">author</span><span class="p">:</span> <span class="o">~</span><span class="s">"Fyodor Dostoevsky"</span><span class="p">,</span>
<span class="p">};</span>
<span class="c">// Burn the oak log!</span>
<span class="nf">start_fire</span><span class="p">(</span><span class="n">lg</span><span class="p">);</span>
<span class="c">// Burn the book!</span>
<span class="nf">start_fire</span><span class="p">(</span><span class="n">book</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>Now as we’d expect, we get the following output:</p>
<blockquote>
<p>The Oak log is burning!</p>
</blockquote>
<blockquote>
<p>The book “The Brothers Karamazov” by Fyodor Dostoevsky is burning!</p>
</blockquote>
<p>Which is exactly as we wanted.</p>
<h2 id="conclusion">Conclusion</h2>
<p>By following the principle behind “programming to an ‘interface’”, we were able
to write a function once that is now completely reusable across any object that
implements the <code class="language-plaintext highlighter-rouge">Burns</code> interface. Since a lot of programmers are paid by the
hour, the more time we spend writing reusable code and the less time we spend
maintaining old code, the better.</p>
<p>This is a very powerful principle for this reason.</p>
<p>It might not always be possible to program to an interface, but often it makes
writing reusable and elegant code easier. It provides a very nice abstraction
and makes working with your code a lot easier.</p>
<h2 id="edit">Edit</h2>
<p>The response to this post was awesome. I was really pleased that it made it to
the front page of <a href="http://www.reddit.com/r/programming/">/r/programming</a>, the
front page of <a href="http://www.reddit.com/r/rust/">/r/rust</a>, and some cool people
tweeted it. In particular I loved the <a href="http://www.reddit.com/r/rust/comments/1hj03k/program_to_an_interface_fool/cauz6ff">feedback some Rust developers
gave</a>. I was able to fix my mistake of naming the trait as well as
learn a bit about owned pointers. This is certainly why I try to contribute back
to the community =]</p>
Phil Zimmermann, Creator of PGP, Quote on Government & Crypto from 19962013-06-22T00:00:00+00:00https://joshldavis.com/2013/06/22/phil-zimmerman-creator-of-pgp-quote-on-government-and-crypto-from-1996<h1 id="phil-zimmermann-creator-of-pgp-quote-on-government--crypto-from-1996">Phil Zimmermann, Creator of PGP, Quote on Government & Crypto from 1996</h1>
<p>Today I finished reading <a href="http://amzn.to/28NxpbQ">The Code Book</a> by Simon Singh. It details the
history of cryptography from millenniums ago until the recent advances with
quantum cryptography.</p>
<p>In it there is a chapter dedicated to <a href="http://en.wikipedia.org/wiki/Pretty_Good_Privacy">Pretty Good Privacy</a> or more
commonly known as PGP. PGP was created by <a href="http://www.philzimmermann.com/EN/background/index.html">Phil Zimmermann</a> in 1991 and turned
strong cryptographic practices into something everyone could use.</p>
<p>In the book it has a quotation from Zimmermann from an interview with a radio
show, <a href="http://www.animatedsoftware.com/hightech/hightech.htm">High Tech Today</a>, recorded in February 1996, over 17 years ago.
Although it is slightly different in the book, I hunted down the original. The
interview can still be read in <a href="http://www.animatedsoftware.com/hightech/philspgp.htm">its entirety</a>.</p>
<p>Here’s the quote:</p>
<blockquote>
<p>Today we live in the information age. Everyone has computers. All the
trappings of the information age are part of our lives. Paper mail is being
replaced by electronic mail. Digital communications is taking over. We need
encryption. The common person needs encryption to function effectively in the
information age. So it’s time for cryptography to step out of the shadows of
spies and military stuff, and step out into the sunshine and be embraced by
the rest of us.</p>
<p>If our government ever goes bad, as sometimes happens in a democracy…
Sometimes in a democracy bad people can be elected, and if democracy is
allowed to function normally, these people can be taken out of power by the
next election. But if a future government inherits a technology infrastructure
that’s optimized for surveillance, where they can watch the movements of their
political opposition, they can see every bit of travel they could do, every
financial transaction, every communication, every bit of email, every phone
call, everything could be filtered and scanned and automatically recognized by
voice recognition technology and transcribed.</p>
</blockquote>
The Rise of the Gang of Four with Rust2013-06-16T00:00:00+00:00https://joshldavis.com/2013/06/16/the-rise-of-the-gang-of-four-with-rust<h1 id="the-rise-of-the-gang-of-four-with-rust">The Rise of the Gang of Four with Rust</h1>
<p>Since I’ve been to Seattle, I’ve had a lot of time to catch up on reading. One
of the books that I’ve been reading has been well regarded since it was released
in 1994.</p>
<p><a href="http://amzn.com/0201633612">Design Patterns: Elements of Reusable Object-Oriented Software</a> (also
called the Gang of Four book) is considered to be one of the best books when it
comes to design patterns. It is often touted as a classic and I always approach
such books skeptically. However, the first two chapters absolutely blew me away.
This post is mainly about the first chapter and how it has changed my view of
programming languages as I took up learning <a href="http://www.rust-lang.org">Rust</a>.</p>
<h2 id="the-standard-object-oriented-paradigm">The Standard Object-Oriented Paradigm</h2>
<p>Before I read this book, when I thought of <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming
(OOP)</a>, the languages that I thought of were usually Java, C++, Python, and
Ruby (and according to GitHub, they are the four most popular OOP
languages, besides PHP) The interesting part is that all four of these languages
use the same notion of OOP with little twists added on.</p>
<p>Using these four languages, let’s look at some common terms that are used when
trying to understand OOP for the first time.</p>
<p>Also, feel free to skim through this section on the standard paradigm if you are
familiar with OOP in Java, C++, Python, and Ruby. The crux of this post is in
the next section on the new paradigm.</p>
<h3 id="types--classes">Types & Classes</h3>
<p>A <strong>type</strong> is a name given to an object to distinguish what kind it is. In OOP
languages, there are many different kinds of types. With Java, the types can be
primitive types, which means they are built into the language, like <code class="language-plaintext highlighter-rouge">int</code> and
<code class="language-plaintext highlighter-rouge">boolean</code>. Or they can be names given to the class an object is. Here’s what
determining an object’s type looks like in Python:</p>
<figure class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="n">s</span> <span class="o">=</span> <span class="s">"Hi there"</span>
<span class="n">x</span> <span class="o">=</span> <span class="mi">9</span>
<span class="n">o</span> <span class="o">=</span> <span class="n">object</span><span class="p">()</span>
<span class="k">if</span> <span class="n">type</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="n">is</span> <span class="n">str</span><span class="o">:</span>
<span class="n">print</span> <span class="s">"A string."</span>
<span class="k">if</span> <span class="n">type</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="n">is</span> <span class="kt">int</span><span class="o">:</span>
<span class="n">print</span> <span class="s">"An int."</span>
<span class="k">if</span> <span class="n">type</span><span class="p">(</span><span class="n">o</span><span class="p">)</span> <span class="n">is</span> <span class="n">object</span><span class="o">:</span>
<span class="n">print</span> <span class="s">"An object."</span></code></pre></figure>
<p>Now in Java:</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Cat</span> <span class="o">{}</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MaineCoon</span> <span class="kd">extends</span> <span class="nc">Cat</span> <span class="o">{}</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Main</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="nc">String</span> <span class="n">argv</span><span class="o">[])</span> <span class="o">{</span>
<span class="nc">Cat</span> <span class="n">c</span><span class="o">;</span>
<span class="nc">MaineCoon</span> <span class="n">kitty</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">MaineCoon</span><span class="o">();</span>
<span class="c1">// Will output: Kitty type = class MaineCoon</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Kitty type = "</span> <span class="o">+</span> <span class="n">kitty</span><span class="o">.</span><span class="na">getClass</span><span class="o">());</span>
<span class="n">c</span> <span class="o">=</span> <span class="o">(</span><span class="nc">Cat</span><span class="o">)</span> <span class="n">kitty</span><span class="o">;</span>
<span class="c1">// Will output: C type = class MaineCoon</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"C type = "</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="na">getClass</span><span class="o">());</span>
<span class="o">}</span>
<span class="o">}</span></code></pre></figure>
<p>As you can see, the idea of a type is used in these languages as a one-to-one
mapping between types and objects. In other words, an object can only have one
type.</p>
<p>I group the terms type and class together because they can be pretty
interchangeable when talking about objects. However, sometimes a class is only
referred to when talking about non-primitive objects.</p>
<p>Using our example, a <strong>class</strong> would only refer to <code class="language-plaintext highlighter-rouge">Cat</code> or <code class="language-plaintext highlighter-rouge">MaineCoon</code>. And
primitives such as <code class="language-plaintext highlighter-rouge">int</code> and <code class="language-plaintext highlighter-rouge">boolean</code> have no class.</p>
<h3 id="signature">Signature</h3>
<p>A <strong>signature</strong> is the term used to describe what a function or method is called,
what it takes in as parameters, and what it returns.</p>
<p>In Ruby signatures look like this:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">def</span> <span class="nf">gcd</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="k">end</span></code></pre></figure>
<p>Ruby is dynamically typed so none of the variable types need to be mentioned.
Java on the other hand is not dynamically typed. Thus a signature in Java looks
like this:</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Algorithms</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="nf">gcd</span><span class="o">(</span><span class="kt">int</span> <span class="n">a</span><span class="o">,</span> <span class="kt">int</span> <span class="n">b</span><span class="o">)</span> <span class="o">{</span>
<span class="c1">// ...</span>
<span class="o">}</span>
<span class="o">}</span></code></pre></figure>
<p>The signature in Java looks different than the one in Ruby because the types
need to be declared. The first type we see is that the method called <code class="language-plaintext highlighter-rouge">gcd</code>
returns an <code class="language-plaintext highlighter-rouge">int</code> and takes two <code class="language-plaintext highlighter-rouge">ints</code> as arguments.</p>
<h3 id="interface">Interface</h3>
<p>An <strong>interface</strong> is a set of signatures that an object must respond to when
implementing it. This is a way of guaranteeing that an object has a method
defined for it.</p>
<p>The only programming language with explicit support for interfaces is Java. One
can create an interface with C++ by just defining a class without providing any
code. A similar thing can be achieved in Python by creating a class but just
throwing a <a href="http://docs.python.org/2/library/exceptions.html#exceptions.NotImplementedError">NotImplementedError</a> as well as Ruby as explained
<a href="http://metabates.com/2011/02/07/building-interfaces-and-abstract-classes-in-ruby/">here</a> (although using “interfaces” in Python and Ruby could
arguably be a bad thing).</p>
<p>Java interfaces look like this:</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">Sloth</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">climb</span><span class="o">();</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">eat</span><span class="o">();</span>
<span class="o">}</span></code></pre></figure>
<p>Now any object that implements the <code class="language-plaintext highlighter-rouge">Sloth</code> interface is guaranteed to respond to
the two methods: <code class="language-plaintext highlighter-rouge">climb</code> and <code class="language-plaintext highlighter-rouge">eat</code>.</p>
<h3 id="polymorphism">Polymorphism</h3>
<p>Polymorphism is considered to be one of the tenets of OOP. <strong>Polymorphism</strong> is
when an object can take on multiple forms. This sounds strange but you’ve
already seen an example of this but let’s look at it more explicitly.</p>
<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Dragon</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">roar</span><span class="o">()</span> <span class="o">{</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Roar!"</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">FireBreathingDragon</span> <span class="kd">extends</span> <span class="nc">Dragon</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">roar</span><span class="o">()</span> <span class="o">{</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Roar + a ton of flames!"</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">DragonTrainer</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">train</span><span class="o">(</span><span class="nc">Dragon</span> <span class="n">dragon</span><span class="o">)</span> <span class="o">{</span>
<span class="n">dragon</span><span class="o">.</span><span class="na">roar</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">Main</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="nc">String</span> <span class="n">argv</span><span class="o">[])</span> <span class="o">{</span>
<span class="nc">DragonTrainer</span> <span class="n">trainer</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">DragonTrainer</span><span class="o">();</span>
<span class="nc">Dragon</span> <span class="n">spike</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">Dragon</span><span class="o">();</span>
<span class="nc">FireBreathingDragon</span> <span class="n">toothless</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">FireBreathingDragon</span><span class="o">();</span>
<span class="c1">// Prints out: Roar!</span>
<span class="n">trainer</span><span class="o">.</span><span class="na">train</span><span class="o">(</span><span class="n">spike</span><span class="o">);</span>
<span class="c1">// Prints out: Roar + a ton of flames!</span>
<span class="n">trainer</span><span class="o">.</span><span class="na">train</span><span class="o">(</span><span class="n">toothless</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span></code></pre></figure>
<p>As you can see, when we create a <code class="language-plaintext highlighter-rouge">DragonTrainer</code>, the trainer doesn’t have to know
about <code class="language-plaintext highlighter-rouge">FireBreatingDragon</code>, it only has to know about the class <code class="language-plaintext highlighter-rouge">Dragon</code>. What
happens is that since <code class="language-plaintext highlighter-rouge">FireBreatingDragon</code> extends <code class="language-plaintext highlighter-rouge">Dragon</code>, it just gets casted
to it during the <code class="language-plaintext highlighter-rouge">train</code> method and calls the appropriate method.</p>
<h3 id="inheritance">Inheritance</h3>
<p><strong>Inheritance</strong> is almost exactly what it sounds like, if one has an object that
extends from another, it will now have all of the same signatures and instance
variables.</p>
<p>Taking our Dragon example from earlier, if we left off the implementation for
the <code class="language-plaintext highlighter-rouge">roar</code> method in our <code class="language-plaintext highlighter-rouge">FireBreatingDragon</code>, then it would just output “Roar!”
again because it inherits the <code class="language-plaintext highlighter-rouge">roar</code> method from <code class="language-plaintext highlighter-rouge">Dragon</code>.</p>
<h2 id="an-object-oriented-paradigm-shift">An Object-Oriented Paradigm Shift</h2>
<p>The Gang of Four book starts off in Chapter One by defining each of the terms I
have listed above. As I read it, I figured it would all be review, yet I was
getting very confused by the definitions. I re-read the chapter and my mind was
forever changed.</p>
<div class="gallery xsmall">
<figure>
<img src="/img/gof/mind-blown.gif" alt="Mind blown" width="300" />
<figcaption>This really did happen to my brain.</figcaption>
</figure>
</div>
<p>Let’s take a look at each of those definitions from earlier and see how they
compare. I’ve switched around the order a bit to aid in explanation.</p>
<h3 id="signature-1">Signature</h3>
<p>In the Gang of Four, a signature is exactly what it is in Java, Python, and
others. A <strong>signature</strong> still refers to the name of a method/function, its
return type, and its parameters. Look above for an example.</p>
<h3 id="interface-1">Interface</h3>
<p>Once again, an <strong>interface</strong> has no difference either. It is still a set of
signatures that an object must respond to.</p>
<p>You may be wondering now why I thought that the Gang of Four was such a
mind-blowing read, well hopefully the next set of terms as well as the examples
in <a href="http://www.rust-lang.org">Rust</a> will explain that.</p>
<h3 id="types--classes-1">Types & Classes</h3>
<p>In the Gang of Four, a <strong>type</strong> is just a name to denote a particular interface.
If an object has a certain type, then it responds to all the requests for that
interface.</p>
<p>This doesn’t seem that revolutionary, but what does this imply? Well this means
that an object can have multiple types. An object can actually have as many
types as it wants, it just needs to implement more interfaces.</p>
<p>Let’s take a look at what this looks like in <a href="http://www.rust-lang.org">Rust</a>. If your Rust is a
little rusty (heh heh) or if you don’t know it, take a look at the
<a href="http://doc.rust-lang.org/">tutorial</a> that is provided. It is an excellent introduction to the
language. Anywho, here’s what it looks like:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">trait</span> <span class="n">Mammal</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">pet_fur</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">trait</span> <span class="n">Flyable</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">fly</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Bat</span><span class="p">;</span>
<span class="k">impl</span> <span class="n">Mammal</span> <span class="k">for</span> <span class="n">Bat</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">pet_fur</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="s">"You pet the bat."</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Flyable</span> <span class="k">for</span> <span class="n">Bat</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">fly</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="p">{</span>
<span class="nf">println</span><span class="p">(</span><span class="s">"The bat flies away!"</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></figure>
<p>The first thing that you probably noticed is the keyword <code class="language-plaintext highlighter-rouge">trait</code>, this is what
Rust calls a set of signatures, also known as an interface. Then we implement
those interfaces in the <code class="language-plaintext highlighter-rouge">impl</code> section based on the <code class="language-plaintext highlighter-rouge">Bat</code> struct.</p>
<p>This paradigm is completely different than the standard idea of a type that is
used in Java, C++, Python, and more.</p>
<h4 id="classes">Classes</h4>
<p>Next is the idea of a <strong>class</strong>. In the Gang of Four, a class is just an
object’s implementation. A class also specifies the object’s internal data,
representation and it defines the operations the object can perform.</p>
<p>Although Rust doesn’t use the keyword <code class="language-plaintext highlighter-rouge">class</code>, following the definition in the
last paragraph, a class could best be described as a <code class="language-plaintext highlighter-rouge">struct</code> with
implementations. Although it isn’t a class in the traditional sense (there is no
<em>class</em> based inheritance), it can sort of be viewed as one (<a href="https://lwn.net/Articles/548560/">better analysis on
classlessness in Rust as well as Go</a>)).</p>
<h3 id="polymorphism-1">Polymorphism</h3>
<p>In Rust the idea of <strong>polymorphism</strong> is made possible all through the type
system. The forms that an object can take are all dependent on the types of an
object, in other words, the interfaces it implements.</p>
<h3 id="inheritance-1">Inheritance</h3>
<p>As I mentioned, Rust doesn’t have the idea of <em>class</em> based inheritance. Instead
it has the idea of <em>trait inheritance</em>.</p>
<p>When creating a trait, it’s possible to inherit other traits to extend
functionality.</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">trait</span> <span class="n">Shape</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">area</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="k">-></span> <span class="nb">float</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Rectangle</span> <span class="p">{</span>
<span class="n">width</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
<span class="n">height</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Shape</span> <span class="k">for</span> <span class="n">Rectangle</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">area</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="k">-></span> <span class="nb">float</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">self</span><span class="py">.width</span> <span class="o">*</span> <span class="k">self</span><span class="py">.height</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">trait</span> <span class="n">Round</span> <span class="p">:</span> <span class="n">Shape</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">center</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="k">-></span> <span class="n">Point</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Point</span> <span class="p">{</span>
<span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
<span class="n">y</span><span class="p">:</span> <span class="nb">float</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">Circle</span> <span class="p">{</span>
<span class="n">radius</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
<span class="n">center</span><span class="p">:</span> <span class="n">Point</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Round</span> <span class="k">for</span> <span class="n">Circle</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">center</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="k">-></span> <span class="n">Point</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">self</span><span class="py">.center</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">impl</span> <span class="n">Shape</span> <span class="k">for</span> <span class="n">Circle</span> <span class="p">{</span>
<span class="k">fn</span> <span class="nf">area</span><span class="p">(</span><span class="o">&</span><span class="k">self</span><span class="p">)</span> <span class="k">-></span> <span class="nb">float</span> <span class="p">{</span>
<span class="k">return</span> <span class="mf">3.14</span> <span class="o">*</span> <span class="k">self</span><span class="py">.radius</span> <span class="o">*</span> <span class="k">self</span><span class="py">.radius</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></figure>
<p>This example shows that if we create a <code class="language-plaintext highlighter-rouge">Shape</code> trait that has one signature, an
<code class="language-plaintext highlighter-rouge">area</code> method, we can then use that trait and implement it for subsequent
structs. Since the area formula for a <code class="language-plaintext highlighter-rouge">Rectangle</code> is different than a <code class="language-plaintext highlighter-rouge">Circle</code>,
we can represent that easily with type inheritance by creating a new type called
<code class="language-plaintext highlighter-rouge">Round</code>. Since the <code class="language-plaintext highlighter-rouge">Round</code> trait inherits the <code class="language-plaintext highlighter-rouge">Shape</code> trait as well, we need to
implement both traits for the <code class="language-plaintext highlighter-rouge">Circle</code> struct.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Rust is only at version 0.6. Mozilla wants to get a stable 1.0 version out by
the end of the year so there is no telling what might change.</p>
<p>The interesting thing is that Rust is following the same pattern that <a href="http://www.go-lang.org">Go</a>
took as well. Go is very similar to Rust in that it has interface inheritance
and no classes.</p>
<p>Although the Gang of Four book certainly wasn’t the first to come up with the
definitions of an interface, type, and class, it was the first place I came
across the new ideas. Since these ideas are a radical shift from the previous
paradigm, I can’t help but think that the Gang of Four has influenced Rust and
Go, the two languages that I’m most excited to see evolve. It’s often said that
“history repeats itself”, yet I can’t help but feel that great design also
follows the same cyclic pattern.</p>
The Legacy of the Clicky Keyboards2013-06-09T00:00:00+00:00https://joshldavis.com/2013/06/09/the-legacy-of-the-clicky-keyboards<h1 id="the-legacy-of-the-clicky-keyboards">The Legacy of the Clicky Keyboards</h1>
<p>Last year I did a co-op at a company in Minneapolis called <a href="http://www.digi.com">Digi
International</a>. During the summer there were 11 Software Engineers all
working in one big cubicle that we dubbed “The Supercube.” One of the most
defining characteristics of this cubicle was the noise of all of us typing away
as we coded up various projects.</p>
<p>Keyboards are interesting because they are the interface between humans and
computers when it comes to code. Nothing gets into a program source unless it
comes through the keyboard. As a result, a keyboard can be incredibly important
for programmers.</p>
<p>There are all types of keyboards. There are some that focus on ergonomics to
prevent <a href="http://en.wikipedia.org/wiki/Repetitive_strain_injury">repetitive strain injury</a>, some that focus on durability such as
mechanical keyboards, and many more.</p>
<h2 id="the-start-of-a-legacy">The Start of a Legacy</h2>
<p>Most of us just used the standard keyboards we were given but four of the
interns had “clicky keyboards”. Clicky keyboards are named (obviously)
for the sound they make when one types on them.</p>
<p>Each of the clicky keyboards was different. The most impressive was a completely
working <a href="http://en.wikipedia.org/wiki/Model_M_keyboard">IBM Model M</a> which was named “The Kremlin” by my Russian
friend. It was the first time I had heard about the keyboard but I understood
the love for it the instant I tried typing on it.</p>
<p>Another one of my coworkers had a <a href="http://www.daskeyboard.com/">Das Keyboard</a> which is by far the most
intimidating of the keyboards. Some models of the Das Keyboards come
without lettering on the keys.</p>
<p>The third type of clicky keyboard that was used was a <a href="http://www.razerzone.com/gaming-keyboards-keypads/razer-blackwidow-ultimate-2013">Razer Blackwidow
Ultimate</a>. It was by far the most visually pleasing of the keyboards.</p>
<h2 id="the-legacy-continues">The Legacy Continues</h2>
<p>I had wanted to buy one while I was there, but I just couldn’t justify spending
the money for one. Instead I promised myself that one day I would get a nice
clicky keyboard that would last awhile.</p>
<p>Although I didn’t return to Digi this summer, I decided a few weeks into my
current internship to make the investment and buy a clicky keyboard. I did a
bit of research and asked some friends that I knew and I decided on getting a
Das Keyboard. I am a pretty good touch typist so I went with the <a href="http://www.daskeyboard.com/model-s-ultimate/">Model S
Ultimate</a>.</p>
<h2 id="the-review">The Review</h2>
<p>I have only had it a few days but I really, <em>really</em> enjoy typing on it. It’s
very easy to tell that the Cherry MX Blue switches are of top notch quality.
They are very responsive and seem to be incredibly durable.</p>
<p>The keys sound completely awesome while typing on them as well. My girlfriend
isn’t the biggest fan of how loud it is over Google Hangouts and I have a
feeling my co-worker that I share an office with isn’t going to enjoy it either,
haha.</p>
<h2 id="conclusion">Conclusion</h2>
<p>So far I’m very happy that I bought a nice keyboard that will last for a long
time. I am also very glad I went with a Das keyboard.</p>
<p>The fellow interns that I worked with last summer have carried the legacy to
various companies. The intern with the Model M will be starting at Microsoft on
July 1st. The intern that had the Das Keyboard is starting a career at Google
soon. I’m at Amazon and there’s no telling where the other very smart interns
will end up as they have yet to graduate.</p>
<p>It’ll be interesting to see where all of the interns from last summer end up and
where they will take their clicky keyboards next. The legacy will indeed carry
on.</p>
The New Google Maps User Experience2013-06-02T00:00:00+00:00https://joshldavis.com/2013/06/02/google-maps-new-user-experience<h1 id="the-new-google-maps-user-experience">The New Google Maps User Experience</h1>
<p>Google had its latest <a href="https://developers.google.com/events/io/2013/">Google IO</a> in May this year. My favorite
announcement was definitely the update to Google Maps. The new Maps was
announced in the main presentation and you can watch it <a href="http://www.youtube.com/watch?v=9pmPa_KxsAM&t=2h25m50s">here</a>. There
have been a lot of changes but I want to focus on the third point, which was how
“the Map is the UI.”</p>
<p><strong>Disclaimer:</strong> I am not a user interface/user experience expert by any means. I
am just a very enthusiastic user that loves things that work well. All of this
is anecdotal.</p>
<h2 id="the-past">The Past</h2>
<p>I think most of us are familiar with the past UX (user experience) and UI (user
interface) on the old Google Maps. The top 10 search results show up on the
left, and then the map with those markers are on the right:</p>
<div class="gallery medium">
<a href="/img/maps/old-google-maps-search.png" rel="lightbox[maps1]" title="The old interface for Google Maps search results.">
<img src="/img/maps/old-google-maps-search.png" alt="Old Google Maps" width="620" />
<span>The old interface for Google Maps search results.</span>
</a>
</div>
<p>It worked pretty well and most of us got very accustomed to navigating the UI
and getting the information we needed.</p>
<h2 id="initial-reaction">Initial Reaction</h2>
<p>When I first heard about the UI overhaul for the new Google Maps, I was pretty
excited. I saw that it was finally using the complete window to show the whole
map and the white search results was gone. I signed up to preview the new
interface almost immediately and received access a few weeks ago.</p>
<h2 id="reaction-after-using-it">Reaction After Using It</h2>
<p>I was pretty let down after I first tried it. I (mistakenly) didn’t do the tour
and assumed that I would be able to figure it out and that it would be
intuitive.</p>
<div class="gallery medium">
<a href="/img/maps/new-google-maps-search.png" rel="lightbox[maps2]" title="The new interface for Google Maps search results.">
<img src="/img/maps/new-google-maps-search.png" alt="New Google Maps" width="620" />
<span>The new interface for Google Maps search results.</span>
</a>
</div>
<p>I was a little confused as to where all of the search results were. I was
expecting a floating window on the left that had a list of everything that
showed up. I also couldn’t find how to access Street View and kept looking for
the friendly little Yellow guy to drag around.</p>
<p>This sort of initial puzzlement can be expected when a UI completely changes. I
usually have an easy time adapting yet I was having issues with the new Google
Maps. I decided that I should do what I initially skipped and do a tour by
clicking the Help in the top right.</p>
<h2 id="forgetting-the-old-google-maps">Forgetting the Old Google Maps</h2>
<p>The tour is incredibly simple. It shows that the new search results intuitively
show up on the map. Street View can be started by either just clicking on the
street or clicking on a search result.</p>
<p>I was very intrigued by all of this. The new Google Maps is incredibly intuitive
yet I had a problem adjusting to it from the old. I had to force myself to
forget the old ways of Google Maps in order to make full use of the new UX.</p>
<h2 id="an-interesting-problem">An Interesting Problem</h2>
<p>Whenever I hear about people creating UIs, they always try to think about what
is the most intuitive and simplest for the user. Yet I hardly ever hear them
mention how the user might <em>expect</em> the new UI to operate based on their past
experiences and preconceived notions.</p>
<p>This may seem like a trivial issue because if the UI is intuitive enough, the
user should just <em>know</em> how to use it. Yet in my case with the new Google Maps,
I expected that I’d be able to figure out how to use the new UI. I wouldn’t even
consider myself a below average user. I rarely have an issue using new UIs.</p>
<h2 id="takeaway">Takeaway</h2>
<p>With the new Google Maps, it was very easy for Google to add a tour to show how
to use the new feature. Yet I doubt that will be utilized by a lot of the users.
Being told how to use something is the last thing a user wants.</p>
<p>This whole situation added a new perspective to how I will approach UI/UX issues
in the future. Sometimes the most intuitive and easiest way to interact with
something might still present issues because of the user’s past experiences and
knowledge.</p>
The Difference Between TDD and BDD2013-05-27T00:00:00+00:00https://joshldavis.com/2013/05/27/difference-between-tdd-and-bdd<h1 id="the-difference-between-tdd-and-bdd">The Difference Between TDD and BDD</h1>
<p>If you keep up-to-date with the latest software development practices, odds are
you have heard of <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test-driven development (TDD)</a> and <a href="http://en.wikipedia.org/wiki/Behavior-driven_development">Behavior-driven
development (BDD)</a>. This post is meant to explain what each practice means,
provide examples, and then contrast the two. Let’s dig in and see what we learn.</p>
<h2 id="test-driven-development">Test-Driven Development</h2>
<p>When I first heard about TDD, the idea seemed to be pretty simple. Just by doing
a little word swizzling, obviously TDD is when you have tests that drive your
software development.</p>
<p>If we were to unpack the definition of TDD a bit more, we’d see that it is
usually broken up into five different stages:</p>
<ol>
<li>First the developer writes some tests.</li>
<li>The developer then runs those tests and (obviously) they fail because none of
those features are actually implemented.</li>
<li>Next the developer actually implements those tests in code.</li>
<li>If the developer writes their code well, then the in next stage they will see
that their tests pass.</li>
<li>The developer can then refactor their code, add comments and clean it up, as
they wish because the developer knows that if the new code breaks something,
then the tests will be an alert by failing.</li>
</ol>
<p>The cycle can just continue as long as the developer has more features to add. A
flowchart is given below of this cycle:</p>
<div class="gallery small">
<figure>
<img src="/img/tdd-vs-bdd/tdd-flowchart.png" alt="TDD flowchart" width="460" />
<figcaption>Test-driven development flowchart.</figcaption>
</figure>
</div>
<h3 id="example">Example</h3>
<p>Let’s see an example of how a developer would do this. The complete source code
for this article is located in this repository: <a href="https://github.com/jdavis/tdd-vs-bdd">tdd-vs-bdd</a>. Feel free to
clone it and run it yourself by issuing the commands <code class="language-plaintext highlighter-rouge">npm install && grunt</code>.</p>
<p>Let’s say a developer wants to write a function that does something simple, like
calculate a factorial (obviously a rather contrived example but it will show us
the difference between TDD and BDD). The normal approach that TDD dictates is to
use the function and then assert that the result satisfies a certain value.</p>
<p>In this example, we’re going to use a JavaScript testing framework called
<a href="http://mochajs.org/">Mocha</a>. The tests might look something
like this:</p>
<figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">assert</span><span class="dl">'</span><span class="p">),</span>
<span class="nx">factorial</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">../index</span><span class="dl">'</span><span class="p">);</span>
<span class="nx">suite</span><span class="p">(</span><span class="dl">'</span><span class="s1">Test</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">setup</span><span class="p">(</span><span class="kd">function</span> <span class="p">(){</span>
<span class="c1">// Create any objects that we might need</span>
<span class="p">});</span>
<span class="nx">suite</span><span class="p">(</span><span class="dl">'</span><span class="s1">#factorial()</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">test</span><span class="p">(</span><span class="dl">'</span><span class="s1">equals 1 for sets of zero length</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nx">factorial</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span>
<span class="p">});</span>
<span class="nx">test</span><span class="p">(</span><span class="dl">'</span><span class="s1">equals 1 for sets of length one</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nx">factorial</span><span class="p">(</span><span class="mi">1</span><span class="p">));</span>
<span class="p">});</span>
<span class="nx">test</span><span class="p">(</span><span class="dl">'</span><span class="s1">equals 2 for sets of length two</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nx">factorial</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span>
<span class="p">});</span>
<span class="nx">test</span><span class="p">(</span><span class="dl">'</span><span class="s1">equals 6 for sets of length three</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="nx">factorial</span><span class="p">(</span><span class="mi">3</span><span class="p">));</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">});</span></code></pre></figure>
<p>The tests will obviously fail because the function hasn’t been written yet. So
let’s write that function to satisfy the tests. It might look something like
this:</p>
<figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">n</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="kc">NaN</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">n</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">n</span> <span class="o">*</span> <span class="nx">factorial</span><span class="p">(</span><span class="nx">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">};</span></code></pre></figure>
<p>Now if we run the tests, we can see that all of them pass! This is how TDD
works. Now let’s take a look at BDD to see how it is different.</p>
<h2 id="behavior-driven-development">Behavior-Driven Development</h2>
<p>Alright, so what is BDD you ask? Well that’s where the line gets a little fuzzy.
Some people will say it is similar to TDD, others will say that it <strong>is</strong> just
TDD but with better guidelines, or even a totally different approach to
developing.</p>
<p>Whatever the actual definition is, it doesn’t matter that much. The main thing
to know is that <strong>BDD is meant to eliminate issues that TDD might cause.</strong></p>
<p>In contrast to TDD, BDD is when we write <em>behavior & specification</em> that
then drives our software development. Behavior & specification might seem
awfully similar to tests but the difference is very subtle and important.</p>
<h3 id="example-1">Example</h3>
<p>Let’s take a look at our previous example of writing a function to calculate the
factorial for a number.</p>
<figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">assert</span><span class="dl">'</span><span class="p">),</span>
<span class="nx">factorial</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">../index</span><span class="dl">'</span><span class="p">);</span>
<span class="nx">describe</span><span class="p">(</span><span class="dl">'</span><span class="s1">Test</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">before</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
<span class="c1">// Stuff to do before the tests, like imports, what not</span>
<span class="p">});</span>
<span class="nx">describe</span><span class="p">(</span><span class="dl">'</span><span class="s1">#factorial()</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">it</span><span class="p">(</span><span class="dl">'</span><span class="s1">should return 1 when given 0</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">factorial</span><span class="p">(</span><span class="mi">0</span><span class="p">).</span><span class="nx">should</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">it</span><span class="p">(</span><span class="dl">'</span><span class="s1">should return 1 when given 1</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">factorial</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="nx">should</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">it</span><span class="p">(</span><span class="dl">'</span><span class="s1">should return 2 when given 2</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">factorial</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="nx">should</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">it</span><span class="p">(</span><span class="dl">'</span><span class="s1">should return 6 when given 3</span><span class="dl">'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="nx">factorial</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="nx">should</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="mi">6</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="nx">after</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="c1">// Anything after the tests have finished</span>
<span class="p">});</span>
<span class="p">});</span></code></pre></figure>
<p>The main difference is just the wording. BDD uses a more verbose style so that
it can be read almost like a sentence.</p>
<p>This is what I meant by saying that BDD eliminates issues that TDD might cause.
The ability to read your tests like a sentence is a cognitive shift in how you
will think about your tests. The argument is that if you can read your tests
fluidly, you will <em>naturally</em> write better and more comprehensive tests.</p>
<p>Although this example is very simple and doesn’t illustrate it, BDD tests should
be more focused on the features, not the actual results. Often you’ll hear that
BDD is to help <strong>design</strong> the software, not test it like what TDD is meant to
do.</p>
<h2 id="tdd-vs-bdd">TDD vs BDD</h2>
<p>The choice between TDD and BDD is a complicated one. It depends on if there is
an appropriate testing framework for your given target language, what your
coworkers are comfortable with, and sometimes other factors.</p>
<p>Some argue that BDD is always better than TDD because it has the possibility of
eliminating issues that might arise when using TDD.</p>
<p>The key to BDD is that it <strong>might</strong> prevent issues; it isn’t guaranteed to.
Issues like poor code organization, bad design practices, etc. will still
persist. You’ll just have a lower likely hood of writing bad tests and thus have
more robust features.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Neither style is better than the other, it really depends on the person. A
person that knows how to write great TDD tests can have just as few bugs as
someone that knows how to write great BDD tests. If you find yourself writing
incomplete tests using TDD and want to design better software? Then give BDD a
shot. If you are new to both TDD and BDD, I’d recommend you learn and use TDD
first. The most important part of these two styles is that it forces you to
write tests for your code. If you don’t test your code, you need to.</p>
<p>I’m not an expert on TDD or BDD by any means. I just didn’t know the difference
myself so I investigated it a bit and this is what I came up with. Once again,
the code for the example in this post is located in this repository:
<a href="https://github.com/jdavis/tdd-vs-bdd">tdd-vs-bdd</a>.</p>
<p>If you have suggestions and/or error corrections for this article, or even if
you just plain out disagree, I’d love to hear it all! Feel free to <a href="/about#contact">contact
me</a>. Thanks for reading! ^_^</p>
The Path to Dijkstra's Handwriting2013-05-20T00:00:00+00:00https://joshldavis.com/2013/05/20/the-path-to-dijkstras-handwriting<h1 id="the-path-to-dijkstras-handwriting">The Path to Dijkstra’s Handwriting</h1>
<h4 id="follow-up">Follow Up</h4>
<blockquote>
<p>Read my follow up blog post from Oct 2017 about how I <a href="/2017/10/11/an-email-from-edsger-dijkstras-son/">received an email from
Edsger Dijkstra’s son</a>.</p>
</blockquote>
<p>My handwriting used to be terrible. I think I got to a point in fourth grade
where it just stopped getting better unlike most people. It didn’t bother me
either. It was still semi-legible to others and perfectly readable to myself.</p>
<div class="gallery medium">
<a href="/img/handwriting/bad1.png" rel="lightbox[bad]" title="One of my to do lists from sophomore year.">
<img src="/img/handwriting/bad1.png" alt="Bad handwriting 1" width="290" />
<span>A to do list from sophomore year</span>
</a>
<a href="/img/handwriting/bad2.png" rel="lightbox[bad]" title="Part of my solution to a Project Euler problem.">
<img src="/img/handwriting/bad2.png" alt="Bad handwriting 2" width="290" />
<span>Part of a solution to Project Euler</span>
</a>
</div>
<p>My letters lacked consistency. Things weren’t spaced very well and it just
looked <em>messy</em>. I have no idea how my professors put up with it.</p>
<h2 id="inspiration">Inspiration</h2>
<p>I’ve mentioned why I’ve admired Dijkstra <a href="/2013/05/11/beginning-of-a-beautiful-blogship/">before</a>, but I’ve read some of his EWDs
and really liked his handwriting. Here’s a sample of what his handwriting looked
like. This was taken from his EWD called <a href="http://www.cs.utexas.edu/~EWD/ewd10xx/EWD1036.PDF">On the Cruelty of Really Teaching
Computing Science (pdf)</a>:</p>
<div class="gallery medium">
<a href="/img/handwriting/dijkstras.png" rel="lightbox" title="Sample of Dijkstra's handwriting.">
<img src="/img/handwriting/dijkstras.png" alt="Dijkstra's handwriting" width="620" />
<span>Sample of Dijkstra's handwriting.</span>
</a>
</div>
<p>The first thing that I noticed when I saw it was just how simple and neat it is.
I’m not calligrapher by any means, but the letters just fit together well and
flow nicely.</p>
<p>I came across a <a href="http://www.reddit.com/r/AskReddit/comments/8rheh/any_tips_to_improve_handwriting_neatness_my/c0a7hoy">comment on Reddit</a> by someone that had Dijkstra as a
professor. Here’s what it said:</p>
<blockquote>
<p>I’ve always had horrible handwriting. When I was a computer science student I
was in a class taught by Edsger Dijkstra. During the class he asked us to
occasionally turn in our notes, because he wanted to see what we thought was
important.</p>
<p>The final was an oral final and after going through a few questions to his
satisfaction he said “You seem competent, but your handwriting is horrible…”
The remaining 30 mins of my final exam by Dijkstra was me writing phrases
repeatedly on a pad of paper while he said, ‘no, you need to round the o’s a
bit more, the A is misformed, etc…’.</p>
<p>It was surreal. I’m sad he died.</p>
</blockquote>
<p>Dijkstra seemed like a really caring professor. When I read this comment, I put
it in the back of my head in case I ever wanted to improve my handwriting. It
wasn’t until the summer of 2011 that I decided to spend some time to refine my
handwriting so that it looked similar to Dijkstra’s.</p>
<h2 id="the-process">The Process</h2>
<p>The first thing that I wanted to do was just develop the muscles around my hand
that helped with consistency and spacing. I did some Googling and came across <a href="http://www.paperpenalia.com/handwriting.html">a
site</a> that had a few exercises.</p>
<div class="gallery xsmall">
<a href="/img/handwriting/loopies.gif" rel="lightbox">
<img src="/img/handwriting/loopies.gif" alt="Handwriting exercises" width="220" />
</a>
<a href="/img/handwriting/slashes.gif" rel="lightbox">
<img src="/img/handwriting/slashes.gif" alt="More handwriting exercises" width="220" />
</a>
</div>
<p>The basic idea is to repeat the exercises over and over until the marks start to
look really, really good. I went through pages and pages in a notebook repeating
the exercises until my hand was numb. Whenever I had some free time, I’d just
take out the notebook and continue practicing. Eventually my lines and loops got
very consistent.</p>
<p>Next I found an image of the complete alphabet in Dijkstra’s handwriting by
someone who turned his handwriting into <a href="http://www.fonts101.com/fonts/view/Uncategorized/34398/Dijkstra">a font</a>. I printed it off and
then used that to base my handwriting off of.</p>
<div class="gallery small">
<a href="/img/handwriting/dijkstra-alphabet.png" rel="lightbox" title="The alphabet formed from Dijkstra's handwriting.">
<img src="/img/handwriting/dijkstra-alphabet.png" alt="Dijkstra handwriting alphabet" width="470" />
<span>The alphabet formed from Dijkstra's handwriting.</span>
</a>
</div>
<p>The next step was to write out the alphabet over and over again for a similar
reason as the above exercises. If you do it long enough, eventually your letters
will become more consistent over time and look a lot nicer.</p>
<p>Once again, I used up a ton of paper for this and did it whenever I wasn’t busy.
Here are a couple pictures of a scrap of paper I was able to find.</p>
<div class="gallery medium">
<a href="/img/handwriting/progress1.png" rel="lightbox[pratice]" title="Lower case practice.">
<img src="/img/handwriting/progress1.png" alt="Lowercase practice" width="300" />
<span>Lower case practice.</span>
</a>
<a href="/img/handwriting/progress2.png" rel="lightbox[pratice]" title="Practice with lower and upper case.">
<img src="/img/handwriting/progress2.png" alt="Upper and lowercase practice" width="300" />
<span>Practice with lower and upper case.</span>
</a>
</div>
<p>Obviously it isn’t perfect and I never want it to be. I only wanted to use it as
a base and customize it from there. I tried to incorporate a few of my own
differences over time.</p>
<h2 id="the-result">The Result</h2>
<p>After three months and a few notebooks later, I had a pretty nice and new
handwriting. Curiously enough, it looked like a hybrid between my mom’s
handwriting and Dijkstra’s.</p>
<div class="gallery small">
<a href="/img/handwriting/final.png" rel="lightbox" title="The final result in pen (top) and pencil (bottom).">
<img src="/img/handwriting/final.png" alt="Final result" width="460" />
<span>The final result in pen (top) and pencil (bottom).</span>
</a>
</div>
<p>Like I said, it isn’t perfect and I can still tidy it up a bit but it certainly
is better than where I started.</p>
<p>I rewrote the sample that I provided above in my own handwriting to compare it
with Dijkstra’s. My script doesn’t flow as well as his and mine is a bit sharper
in the lines. Still though, it is a lot better than what it was before.</p>
<div class="gallery small">
<a href="/img/handwriting/comparison.png" rel="lightbox" title="Comparison of the sample paper from above">
<img src="/img/handwriting/comparison.png" alt="Comparison" width="460" />
<span>Comparison of my rewrite from the paper sample above</span>
</a>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>The thing that I learned is that often someone’s handwriting isn’t exactly
“bad”, usually the person just doesn’t take the time to slow down and write
things nicely. There are still sometimes when my handwriting becomes a bit
sloppy during times when I’m trying to write quickly like taking notes or taking
a test. It is pretty inevitable. As long as I’m not in a rush I’m always able to
write the way I learned to.</p>
The Beginning of a Beautiful Blogship2013-05-11T00:00:00+00:00https://joshldavis.com/2013/05/11/beginning-of-a-beautiful-blogship<h1 id="the-beginning-of-a-beautiful-blogship">The Beginning of a Beautiful Blogship</h1>
<p>I have been a fan of <a href="https://twitter.com/nathanmarz">Nathan Marz</a> ever since I came across his blog post
on his <a href="http://nathanmarz.com/blog/my-experience-as-the-first-employee-of-a-y-combinator-startu.html">experience working at a startup</a>. I was pretty young at the
time (my first summer in 2010 after starting university) and was pretty influenced by
what he said. Just this past month I saw a new post by him on <a href="https://news.ycombinator.com">HackerNews</a>.
The post was about <a href="http://nathanmarz.com/blog/break-into-silicon-valley-with-a-blog-1.html">creating opportunities in Silicon Valley with a
blog</a>. I’ve always considered creating a place for me to post some
writings/musings that I have, but that post really persuaded me. I also came
across an <a href="http://nathanmarz.com/blog/you-should-blog-even-if-you-have-no-readers.html">older post</a> of his that also has the same convincing
argument.</p>
<h2 id="isolationism">Isolationism</h2>
<p>Ever since I started using the internet way back in elementary school, I’ve
always been rather hesitant to reveal my identity to online communities. I’d
never use the same username across websites. I filtered everything I said to
remove any personal references.</p>
<p>I was late to get a Facebook profile because I didn’t see the value in it. I
didn’t get a Twitter account for years even though I had known about it for
ages. I even went through a period of roughly 1.5 years where I deactivated my
Facebook account to focus on school and save time. It wasn’t until about last
year that I realized this was just harming myself and decided to reverse it.</p>
<h2 id="creating-an-identity">Creating an Identity</h2>
<p>The first thing I did was to start to update my GitHub profile. I reasoned that
having an active GitHub would be the most beneficial. I updated my profile
picture and email, updated my dotfiles, created a few more repositories, and
started following more people.</p>
<p>Next I bought a domain for myself and started to set up a personal web page. I
started to link all of my profiles together. I started with GitHub but
eventually started adding other profiles like Goodreads, Strava, Facebook, and
so on.</p>
<p>In January, I decided to dedicate more time to using Twitter. I started tweeting
regularly and started following some of the people pretty involved in the
programming community. I quickly realized that Twitter was a great source for
new and emerging technology as well as just general news.</p>
<p>After Twitter, a few more social sites followed. I created a Google+ profile
even though the majority of my friends use Facebook. I also set up a LinkedIn
profile which was arguably the most important social network that I wasn’t a
part of.</p>
<p>To see all of my profiles, check out my <a href="/about/">About</a> page.</p>
<h2 id="writings">Writings</h2>
<p><a href="http://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Edsger W. Dijkstra</a> is possibly one of my favorite Computer Scientists.
His work has been completely pervasive in the field and has influenced many
things. One of his most cherished habits was in creating amazing articles,
called EWDs (for his initials), written in a fountain pen on a subject that
interested him. He decided to start doing this because he suffered from writer’s
block for over a year and discovered that if he writes just for himself, his
writing just flowed. The University of Texas has since published over 1300 EWDs
in an <a href="http://www.cs.utexas.edu/users/EWD/">online archive</a>.</p>
<p>I’ve thought about Dijkstra a lot. I really liked his idea of writing just for
himself. I’ve kept numerous journals over the past few years and that’s always
what motivated me to continue writing in them. I’ve just never had the
motivation to share those writings with others.</p>
<p>I plan on changing all of that by making blogging a habit. My blog is probably
going to <a href="http://vimeo.com/24715531">suck at first</a> but hopefully in a few years my ability will be
quite refined. I’m going to set a strict minimum of two posts a month. I plan on
exploring some things that interest me and already have a list of topics that I
wish to write about.</p>
<h2 id="final-thoughts">Final Thoughts</h2>
<p>I was very clearly wrong in thinking that social networks were a waste of time.
I was also very wrong in thinking that if I just focused on my studies, I could
still create opportunities for myself. I’m just glad I’ve realized this before I
graduate from college next year.</p>
<p>I’d encourage everyone to start making an online presence as soon as possible
even if you aren’t in the tech industry. If you are in the tech industry, there
is nothing better that you can do with your time than invest in creating a
blog/website. Like Nathan says, the return on investment is one of the highest
things you can do.</p>