Category Archives: geek

On this page:

Emacs, coaching, and unknowns: Figuring out what I want to learn

I’ve been playing around with the idea of hiring an Emacs coach, since Steve Purcell, Christopher Wellons, and Bastien Guerry all offer this service. It helps to go in with a clear idea of what I want to learn, though, so let me figure this stuff out.

Here are some general topics, sketching out an order for learning the subtopics:

  • Thinking syntactically, so that I can work faster and more reliably
    1. Expand-region: Faster selection.
    2. Smartparens: Logical manipulation. This is probably the biggest chunk.
    3. Erefactor, redshank: Other tools for working with Lisp.
    4. Magit: Thinking of changes in terms of commits; low priority because I rarely need to coordinate with others, although I can bump this up if working on community code
    5. In general, working with larger chunks – so also projectile and other cool tools
  • Web development workflow, so I can work more professionally and handle more complexity. Focusing on Rails, NodeJS, and AngularJS
    • Rails workflow
      1. Testing
      2. Constant testing with guard, better interaction with browsers, etc.
      3. Navigating between files in a project with Rinari or Projectile
      4. Code navigation and documentation lookup with Robe
      5. Working with things like HAML, Sass/Less, CoffeeScript
      6. Refactoring Ruby code
    • Javascript workflow
      1. Testing frameworks, running tests
      2. Getting autocomplete sorted out
      3. Integrating Skewer into the way I work
      4. Working with things like HAML, Sass/Less, CoffeeScript
      5. Rapid prototyping: Grunt, Yeoman, etc.
    • General-purpose tools
      1. Folding/overview, imenu?
      2. Jumping to specific points quickly – ace-window, ace-jump, helm-swoop
  • Integration, so that I can take advantage of Emacs in more parts of my life
    1. Organizing my journal
    2. Trying out Elnode so that I can expose Emacs information to Javascript
    3. Getting back to doing mail in Gnus
    4. Using MobileOrg to review Org on the go?
  • Internals, debugging, and contributing to the community so that I can help out, and so that I can customize and debug more extensively
    • Emacs core, Org internals, syntax, font-locking, indentation, macros, Helm, …

Coaches are also good for pointing out what you don’t even know you don’t know, which is a lot when it comes to Emacs. That’s another nice benefit of having someone look over your shoulder – they can catch you doing something in a round-about way even if you don’t even know that a more efficient way exists. But even with the stuff I know I don’t know (and that I have a reasonable plan for learning), there’s plenty to keep me occupied for the next few years. =) Besides, helping out on IRC and in mailing lists/newsgroups will expose me to stuff I don’t know too.

So instead of turning up on one of these people’s (virtual) doorstops and asking, “Can you teach me all the stuff I don’t know?”, maybe this is what I can do instead:

  • Lay the groundwork by writing about and demonstrating the things I do know, so that I explore my limits, help other people learn, possibly get suggestions from random passers-by, and help potential mentors/coaches quickly get a sense of what I might be missing
  • Double-check my plans for learning different things with more experienced people who can give me feedback on sequence, exercises, and things I should include
  • Develop plans for deliberate practice of different components; slow down and notice opportunities to try things out
  • Share what I’m learning and my plans for what to learn next
  • Touch base once in a while

So much to learn! =)

Publishing WordPress thumbnail images using Emacs and Org2Blog

I often include large images in my blog posts since I use sketches as another way to think out loud. I’d gotten used to using the WordPress web interface to drag and drop them into the relevant section of the page. I write most text in Emacs/Org Mode/Org2Blog because of the better outlining and writing tools, and then I used sacha/org-copy-region-as-html (which you can grab from my Emacs configuration) to copy the HTML markup and paste it into WordPress. Of course, I use Emacs for source-code heavy posts that make the most of its syntax formatting support.

Someone asked me recently about how to post and update blog posts with images through Org2blog, and if I had any recommendations for workflow. I’d dropped Windows Live Writer since it was flaking out on me and the WordPress web interface had improved a lot, but before recommending just using WordPress to add images, I was curious about whether I could improve my blogging workflow by digging into Org Mode and Org2Blog further.

It turns out (like it usually does in the Emacs world) that someone had already solved the problem, and I just didn’t have the updated version. Although the upstream version of Org2Blog didn’t yet have the thumbnail code, searching for “org2blog wordpress thumbnail” led me to cpbotha’s Github issue and pull request. Punchagan’s version had some changes that were a little bit ahead of cpbotha’s, so I dusted off my ancient org2blog repository, cloned it onto my computer, and issued the following commands:

git remote add upstream https://github.com/punchagan/org2blog
git pull upstream master
git remote add cpbotha https://github.com/cpbotha/org2blog.git
git pull cpbotha image-thumbnail

and tested it out on a blog post I’d already drafted in Org. It took me a little while to remember that the file URLs didn’t like ~, so I specified a relative path to the image instead. But then it all worked, yay! A quick git push later, and my Github repository was up to date again.

So now I’m back to running a Git version of org2blog instead of the one that I had installed using the built-in packaging system. The way I make it work is that I have this near the beginning of my Emacs configuration:

;; This sets up the load path so that we can override it
(package-initialize nil)
;; Override the packages with the git version of Org and other packages
(add-to-list 'load-path "~/elisp/org-mode/lisp")
(add-to-list 'load-path "~/elisp/org-mode/contrib/lisp")
(add-to-list 'load-path "~/code/org2blog")
(add-to-list 'load-path "~/Dropbox/2014/presentations/org-reveal")
;; Load the rest of the packages
(package-initialize t)
(setq package-enable-at-startup nil)

This allows me to mostly use the packages and to satisfy dependencies, but override some of the load paths as needed.

Hope that helps someone else!

Emacs hangout notes

Prompted by Michael Fogleman’s tweet that he’d like to see a bunch of us Emacs geeks get together in one room for a hackathon, Nic Ferrier and I tried out a casual Emacs hangout. Tinychat didn’t work, but Google Hangouts worked fine. A bunch of people saw our tweets about it too and dropped by, yay! Here are some things we talked about (mostly nifty tweaks from Nic):

  • shadchen is great for pattern matching, especially within trees
  • Alec wanted to know about Emacs and Git, so Nic demonstrated basic Magit
  • after-init-hook – load things there instead of in your ~/.emacs.d/init.el, so that your init.el does not break and you can test things easily from within Emacs
  • I shared isearch-describe-bindings, which had a number of goodies that I hadn’t known about before
  • Recognizing the opportunity to share what you’re working on (ex: nicferrier’s working on an Emacs Lisp to Javascript compiler)

Google Hangouts screensharing worked well for us, giving multiple people the opportunity to share their screen and allowing people to choose what they wanted to focus on. Nic also started up a tmux session and a repository of public keys, but that’s a bit more involved and requires more trust/coordination, so screen-sharing will likely be the way to go unless people have more of a pairing thing set up. This kind of informal hangout might be a good way for people to share what they’re working on just in case other people want to drop by and help out or ask questions (which people can optionally answer, or postpone if they want to stay focused on their work). Something a little more focused than this might be to pick one bug or task and work on it together, maybe starting with a “ridealong” (one person screenshares, thinking out loud as he or she works, and taking the occasional question) and moving towards full pairing (people working on things together). Some of my short-term Emacs goals are:

  • Improve my web development workflow and environment (including getting the hang of Magit, Smart Parens, Skewer, AutoComplete / Company Mode, and other good things)
  • Learn how to write proper tests for Emacs-related things
  • Get back into contributing to the Emacs community, perhaps starting to work on code/tests
  • Look up my Org agenda on my phone, probably with Org Mobile or some kind of batch process

Let’s give this a try. =) I set up a public calendar and added an event on Nov 5, 9-11PM Toronto time. If folks want to drop by, we’ll see how that works out!

Upgrading from Rails 3 to Rails 4; thank goodness for Emacs and rspec

I spent some time working on upgrading Quantified Awesome from Rails 3 to Rails 4. I was so glad that I had invested the time into writing enough RSpec and Cucumber tests to cover all the code, since that flushed out a lot of the differences between versions: deprecated methods, strong parameters, and so on.

rspec-mode was really helpful while testing upgrade-related changes. I quickly got into the habit of using C-c , m (rspec-verify-matching) to run the spec file related to the current file. If I needed to test specific things, I headed over to the spec file and used C-c , s (rspec-verify-single). Because RSpec had also changed a little bit, I needed to change the way rspec-verify-single worked.

(defun sacha/rspec-verify-single ()
  "Runs the specified example at the point of the current buffer."
  (interactive)
  (rspec-run-single-file
   (concat
     (rspec-spec-file-for (buffer-file-name))
     ":"
     (save-restriction
               (widen)
               (number-to-string (line-number-at-pos))))
   (rspec-core-options)))

(sacha/package-install 'rspec-mode)
(use-package rspec-mode
  :config
  (progn
    (setq rspec-command-options "--fail-fast --color")
    (fset 'rspec-verify-single 'sacha/rspec-verify-single)))

C-c , c (rspec-verify-continue) was also a handy function, especially with an .rspec containing the --color --fail-fast options. rspec-verify-continue starts from the current test and runs other tests following it, so you don’t have to re-run the tests that worked until you’re ready for everything.

I should probably get back to setting up Guard so that the tests are automatically re-run whenever I save files, but this is a good start. Also, yay, I’m back to all the tests working!

Test coverage didn’t mean I could avoid all the problems, though. I hadn’t properly frozen the versions in my Gemfile or checked the asset pipeline. When I deployed to my webserver, I ran into problems with incompatible changes between Rails 4.0 and 4.1, and Bootstrap 2 and Bootstrap 3. Whoops! Now I’m trying to figure out how to get formtastic-bootstrap to play nicely with Bootstrap 3 and Rails 4 and the latest Formtastic… There are some git repositories that claim to do this correctly, but they don’t seem to work.

Grr.

Fine, I’ll switch to simple_form, since that seems to be sort of okay with Bootstrap 3. I ended up using this simple_form_bootstrap3 initializer along with

# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
config.collection_wrapper_tag = :div

# You can define the class to use on all collection wrappers. Defaulting to none.
config.collection_wrapper_class = 'collection'

and this in my style.css.sass:

.form-horizontal
  .control-group
    @extend .form-group
  .control-label
    @extend .col-sm-2
  .control-group > .form-control, .form-group > .form-control, .form-group > .collection
    @extend .col-sm-10
  .help-block
    @extend .col-sm-offset-2
  .control-label.boolean
    text-align: left
    font-weight: normal
    @extend .col-sm-offset-2
  label.radio
    font-weight: normal

which is totally a hack, but it sort-of-semi-works for now.

More changes to come, since I’ve got to get it sorted out for Rails 4.1 too! Mrph.

Sleep as Android

Following W-‘s example (I’m such a copycat!), I’ve been trying out a few sleep-related applications on my phone. I get more sleep than he does and my schedule is pretty flexible, but I figure that an app might let me swap out the diminishing returns of sleeping in for some extra discretionary time. For a while, I ran Sleep as Android in parallel with SleepBot, and I also tried each of them separately. I used a sturdy, extra-long USB cable to charge my phone, and I slept with my phone under my pillow.

Both apps seem to agree with each other on the motion they detect, and they also appear to do a decent job of distinguishing between my motion and W-‘s motion (we have different-looking graphs). I’m not sure if there’s a significant difference, but I prefer Sleep as Android’s timing, so I bought it after the trial ended.

I also like Sleep as Android’s way of gradually waking me up with short buzzes, gradually leading up to an audio alarm. I like buzzes because they feel more discreet. I don’t have to feel guilty about interrupting W-‘s sleep.  They also don’t lead to overexposure to whatever tones I picked for my alarm. I’d previously used the built-in Medieval Jaunt and songs like Shonen Knife’s Cookie Day, and those still result in an odd tug on my concentration whenever I hear them.

I’m still not keen on morning meetings, but I can make them with less grumbling now!

Microsoft Excel: Converting a summary table / crosstab back into data rows

I recently wanted to transform a summary table of the form:

2014-10-15 20_36_58-Microsoft Excel - Book2

into a table with rows of (activity, date, value) so that I could add columns for year and month and then analyze the data using a pivot table.

It turns out that you can do this with another pivot table, yay! I followed this tutorial to convert my summary columns into data rows using Microsoft Excel 2010.

  1. Press Alt-D, P to get to the secret pivot table wizard that’s different from the one you get from Insert > Pivot table.
  2. Choose Multiple consolidation ranges. Click Next.
  3. Choose I will create the page fields. Click Next.
  4. Select the range and add it. Go through the rest of the wizard to create a pivot table.
  5. Remove the row and column fields.
  6. Double-click on the total.

You should now see a table with the data from your crosstab.

2014-10-15 20_43_25-Microsoft Excel - Book2

Neato! Pivot tables are even cooler than I thought.