<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom"><title>Alex R. Young</title><link href="http://alexyoung.org/feed.xml" rel="self"></link><link href="http://alexyoung.org"></link><updated>2012-01-15T00:01:00Z</updated><id>http://alexyoung.org</id><author><name>Alex R. Young</name></author><entry><title>A vim-friendly Mac Keyboard</title><link href="http://alexyoung.org/2012/01/15/vim-keyboard"></link><updated>2012-01-15T00:01:00Z</updated><id>http://alexyoung.org/2012/01/15/vim-keyboard</id><content type="html">&lt;p&gt;I suspect the ultimate vim keyboard is the &lt;a href="http://elitekeyboards.com/products.php?sub=pfu_keyboards,hhkbpro2&amp;amp;pid=pdkb400b"&gt;Happy Hacking Professional 2&lt;/a&gt;.  The &lt;code&gt;Control&lt;/code&gt; key placement is good for vim, tmux, and screen, and the removal of uncessary arrow and function keys appeals to me.  However, it's $300, so I wondered if it's possible to hack the keyboard I already own into being a little bit more vim-friendly.&lt;/p&gt;

&lt;h3&gt;Swapping Modifier Keys&lt;/h3&gt;

&lt;p&gt;The position of &lt;code&gt;Control&lt;/code&gt; sucks.  Fortunately, Apple gives us the ability to swap modifier keys around with no hacking at all.&lt;/p&gt;

&lt;p&gt;Under System Preferences, Keyboard, Modifier Keys..., the &lt;code&gt;Control&lt;/code&gt; and &lt;code&gt;Caps Lock&lt;/code&gt; keys can be switched:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/mac_modifier_keys.png" alt="Mac keyboard settings" title="" /&gt;&lt;/p&gt;

&lt;p&gt;It only took me a few days to get used to this, and it works well for those of us who type &lt;code&gt;Control&lt;/code&gt; a million times more often than &lt;code&gt;Caps Lock&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Use hjkl Instead of Arrows&lt;/h3&gt;

&lt;p&gt;&lt;img src="/images/hjkl_mac.png" alt="hjkl hacking" title="" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://pqrs.org/macosx/keyremap4macbook/index.html"&gt;KeyRemap4Macbook&lt;/a&gt; allows any key to be remapped, and key repeats to be accelerated.  Of interest to us is the 'Vi mode' setting list, and 'Ubiquitous Vim Bindings'.  I selected 'Fn+hjkl to Left/Down/Up/Right' so I can use &lt;code&gt;hjkl&lt;/code&gt; to move in any application.&lt;/p&gt;

&lt;p&gt;KeyRemap4Macbook requires a reboot after installation, but once it's running the settings can be changed and experimented with at any time.&lt;/p&gt;</content></entry><entry><title>Using Powerline with Mac OS</title><link href="http://alexyoung.org/2012/01/13/using-powerline-with-mac-os"></link><updated>2012-01-13T00:01:00Z</updated><id>http://alexyoung.org/2012/01/13/using-powerline-with-mac-os</id><content type="html">&lt;p&gt;&lt;img src="/images/vim-powerline.png" alt="Powerline, Mac OS Style" title="" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Lokaltog/vim-powerline"&gt;vim-powerline&lt;/a&gt; by Kim Silkebækken is a great plugin, but it's a little bit tricky to get it looking right in Mac OS.  I've tested it in both Snow Leopard and Lion and figured out how to get it working nicely.&lt;/p&gt;

&lt;p&gt;Snow Leopard's Terminal application doesn't support 256 colours, so I started using &lt;a href="http://www.iterm2.com/"&gt;iTerm2&lt;/a&gt; instead.  With a little bit of configuration it's functionality equivalent to Terminal, and offers tonnes of extras.  Lion's Terminal is fine.  Both need to report &lt;code&gt;xterm-256color&lt;/code&gt;, so ensure this is set up in the Preferences pane.
To get the cool UTF-8 fonts you'll need patched fonts.  Nick Quaranto posted some suitable fonts here: &lt;a href="https://gist.github.com/1595572"&gt;vim-powerline patched fonts&lt;/a&gt;.  I like "Menlo" myself.&lt;/p&gt;

&lt;p&gt;Next, read the Powerline documentation.  When the author says &lt;code&gt;set nocompatible&lt;/code&gt; and &lt;code&gt;set laststatus=2&lt;/code&gt; are required he means it, so add those to &lt;code&gt;~/.vimrc&lt;/code&gt;.  I also had to add &lt;code&gt;set t_Co=256&lt;/code&gt; and &lt;code&gt;let g:Powerline_symbols = 'unicode'&lt;/code&gt; (Kim notes that setting it to &lt;code&gt;fancy&lt;/code&gt; will work as well, and make better use of the patched fonts).&lt;/p&gt;

&lt;p&gt;Changing &lt;code&gt;Powerline_symbols&lt;/code&gt; requires the cache to be cleared, so &lt;code&gt;rm /tmp/Powerline.cache&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now your vim should look like Kim's screenshots in the Powerline repository.&lt;/p&gt;</content></entry><entry><title>Build an IDE with tmux and vim</title><link href="http://alexyoung.org/2011/12/19/build-an-ide-with-tmux-and-vim"></link><updated>2011-12-19T00:12:00Z</updated><id>http://alexyoung.org/2011/12/19/build-an-ide-with-tmux-and-vim</id><content type="html">&lt;p&gt;&lt;img src="/images/vimtmux.png" alt="Screenshot of vim and tmux" title="" /&gt;&lt;/p&gt;

&lt;p&gt;A friend of mine had visited an office where the employees used tmux and vim to edit Ruby projects.  He wanted to know why people would work with the console version of vim, considering the loss of the convenience of mouse input.&lt;/p&gt;

&lt;p&gt;I actually find this a good way to work, for several reasons.  Originally, using console vim forced me to learn vim's motion commands properly.  Combined with touch typing, this opened up a range of powerful ways to jump around files and lines arguably more efficiently than by using a mouse.&lt;/p&gt;

&lt;p&gt;I like to tile terminals alongside my editor.  My web development work usually requires a console for issuing ad-hoc commands, a database console, and a log viewer.  Some of my projects have test suites that run automatically when files change, so I like to be able to see the status of my tests as well.&lt;/p&gt;

&lt;p&gt;There are vim plugins that provide integration with these things, but I feel more comfortable with the vim/tmux combination.  I think it's a visualisation thing.&lt;/p&gt;

&lt;p&gt;By using command-line tools this way, we're effectively building a customised, lightweight IDE.  I also find the idea of using Unix commands in my spare tmux console panes appealing, because it's easy to pipe commands together thereby performing complex scriptable operations without the bloat of an IDE.&lt;/p&gt;

&lt;p&gt;The difference between this approach and a traditional IDE is this interface adapts around my &lt;em&gt;current task&lt;/em&gt;, and is only limited by the thousands of commands and scripting languages that I have installed.  Rather than creating a template of some kind, I create tmux panes and vim split windows as required.  Despite Eclipse and Xcode offering task-focused interfaces, I still feel like they get in the way too much.  Particularly in Xcode, where keyboard shortcuts feel like an afterthought, and my hand is consistently on the mouse.&lt;/p&gt;

&lt;p&gt;Task switching is another benefit.  I'm a freelancer, so in a typical working day I may switch between three or four projects.  By using tmux, I can detach from a session and come back later, keeping me focused on the current task at hand.  I think this is really an advantage of console vim over GUI vim and a collection of terminals, because Eclipse and Xcode attempt to save interface state when closing a project (although the latest Xcode seems to close my split panes all the time).&lt;/p&gt;

&lt;h3&gt;Why People Use &lt;code&gt;hjkl&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;It may seem needlessly awkward or elitist to some, but if you can touch type relatively correctly, vim and tmux (set to using vim's keys) make it easier to keep fingers on home row and off the mouse.&lt;/p&gt;

&lt;p&gt;That's the secret of &lt;code&gt;hjkl&lt;/code&gt; -- people who like it generally touch type correctly.  For those unaccustomed to these keys, try taking it slowly for a few days.  Type deliberately and methodically, making full use of the little fingers.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;hjkl&lt;/code&gt; argument reminds me of trying to convince novice PC gamers to learn &lt;code&gt;wasd&lt;/code&gt; over the arrow keys.  At first &lt;code&gt;wasd&lt;/code&gt; feels less intuitive, but it makes using the keyboard and mouse &lt;em&gt;together&lt;/em&gt; a lot easier.  The advantage becomes apparent when actually trying the alternative in earnest.&lt;/p&gt;

&lt;h3&gt;Configuration Tips&lt;/h3&gt;

&lt;p&gt;I use this in my &lt;code&gt;.tmux.conf&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="prettyprint lang-text"&gt;
set-window-option -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
&lt;/pre&gt;

&lt;p&gt;This allows me to move around tmux using vim's movement keys.&lt;/p&gt;

&lt;p&gt;If you're struggling to get used to vim's movement keys, try disabling arrow keys for insert mode: &lt;a href="http://jeetworks.org/node/89"&gt;Vim: Making those Arrow Keys Work With You&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're new to vim, it's also worth remembering that it supports ctags.  The &lt;a href="https://github.com/abudden/TagHighlight"&gt;TagHighlight&lt;/a&gt; plugin can dynamically display a panel of tags in a pane for the current buffer.  This is yet another IDE-like feature.&lt;/p&gt;

&lt;h3&gt;Dotfiles&lt;/h3&gt;

&lt;p&gt;Does your IDE's configuration sync between multiple computers?&lt;/p&gt;

&lt;p&gt;I have a private git repository called &lt;code&gt;dotfiles&lt;/code&gt; that has my vim and ctags configuration and plugins.  I wrote a little install script to automatically symbolically link configuration files with the files in my local &lt;code&gt;dotfiles&lt;/code&gt; repository.  When I get a new computer, one of the first things I do is to check out this repository.  When I start editing a project, vim and tmux behave exactly as expected.&lt;/p&gt;

&lt;h3&gt;Copy and Paste&lt;/h3&gt;

&lt;p&gt;I usually copy and paste console output into vim by using tmux's copy and paste commands.  Depending on how tmux is configured, the exact keyboard shortcuts may vary, so it's worth reading &lt;code&gt;man tmux&lt;/code&gt; about how this works.  The default should be &lt;code&gt;ctrl-b [&lt;/code&gt; to enter copy mode, &lt;code&gt;Space&lt;/code&gt; to start making a selection, &lt;code&gt;Enter&lt;/code&gt; to copy the selection, then &lt;code&gt;ctrl-b ]&lt;/code&gt; to paste.&lt;/p&gt;

&lt;h3&gt;Motion Commands&lt;/h3&gt;

&lt;p&gt;To really get efficient with vim, try to always question when a keyboard-heavy operation could have been better served by using the appropriate motion commands.  For example, when I first saw &lt;code&gt;~&lt;/code&gt; (swap case) I thought "that's cute, I'm never going to use that".  I've actually used it three times while editing this post.&lt;/p&gt;

&lt;p&gt;I started to get the hang of motion commands when I noticed more experienced vim users avoid going into insert mode unless necessary.  Keep coming back to vim's help, and you'll be surprised how many ways there are to improve your editing skills.&lt;/p&gt;</content></entry><entry><title>iOS 5 Redemption: ARC, UIAppearance, Blocks</title><link href="http://alexyoung.org/2011/12/07/ios-5-redemption"></link><updated>2011-12-07T00:12:00Z</updated><id>http://alexyoung.org/2011/12/07/ios-5-redemption</id><content type="html">&lt;p&gt;iOS 5 redeems iOS development in my eyes through several new features.  There are Objective-C changes, but also new APIs that make common tasks a lot easier.  When Apple released the new SDK, I created a blank project to see what fundamental project organisation changes had been made, and the only major thing I noticed was the addition of Storyboards.&lt;/p&gt;

&lt;p&gt;Unfortunately, Storyboards are not compatible with iOS 4.  It may be possible to create a fork of a project with iOS 4 support that has a different UI, or to somehow conditionally use Storyboards.  However, we all know how much hand-coded interface development is required for real iOS projects, so I can't see myself using Storyboards.&lt;/p&gt;

&lt;h3&gt;Automatic Reference Counting&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need explicitly insert retains and releases. It does not provide a cycle collector; users must explicitly manage lifetime instead.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;From&lt;/em&gt;: &lt;a href="http://clang.llvm.org/docs/AutomaticReferenceCounting.html"&gt;LLVM: Automatic Reference Counting&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When friends tell me they're learning iOS development, the first thing I find myself helping them with is memory management.  Learning where to use &lt;code&gt;retain&lt;/code&gt;, &lt;code&gt;release&lt;/code&gt;, and &lt;code&gt;autorelease&lt;/code&gt; isn't too difficult, but it's sometimes hard for people to realise it's a convention rather than something the compiler will automatically help with.  That has now all changed with Automatic Reference Counting (ARC).&lt;/p&gt;

&lt;p&gt;ARC is a build setting, and once it's enabled properties get new keywords and the compiler will raise errors where the old memory management keywords are used unexpectedly.  Now we can &lt;code&gt;alloc&lt;/code&gt; and initialize objects without worrying about releasing them.  If you work with pure Objective-C (no C data structures) then this is easy and cuts down a lot of code.  It feels &lt;em&gt;wrong&lt;/em&gt; at first, but after a while it's completely natural.&lt;/p&gt;

&lt;p&gt;Be sure to study the notes in &lt;a href="http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_7.html"&gt;What's New In Mac OS X: Automatic Reference Counting&lt;/a&gt; because it's not quite as simple as throwing away all &lt;code&gt;retain&lt;/code&gt; and &lt;code&gt;release&lt;/code&gt; keywords.  &lt;a href="http://www.learn-cocos2d.com/2011/11/everything-know-about-arc/"&gt;Everything you need to know about automatic reference counting&lt;/a&gt; is also a thorough post on the topic.&lt;/p&gt;

&lt;p&gt;In terms of accessibility, ARC makes iOS a lot easier for new developers.&lt;/p&gt;

&lt;h3&gt;&lt;code&gt;UIAppearance&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;I've always struggled with meeting client expectations in terms of application appearance.  Apple's iOS apps tend to have intricately themed interfaces, and while the default widgets and colours are adequate, corporate branding soon rears its ugly head and forces me to write lots of custom UI code.&lt;/p&gt;

&lt;p&gt;The first tool in my application skinning arsenal was &lt;code&gt;stretchableImageWithLeftCapWidth:topCapHeight:&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="prettyprint lang-objective-c"&gt;
UIImage *buttonImage = [[UIImage imageNamed:@"button.png"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
&lt;/pre&gt;

&lt;p&gt;This makes it possible to create buttons with gradients, shadows, and rounded corners -- anything you can put in a PNG.  &lt;a href="http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/"&gt;iDev Recipes: Stretchable Images and Buttons&lt;/a&gt; is a good post on this because it includes a diagram showing how images get stretched.&lt;/p&gt;

&lt;p&gt;Skinning buttons isn't enough for most clients.  I think every freelance client I've had has demanded a background image in a &lt;code&gt;UIToolbar&lt;/code&gt;.  Not just a tint, but an image.  I typically subclasses &lt;code&gt;UIToolbar&lt;/code&gt; and change &lt;code&gt;drawRect&lt;/code&gt; to draw an image.  This solution goes against the general wisdom that, if possible, subclassing API classes should be avoided in Objective-C.  Incidentally, there's an interesting on Stack Overflow about this very topic: &lt;a href="http://stackoverflow.com/questions/844199/is-subclassing-in-objective-c-a-bad-practice"&gt;Is subclassing in Objective-C a bad practice?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We now have an adequate solution for application-wide skinning through the &lt;code&gt;UIAppearance&lt;/code&gt; protocol.  It's now possible to skin an entire app with very little code:&lt;/p&gt;

&lt;pre class="prettyprint lang-objective-c"&gt;
UIImage *navBarImage = [UIImage imageNamed:@"images/menubar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage
                                   forBarMetrics:UIBarMetricsDefault];

UIImage *barButton = [UIImage imageNamed:@"images/barbutton.png"];
[[UIBarButtonItem appearance] setBackgroundImage:barButton
                                        forState:UIControlStateNormal
                                      barMetrics:UIBarMetricsDefault];

UIImage *backButton = [UIImage imageNamed:@"images/back.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton
                                                  forState:UIControlStateNormal
                                                barMetrics:UIBarMetricsDefault];

UIImage *tabBarBackground = [UIImage imageNamed:@"images/tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"images/selection-tab.png"]];
&lt;/pre&gt;

&lt;p&gt;Given suitable high quality 24bit PNGs with subtle shadows and textures, your app will now blow your client's mind.&lt;/p&gt;

&lt;h3&gt;Blocks&lt;/h3&gt;

&lt;p&gt;At first I thought blocks were pretty needless, because after years of working with asynchronous APIs in Objective-C I'm comfortable with delegates.  After using blocks in a project I'm now a convert.  I actually write a lot of JavaScript, so I'm a master manipulator of closures, and I feel like some of the same code organisation techniques transition to Objective-C.&lt;/p&gt;

&lt;p&gt;What convinced me was actually something unexpected: &lt;a href="http://parse.com"&gt;Parse&lt;/a&gt;.  Parse is a service aimed at mobile developers that provides a backend that can be used to sync user data.  It can handle user registration, password resets, and arbitrary structured data and files.  While iCloud is great, Parse allows us to sync our data across iOS and Android, and potentially more platforms in the future --  all without having to write a web app.&lt;/p&gt;

&lt;p&gt;Parse's code samples have a button for displaying code that uses blocks or callbacks.  This is an example of block-based code:&lt;/p&gt;

&lt;pre class="prettyprint lang-objective-c"&gt;
[PFUser logInWithUsernameInBackground:@"myname" password:@"mypass"
  block:^(PFUser *user, NSError *error) {
    if (user) {
        // do stuff after successful login.
    } else {
        // the username or password is invalid.
    }
}];
&lt;/pre&gt;

&lt;p&gt;Once the reader understands the block syntax, this code is immediately understandable.  Contrast this to the callback-based code:&lt;/p&gt;

&lt;pre class="prettyprint lang-objective-c"&gt;
// First set up a callback.
- (void)handleUserLogin:(PFUser *)user error:(NSError **)error {
    if(user) {
        // do stuff after successful login.
    } else {
        // the username or password is invalid. 
    }
}

// Then, elsewhere in your code...
[PFUser logInWithUsernameInBackground:@"myname" 
                             password:@"mypass" 
                           withTarget:self
                             selector:@selector(handleUserLogin:error:)];
&lt;/pre&gt;

&lt;p&gt;As Objective-C developers we know the second part of this code is in another method, and that's the key.  Blocks keep related code together.  As long as your block isn't too large, this is easier to follow and therefore potentially easier to maintain.&lt;/p&gt;

&lt;p&gt;Blocks are largely intuitive, but &lt;code&gt;__block&lt;/code&gt; is a syntactical wrinkle that's worth learning properly.  Apple's &lt;a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW1"&gt;Blocks and Variables&lt;/a&gt; documentation covers this, but I also found &lt;a href="http://thirdcog.eu/pwcblocks/#objcblocks"&gt;Programming with C Blocks on Apple Devices&lt;/a&gt; useful as well.&lt;/p&gt;

&lt;p&gt;All three of these of these features make iOS development more accessible to newcomers, so if you've been putting off iOS development, now would be a good time to jump aboard.&lt;/p&gt;</content></entry><entry><title>Changing APIs and Package Managers</title><link href="http://alexyoung.org/2011/10/14/api-design"></link><updated>2011-10-14T01:10:00Z</updated><id>http://alexyoung.org/2011/10/14/api-design</id><content type="html">&lt;p&gt;When I started programming there was a real &amp;#8216;if it ain&amp;#8217;t broke&amp;#8230;&amp;#8217; mentality.  At least, I think there was &amp;#8212; this was in the 90s and I connected to the community through magazines, computer shops, and public domain disks (that&amp;#8217;s disks with a &amp;#8216;k&amp;#8217;, as in floppy diskettes).  I learned a lot of BASIC derivatives from magazines, and eventually picked up some books on C.  Then I heard about K&amp;R C at university and flipped through a copy at the library.  I think one of my friends bought a copy, and I was envious because I couldn&amp;#8217;t afford it at the time.&lt;/p&gt;
&lt;p&gt;Then later on I started playing with Ruby, and there seemed to be a huge amount of experimentation and creativity within the community.  I dimly recall trying to work my way through Japanese documentation and giving up, but I came back to it a few years later when a lot of English&amp;#8211;speaking developers had jumped aboard.  The creativity in the Ruby community seemed to solidify when _why became well known and cartoon foxes and meta&amp;#8211;programming were everywhere.&lt;/p&gt;
&lt;p&gt;Then I started working with Rails, and there was a new mentality of constantly refining and changing things, sometimes based purely on aesthetic preferences, but other times to genuinely improve APIs and libraries.&lt;/p&gt;
&lt;p&gt;In contrast to this, I&amp;#8217;ve dabbled with Objective&amp;#8211;C over the years and got paid to write several iPhone apps.  I started taking Objective&amp;#8211;C seriously partly because the iPhone was such a phenomenon, but also because I like C&amp;#8211;like languages.  Apple&amp;#8217;s APIs don&amp;#8217;t change fundamentally, perhaps because they were based on solid principles established by engineers at NeXT in the 80s and 90s.  I&amp;#8217;ve found I&amp;#8217;m extremely happy writing code with events in Objective&amp;#8211;C, and data storage is trivial thanks to Core Data.&lt;/p&gt;
&lt;p&gt;Meanwhile, I&amp;#8217;ve enjoyed building Node apps because I like event&amp;#8211;based code, and JavaScript&amp;#8217;s first class functions suit me as a Lisp hobbyist who never gets paid to write Lisp.  Another reason I enjoy Node is npm&amp;#8217;s move away from system&amp;#8211;wide library installation, which makes dependency management easy.&lt;/p&gt;
&lt;p&gt;Node&amp;#8217;s core developers and prominent library and framework authors seem to be acutely aware of how frustrating API changes are.  In some ways JavaScript and Objective&amp;#8211;C seem to inspire a smaller range of API designs than Ruby &amp;#8212; Ruby libraries will come with anything from a DSL to a simple object that can be called with public methods.  JavaScript library APIs are usually designed around simple objects or chaining, and Objective&amp;#8211;C APIs use a range of design patterns, Apple&amp;#8217;s APIs in particular are focused around patterns that suit GUI development.&lt;/p&gt;
&lt;p&gt;It can be frustrating to work with Rails when API changes create unexpected problems.  The Ruby community has always had a culture of testing, which fits a dynamic language.  Tests are generally part of the development process, so code can be updated to reflect API changes with a manageable cost in terms of additional testing and time.&lt;/p&gt;
&lt;p&gt;API changes can be mitigated by locking down every library to a specific version.  That means mastering a language&amp;#8217;s package manager is now a core skill, rather than something that can be picked up on the job.  It&amp;#8217;s equivalent to the build process in a compiled language.  Don&amp;#8217;t write your &lt;code&gt;Gemfile&lt;/code&gt; or &lt;code&gt;package.json&lt;/code&gt; without putting serious thought into how library versions should be locked down.  Certain contexts and libraries can generally be on the bleeding edge, others should be locked to a specific version.  Also learn the features of your package manager -- I wouldn't like to develop npm modules without knowing about &lt;code&gt;npm link&lt;/code&gt;.&lt;/p&gt;
</content></entry><entry><title>Google+, Privacy and Engineering Consent</title><link href="http://alexyoung.org/2011/09/04/google"></link><updated>2011-09-04T01:09:00Z</updated><id>http://alexyoung.org/2011/09/04/google</id><content type="html">&lt;p&gt;At dConstruct 2011, Don Norman gave a talk entitled &lt;a href="http://2011.dconstruct.org/conference/don-norman"&gt;Emotional Design for the World of Objects&lt;/a&gt; in which he said Google&amp;#8217;s main product is &lt;em&gt;us&lt;/em&gt; and the service they sell is advertising.  The services Google make aren't just a way of getting eyes on adverts, but a way of gathering information about us to improve advertisement targeting.  If this is true, where is the evidence?  And what does it mean for social products like Google+?&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s now possible to &lt;a href="http://googlesystem.blogspot.com/2010/08/google-multiple-sign-in-now-available.html"&gt;link Google accounts together&lt;/a&gt;, which can make the awkward necessity of using several Google accounts more manageable.  I have Google Apps accounts for work and personal use, as well as an obligatory Gmail account for services the Apps accounts can&amp;#8217;t yet access.  I&amp;#8217;ve linked these together to make it easier to switch between them.  Does this mean I&amp;#8217;m now represented as one person internally within Google?&lt;/p&gt;
&lt;p&gt;Google&amp;#8217;s &lt;a href="http://www.google.com/intl/en/privacy/privacy-policy.html"&gt;Privacy Policy&lt;/a&gt; seems to indicate that this could be possible:&lt;/p&gt;
&lt;blockquote&gt;We may combine the information you submit under your account with information from other Google services or third parties in order to provide you with a better experience and to improve the quality of our services.&lt;/blockquote&gt;
&lt;p&gt;This doesn&amp;#8217;t specifically mention linking data between accounts, but implies information may be shared between services.  There&amp;#8217;s actually a page called &lt;a href="http://www.google.com/ads/preferences/"&gt;Ads Preferences&lt;/a&gt; that shows what Google&amp;#8217;s advertising knows about you, based on an anonymous cookie.  According to the &lt;a href="http://www.google.com/privacy/ads/"&gt;associated documentation&lt;/a&gt; consent is required before collecting personally identifying information:&lt;/p&gt;
&lt;blockquote&gt;We will not collect, sell, or share personally identifying information from ad serving cookies without your explicit consent.&lt;/blockquote&gt;
&lt;p&gt;This is interesting, because &amp;#8220;explicit consent&amp;#8221; in our field is something more malleable than it sounds.  What it amounts to is agreeing to terms and conditions, which people do on a daily basis without having to read or understand.  It&amp;#8217;s entirely possible that I&amp;#8217;ve already &lt;em&gt;explicitly&lt;/em&gt; agreed to linking my personal information with Google's anonymous advertising cookies without even realising it.&lt;/p&gt;
&lt;p&gt;This brings to mind two things: &lt;a href="http://en.wikipedia.org/wiki/Manufacturing_Consent"&gt;The Engineering of Consent&lt;/a&gt; and subsequently &lt;a href="http://en.wikipedia.org/wiki/Manufacturing_Consent"&gt;Manufacturing Consent&lt;/a&gt; by Edward S. Herman and Noam Chomsky, and &lt;a href="http://www.newscientist.com/article/mg21128225.800-internet-activist-the-dark-side-of-web-personalisation.html"&gt;Eli Pariser&amp;#8217;s filter bubble&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thefilterbubble.com/"&gt;The Filter Bubble&lt;/a&gt; is an ongoing argument against personalisation through technologies like Google&amp;#8217;s advertising profiling:&lt;/p&gt;
&lt;blockquote lang="..."&gt;Increasingly we don&amp;#8217;t all see the same internet. We see stories and facts that make it through a membrane of personalised algorithms that surround us [&amp;#8230;] The filter bubble is the personal, unique universe of information that results and that we increasingly live in online.&lt;/blockquote&gt;
&lt;p&gt;Digesting all of these ideas around online advertising and privacy ethics finally leads me to this: &lt;a href="http://www.google.com/support/+/bin/answer.py?answer=1228271"&gt;Your name and Google+ Profiles&lt;/a&gt;.  Google+ demands real names, and accounts have been deleted for using names other than the name on your birth certificate, driving license, and passport.  If Google wanted to be in a position to clearly build accurate profiles of people, account linking and real names would be the way to do it.&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://2011.dconstruct.org/conference/don-norman"&gt;Emotional Design for the World of Objects&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.privacysense.net/different-types-consent/"&gt;Explicit Consent, PrivacySense.net&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.google.com/support/+/bin/answer.py?answer=1228271"&gt;Your name and Google+ Profiles&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.thefilterbubble.com/"&gt;The Filter Bubble&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Manufacturing_Consent"&gt;Manufacturing Consent: The Political Economy of the Mass Media&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/The_Engineering_of_Consent"&gt;The Engineering of Consent by Edward Bernays&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.bbc.co.uk/news/technology-12668552"&gt;New net rules set to make cookies crumble&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.newscientist.com/article/mg21128225.800-internet-activist-the-dark-side-of-web-personalisation.html"&gt;Internet activist: The dark side of web personalisation&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.google.com/privacy/ads/"&gt;Google Privacy Center: Advertising and Privacy&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.google.com/intl/en/privacy/privacy-policy.html"&gt;Google Privacy Policy&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://googlesystem.blogspot.com/2010/08/google-multiple-sign-in-now-available.html"&gt;Google Multiple Sign-in&lt;/a&gt;</content></entry><entry><title>Designing for Password Managers</title><link href="http://alexyoung.org/2011/08/15/passwords"></link><updated>2011-08-15T01:08:00Z</updated><id>http://alexyoung.org/2011/08/15/passwords</id><content type="html">&lt;blockquote&gt;
  &lt;p&gt;1Password works so well because it isn't just a security product, but it changes the way we deal with with website logins. That is, we do things more securely and more easily when 1Password is around.&lt;span class="source"&gt;- &lt;a href="http://blog.agilebits.com/2011/04/looking-ahead-in-security/"&gt;Looking ahead in security&lt;/a&gt;, AgileBits&lt;/source&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I currently have 258 unique passwords.  I'm not addicted to creating accounts on web services; I have multiple identities as a result of separating personal and professional concerns.  Memorising 200+ unique passwords is never going to happen, so naturally I use a password manager.&lt;/p&gt;

&lt;p&gt;Password managers are &lt;a href="http://blog.lastpass.com/2011/05/lastpass-security-notification.html"&gt;probably best kept offline&lt;/a&gt; but they basically all work the same way -- there's some form of local application that integrates with browsers through plugins or the operating system's built-in password management framework.  That means password managers generally associate web form fields with credentials.&lt;/p&gt;

&lt;p&gt;Using such a high number of accounts quickly reveals the vast differences in form design, and they don't all work well with password managers.  For example, Google Apps email has a form specific to the email domain -- it uses "username" but elsewhere Google's forms use "username@domain.com".  Should the password manager be designed to cope with this, or should Google simply use a consistent form design?&lt;/p&gt;

&lt;p&gt;Some sign in forms contain fields that appear multiple times on the page.  Using &lt;a href="http://agilebits.com/products/1Password"&gt;1Password&lt;/a&gt; to log in could leak the sign in username to the registration form.  I've always wondered if this is a potential security issue, but regardless, should pages be designed this way?&lt;/p&gt;

&lt;p&gt;I've also found sites that include server-side generated random field names so it's extremely difficult to use my password manager at all.  I end up copy and pasting the credentials manually.  This has led me to research whether it's possible for browser plugins to silently access the contents of the paste buffer and extract plain-text passwords.&lt;/p&gt;

&lt;p&gt;Not to mention banks.  Is it more secure to ask me for parts of my password, or let me use my password manager with a high-entropy password that I can easily change regularly?&lt;/p&gt;

&lt;p&gt;Password managers also detect when an account has been created or signed into for the first time.  Is it practical to support this directly?  I've often looked at new accounts in my password manager and found a mess of fields that aren't actually authentication credentials.&lt;/p&gt;

&lt;h3&gt;Checklist&lt;/h3&gt;

&lt;p&gt;The next time I design a log in form, I'm going to follow a checklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure the field names are commonly used ones: username, email, password&lt;/li&gt;
&lt;li&gt;Use these field names consistently&lt;/li&gt;
&lt;li&gt;Keep the registration form on another page&lt;/li&gt;
&lt;li&gt;Make sure the sign in form is consistent across all entry points&lt;/li&gt;
&lt;li&gt;Test registration and sign in with popular password managers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As designers we need to cater for password managers.  &lt;a href="http://www.lightbluetouchpaper.org/2011/08/12/pico-no-more-passwords-at-usenix-security/"&gt;Hopefully something better will come along&lt;/a&gt;, but until then we're in the era of post-human password management (that doesn't mean passwords managed by super-advanced human entities, it just means nobody can be expected to do it properly anymore).&lt;/p&gt;

&lt;p&gt;Perhaps conversely password managers should cater for us?  AgileBits could publish a set of guidelines for designers that demonstrate both best practices for authentication forms and also what works well with their product.&lt;/p&gt;</content></entry><entry><title>Lessons From Two Lightweight Markup Parsers</title><link href="http://alexyoung.org/2011/08/01/lightweight-markup"></link><updated>2011-08-01T01:08:00Z</updated><id>http://alexyoung.org/2011/08/01/lightweight-markup</id><content type="html">&lt;h3&gt;stextile&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://github.com/alexyoung/stextile"&gt;stextile&lt;/a&gt; (License: &lt;em&gt;MIT&lt;/em&gt;, npm: &lt;em&gt;stextile&lt;/em&gt;) is a &lt;a href="http://www.textism.com/tools/textile/"&gt;Textile&lt;/a&gt; parser for JavaScript.  The lack of a good Textile implementation held me back from developing &lt;a href="http://popjs.com/"&gt;Pop&lt;/a&gt;.  While researching the project I found some amazing Textile implementations.  Possibly my favourite is &lt;a href="http://redcloth.org/"&gt;RedCloth&lt;/a&gt;, which I remember from back when _why rewrote it with &lt;a href="http://www.complang.org/ragel/"&gt;Ragel&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As I was desperate for something that would parse my articles, I created a straightforward parser using regular expressions.  I wrote tests as I went so it wasn&amp;#8217;t too painful.&lt;/p&gt;
&lt;p&gt;This project made me aware of a few interesting uses of &lt;code&gt;replace&lt;/code&gt; in JavaScript that I hadn't really thought about before.&lt;/p&gt;
&lt;p&gt;Early versions of stextile used callbacks with &lt;code&gt;replace&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="prettyprint lang-javascript"&gt;
string.replace(/expression/, function(match) {
  return match; // Alter the match in some way then return it
});
&lt;/pre&gt;
&lt;p&gt;This form is extremely useful when additional operations are required before replacing values.&lt;/p&gt;
&lt;p&gt;I settled on this pattern for replacing links:&lt;/p&gt;
&lt;pre class="prettyprint lang-javascript"&gt;
var re = /expression/
  , m
  , result;

while ((m = re.exec(text)) !== null) {
  // Process each link
}
&lt;/pre&gt;
&lt;p&gt;This is ideal for conditional matching and replacement.  Iterating over each result until every item has been matched makes it easier to deal with things like turning off matching inside pre&amp;#8211;formatted tags.&lt;/p&gt;
&lt;h3&gt;Jadedown&lt;/h3&gt;
&lt;p&gt;I made &lt;a href="https://github.com/alexyoung/jadedown"&gt;Jadedown&lt;/a&gt; (License: &lt;em&gt;MIT&lt;/em&gt;, npm: &lt;em&gt;jadedown&lt;/em&gt;) purely for fun.  I was desperately trying to learn Bison, Flex, and &lt;a href="http://zaach.github.com/jison/"&gt;Jison&lt;/a&gt; to build a better Textile parser, but then I realised I never really liked the syntax anyway.  I&amp;#8217;m increasingly using &lt;a href="http://jade-lang.com/"&gt;Jade&lt;/a&gt; for open source and commercial work, so I thought it would be interesting to reuse the selector&amp;#8211;based syntax for a lightweight markup language.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://daringfireball.net/projects/markdown/"&gt;Markdown&lt;/a&gt; makes certain things very convenient for programmers: raw files read like simple text files, code tags can be inserted with backticks; and the syntax is consistent and easy to parse.&lt;/p&gt;
&lt;p&gt;To understand what I mean by &lt;em&gt;easy to parse&lt;/em&gt;, consider this Textile markup:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
"Markdown":http://daringfireball.net/projects/markdown/ is clean and easy to learn.

"Jadedown":https://github.com/alexyoung/jadedown, although versatile, is currently purely experimental.

It's worth learning "Jade":http://jade-lang.com/.
&lt;/pre&gt;
&lt;p&gt;A simple regular expression is all that&amp;#8217;s required for the first example.  Things start to get harder when a comma or full stop follows the link.  Markdown makes the author&amp;#8217;s intent much clearer by surrounding the link text and URL with brackets &amp;#8212; a bonus is these brackets don&amp;#8217;t usually occur in links.&lt;/p&gt;
&lt;h4&gt;Generic Tags&lt;/h4&gt;
&lt;p&gt;I believe lightweight markup languages should offer a convenient, but generic, tag representation.  By using Jade&amp;#8217;s syntax, I came up with this:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
This is some a(href="https://github.com/alexyoung/jadedown")[Jadedown], it's easy to learn and parse!
&lt;/pre&gt;
&lt;p&gt;Tags take the form &lt;code&gt;tagName#id.class1.class2(attributes)[innerHTML]&lt;/code&gt;.  In a sense it's how tags look from a JavaScript developer's perspective.&lt;/p&gt;
&lt;h4&gt;Shorthand&lt;/h4&gt;
&lt;p&gt;Of course, I use links and a few other bits of markup all the time, so I introduced a handful of useful shorthand operators.  Links can be written in the form &lt;code&gt;(http://example.com)[Example 1]&lt;/code&gt;, asterisks and underscores can use used for strong and em, starting a line with an asterisk or hash will generate a list; and backticks are used for code.&lt;/p&gt;
&lt;p&gt;Like Jade, starting a line with a recognised tag makes a block&amp;#8211;level element.  This part of the parser is currently the most underdeveloped.  I&amp;#8217;d like to add whitespace indentation for code like Markdown, but I haven&amp;#8217;t considered the implications of combining that with Jade&amp;#8217;s use of whitespace for handling nested tags.&lt;/p&gt;
&lt;h4&gt;Jison&lt;/h4&gt;
&lt;p&gt;Although this is intended as a toy language for now, it&amp;#8217;s written with &lt;a href="http://zaach.github.com/jison/"&gt;Jison&lt;/a&gt;.  I got a big kick out of writing a &lt;a href="https://github.com/alexyoung/jadedown/blob/master/lib/lexer.l"&gt;Flex-style lexer&lt;/a&gt;, and a &lt;a href="https://github.com/alexyoung/jadedown/blob/master/lib/grammar.y"&gt;Bison-inspired parser&lt;/a&gt; &amp;#8212; I&amp;#8217;ve even included a test suite.&lt;/p&gt;
&lt;p&gt;An issue I struck early on was I wanted to use capturing groups in the lexer&amp;#8217;s regexes, but it seemed like accessing the matches in the grammar file was impossible.  I didn&amp;#8217;t want to use regular expressions twice &amp;#8212; why match text in the lexer and then use a similar regular expression later to extract groups?  However, after reading through several Jison projects I discovered this lexer pattern:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
&amp;lt;p,b,ol,li&amp;gt;\(([^)]*)\)\[([^\]]*)\] %{
  yytext = {
      tag: 'a'
    , attr: 'href="' + yy.lexer.matches[1] + '"'
    , html: yy.lexer.matches[2]
  }
  return 'LINK';
%}
&lt;/pre&gt;
&lt;p&gt;The regex here uses groups, then the code that gets run by the lexer splits the matches into a structured form that can be used by the parser.  Unlocking this pattern drove development of Jadedown from a scrap on my harddrive to a fully&amp;#8211;fledged parser.&lt;/p&gt;
&lt;p&gt;The discussion that led to the development of Jadedown was from a &lt;a href="https://gist.github.com/82c32f0e742505e90d2a"&gt;gist&lt;/a&gt; I posted to Twitter about my ideas for a lightweight markup language.  I like the idea of using CSS selectors across the entire stack of a project; working with Jade, Stylus, and jQuery makes it feel like everything revolves around them.  Maybe Jadedown or something like it can extend this theme into content too?&lt;/p&gt;
</content></entry><entry><title>Pop: A Static Site Builder</title><link href="http://alexyoung.org/2011/07/24/pop"></link><updated>2011-07-24T01:07:00Z</updated><id>http://alexyoung.org/2011/07/24/pop</id><content type="html">&lt;p&gt;&lt;a href="http://popjs.com/"&gt;Pop&lt;/a&gt; (GitHub: &lt;a href="https://github.com/alexyoung/pop"&gt;alexyoung / pop&lt;/a&gt;, License: &lt;em&gt;MIT&lt;/em&gt;, npm: &lt;em&gt;pop&lt;/em&gt;) is my attempt at building something largely compatible with Jekyll that satisfies my own requirements.&lt;/p&gt;
&lt;p&gt;Highlights:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Generates sites quickly  &lt;/li&gt;
&lt;li&gt;Extensible through CommonJS modules  &lt;/li&gt;
&lt;li class="rather than the entire site"&gt;Can regenerate a single post as I&amp;#8217;m working on it (rather than the entire site)  &lt;/li&gt;
&lt;li&gt;Generates stub posts with sensible defaults  &lt;/li&gt;
&lt;li&gt;Comes complete with helpers for HTML5 articles, feeds, pagination  &lt;/li&gt;
&lt;li&gt;Post summaries&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Installing Pop is easy with npm:&lt;/p&gt;
&lt;pre class="prettyprint lang-javascript"&gt;
npm install -g pop
&lt;/pre&gt;
&lt;p&gt;This makes a binary available called &lt;code&gt;pop&lt;/code&gt;.  Running &lt;code&gt;pop -h&lt;/code&gt; displays usage:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
pop is a static site builder.

Usage: pop [command] [options]
new    path           Generates a new site at path/
post   "Post Title"   Writes a new post file
server                Create a server on port 4000 for _site/

-v, --version         Display version and exit
-h, --help            Shows this message
&lt;/pre&gt;
&lt;h3&gt;Tutorial&lt;/h3&gt;
&lt;p&gt;Let&amp;#8217;s generate a site:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
$ pop new myblog
Site created: myblog
&lt;/pre&gt;
&lt;p&gt;The results should look familiar to Jekyll users:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
$ cd myblog/
$ ls
_config.json _includes    _layouts     _lib         _posts       index.jade   stylesheets
&lt;/pre&gt;
&lt;p&gt;If you open the templates you&amp;#8217;ll see where Pop starts to diverge from Jekyll.  The index page uses helpers to generate paginated posts and pagination controls:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
---
layout: default
title: My Site
paginate: true
---

!{paginatedPosts()}
!{paginate}
&lt;/pre&gt;
&lt;p&gt;I&amp;#8217;ve retained YAML front&amp;#8211;matter.  The primary motivation for this was to make &lt;strong&gt;posts&lt;/strong&gt; compatible.  Templates are not compatible, but writing templates with &lt;a href="http://jade-lang.com/"&gt;Jade&lt;/a&gt; and &lt;a href="https://github.com/learnboost/stylus"&gt;Stylus&lt;/a&gt; is extremely simple for those of us versed in JavaScript and CSS selectors.&lt;/p&gt;
&lt;p&gt;The resulting HTML can be generated by either running &lt;code&gt;pop&lt;/code&gt; or &lt;code&gt;pop server&lt;/code&gt;.  The server mode will regenerate files when they change, but it can&amp;#8217;t currently track dependencies &amp;#8212; if you change a post it&amp;#8217;ll regenerate the post but not the index page.  To use the server you&amp;#8217;ll need to have Express installed (I might make this a dependency if this confuses people).&lt;/p&gt;
&lt;p&gt;The end result is a nice little HTML5 blog:&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/pop.png" alt="" /&gt;&lt;/p&gt;
&lt;h3&gt;Extending Pop&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;_lib/&lt;/code&gt; directory may contain two files: &lt;code&gt;helpers.js&lt;/code&gt; and &lt;code&gt;filters.js&lt;/code&gt; -- both should be CommonJS modules.  Helpers are functions available to templates.  They're bound to a &lt;code&gt;SiteBuilder&lt;/code&gt; object, so site configuration values can be accessed using &lt;code&gt;this.config&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Filters are used to pre&amp;#8211;process entire files before they&amp;#8217;re put through Textile, Markdown, or Jade.  I&amp;#8217;ve used this to support the syntax highlighting liquid tags used by Jekyll.  I&amp;#8217;m planning to use &lt;a href="http://code.google.com/p/prettyprint/"&gt;prettyprint&lt;/a&gt; with DailyJS instead of Pygments.&lt;/p&gt;
&lt;h3&gt;Post Stubs&lt;/h3&gt;
&lt;p&gt;Stub posts can be quickly generated like this:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
$ pop post "Awesome Post"
Post created: _posts/2011-07-24-awesome-post.md
&lt;/pre&gt;
&lt;p&gt;It includes example YAML front&amp;#8211;matter, in case you don&amp;#8217;t like typing it or forget the format.&lt;/p&gt;
&lt;h3&gt;HTML5&lt;/h3&gt;
&lt;p&gt;I want people to be able to get writing with Pop in no time at all, so I&amp;#8217;ve been researching how to generate a flexible site that can be easily customised.&lt;/p&gt;
&lt;p&gt;To this end, a default Pop site generates posts according to the &lt;a href="http://www.readability.com/publishers/guidelines/"&gt;hNews&lt;/a&gt; format, and the templates themselves use HTML5.  The default stylesheet makes heavy use of CSS3 features, so you get a lot of bang&amp;#8211;for&amp;#8211;buck without using any images.&lt;/p&gt;
&lt;p&gt;The blog at &lt;a href="http://popjs.com"&gt;popjs.com&lt;/a&gt; uses the default templates and styles.&lt;/p&gt;
&lt;h3&gt;Tests&lt;/h3&gt;
&lt;p&gt;Pop includes Expresso tests; run them with &lt;code&gt;make test&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Plans&lt;/h3&gt;
&lt;p&gt;Pop is optimised for my requirements, which means it might not have the broad appeal that Jekyll has.  I&amp;#8217;m working hard to make it friendly and extensible, with ideas inspired by popular Node projects like &lt;a href="http://expressjs.com/"&gt;Express&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The biggest thing on the horizon is documentation &amp;#8212; I&amp;#8217;ve included detailed code comments and the dox output can be found here: &lt;a href="http://popjs.com/doc/"&gt;Pop API documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Why &amp;#8220;Pop&amp;#8221;?&lt;/h3&gt;
&lt;p&gt;I wanted a short, easy to type name that wasn&amp;#8217;t taken by a package in npm.  It probably isn&amp;#8217;t the best name for SEO, but I&amp;#8217;m going to be typing &lt;code&gt;pop&lt;/code&gt; a lot in the near future!&lt;/p&gt;
</content></entry><entry><title>Bulletproof Deployment: Put Down the Pickaxe</title><link href="http://alexyoung.org/2011/05/17/deployment"></link><updated>2011-05-17T01:05:00Z</updated><id>http://alexyoung.org/2011/05/17/deployment</id><content type="html">&lt;p&gt;I have an axe to grind with web app deployment.  I&amp;#8217;ve never been totally happy with any solution, and almost everything I&amp;#8217;ve tried has let me down repeatedly.&lt;/p&gt;
&lt;p&gt;This is where a programmer typically sees a problem and creates a project to solve it.  And this is where it all starts to go wrong.&lt;/p&gt;
&lt;p&gt;The need for scripted deployment comes when a combination of factors makes simply uploading files unworkable.  Modern applications depend on a complex environment of libraries, daemons, and database schema management.  Scripting this process should make it repeatable.&lt;/p&gt;
&lt;p&gt;The first tool I used regularly was &lt;a href="http://capify.org/"&gt;Capistrano&lt;/a&gt; (back when it was SwitchTower).  It did the job fairly well for Rails projects, but there were a few things that concerned me.  It duplicated lots of functionality from Ruby&amp;#8217;s &lt;a href="http://rake.rubyforge.org/"&gt;Rake&lt;/a&gt;, and it relied on a Ruby SSH library rather than shelling out.  &lt;code&gt;Net::SSH&lt;/code&gt; is an implementation of the SSH protocol in pure Ruby, and it wasn't particularly portable -- I couldn't deploy from Windows (I had to sometimes work in Windows 5 years ago), and it seemed to have issues communicating with one of the Solaris servers I was deploying to.&lt;/p&gt;
&lt;p&gt;Capistrano felt like thousands of lines of code that would be better served by Rake and SSH(1).  Then I found &lt;a href="http://rubyhitsquad.com/Vlad_the_Deployer.html"&gt;Vlad the Deployer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/vlad.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Vlad is a small project that builds on Rake and SSH(1).  It has some recipes that makes deploying to various environments fairly straightforward &amp;#8212; using it is a configuration problem more than scripting.  Like Capistrano, it uses symbolic links to the project&amp;#8217;s directory so rolling back a failed deploy should be simple.  However, in reality these &amp;#8220;release checkpoints&amp;#8221; are better served with tags in the project&amp;#8217;s version control system, and messing around with symbolic links feels awkward and can lead to unexpected problems.&lt;/p&gt;
&lt;p&gt;The biggest problem with Vlad is a failed command doesn&amp;#8217;t return a neat line of shell code; instead it spits out a huge block of several commands making debugging extremely difficult.  It can result in situations where the state of a failed deployment isn&amp;#8217;t clear.&lt;/p&gt;
&lt;h3&gt;Back to UNIX&lt;/h3&gt;
&lt;p&gt;&lt;img src="/images/unix_plate.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;After many, many bad experiences with Vlad, I gave up.  However, I&amp;#8217;m not just a lazy programmer, I&amp;#8217;m also a lazy sysadmin, so I thought it was time to break out my vestigial UNIX skills and script the whole thing myself.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m starting to get tired of seeing Rake everywhere.  What was wrong with Makefiles?  And why are we using version control systems to check out the latest version of a project?  Why can&amp;#8217;t I run &lt;code&gt;rsync&lt;/code&gt; on the code that I'm looking at on my computer?&lt;/p&gt;
&lt;p&gt;One reason I get tired of everything being managed by Rake in Rails projects is booting the Rails environment.  I don&amp;#8217;t want to wait around for Rails to load when I&amp;#8217;m doing something that isn&amp;#8217;t related to the application&amp;#8217;s environment.  This is UNIX country!&lt;/p&gt;
&lt;p&gt;And running migrations?  Seriously, is &lt;code&gt;ssh server cd /app/path &amp;&amp; RAILS_ENV=production rake db:migrate&lt;/code&gt; really that hard?  This stuff is better left to shell scripts!&lt;/p&gt;
&lt;p&gt;So I&amp;#8217;ve given up on deployment scripts and embraced my UNIX heritage.  I sat down and wrote a shell script that uses &lt;code&gt;rsync&lt;/code&gt;, &lt;code&gt;ssh&lt;/code&gt;, and &lt;a href="http://gembundler.com/"&gt;Bundler&lt;/a&gt; to deploy a client&amp;#8217;s app.  It took me about 30 minutes and worked first time.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the real script that I&amp;#8217;m actually using for that project as a Gist: &lt;a href="https://gist.github.com/976283"&gt;deploy.sh&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Bonus Features&lt;/h3&gt;
&lt;p&gt;This simple script actually gives me things I didn&amp;#8217;t have before &amp;#8212; &lt;code&gt;rsync&lt;/code&gt; can be run in &lt;em&gt;dry run&lt;/em&gt; mode, which allows me to see what will happen before I commit to deploying.  I can tag each deploy in git if I want, then easily switch between versions.  It's also easy to see where a deployment fails, because I can see the line in the script and look at the command.&lt;/p&gt;
&lt;p&gt;Tools like Bundler make library management on the remote server much easier.  I also write &lt;code&gt;package.json&lt;/code&gt; files for use with &lt;a href="http://npmjs.org/"&gt;npm&lt;/a&gt; when deploying JavaScript projects.&lt;/p&gt;
&lt;p&gt;And &lt;a href="https://twitter.com/#!/regularfry/status/70106572650582017"&gt;a friend pointed out&lt;/a&gt; that using &lt;a href="http://www.debian-administration.org/articles/290"&gt;ssh master channels&lt;/a&gt; can help speed things up.  The easiest way to do this is through &lt;code&gt;.ssh/config&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="prettyprint lang-text"&gt;
Host *
  ControlMaster auto
  ControlPath /tmp/%r@%h:%p
&lt;/pre&gt;
&lt;h3&gt;Test&amp;#8211;Driven Deployment&lt;/h3&gt;
&lt;p&gt;One of my static sites is deployed with &lt;code&gt;rsync&lt;/code&gt;.  That means only changed files are updated each time, so publishing is extremely simple and stress free.  When I wrote the script I noticed there were a few things I could accidentally break, so I added a validation stage that could stop deployment:&lt;/p&gt;
&lt;pre class="prettyprint lang-ruby"&gt;
namespace :remote do
  task :validate do
    puts 'Validating _site/'

    # These files may be lost in a completely new _site
    unless File.exists? '_site/.htaccess'
      puts "[WARN] Copying .htaccess file"
      File.copy '.htaccess', '_site/.htaccess'
    end

    # The jekyll I first started using got this wrong
    unless File.exists? '_site/atom.xml'
      if File.exists? 'atom.xml'
        File.copy 'atom.xml', '_site/atom.xml'
      elsif File.exists? 'atom.html'
        puts "[WARN] An atom.html file has been generated instead of .xml"
        File.mv 'atom.html', 'atom.xml'
        File.copy 'atom.xml', '_site/atom.xml'
      end

    end

    File.copy '_site/atom.xml', '_site/feed.xml'
    puts 'Done.'
  end

  task :deploy do
    puts "Deploying..."
    Rake::Task['tags:generate'].invoke
    Rake::Task['remote:validate'].invoke
    puts `rsync -avz "_site/" dailyjs.com:/var/www/dailyjs.com/`
  end
end
&lt;/pre&gt;
&lt;p&gt;The validation here is just to patch behaviour that I didn&amp;#8217;t like in my static site generator.  It may have since fixed these issues.  However, the concept of validating deployment first stuck with me.&lt;/p&gt;
&lt;h3&gt;Script Your Own Deployments&lt;/h3&gt;
&lt;p&gt;Rather than relying on programmers who don&amp;#8217;t know any better, let&amp;#8217;s just script our deployments.  Read about the features of &lt;code&gt;rsync&lt;/code&gt;, &lt;code&gt;bash&lt;/code&gt;, and &lt;code&gt;ssh&lt;/code&gt; to find seriously powerful features, then exploit them instead of hitting the problem with a pickaxe.&lt;/p&gt;
&lt;p&gt;There are some simple updates I&amp;#8217;d like to add to my bash deployment script:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Validation, perhaps checking things like file permissions before doing anything  &lt;/li&gt;
&lt;li&gt;Make it possible to run each function in isolation from an option  &lt;/li&gt;
&lt;li class="for deploying to staging or production"&gt;Configuration options per environment (for deploying to staging or production) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;ll add these features when I need them!&lt;/p&gt;
&lt;h3&gt;Previously Ground Axes&lt;/h3&gt;
&lt;p&gt;I wrote a script to compare Rails dependencies between a local machine and server: &lt;a href="https://github.com/alexyoung/depwhack"&gt;depwhack&lt;/a&gt;.  This is pretty pointless, since Bundler has largely solved gem management.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/alexyoung/rsyncdiff"&gt;rsyncdiff&lt;/a&gt; uses the changes generated by &lt;code&gt;rsync&lt;/code&gt; in dry run mode to show what files will change before a deploy.  It's basically a parser for &lt;code&gt;rsync&lt;/code&gt;'s &lt;code&gt;--itemize-changes&lt;/code&gt; output, which isn't human-readable (unless you're a wizard).&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;man ssh&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;&lt;code&gt;man rsync&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;&lt;code&gt;man make&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="http://tldp.org/LDP/abs/html/"&gt;Advanced Bash&amp;#8211;Scripting Guide&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/976283"&gt;deploy.sh&lt;/a&gt;</content></entry></feed>

