Mini Magick

I just discovered MiniMagick. It is exactly what I was looking for in a ruby-language wrapper for ImageMagick.

I’ve been using ImageMagick forever. Like, more than 20 years foreer. Maybe 30 years;  I don’t know when it was first developed, or how old it was when I discovered it.

Some of the time, I use ImageMagick from the command line: just convert a file or montage a couple of them, or whatever. But sometimes, I do the same three things to an image and expect to do it over and over again for multiple images, I’ll write a shell script.

Writing shell scripts is hard. (Like, do you use trap? Of course you don’t.)

Writing Ruby is easy. But the only Ruby wrapper for ImageMagick I knew about was RMagick, which is big and complex and the first couple of times I tried to use it I had build problems (this was back before gems and github).

So there I was. Use bash and keep it simple, or use ruby with some crazy backtick `convert foo.png foo.jpg` shell escape there instead of doing it right.

But MiniMagick is just a well-designed wrapper around those backticks. Kudos!

Pandoc for Word Document conversion

I just discovered pandoc. Well, I first bookmarked it in 2008, and again in 2016, so I guess I rediscovered it. But what I mean is that I finally discovered what to use it for: converting Word files to Markdown. It’s dead easy:

$ pandoc -f docx -t markdown sample.docx > sample.md

I’ve been using Antiword for years to convert Word 2006 (DOC) files to text, but it doesn’t do DOCX, and, instead of producing Markdown or something more neutral, it tries to recreate the DOC experience in text by centering lines, etc. Not complaining: it gets me plain text and I can take it from there, but Markdown is a big improvement. DOCX is even better, since, apart from pandoc, the only way I knew to read those at the command line was via Libre/OpenOffice:

$ libreoffice –headless –convert-to “txt:Text (encoded):UTF8” sample.docx > sample.txt

(I see — now, when it is too late — that there is also code to do this in ruby: antiword-xp-rb. I hope that’s an awesome tool, but it took me 9 years to figure out what to do with pandoc so don’t wait for me to tell you.)

Tech Tab Sweep

Krita appears to be Gimp spelled sideways, but cross-platform, or more accurately, Gimp:Photoshop::Krita:Painter.

OpenSSH best practices. Mac OS X 10.10 “Yosemite” takes SSH security so seriously that after you upgrade, you can’t log in remotely. Even if you tell it you want to.

Use Ruby to make your graphs look hand-drawn, like the ones in XKCD.

Via RubyFlow: A set of step-by-step TDD tutorials, a library for importing real-world CSV data.

Gruff: a library for creating beautiful charts in Ruby.

Honeybadger.io: Use capture3 instead of backticks: capturing I/O from shell commands. I should be using pry instead of irb, and when I switch, here’s how to work with exceptions in pry.

Microsoft promises that you can clean install Windows 10 after upgrading. Hanselman confirms, but look at the questions in people’s comments. Someone at Microsoft should be asking, why don’t they trust us, and what do we have to do so they start?

Google’s new build tool: Bazel. What are the odds I’d switch when I’m still learning Rake?

More rbenv notes

My last post on rbenv mentioned some things you need to do to get ruby to build on Mountain Lion. Here are a few more things.

This guy Jacob Swanner didn’t want to use either Xcode or gcc. He just used the Xcode command-line tools, with a CC environment variable, thus:

$ CC=/usr/bin/clang rbenv install 1.9.3-p194
$ rbenv global 1.9.3-p194

That won’t work with older versions of Ruby, however, as I mentioned before.

I noted he is also a Homebrew user. I’m not yet ready to go there, although macports gets more and more frustrating with each OS release. (I’m not alone.) (But that’s a subject for some other time.)

And, for convenience, here’s another Homebrewer’s notes on how to get ruby building again with Mountain Lion

rbenv notes

I used to use rvm to manage my ruby environment, but the latest hotness seems to be rbenv. Here are some tips about using it. They’re aimed at me, because by the next time I need to use it, I’ll have forgotten. But you can read them too:

One of the things you want is rbenv-build:

Installing ruby-build as an rbenv plugin will give you access to the rbenv install command.

$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone git://github.com/sstephenson/ruby-build.git

(Note the assumption you’re using git. I don’t know what people who prefer mercurial are supposed to do.)

This will install the latest development version of ruby-build into the ~/.rbenv/plugins/ruby-build directory. From that directory, you can check out a specific release tag. To update ruby-build, run git pull to download the latest changes.

But that won’t work with Mountain Lion. So you’ll need a version of ruby that can be built with clang.

$ rbenv install 1.9.3-p125

Ruby and Mac OS X Lion

When Apple switched from GCC to LLVM in Xcode 4.2, they made it significantly more difficult for me to run ruby 1.9.2. (What are the odds this will get easier with Mountain Lion?)

I was using rbenv and its rbenv-build plugin to install ruby 1.9.2 and it told me this:

$ rbenv install 1.9.2-p320

ERROR: This package must be compiled with GCC, but ruby-build couldn't
find a suitable `gcc` executable on your system. Please install GCC
and try again.

DETAILS: Apple no longer includes the official GCC compiler with Xcode
as of version 4.2. Instead, the `gcc` executable is a symlink to
`llvm-gcc`, a modified version of GCC which outputs LLVM bytecode.

For most programs the `llvm-gcc` compiler works fine. However,
versions of Ruby older than 1.9.3-p125 are incompatible with
`llvm-gcc`. To build older versions of Ruby you must have the official
GCC compiler installed on your system.

TO FIX THE PROBLEM: Install the official GCC compiler using these
packages: https://github.com/kennethreitz/osx-gcc-installer/downloads

You will need to install the official GCC compiler to build older
versions of Ruby even if you have installed Apple's Command Line Tools
for Xcode package. The Command Line Tools for Xcode package only
includes `llvm-gcc`.

Note: when you install that, it doesn’t (appear to) provide an uninstaller. Instead it says this:

If something doesn’t work as expected, feel free to install Xcode over this installation.

Once installed, you can remove Xcode completely with the following:

sudo /Developer/Library/uninstall-devtools –mode=all

Bummer for me, huh? Mercifully, the GCC installation package doesn’t mess up the llvm-gcc link in /usr/bin/gcc. But that means when I do the ruby build, I need to add:

export CC=/usr/bin/gcc-4.2

Google Refine

A while ago, Google bought the company that made Freebase, a tool for making sense of messy data. Earlier this week, they released a 2.0 version of that software, now renamed Google Refine. Watch the videos to see what that does.

This looks pretty darned impressive. For great chunks of my career, I’ve been doing work like that the hard way. In the 1980s, I started my career by doing data reduction in Fortran, but quickly graduated to sed and awk, and in the 2000s I used perl and ruby. Of course, when I say “the hard way,” that is in hindsight. Each of those was an improvement over what I used before, and this looks like it could be a similar type of improvement.

(I still do some of that kind of work even now. It’s been a couple of years, but I probably spent at least a week, spread across too many evenings and weekends, massaging the church directory from a text format Word document into tabular spreadsheet data.)

RVM is pretty impressive

One of my frustrations as a casual Rubyist is trying to use some of these wonderful CPAN-like things that have appeared since I began playing with Ruby after the Hunt and Thomas article in Dr. Dobb’s. For example, gems.

The problem with Ruby (and especially rubygems) is that they don’t play nicely with the other package management tools on your system. (Ubuntu/Debian’s .deb‘s and MacPorts‘ ports). And I’m too stupid and lazy to bypass all that and go back to using tarballs and stashing everything in /usr/local.

Enter RVM, the Ruby Version Manager. It bypasses your system’s package management system. It creates a hidden folder ($HOME/.rvm) and puts whatever Ruby versions (and gems, etc.) there. But it does it all so cleverly you don’t realize what’s going on in the background. I like it.

Installing Ruby on Snow Leopard

Thanks to my helpers at Google and Hive Logic, I was able to install Ruby on Snow Leopard.

It amazes me that so many Rubyists use the Mac, because it’s always a pain in the neck to get it set up right. You have to decide whether to use the stock version, or one from the MacPorts or Fink package managers. Note that your answer doesn’t just need to address Ruby but also the RubyGems extension library system. The problem with a black box is you have to trust the people who boxed it up.

Alternatively, you can just install from source, per the above instructions.