Tag Archives: ruby

Psych 4.0 is broken

That’s what I hear, anyway, that Psych 4.0 quit working.

The toolchain I’ve constructed to publish my podcast quit working after a recent upgrade I’ve been trying to get it working.

Unfortunately, while I’ve been using ruby since 2001, I’ve never had to figure out how rubygems work. I program for a hobby. It’s not my day job. For what I do, I’ve always been able to use the most recent version. I don’t even know how to use Bundler. (As a first step, I should try it in a single script.)

I did figure out that I could uninstall 4.0, but I might need something that depends on it. So I need to learn how to specify a particular version in my own scripts.




OpenSSL problem on (older?) Macs

I had a whole bunch of problems break my podcast all at once, and I’m slowly figuring them out, one by one.

One of the problems is keeping both ruby 2.7.4 and 3.0.2 from building:

Installing openssl-1.1.1l...

BUILD FAILED (Mac OS X 10.13.6 using ruby-build 20211109)

Inspect or clean up the working tree at /var/folders/2h/930zdx_d2dv8l6tg8m_kw_fh0000gn/T/ruby-build.20211114160436.20979.mnlPJV
Results logged to /var/folders/2h/930zdx_d2dv8l6tg8m_kw_fh0000gn/T/ruby-build.20211114160436.20979.log

Last 10 log lines:
        ^
clang  -I. -Iinclude -fPIC -arch x86_64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/Users/luke/.rbenv/versions/2.7.4/openssl/ssl\"" -DENGINESDIR="\"/Users/luke/.rbenv/versions/2.7.4/openssl/lib/engines-1.1\"" -D_REENTRANT -DZLIB -DZLIB_SHARED -DNDEBUG -I/Users/luke/.rbenv/versions/2.7.4/include  -MMD -MF crypto/rand/randfile.d.tmp -MT crypto/rand/randfile.o -c -o crypto/rand/randfile.o crypto/rand/randfile.c
crypto/rand/rand_unix.c:385:47: error: use of undeclared identifier 'kCCSuccess'
    if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess)
                                              ^
2 errors generated.
make[1]: *** [Makefile:4637: crypto/rand/rand_unix.o] Error 1

Because I’m the next thing to a Normie, I never discover a new problem. This one has been observed since September (or earlier). That post says “the OpenSSL fellows do not develop on MacOS.” Fortunately, some people do. But I have to learn how to use the workarounds.

Useful gems, 2020 edition

Since the gem ecosystem keeps changing, and since I don’t write new programs very often, here’s a list of my favorite gems for developing command-line interface tools.

Option parsing gem: slop. (Since micro-optparse looks moribund; see here.) But (looking at programs I’ve written) I also seem to like trollop, a/k/a optimist. But I also like the fine-grained control of OptionParser.

Debugging output (not the same as logging): pastel

Invoking system functions gem: tty-command. (See also tty-config and tty-file.) But sadly, tty-command (or how I’ve used it) gets me warnings that bellyache about the 2.7 named argument splat problem.

Wrapper for ImageMagick: About a decade ago, I couldn’t get RMagick (rubymagick?) to compile and I’ve never gotten around to checking back. For awhile I used %x<convert ...> or whatever, but now, if I’m working with images, I’ve sometimes found mini-magick helpful.

Proper Capitalization of Text Strings That Are Titles: titleize.

Parsing Biblical references (e.g., Romans 8:39 and Genesis 12:1-4): pericope.

Plus Kramdown and HAML and SASS (which is no longer written in Ruby).

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.

Setting Up a Mac

Fixing mouse scroll direction, key bindings, setting up Exposé spaces, etc.

Installing Keynote, Numbers, and Pages plus any software previously purchased from the App Store.

Installing replacement browsers: Chrome, Firefox, and Brave, along with Xee and iTerm2 and Skim.

Installing MacPorts, then software starting with ImageMagick. Imagemagick because it’s a good test of everything working properly.

$ sudo port install imagemagick +graphviz -x11

Then adding some of my favorite utilities

$ sudo port install antiword bat colordiff exiftool jhead lame sox tree xz

$ sudo port install ffmpeg -x11

$ sudo port install nnn ranger

Then install software development languages: go, rust, and ruby. Follow them with some CLI utilities written in those languages:

$ cargo install broot cw du-dust dutree exa fd hexyl \
just lsd pastel ripgrep sd

$ go get -u github.com/gokcehan/lf

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!

iMac configuration

I mentioned previously how I’ve rehabilitated the 10-year old iMac. Today, I’ve been setting up the software environment.

First, I transferred my iTunes library over to the new computer.

Then I installed some non-Safari browsers: Chrome, Firefox, and Brave.

Then I set up Homebrew, and after that, ruby:

$ brew install openssl # various messages because Apple doesn’t like openssl
$ brew install sqlite pcre
$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install -l
$ rbenv install 2.4.1 # (as of May 19, 2017)
$ hash -r # rehash your environment

Things I Did After Installing 17.04

Here in one place is my list of things to do after installing a new operating system.

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install ssh

Then try to ssh into the computer. If needed, apply the fix to Zeroconf / Avahi / NSSwitch.conf.

Next:

$ sudo apt install git
$ sudo apt install colordiff
$ sudo apt install libreadline-dev
$ sudo apt install vim vim-gtk3
$ sudo sudo apt-get --purge --reinstall install ttf-mscorefonts-installer

Then I got things ready for ruby. I prefer rbenv:

$ sudo apt install libssl-dev zlib1g-dev # needed for ruby
$ sudo apt install sqlite3 sqlite3-pcre
$ cd ; git clone git://github.com/sstephenson/rbenv.git .rbenv
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install -l
$ rbenv install 2.4.1 # (as of April 28, 2017)
$ hash -r # rehash your environment

P.S. if later on you want a later version of ruby, the way you update the list of installable ruby’s is:

$ cd ~/.rbenv/plugins/ruby-build ; git pull

Then use gdebi to install Google Chrome.

$ sudo apt install gdebi
$ apt install chromium-browser chromium-codecs-ffmpeg chromium-codecs-ffmpeg-extra
$ apt install telegram-desktop

I’d love to be able to pre-populate Dropbox from a local backup when I setup a new computer. But I’m not smart enough, I guess.

$ sudo apt install antiword wv jhead
$ sudo apt install imagemagick poppler-utils

Tech Links

LinuxUser (UK): Create a NAS box from spare parts.

Ars: Intel’s Broadwell mini-PC. I love the form factor. But then, I’ve owned three Mac Minis.

I keep thinking I should learn the R language. Of course, I used to think that about GnuPlot.

HowToForge: Installing Git and Using GitHub on Ubuntu.

GSoC: SciRuby. There’s a program I’d love to rewrite 20 years later using a high-level language to do the Fast Fourier Transforms. I’m not sure what I’d use for the GUI.

Web UpD8: Install the official Telegram client for Linux.