h4ck3r+=boi v 2.0

  1. Search
  2. About
  3. Subscribe
  4. Archive
  5. Random
  1. Posts about Rails
  2. Posts about Python
  3. Posts about Agile
  4. Posts about development
  5. Posts about startups

h4ck3r+=boi v 2.0

Newer
Older
  • My mobile setup - Rails development on the Road

    Introduction

    The last two weeks I’ve been on my honeymoon. However, there is a disadvantage of going on vacation when you’re self employed - that means no money is coming in either.

    To keep some small amount of money coming in I put in 2-3 hours a day of work, during downtime. This happened to work for the clients involved, so it all worked out.

    However, I knew I didn’t want to lug my main setup (a 15” MBP) to Amsterdam and back - every pound counts when you’re on the road. I also wanted to avoid having too much client data on my machine - sometimes you hear about hard drive scans at the US border, etc. I worry about the confidentiality of my client’s data (and my own).

    And seriously? I’m on honeymoon - I’m not going to be doing that much work. I really don’t need my main saw.

    So we packed light, tech speaking: my 13” Acer netbook (1.3 Ghz, 30 GB hard drive), and my iPad. And of course our phone and cameras.

    The choice of the netbook was an excellent one: I was able to find an Amsterdam power to 3 prong netbook size cable very easily. The netbook also charged the iPad and iPhones pretty well, and was ok for super (super) light photo import and publishing on the web.

    Taking just the netbook has one significant problem: all my project work won’t fit on that size hard drive! One of my projects has a 30GB MySQL database, and another has a massive test suite (taking 90 minutes to run on reasonable hardware… which the netbook is not. So I needed more iron than I could take with me.

    Enter EC2

    A few months before my trip I experimented with using EC2 as a build environment for Wilcox Development Solutions. I liked the setup, and I liked being able to quickly add hard drive storage. So I devised a plan: ssh into a EC2 medium instance, and work off that.

    Setting up the Remote Instance

    I recommend getting an EC2 medium instance. This was mostly an experiment for me, so EC2 might not be the most economical way to go (I was surprised at my EC2 bill, actually, in the “bad surprise” way). However, EC2 is a cheap way to see if working this way works for you.

    EC2 medium is about a 2 core 1Ghz machine (approximately) - not the fastest thing in the word, but bigger iron than my netbook. I did experiment with an EC2 Small instance, but I felt Small might be too small given my requirements (large MySQL database, long test suite).

    Now I’m considering a Linode instance, or (probably) spend $800 on a tricked out Dell machine that I install a Linux variant on (probably Ubuntu).

    Whatever way you go, in addition to installing your normal development tools, you’ll also want to set up some extra things.

    SSH Magic

    SSH can do a lot more than what we normally use it for. For example, SSH Agent forwarding.

    SSH Agent forwarding is awesome. So you’re on a physical machine (let’s call it Scooter), and SSHing into another machine (let’s call that Amazon). You’re also trying to connect to Github. You had previously uploaded your private key, from Scooter, to Github. But wait, you’re technically connecting to Github through Amazon - which has a different SSH private key!

    With SSH Agent Forwarding, when SSH tries to communicate with Github, the Amazon machine will actually ask Scooter for it’s private key, then forward that to Github. It’s more complicated than that (I’m sure), but that’s the idea.

    I wanted this feature, so I set up my ~/.ssh/config file as such:

    Host wd_ec2
      Hostname (the public DNS from Amazon. This of course changes when you terminate and restart instance)
      IdentityFile (the .pem file that Amazon gives you when you set up the instance)
      User ec2-user
      ForwardAgent yes
    

    When I wanted to ssh into my ec2 box I just ssh wd_ec2_med.

    There’s one last thing to get SSH Agent Forwarding working: you need to tell your physical machine to accept forward agent requests. Edit /etc/ssh/ssh_config and uncomment the ForwardAgent no line, and change the no to yes.

    Now the only SSH private key that matters is the one of my physical machine (Scooter).

    Make it easy on yourself with MORE SSH Magic

    If you’ve noticed the public DNS entries from Amazon, you’ll see that they are terribly long, complex URLs. All my client work involves web apps, right now, so I’ll be typing that long address into the URL bar a lot.

    Screw that noise.

    I set up SSH port forwarding: visiting localhost:3001 will actually visit port 3000 (Ruby on Rails server port) on the Amazon machine I’m SSHed into.

    This is really easy to set up: just another line in the Host section of the ~/.ssh/config file:

      LocalForward 3001 (public ip address of the Amazon EC2 instance):3000
    

    Simple: going to localhost:3001 in a web browser on my physical machine (Scooter) will access the Rails server on the Amazon instance. Easy-peasy.

    There are other ways to do this without LocalForward: setting up a DNS name for the Amazon instance (somewhat poor if I need to restart the instance), or if I wasn’t using EC2 I would have a sane name or public, static, IP. LocalForward is an awesome hack if you’re using EC2, however.

    My Unix Tools

    Once I had the Amazon EC2 instance set up, I needed an editor. The cheapest opinion was to just use VIM directly on the Amazon instance. At this point my netbook does two things: maintains an SSH connection, runs a web browser, and Skype. The more I can offload to the cloud the better.

    So I used the following tools:

    Vim

    Vim is my go-to console editor. I’ve been doing minor edits in Vim for the last 10 years, but this was the longest time I’ve used it as my primary editor. But I’ve got some tricks up my sleeve:

    • Rails.vim: This is pretty much amazing. Favorite commands? :Redit, which tab completes. Enter :Redit ap(TAB)/mo(TAB)/use(TAB) will complete to :Redit app/models/user.rb. This is a fast enough finder for me, and I really didn’t want to mess with setting up Command-T Vim plugin… but I knew I needed fast access to files in my Rails project.

      Second favorite Rails.vim command? :Rmigration 0 (opens db/schema.rb)

    • NERDTree: for those times when I really didn’t know where a file was, or wanted to open a file in a split or tab.

    • twitvim: I discovered this my last day, but I’m so sold. I wish I would have known about this earlier. Best way to view Twitter, outside of Hibari.

    • Pathogen: the safe sex for vim.

    • Fugitive: A Git plugin for VIM. That was awesome

    VIM tools I wanted to use (but didn’t, because of old vim version on ec2 instance or other software staleness):

    • gundo.vim
    • taglist

    If I was moving to vim as my primary environment I’d get these last two set up, and then I think I would be happy. Maybe throw snipmate in there. I actually had SnipMate installed, but never used it.

    Would I switch to vim full time? I don’t think so: I consider myself an expert level TextMate user, and I’m also someone who sticks with tools for years (I’m still using the email client I started using in 1995, for instance). I’ve only been using TextMate for 4 years - no time to jump ship now. However there is some interesting stuff in Vim I’d love in TextMate (split screen, and sometimes a Redit file jump semantics (vs name only) would be useful in TM.

    GNU Screen

    I love GNU Screen. I typically worked with 3 virtual screens, with a (horizontal) split: top split would be VIM (taking up 3/4 of the real estate), and the bottom split for command line work.

    I use Screeninator at home, but didn’t use it here. At the end of 2 weeks I was starting to define my pattern (I need at least 3 virtual screens), and had I stayed another week I would have set up screeninator.

    Three other reasons: * I assumed Internet would be flakey. (It actually was quite solid) * I can do everything in one SSH connection. (I don’t know how my LocalForward directives would have worked with more than one SSH connection up…) * I could detach my workspace and come back to it later.

    NOTE: SSH Agent Forwarding and detaching / attaching back to GNU Screen sessions… they don’t play well together. There’s a script to refresh the various SSH variables involved (http://crumbtrail.chesmartin.net/post/213631924/gnu-screen-wrapper-for-ssh-agent-forwarding).

    Mutt

    Mutt is my preferred command line email tool. I was able to set up Mutt to check my IMAP email boxes, and send via SMTP easily (you need a recent Mutt for this, but it’s awesome).

    Note: with the SMTP sending you’ll also want to set your from address, or it will be (username@host you’re sending email from)… so it could be username@localhost.localdomain … which won’t work.

    Mutt’s thread sorting was cool, or you can switch to date sorting easily (:set sort=date)

    Best way to use email outside of Mailsmith.

    Misc tools

    I installed some minor tools on EC2 that played an integral part:

    • hcl: Harvest Command Line client. I use Harvest to track time: hcl works exactly like I want it to (and I’m very picky about how my hours are entered). I might create a vim plugin and TextMate bundle wrapper for this tool - I love it that much.

    • Dropbox. Installed on my netbook

    • 1Password Anywhere: Installed on my netbook (via dropbox). It’s not as good as 1Password as a browser extension, but hands down beats actually remembering passwords.

    • I ran 4 workspaces on my netbook: one with a full screen console (sshing into EC2), one with a full screen browser, one with Skype and Pidgin. This was great as long as nobody talked to me on Skype… it was impossible to hold a Skype conversation and get work done.

    • rvm: Safe sex for multiple Rails projects. Also: the Ruby distributed with my EC2 instance was complied bad (problems with zlib). Using RVM to install a Ruby gave me a known-sane version of my compiler/runtime. Because the last thing I like doing? Debugging oddball ass Ruby problems.

    What would I do differently

    I like working by connecting to a remote server. Over the last 3 months one of my projects has been in crunch mode. There were often nights when I didn’t join my wife in the living room because all my state was on my desktop machine.

    If I develop off a central machine (like an EC2 instance), I can detach the GNU screen session, then resume on another machine (like my laptop, in the living room).

    As I said earlier: EC2 was a great platform for this experiment, but the cost was surprising (~ $100). I’m considering setting up my own server for this purpose, potentially using Vagrant.

    As a user I’m very interested in the iOS: it provides an awesome experience if you’re doing one thing. However, as developers we are doing multiple things by definition. Just keeping an SSH connection open while also browsing the web is something the iPad can’t do (at least, of this writing).

    As a developer I’m interested in Android/x86 and/or Chrome OS on a netbook. If an OS can be lighter weight than my Ubuntu install, I’m all for it.

    Next time I’m bringing a netbook with more battery life (I get about 2.5 hours of charge on this machine).

    Tagged: rails tools

    Posted on August 9, 2012 with 1 note

    1. sch1zo reblogged this from rwilcox
    2. rwilcox posted this
  • staff

Field Notes Theme. Designed by Manasto Jones. Powered by Tumblr.