How to rename a file in a File upload dialog on Mac

Windows users will scoff at this, but renaming a file in a File Upload dialog box on Mac is a surprisingly obscure action. Renaming is not available in the context menu, nor does the usual shortcut work.

Screenshot 2014-03-24 18.01.26To rename a file in a regular Finder window, you can select it and hit the Enter key. However, you can’t do this in a File Upload dialog as the Enter key has a different meaning.

To rename a file, select it, hit Cmd+I, open up the Name & Extension pane, and change the name.

Windows to Mac: Keyboard shortcuts

In December, I got a Macbook Air that I’m now using as a primary development machine. Before that, I was developing on a Windows 7 machine with heavy reliance on Git bash and Cygwin, and using Linux on the server. I’ve used Linux as a primary desktop at times, but found both dual-boot and VMs too much of a hassle.

I’m enjoying the Mac, but one of the biggest adjustments is keyboard shortcuts.

Here are some shortcuts that are specific to the Mac Terminal (and Terminal alternatives like iTerm 2):

Mac Mac Terminal Windows Action
Cmd+Left Arrow Ctrl+A Home Go to start of line
Cmd+Right Arrow Ctrl+E End Go to end of line
Shift+Cmd+Left Arrow Shift+Home Select to start of line
Shift+Cmd+Right Arrow Shift+End Select to end of line
Ctrl+K Clear line after cursor
Ctrl+U Clear line before cursor

Some general shortcuts:

Mac Windows Action
Cmd+Down Arrow PageDn Go one page down
Cmd+Up Arrow PageUp Go one page up
Cmd+Space Windows key Start menu/Spotlight
Cmd+Opt+Esc Ctrl+Shift+Esc Open Task Manager
Cmd+Delete Delete Delete selected files
Cmd+Delete Delete Delete character in front of the cursor
Cmd+R F5 Reload current webpage
Cmd+Shift+3 Save screenshot to desktop/Dropbox
Cmd+Ctrl+Shift+3 PrtScr Copy screenshot to clipboard
Cmd+Shift+4 Save screenshot of an area of screen to desktop/Dropbox
Cmd+Ctrl+Shift+4 PrtScr (SnagIt) Copy screenshot of an area of screen to clipboard

Of course, there are many more shortcuts.

libdb2.so.1: cannot open shared object file: No such file or directory – … ibm_db.so

Got this error while deploying a Rails app on Nginx:

This means that the ibm_db adapter is installed, but it can’t find the DB2 libraries. The issue is that IBM_DB_HOME and some other environment variables are not set.

The best solution is to make sure all users have db2profile loaded. Edit /etc/profile and add:

You should now reload your profile (. /etc/profile) and restart Nginx.

This assumes that you already have IBM Data Server Driver installed under /opt/dsdriver.

Linux command of the day: banner

banner can be a useful command for setting login and welcome messages (e.g via /etc/profile).

The Mac implementation is less useful than the GNU/Linux one.

 

JRuby for the Java .class is .java_class

I’ve been having a lot of fun working with a Apache jclouds in JRuby. All the examples for the API are in Java and Clojure, while online JRuby docs could be better, so there’ve been some interesting translation challenges.

I just had to re-Google what .class becomes in JRuby, so a quick note for the future.

Java:

JRuby:

 

Exploring Ruby and Python interactively

Both Ruby and Python offer great interactive shells, also known as REPLs (Read Eval Print Loops). These are handy for verifying snippets of code. You can invoke Python’s by simply running python or Ruby’s by running irb, jirb (for jRuby), or rails c (for Rails).

Sometimes, however, one can be mystified as to what one can do with an object or module. Lately, I’ve been finding the Ruby API documentation especially frustrating.

Fortunately, both Python and Ruby let you see what’s available. In Python, you can call the dir() function, while Ruby has the handy .methods() method.

Python:

And Ruby:

 

Circular dependency detected while autoloading constant

I recently ran into this frustrating and intermittent error in Ruby on Rails 4 (JRuby, actually):
Circular dependency detected while autoloading constant

Googling turned up several articles advising one to abide by the Rails conventions, but that was not the issue.

The application I’m writing uses background threads. The problem shows up when trying to instantiate a Rails controller in one of them. Rails searches for object definitions dynamically, so when multiple threads are trying to instantiate the same object, there’s a race condition.

The fix is define a mutex for access control:

And then use it in the threads when instantiating the controller, model, or some Ruby class: