Faster emacs key repeats

My secret intent behind creating a course on emacs was to become much more proficient with it myself. One of the course beta testers, Jack Kelly (software engineer turned pirate) mentioned something really spiffy that I hadn’t heard before.

In the second lesson, we cover C-u which (among other things) can be used to repeat keystrokes, like this: C-u 80 *. However, it turns out that you can leave off the C-u prefix and achieve the same thing by holding control while typing the number, like so: C-8 C-0 *.

Now your crafting of comment headers and ascii art can be that much more enjoyable.

Emacs-fu launches on the 1st of May. Sign up and impress us with your emacs-crafted ascii art.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Using Spree and Refinery together

The combination of Spree and Refinery is promising for e-commerce sites incorporating some CMS pages. I recently ran through the process of installing both of these engines and configuring them to play nice with each other. You can do this too!

Firstly, a note on versions. For this guide, I’ve use Rails 3.2.3, Spree 1.1rc and Refinery 2.0.2. I’ve used the Spree 1.1rc instead of the stable 1.0.x version because the stable version depends on Rails 3.1 and Refinery 2.0.x expects Rails 3.2. The Spree 1.1rc is Rails 3.2 compatible, so our whole project can happily run on Rails 3.2.

Install Rails

$ rails new spreefinery
Uncomment therubyracer in the Gemfile

Install Spree 1.1rc

$ cd spreefinery
$ spree install --git=git://github.com/spree/spree.git --branch=1-1-stable

Install Refinery

Add to Gemfile: gem 'refinerycms', '~> 2.0.0'
$ bundle install
Comment out the Spree lines in db/seeds.rb to avoid double-seeding Spree
$ rails generate refinery:cms --fresh-installation
Uncomment the Spree lines in db/seeds.rb

Reference: http://refinerycms.com/guides/with-an-existing-rails-app

Patch will_paginate

Refinery uses the will_paginate gem for pagination, while Spree uses Kaminari. Unfortunately, these two gems are incompatible. To work around this, add the following to config/initializers/spreefinery.rb:

if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        alias_method :per, :per_page
        alias_method :num_pages, :total_pages
      end
    end 
  end
end

References:

Configure routes

I wanted my home page and an about page served by Refinery, and the products page served by Spree. To accomplish this:

Mount Spree before Refinery in config/routes.rb
Above both engine mounts, add:
root :to => "refinery/pages#home"

You should now have Spree and Refinery running together. There’s room for some further improvements to this configuration, since Spree and Refinery still use their own authentication systems and layouts, but it should be enough to get started with.

Become so much more better at emacs. Maybe not grammar, though.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Introducing Emacs-fu

TL;DR

  • There’s lots to learn about emacs.
  • I learnt some of it and made a course.
  • It’s coming out 1st May and it’s going to be awesome.
  • Put your email down at the bottom of this post to be the first to hear when it’s ready.

There’s a lot to Emacs

There’s so much I don’t know about it. I’ve been using emacs as my main editor for who knows how many years, so I’m pretty comfortable with it. But I started to get frustrated with a few work habits that seemed embarrassingly clunky, and there was a growing feeling that I was actually doing a lot of things the slow way.

On top of this, I’d been dancing around Lisp ever since reading Paul Graham’s gospel writing on the subject. Never quite learning it properly, but interested enough to read up on it. And of course emacs uses its own flavour of lisp at the core, so the glimmering possibility of being able to shape my editor was definitely alluring. But I hadn’t actually reached the point of, you know, actually writing any lisp.

So here I was, basically frustrated with my work habits and non-ninja-ness.

So I went out and learnt a bunch of stuff

A bunch of screencasts, tutorials, features, shortcuts, customisations. I dug through them, kept track of the bits I found useful, and kept them post-it noted on my laptop until they’d sunk in. I haven’t reached any sort of mastery, but it was definitely an upgrade.

I wrote down the good stuff

I made a course, in fact. An email course, in four parts. An email course is perfect for this because you can become a lot more effective with emacs by learning new habits. An email course, with an email every week, is ideal for that because you get plenty of time to practice and internalise each week’s lesson before moving on to the new stuff. Once the new habits are internalised, you don’t have to think about them and you just automatically do the new, more productive thing.

The course consists of four emails, one per week. Here are the lessons:

  • The Basics – get the fundamentals down for speedy editing
  • Nifty built-ins – extend your repertoire of nifty functions
  • Regexp – get your head around emacs’ very special flavour of regular expressions
  • Customisation – tweak emacs to your liking

The course is at an intermediate level. It starts off with some basics to fill in some gaps, but doesn’t dwell there, moving on to more interesting topics. It’s also not super-advanced. There’s a touch of lisp in the last section, but the focus of that lesson is not on the lisp technicalities, but on getting emacs customised to your liking.

There’s lots of good stuff there. It’s going to be awesome, and it’s coming out 1st May. Pop your email in this box and I’ll let you know when it’s ready.


Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Relative money buckets

Leaving out edge cases, no matter what your level of financial abundance, there’ll always be things that fall into each of these buckets:

  • Easy to afford. You don’t even think about it. For example, if you work full-time, you can probably buy yourself a coffee without considering your budget.
  • Save for it. You might have to save for a little while, and you’re not comfortable buying things in this price range on impulse, but you know that you’re capable of achieving these savings goals.
  • Hard. You can afford these things, but they’re at the edge of what you consider possible for you. An example might be an expensive holiday that you feel you can only make happen once every few years.
  • Seemingly impossible. Things you don’t consider possible for yourself. A private jet, your own skyscraper in the CBD, etc.
When you’re income goes up a notch, the things you might spend money on drop down into a more achievable bucket, but the buckets remain the same. If you develop a good relationship with the purchases you make in each bucket, that relationship will serve you well no matter your income level.
Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Programming with molecules

I’ve loved Homespring (the world’s favourite salmon-centric programming language) for a long time. Now I’ve finally gotten round to beginning the design for my own language, RBF (round-bottomed flask). To give you a taste of it, here’s the draft of a program that asks the user a question, and tells them if they have the correct answer or not:

Commercially available What’s_six_times_four? was distilled under reduced pressure at 175 oC, affording a light yellow oil.

To a magnetically stirred solution of 24-rightyo aldehyde (1 mmol) and you_lie methyl ketone (1 mmol) in DCM (10 mL) was added input alcohol (1 mmol) and two drops of concentrated sulfuric acid. The resulting mixture was heated under refluxing conditions for 0.5 h, concentrated under reduced pressure, and the residue thus obtained was subjected to flash chromatography (silica, ethyl acetate). Concentration of the fraction eluting at Rf = 0.9 resulted in a pale-yellow oil.

You can follow the design (currently a disorganised smattering of thoughts) over at the RBF github repository.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

What is it like living in Black Rock City?

I’ve tried writing a description of my time at Burning Man, but I found writing about the physical environment uninspiring – lots of other people have already done it, more eloquently than I could. Instead, here are some of the things that stood out in my experience.

Relaxedness with appearance

At Burning Man, as the week progressed, I began to care less about my appearance. Actually, that’s not quite right. I cared less about what others thought of my appearance. Normally I’m very self-conscious about this, so this was a big change for me.

At Burning Man, there is always someone crazier, more naked (can you be more naked than naked?), more out there than you are. It’s implicitly okay to experiment. It’s fine to wander around in your PJs in the morning (or at any other time, for that matter). More than just being okay, I would have felt out of place if I hadn’t pushed my boundaries a bit. The norm, the average is much further out along the do-crazy-stuff continuum than the default world, and living in that environment was quietly liberating.

By the end of the week, I wanted to get rid of most of my default world wardrobe (it’s so grey and boring!). As I travelled back to San Francisco, even dressed in default world clothes, I gradually began to feel more and more out of place. We stopped at a rest stop, and I was reminded by the mirror that my hair was full of playa dust and that I hadn’t shaved in a week. I felt out of place amongst the other people there. I’m trying to pin down what it was about those people at the rest-stop that made me feel out of place. It wasn’t that they were clean; there were clean people on the playa (fresh from a shower), and I didn’t feel unclean for their cleanliness. It wasn’t that they were well-presented; there were plenty of people in amazing outfits and I didn’t feel inadequate (perhaps inspired). Maybe it was something like conformity, an implicitly agreed-upon set of boundaries for what was okay to wear, do, look like. An implicit agreement to not stand out too much, to blend in and not attract attention. This is the sea we swim in normally, and don’t notice because we can’t see it until it’s gone.

Nudity

It’s no secret that there’s lots of nudity at burning man. What was new for me, not having spent much (or indeed any) time on nudist beaches, was being in an environment where nudity is not a big deal. In comparison, regular society is comically uptight about this stuff.

As well as physical nudity, I found the environment at Burning Man very authentic. I only noticed this when I returned home and found several things in my life feeling artificial and fake.

Community

At Burning Man, I felt like I always had something in common with the people around me. I’m learning to be more open to starting conversations with strangers, and I could have used a good three months in an environment like that to really sink into it and open up more. Friendliness was the default, but it was more open-hearted than regular everyday friendliness. Hugs, compliments, gifts, hugs, cooking meals for people, conversations about important stuff, hugs. In essence, I found the people there to be very openly loving. There are people and whole groups of friends in my regular life who are like this, and I’d love to expand their part in my life. Being surrounded by so many awesome people for a solid week was pretty special.

Beauty

Constantly seeing little things that made me go “Hell yeah” provided continual doses of awesome (Cars with flamethrowers! Glowy bikes! Fishing for hippies with glowsticks! A random oasis in the desert with a cushion pile!). More than any one particular thing, the city as a whole, especially at night, was beautiful. I felt like the city was constantly inviting me to go out and have an adventure.

Go fourth and Burn!

Like reading about a city you’ve never visited, all of this writing can’t convey what it’s like to live in Black Rock City. It’s merely an invitation and an encouragement to check it out for yourself, if you feel so inclined. See you in the dust!

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

San Francisco, authority and city-diffing

There’s a feeling that I’ve been getting since I came to San Francisco that’s been gradually becoming clearer. At first, I thought I was picking up on the American pioneer spirit. It seemed that there was less of sense of a central authority who would take care of things for you. Canberra has this in droves – it (and we, the residents) are drowning in it.

But I think it’s something a little subtler. And it comes not from something that’s present, but from something that’s absent. There’s hardly anyone here wearing suits.

The presence of big business and government is nearly non-existent. Well, not quite. There’s plenty of police (SFPD) and fire trucks around. And you know about it; their sirens are pretty attention-grabbing. But not the public service sort of government. Instead of the government being this massive nannying entity (hello, Canberra), it seems like it’s just one force here (and not the dominant one), doing its best to hold things together in a mostly orderly fashion.

And big business? There’s lots of Starbucks chains. Surprisingly few McDonalds. Barely any supermarkets, at least in the areas I’ve seen. Lots of independently run grocery stores. Plenty of advertising, a few slightly-larger-than-Canberra-scale skyscrapers, but not a bunch of people running around in suits.

So if government and big business aren’t the major forces, what are? This seems much more up to the individual. There’s a sense that without so much protection from the government, everyone has to fend for themselves. It seems like there’s more space for people to make what they want of it, which leads to more extremes. There seem to be more homeless people and beggars, but also a lot of character to the place. And although I haven’t knowingly met the rich, the success stories are pretty well known (Twitter for starters).

This might be premature; I’ve only been here a few days, and there’s plenty of areas that I haven’t visited yet. But it’s certainly been fascinating to be able to diff cities.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Getting tomboy notes to appear on the correct monitor in Ubuntu

I’m using a dual monitor setup using multiple X sessions instead of a Xinerama ultra-wide desktop. This means that I can’t drag windows between monitors, but it allows me to change desktops on them independently.

I found that when I set up the Tomboy notes Gnome panel applet on my secondary monitor, the notes would always appear on my primary monitor. To fix it, I had to:

$ sudo emacs /usr/bin/tomboy-panel
# Add the following line before the final “exec mono” line:
export DISPLAY=:0.1

There’s probably a neater solution (ie. could we set this when the tomboy-panel script is invoked?), but this was enough for me.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Export from OpenOffice to clean HTML

OpenOffice’s export to HTML feature produces very crufty HTML because it attempts to make the outputted document appear as similar as possible to the original document. Most of the time, I just want clean HTML. Here’s one way to get it:

  1. Export your OpenOffice document to HTML (I used the XHTML strict option)
  2. Install Ruby and the Sanitize gem
  3. Download this handy script
  4. Run like so:
    ruby sanitize_oo_html.rb < unwashed.html > pretty.html

The script contains a custom Sanitize filter that’s very simple, and it may not meet your needs. If not, feel free to tweak it. The Sanitize docs should help with that.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Deploy a subversion repository to a server without subversion

The problem

You have a website, stored in a subversion repository. The server you’d like to deploy to has shell access (ssh) but subversion is not installed, and you can’t install it. You want to be able to deploy changes to your website quickly and easily.

The solution

  1. Download this ruby script and place it in the parent directory of your working copy of the site.
  2. Edit the script and change the “src” parameter to the name of the directory containing your website.
  3. Determine the SVN revisions you’d like to deploy. This might be something like “128:132″.
  4. Run the script, like so: ruby deploy.rb 128:132
    Insert your own revisions as the command line parameter.
  5. The script will generate a file deploy-128-132.tgz. Copy this to your server.
  6. From within the production directory, untar the deploy-128-132.tgz file. This will overwrite the files that are to be modified in this update. It will also untar a delete script: delete-128-132.sh.
  7. Run the delete script: . delete-128-132.sh
  8. Remove the delete script: rm delete-128-132.sh
  9. Party!

Has this been useful? Drop me a line in the comments!

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter