rubocop and rufo

I’ve been writing in the Ruby language since sometime in 2002, but if I was looking for a job, I don’t know enough to call myself a ruby programmer. I don’t know rails or anything of the other cool things people do with ruby. I’ve learned to use gems, but haven’t bothered to learn how to write them myself.

But I’m not opposed to learning. I just haven’t gotten around to it yet.

Or so I thought. Then I ran into rubocop, which is a sort of linter and style cop. Those can be helpful, so I thought I’d give it a try. And it’s mostly good. Except it’s opinionated, and some of their opinions are wrong. For example:

  • the indentation should be four spaces, not two as they suggest
  • parallel assignment is the bomb, despite what they say
  • I use double quotes (") pretty much everywhere I’m not forced to use single quotes ('). They want to save time for the compiler, I guess.
  • You need space inside parentheses (although I will grant the extra whitespace is less important with syntax highlighting than without it).
  • And if I’m declaring a RE that’s so complicated I’m using /x flag, then don’t tell me to use /.../ instead of %r<...>.
  • And speaking of which, go ahead and use $1 and $' when retrieving the results of an RE match. (In moderation.) Honestly, this is a tie. Go ahead and use named groups if you want to.

But you can’t fight city hall. If some younglings want to make Ruby over in the style of Python, well, that’s a crying shame. Ruby is supposed to occupy the perfect spot between Perl and Python. But these kids today! If they’re on your lawn, you might as well go along with their misguided project. And that brings us to rufo, the ruby reformatter. You can use it to do like 10% of the things that rubocop whinges about.

More of those CLI Utilities

I’ve found some more CLI utilities (via this thread) that look like they’re worth further investigation.

  • Zola, a static site generator
  • fd (a/k/a fd-find), an “80% replacement” for find; see also fselect
  • xsv, a tool for working with CSV files
  • broot, another disk analysis/tree replacement
  • sd, a sed replacement
  • cw, a wc replacement
  • hors, a combination of lynx and the technical web (which I couldn’t build on my Linux system because it’s running gcc instead of clang). (Ditto ‘bat’ btw.)
  • lolcate, a locate/updatedb replacement

I’m intrigued by topgrade but a little terrified of actually using it.

And I found the indispensable utility called genact.

Rust Command-Line Utilities

I’ve been learning (or maybe beginning to learn) the Rust programming language. (It was a toss-up between that and Go, and I probably picked wrong, but I won’t know until I know a lot more than I do now.)

  • Tokei (for counting source code lines) and
  • diffr as an alternative to colordiff
  • ripgrep as an alternative to ack (etc.)
  • just as a command runner (think “make”)
  • lsd and exa as replacements for ls
  • pastel for working with colors on the command line
  • skim (not to be confused with the excellent Skim) as a fuzzy finder
  • dust, dutree, and dua-cli as replacements for du
  • bat (“better cat”) and mdcat (cat for markdown)
  • starship (prompt)

I’m only beginning to play with these. But I was surprised to see so much activity developing command line utilities. There is some misunderstanding of the Unix philosophy, but it’s understandable (cat isn’t for viewing files, but of course that’s how most of us use it). Yay open source!

installing eyeD3

I keep thinking I should learn the basics of Python programming. But I never seem to get around to it.

Today I needed to know how to install a program written in Python, because Homebrew used to include eyeD3 and today it didn’t. Here’s what I ended up doing:

$ sudo easy_install pip   # because pip isn’t installed

$ sudo pip install eyeD3

then it says that won’t work because libmagic isn’t installed. But fortunately, Homebrew provides that (whatever it is). So try again:

$ brew install libmagic

$ sudo pip install eyeD3

P.S. eyeD3 is the best command-line ID3 tag editor I’ve found. It is the only thing I’ve found that allows you to install album art from the command line. (See my earlier post.)

 

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.)

Dodged the XML bullet

Years ago, when XML was the new hotness, I kept meaning to learn it. (I mean, I learned it, except the headers and CDATA, but I never figured out how to use XPath or XQuery or XSLT or do anything useful with it. I learned just enough to write a toolchain that emits an RSS feed that iTunes is happy with and stopped there. Tidy is your friend.)

Maybe I dodged a bullet. The other day Manton Reece and Brent Simmons came up with JSON Feed, a replacement (or at least an alternative to) Atom and RSS. Suits me. I prefer YAML to JSON, but I’d take either one over XML even if I could only see them upside down in a mirror.

It’s not there any more, but in their first announcement (quoted here), Reese and Simmons committed a gaffe and said what they thought:

developers will often go out of their way to avoid XML. JSON is simpler to read and write, and it’s less prone to bugs.

Duh. But the rationale they state now is still true, if a little less transparent.

While I’m thinking about it: a pet peeve. RSS says that <pubDate> wants an RFC 822 compliant timestamp for feeds, but good luck if you’re in Alaska, which is part of the US not in the big four time zones. (Use Zulu -0900 instead.)

Updated. More brutal honesty:

Reece and Simmons decided the time was right to build an updated syndication format, as more and more developers are refusing to work with XML.

“I believe that developers (particularly Mac and iOS developers, the group I know best) are so loath to work with XML that they won’t even consider building software that needs an XML parser,” Simmons said. “Which says to me that JSON Feed is needed for the survival of syndication.”

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?

Tech Links – May 29

Three open-source Python shells.

Don’t catch Exceptions. I must have known why I always do rescue => boom to catch exceptions. The reason is that Ruby makes that shorthand for rescue StandardError => boom. Nifty.

libgrader: find quality gems for your next project. It knows about two of my favorites gems: pericope and titleize. (Unlike awesome-ruby.)

Sequel: the database toolkit for Ruby. (Here’s an introductory screencast at RubyTapas.) I keep thinking I should do something with sqlite. Well, really I think I should do something with a database, but I’d rather put it on Drobox than try to figure out how to have a mysql server out on the internet and not regret it.

The reason? Once you’ve used a join you’ll never be content using a spreadsheet for a database. Here’s a quick introduction to joins.

Mac audio graphing tool FuzzMeasure updated. I didn’t remember that it had a name of its own. I thought it was just SuperMegaUltraGroovy. Anyway, every time I look at this I think to myself about the software I wrote in the mid-90s and all the cool graphs I’d like to have implemented.

Tech Tab Sweep

It’s time to upgrade your Ubuntu machines.

8 things to do after installing Ubuntu 15.04. One of the items is to add a tweak tool, which reminded me of Unsettings.

I’m working on a similar list for Windows, except (a) nobody gets to install Windows, you have to buy a PC with it preinstalled, and (b) there are about 300 things you have to do next.

Speaking of Ubuntu…. I barely know what a .deb is, so this article was complete gibberish to me, with all this talk about Snaps and Snappy for future releases of Ubuntu.

Bjarne Stroustrup outlines changes in store for C++ in v17. I can barely remember how awesome I used to think C++ was back in 1986. And compared to C, I guess is was, then. Today—forget about it. Just give me a scripting language.

Finally: During the 1990’s I used to be a DIY system builder, but the past decade or two I’ve been too busy and too impoverished. And there’s a lot to be said for buying something small. Still, I might get around to building something again someday. This sounds like fun: