Firemacs

29 Nov 2014

One of the downsides of using Emacs I have found is that it really starts to grate on you after a while just how much everything else sucks. And none more than does the web, with all its clicky buttons and animated dropdowns and so on and so forth and suchlike.

Seems like every day I find the web ever more excruciating to use. But i’m not quite ready to turn off javascript in my browser completely. And so it was with delight that I discovered firemacs for firefox to ease the pain.

Firemacs is simply a plugin that enables you to use all the most basic emacs keybindings within the context of webpages and tabs in the browser.

With it you can:

  • Scroll up and down using the familiar C-n, C-v, C-p and M-v.
  • Go back and forth through your list of tabs with C-b and C-f.
  • Search and reverse search using C-s and C-r.
  • Go forward and back through your history with F and B.
  • Edit text with…all your favorite keybindings.
  • Go to the first input or button.

And many more! hell, if you don’t like any of the above, firemacs even makes it a cinch to modify.

Two caveats I have found are that pages that define their own keybindings (services such as github, gmail, etc..) will break firemacs by imposing their own keybindings on top of yours. I’ve also found a problem with using a macintosh as the alt or meta key does not work. Fortunately the escape key will function as meta as with emacs, but since I don’t plan to use OS X for much longer this is not a deal-breaker for me.

So if you’re an emacs/firefox user I highly recommend giving firemacs a shot. That is of course unless you are using conkeror, in which case well done to you. If you use a different browser/editor combo I’ve heard that there are other ahem alternatives out there, but seriously why would you want to do that?


How to Type

25 Aug 2014

When I was in college I relearned to play the piano. It’s not that i had forgotten or even played especially badly, but I was in some sense doing it all wrong. The process of relearning was at times deeply upsetting as my body continued to complain, hey, I’ve got this! if i tried to get it to do something different. And the rewards only became clear years after as I continued to teach myself in the afterlife of my schooling. Here are some of them:

  • greatly reduced risk of injury
  • freedom from discomfort and cramping
  • penalty for not playing every day greatly reduced
  • need to play hours of advanced technical studies in order to stay in top form greatly reduced
  • increased sensation of freedom and joy in all movements
  • greater sensitivity and range of expression

What’s maybe surprising is how few of these directly address any elements of musicality. It’s enormously reassuring to me to think that someone was looking out for my well-being at a time when clearly i wasn’t. Not injuring myself, I am finding, is increasingly appearing at the top of my list of goals for just about any endeavor that has a risk of injury.

If you’ve ever suffered an RSI as a result of typing, I’m going to urge you to hold a similar attitude whenever you sit at the keyboard. Were you pairing programming with me, I’d want for you to experience the same freedom and joy as you type that I feel when playing a musical instrument. Even above, say, not violating the law of demeter or single responsibility principle. If that doesn’t surprise you, do read on. You may even be interested in how i synthesized the principles of touch typing, ergonomic keyboards, the Alexander Technique and emacs in pursuit of these goals as a software developer.

The Posture

The Alexander Technique has a great deal to say about posture. Too much, in fact, to cover fully here. But here are some points that have served me well over many years as a keyboardist:

  • Use a chair and desk that allow you to sit up straight with the spine elongated and curved in the lumbar and neck.
  • Sit (or stand!) at the desk so that the arms may hang down freely from the shoulders, the elbows dangling at the side.
  • When striking a key, avoid resting the wrists on the desk, or raising them too high. From the side, the top of the forearm down to the knuckle will describe almost a straight line, the underside curved, like a bridge.
  • The hand is strong, relaxed and curved, as if formed around a ball.

What I learned from touch typing

  • When pressing shift, control or meta (also known as the alt or option key) in combination with another key, avoid pressing both with the same hand. And by avoid I mean don’t ever, ever do that.

The keyboard

  • If your keyboard does not have a shift, control and meta key on both sides, then it is defective by design. Get a better keyboard, or rebind the keys (I’m looking squarely at you, MacBook).
  • For greater ease in pressing the control key, use an ergonomic keyboard that allows you to use the palm of your hand. Emacs pinkie be gone!
  • Use an ergonomic/split keyboard that allows your hands and arms to be square and roughly a shoulder’s width apart, not bunched in the middle of your desk.
  • Up to a point, the more resistance the keys offer, the easier it will be. If you can’t relax the hand and arms without depressing keys by mistake, consider trying another.

The Alexander Technique

  • Type from the shoulders. The greatest movement will begin in the upper body, the smallest movement will be performed by the fingers themselves. Hardly move your fingers at all.
  • Do not extend the fingers in order to press a key that lies outside of the home row. Move the hand and arm to accommodate.
  • You unavoidably need to create tension in order to perform a movement. Learn to observe that tension, and release it after the execution of each movement.
  • Practice, sitting down away from the desk, by holding one arm by the wrist using the other hand at chest height, the elbow by the side. Relax the arm completely by holding the complete weight in the supporting hand (even better - have someone else support you). Observe the sensations you feel and try to recreate them at all times. Remove the supporting hand and let the arm freefall into the lap.
  • Try to imagine this movement as you lift the arm and let it fall as you depress a key. At the moment of impact, a small amount of tension is needed to form your bridge in order to strike the key accurately. Immediately after, this tension can be completely released, as when resting in the lap.
  • Practice alternately forming that strong bridge-like position in the hands and arms and then allowing them to relax completely.
  • The hand and arm is heavy enough to depress a key using gravity alone. You will gradually learn to type by transferring this weight from key to key in a fluid and effortless motion.

Padrino with Sidekiq

30 Jul 2014

I recently added sidekiq to a padrino app. Mounting the sinatra app wasn’t completely straightforward, and I didn’t find everything I needed in one place. So here’s an attempt to do just that.

First, add sidekiq to your gemfile, and bundle install:

# Gemfile
# Project requirements
gem 'sidekiq'
bundle install

Now, tell padrino to mount the app, and stub some methods to make it play nice:

# config/apps.rb
require 'sidekiq/web'

class Sidekiq::Web < ::Sinatra::Base
  class << self
    def dependencies; []; end
    def setup_application!; end
    def reload!; end
  end
end

Padrino.mount(
  'Sidekiq',
  app_class: 'Sidekiq::Web',
  app_root: Sidekiq::Web.root
).to('/sidekiq')

Now, create a workers directory in your app, and add all workers to the load paths:

# app/workers/sample_worker.rb
class SampleWorker
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform
    # Lots of hard working code....
  end
end
# config/boot.rb
Padrino.before_load do
  Padrino.dependency_paths << Padrino.root('app/workers/*.rb')
  Padrino.set_load_paths('app/workers')
end

Add the following to your rackup config file:

# config.ru
require 'sidekiq/web'
map('/sidekiq') { run Sidekiq::Web }

Add workers.rb to your config directory and tell it how to find your workers:

# config/workers.rb
path = File.expand_path('../../workers/*.rb', __FILE__)
Dir[path].each { |file| require file }

Finally, add a Procfile with the following content:

# Procfile
web: bundle exec thin start -p $PORT
worker: bundle exec sidekiq -r ./config/workers.rb

Choco

30 May 2014

One of the first things I knew I had to do when I switched to emacs was to have it use my favorite color theme, choco. Choco was created by Ludvig Widman for the TextMate editor and later adapted for gedit.

Now, I feel guilty for possibly putting too much emphasis on aesthetics, but I do love choco and it’s for a number of reasons:

  • It is dark, and I will often look at it all day. anything lighter feels like staring at a lightbulb.
  • Just looking at its combination of colors makes me intensely happy, and I’ve never experienced that with any other theme, and maybe anything in art or nature (okay, okay…)
  • Yes, I love chocolate. which in turn makes me intensely happy
  • It reminds me, for various reasons, of games from childhood, such as super mario world, super mario kart, and m.c. kids, which in turn makes me intensely happy

If anything, adding the theme to emacs seemed like the perfect introductory elisp project. Among the more delightful things I learned along the way was that ruby-mode ships with ruby. Alright!

The results are here. Contributions are welcome!