When in Sed Land, Read the Input File

A couple of days ago I was playing around with sed in Mac just for fun, and came up to a quite confusing issue: I could not match NAME using /NAME/ as a context address. In fact, trying to match anything using a longer-than-2-chars regexp would not work:

/NA/ would match NAME
/AM/ would match NAME
/ME/ would match NAME
/NAM/ would not match NAME
/AME/ would not match NAME

This was quite puzzling. After trying different things and looking around the internet I was still where I had started. Then I decided to try using small letters:

/th/ would match many different lines in the input file
/the/ would match many different lines in the input file

Woah! I could use longer-than-2-chars with small case letters, but not with capital ones. WTF? I continued trying with different combinations using capital letters, and anything with 1 or 2 chars would work, but more than 3 chars wold fail to match anything even though there seemed to be matches in the input file.

After a long time with this I decided to check the input file as a last act of hope. I found the problem.

At this point I should tell you how I got the input file. Remember how I said I was just practicing some sed. Well, I thought that an easy way to get a practice input file would be to put the contents of the man page for sed in a regular text file:

man sed > input_file

Well, that was not the best idea. My file ended up something like:

N^HNA^HAM^HME^HE

I didn’t notice that when I fist made the file because ^H is a BS control character, and doing

cat input_file

produces the expected text NAME because cat interprets those control characters, but opening the input file in vim revealed the control characters.

This is one of those life lessons that you never really forget, but if you do, you will feel stupid the next time you have to re-learn it. Read the input file in a text editor.

Ruby Bundler Install Error on Mac OS

I migrated a project a couple of days ago from Fedora to Mac OS. The project uses bundle to install the required ruby gems, and I ran bundle install when I migrated the project, so today I expected it to just work. But it did not.

One of the gems the project uses is sass, and it also uses a watch task in grunt to compile sass files automatically, However, when I edited a file, I got an error. Sass was not installed. I ran bundle install again, and noticed that the command was returning some errors about certain files not being writable. This is because of the ‘rootless‘ feature in Mac OS, which prevents anybody, even root, from writing to certain locations. One of those locations is /usr/bin, which bundle was trying to write to to add the gem executable files. No wonder I was getting a not-istalled error for sass. However, I hadn’t really realize that just jet.

I decided to investigate the issue, and found that some people who had the same problem fixed it by adding certain location to their path. This is when I actually understood what was going on, because even though I had seen the bundle errors, I hand’t really understood the issue. As I said before, bundle was trying to write to a location where it could not. I.e. /usr/bin.

I did some more researching and found some information about the gemrc file, and how it can be used to tell gem where it should install gems. I created a gemrc file, and tried bundle install. The error didn’t get fixed.

I decided to look for the documentation for bundle install, and there I found that you can specify where gems should be placed, and where the executable files should be placed. I finally ran the command

bundle install --force --path=~/ --binstubs=~/bin

It failed with error

Errno::EACCES: Permission denied @ rb_sysopen – /Users/me/bin/bundle
An error occurred while installing bundler (2.0.0), and Bundler
cannot continue.

AT this point I was loosing hope, and getting frustrated, but I continued looking for an answer. That is how I found that I probably had the wrong permissions for bundle. I listed the contents of my ~/bin directory, and found that the bundle file was owned by root. I changed ownership of the file to me, and this finally got everything working correctly.

It may seem like I fixed this issue in no time, but the reality is that I spent over two hours trying until finally being able to make it work. I should say, though, that I am no ruby developer. This project is the only place were I’ve ever used bundle, and gems that I can think of. Plus, I’m finding out that the ‘rootless‘ feature is at a minimum as annoying as selinux, but I would never, ever, advice anybody to disable it, nor would I do it in my own computer:

Setting Up Canon G3111 on Mac OS Mojave

Today I was setting up the home printer on the Mac OS Mojave machine, and, although there is a driver download page from canon, there is no download button, or at least I  couldn’t find one. The printer doesn’t seem to support AirPrint, and none of the other options in the printer settings seemed to work. The solution: find a driver.

A quick search got me to this page https://ijcanon.com/canon-pixma-g3110-drivers-download/ where I selected the CUPS driver for Mac OS, and went through the set up process. After that was done, I went to system preferences > Printers & Scanners, and clicked the plus button. The printer was listed in the Default section, and I selected it as I had been doing previously, and again, no driver was auto-selected for it. I selected the “Select software” option in the section labeled “Use”, and this time, there was a G300 driver option on the list that appeared. That option wasn’t there previously. I selected that, and Clicked Add to add the printer. The printer is now set up and working.