Mike Conigliaro

My Essential Sublime Text Plugins

Sublime Text has been my go to editor since John De Goes introduced me to it around 2010, during our time at SocialMedia.com. I had already been looking for a new cross-platform editor to replace my beloved jEdit, which even then was feeling a bit old and neglected. It took a year or so before I was able to fully make the switch (Sublime Text was in pretty heavy development at the time), but these days, you can find a plugin to help with just about anything.

Package Control

Package Control is the package manager for Sublime Text, and the main Package Control website is the place to search for new plugins.

Once it’s installed, type ctrl+shift+p (Win, Linux) or cmd+shift+p (OS X) followed by package (all Package Control commands begin with “Package Control:”).

SublimeLinter

SublimeLinter is a lint framework for Sublime Text. Once it’s installed, you’ll be able to use several lint plugins that make use of it. My favorites include:

These plugins have saved me from countless errors.

GitGutter

GitGutter shows you what lines were changed, added, or removed since your last commit. It’s like having a constantly updated git diff built in to your editor.

MarkdownEditing

There’s nothing worse than updating a README.md and not realizing that your formatting is all screwed up until you look at it on GitHub. The MarkdownEditing plugin gives you some nice Markdown syntax highlighting, so you can preview your changes before committing them. Like the SublimeLinter plugins above, this one has saved me from countless errors.

SideBarEnhancements

The context menus in Sublime Text’s sidebar are pretty limited by default. The SideBarEnhancements plugin adds lots of useful file operations.

Chef

The Chef plugin hasn’t been updated in a long time, but it’s still useful in Sublime Text 3. It provides auto-completions for most of Chef’s built-in resources, which makes writing cookbooks faster and easier.

Troubleshooting Headless Tests on a Remote CI Server

I just ran into a problem that was causing the Jasmine tests on our Jenkins CI box to hang forever, and I figured I should document this handy little troubleshooting tip in case someone else might find it helpful.

If you hop onto your CI box while your headless browser tests are running, you should see an Xvfb process that looks something like this:

# ps -efww | grep Xvfb
jenkins  18833     1  1 21:18 ?        00:00:00 /usr/bin/Xvfb :99 -screen 0 1280x1024x24 -ac

Since Xvfb is using display :99, you’ll want to run x11vnc accordingly:

$ x11vnc -display :99

Now you should have a VNC server listening on port 5900. Just fire up your VNC viewer and connect as usual:

$ vncviewer host.example.com:5900

But what if you’re accessing your CI server over an insecure network? You can use SSH local port forwarding to create a secure tunnel:

$ ssh -L 5900:localhost:5900 host.example.com x11vnc -display :99

Now you can connect to the VNC server over the secure tunnel:

$ vncviewer localhost:5900

From WordPress to nanoc

I finally decided to start blogging like a hacker, which is ironic, considering that I’ve actually come full-circle now. Back in the late-nineties (before I knew about databases, and before the term “blog” even existed), I spent a lot of time working on a Perl-based blogging engine that actually worked pretty similarly (though much less sophisticatedly) to how a lot of today’s static site generators work. Instead of working with sane formats like YAML or Markdown (which didn’t exist back then), I ended up managing everything in my own pseudo-XML format. As ugly and hackish as this system was, the resulting output was pretty nice, and the project was definitely a good learning experience for me as a teenager. But now that static site generators are all the rage, there are a lot of much better options out there, which gives us “hackers” a good opportunity to migrate away from WordPress without a ton of effort.

After reading this thread on Hacker News about yet another new static site generator, I decided to give nanoc a spin (mostly because it seemed to be the most popular option by people commenting on that thread). I skimmed through the nanoc Getting Started guide and (for the first time in several years) set out building a new layout for my new site. Since I didn’t want to revisit the pain of the old days of web design, I made sure to get Compass integration working right away.

Once the layout was done, I spent about a week slowly reimplementing features and moving data over from my old WordPress site. The static pages were basically just a copy & paste (with some manual converting to Markdown), but there was no way I was going to repeat that process for 100+ blog posts. There are a few example WordPress-to-nanoc scripts floating around, but they all left a lot to be desired, so I ultimately ended up writing my own. The result of that effort can be found in wp2nanoc.rb. Besides the addition of some nice command line option parsing, my script also does some basic conversion from HTML to Markdown and from WP-Syntax to SyntaxHighlighter.

The last thing to bring over were my comments, and Disqus handled most of that for me. I basically just installed the Disqus WordPress plugin and ran through the automatic import process. Then to make the comments show up on my new site, I set disqus_shortname and disqus_url to the appropriate values in my embed code. Note: If you find the developer documentation as confusing as I did, just know that these are the only values that need to be set. I originally tried using disqus_identifier, but that didn’t work, because the plugin uses unconfigurable, WordPress specific values for this option which obviously won’t be available in nanoc.

So what did I gain from my migration to nanoc?

  • I can now keep my entire site (data and all) in git
  • Static files mean blazing speed
  • No database means I can host my site in Amazon S3 for pennies
  • No more worrying about PHP/WordPress security issues
  • I got to experiment with new (to me) technologies like Haml, Sass/SCSS, Compass and Blueprint

PHP Considered Harmful

I know what you’re thinking. “Not another anti-PHP blog post!” But instead of complaining about specific deficiencies in the language, or how I think PHP encourages you to be a bad programmer or whatever, I want to talk about a fairly eye-opening conversation I just had with a friend. We were talking about possible optimizations for some of our Project Euler solutions. Since I don’t have enough of a background in number theory to come up with many of those kinds of tricks, I suggested that threading might be a simple way to make a big difference for some problems.

Friend: “I don’t know what you’re talking about.”

Well, for example, instead of iterating through a huge range of numbers with one giant loop, you could break the range up into several smaller ranges (according to the number of cores on your machine), then run your algorithm several times in parallel and just sum up your results at the end.

Friend: “Haha, I still have no idea what you’re talking about.”

And then it dawned on me; my friend doesn’t have a formal computer science or engineering background, and he’s been working with PHP (a language with no concept of concurrent programming) almost exclusively for about a decade now. He’s a smart guy, and not what I would describe as a stereotypical “bad PHP programmer,” but the fact that he hasn’t spent much time with any other languages means he’s never been exposed to this very fundamental concept in computer science. Now, I’m fully aware that most web developers don’t normally have to deal with concurrent programming at all, but I still think it’s something every programmer should have some rudimentary knowledge of. And I’m willing to bet that if my friend had been working with Python or Ruby all these years, he would have at least seen some mention of threads in library documentation or someone else’s code.

But maybe the point isn’t just that PHP is harmful. Maybe it’s that spending all your time working with any one language is harmful. This conversation made me wonder what kinds of things I might be missing out on by spending all of my time working with Ruby and Python!

Project Euler

I’ve been working on Project Euler problems in my spare time for the last few weeks. I don’t really know what a “good” score is, but here’s my ranking so far:

I think one of the reasons these problems are so much fun to solve is because no single algorithm is necessarily more “correct” than any other (assuming you get the correct answer at the end). Consequently, there are widely varying philosophies when it comes to how they should be solved. Some people go for the most efficient algorithms, using all kinds of arcane bit-shifting tricks in low-level languages like C and assembly. Other people are only concerned with programmer productivity, opting for simple brute-force solutions that may take several hours to finish.

My personal goal has been to come up with elegant and reasonably efficient algorithms in as few lines as possible. Nice looking code almost always wins out over efficiency for me, but if my solution takes more than 30 seconds to finish, then I know I have some serious optimization to do. For a non-math guy, I think I’ve been doing pretty well so far, considering that most of my solutions finish in a fraction of a second, and the average across all my solutions is currently less than 3 seconds.

Which brings me to my next point. As a person who went through school absolutely dreading my next math class, I find it kind of amazing that I’ve been willing to spend hours solving these problems in my spare time. This tells me that there’s something seriously wrong with the way math is currently being taught. I suspect Bret Victor is on to something when he says “math needs a new interface.”