Mac OS X Mavericks, rbenv, and ruby-build "Missing the OpenSSL lib?"

openssl version: 1.0.1i, rbenv version: 0.4.0, ruby-build as plugin in the ~/.rbenv/plugins directory.

The version of openssl on a Mavericks machine got out of sync with rbenv and ruby-build for some reason. For every attempt at installing a ruby version through rbenv attempted, we got the following message:

"The Ruby openssl extension was not compiled. Missing the OpenSSL lib?"

Tried every permutation of trying to fix one thing at a time, but ultimately ended up doing the following:

~/.rbenv/plugins/ruby-build directory
brew unlink openssl rbenv ruby-build
brew uninstall openssl rbenv ruby-build
brew update
brew install openssl
brew link openssl --force
brew install rbenv
eval "$(rbenv init -)"
brew install ruby-build

Then we were able to install whatever ruby version we wanted.

I'm sure some of the above process was overkill and unnecessary, but the steps in total did the job.

Excel for Mac Breaks Up Spreadsheets Into Pages

Excel for Mac seems to use "Page Layout" view by default. This can be switched to the more sane Normal view by selecting View -> Normal from the menu.

You can change the default view in Excel -> Preferences -> View -> Preferred view for new sheets.

Still trying to figure out if there is a way to force all document openings to this setting as well.

powerline vim, NameError, invalid expression error on the latest update.

I have vim with pathogen and on the latest update of the powerline.vim, everything broke.

It turns out that my old default config files are incompatible with the new version of powerline. See GitHub issue.

When I ran vim with --cmd 'let g:powerline_config_overrides={"common":{"log_file":"/tmp/powerline.log"}}' as suggested, a bunch of config mapping errors showed up:

2014-09-03 15:36:33,992:ERROR:vim:matcher_generator:Failed to import attr ctrlp from module powerline.matchers.plugin.ctrlp: No module named plugin.ctrlp
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/__init__.py", line 311, in get_module_attr
    return getattr(__import__(module, fromlist=(attr,)), attr)
ImportError: No module named plugin.ctrlp
2014-09-03 15:36:33,993:ERROR:vim:matcher_generator:Failed to import attr gundo_preview from module powerline.matchers.plugin.gundo: No module named plugin.gundo
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/__init__.py", line 311, in get_module_attr
    return getattr(__import__(module, fromlist=(attr,)), attr)
ImportError: No module named plugin.gundo
2014-09-03 15:36:33,995:ERROR:vim:matcher_generator:Failed to import attr nerdtree from module powerline.matchers.plugin.nerdtree: No module named plugin.nerdtree
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/__init__.py", line 311, in get_module_attr
    return getattr(__import__(module, fromlist=(attr,)), attr)
ImportError: No module named plugin.nerdtree
2014-09-03 15:36:33,998:ERROR:vim:matcher_generator:Failed to import attr gundo from module powerline.matchers.plugin.gundo: No module named plugin.gundo
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/__init__.py", line 311, in get_module_attr
    return getattr(__import__(module, fromlist=(attr,)), attr)
ImportError: No module named plugin.gundo
2014-09-03 15:36:34,010:ERROR:vim:segment_generator:Failed to generate segment from {u'name': u'mode', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,010:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 10, u'name': u'visual_range', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 10, u'name': u'paste_indicator', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 30, u'name': u'branch', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'after': u' ', u'name': u'readonly_indicator', u'draw_soft_divider': False}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 40, u'name': u'file_directory', u'draw_soft_divider': False}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'name': u'file_name', u'draw_soft_divider': False}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'name': u'file_vcs_status', u'draw_soft_divider': False, u'before': u' '}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'name': u'modified_indicator', u'before': u' '}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 50, u'module': u'powerline.segments.plugin.syntastic', u'exclude_modes': [u'nc'], u'name': u'syntastic'}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,011:ERROR:vim:segment_generator:Failed to generate segment from {u'draw_soft_divider': False, u'priority': 50, u'module': u'powerline.segments.plugin.tagbar', u'exclude_modes': [u'nc'], u'name': u'current_tag'}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 60, u'name': u'file_format', u'draw_soft_divider': False, u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 60, u'name': u'file_encoding', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 60, u'name': u'file_type', u'exclude_modes': [u'nc']}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'priority': 50, u'width': 4, u'align': u'r', u'name': u'line_percent'}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'width': 3, u'align': u'r', u'name': u'line_current', u'draw_soft_divider': False}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'
2014-09-03 15:36:34,012:ERROR:vim:segment_generator:Failed to generate segment from {u'name': u'virtcol_current', u'align': u'l', u'priority': 20, u'width': 3, u'draw_soft_divider': False, u'before': u':'}: u'function'
Traceback (most recent call last):
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 240, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/Users/tpowell/.vim/bundle/powerline/powerline/segment.py", line 62, in get_function
    function_name = segment['function']
KeyError: u'function'

The quickest solution is to take the new default config files and dump them in your ~/.config/powerline directory.

The Mohu Leaf worked so well, I upgraded to a Mohu Sky

Ok, I had the Mohu Leaf working for almost the entire house using the DirecTV cable in and with 2 indoor antenna amplifiers on the HDTVs. The signal was almost strong enough just by putting it against the side of the house facing the station antennae (according to AntennaWeb, even though we're about 20 miles out from the station broadcasts. One downside was that the paper thin design was too prone to being blown around by storms.

Decided to upgrade to the Sky and have it "mounted" on the inside of our privacy fence (with open air in the direction of the antennae). I plugged the amp into the 4-way splitter and removed all other amps. We're now even getting the obscure channels.

Refinements in Ruby: in map: super: no superclass method

I was trying out refinements to see if they would help clean up some parsing code. I liked defining a couple of methods for the String class to respond to, but really didn't want them as permanent monkey patches on String.

And so, I had a pipe mapping module with refinements:

module PipeMapping
  refine String do
    def only_lines_with_pipes
      self.lines.select { |s| s =~ /\|/ }
    end
    def pipes_to_array
      self.split('|').map(&:strip)
    end
  end
end

I added the following to my class to allow it to load itself:

  using PipeMapping
  def self.initalize_mappings
    data_to_load.only_lines_with_pipes.map(&:pipes_to_array).each do |mapping|
      # do stuff
    end
  end

I got the following output:

...in `map': super: no superclass method `pipes_to_array' for "A|B|C\n":String (NoMethodError)

The problem is that Symbol#to_proc will end up operating outside of the scope of the refinement using invocation, and will, therefore, have no knowledge of the method.

A quick change to a block works:

  using PipeMapping
  def self.initalize_mappings
    data_to_load.only_lines_with_pipes.map{|s| s.pipes_to_array}.each do |mapping|
      # do stuff
    end
  end

I'm still trying to decide if this is a satisfactory trade-off.

rails (4) generate migration behaviors I forget to use

When I'm generating a migration, I usually don't go any deeper than specifying column_name:data_type on the command line, and often I only use the command line to generate the file itself.

I don't know that the other options really save all that much typing, but stopping to think about the other options for a few seconds might just help avoid having to go back later and add things.

Elementary things I don't make enough use of:

  • rails g migration AddXXXtoYYY automatically creates an add_column for table YYY for every column name specified.
  • rails g migration RemoveXXXtoYYY automatically creates a remove_column for table YYY for every column name specified.
  • Specifying column_name:data_type:index also adds an index to the new column.
  • rails g migration CreateJoinTableXXXYYY will produce a join table.

Applescripts to Mute or Unmute Lync

In preparation for hooking up Lync muting and unmuting to separate hotkeys, I wanted to make sure that my scripts no longer toggled the mute button, but only muted or unmuted.

For that to work, I needed to retrieve the current state of the checkbox.

set theCheckbox to checkbox 5 of splitter group 1 of aWindow
tell theCheckbox
  set checkboxStatus to value of theCheckbox as boolean
  if checkboxStatus is true then click theCheckbox
end tell

In this case, I store off the checkbox into a variable theCheckbox and then later the checkbox status into a variable, allowing me to unset the checkbox if it is true.

This results in the following script for unmuting:

tell application "Microsoft Lync"
	activate
end tell
tell application "System Events"
	tell process "Microsoft Lync"
		repeat with aWindow in (get every window)
			set aName to get the name of aWindow
			set initialName to ((characters 1 through 12 of aName) as string)
			if (initialName = "Conversation") then
				activate aWindow
				set theCheckbox to checkbox 5 of splitter group 1 of aWindow
				tell theCheckbox
					set checkboxStatus to value of theCheckbox as boolean
					if checkboxStatus is true then click theCheckbox
				end tell
			end if
		end repeat
	end tell
end tell

And for muting:

tell application "Microsoft Lync"
	activate
end tell
tell application "System Events"
	tell process "Microsoft Lync"
		repeat with aWindow in (get every window)
			set aName to get the name of aWindow
			set initialName to ((characters 1 through 12 of aName) as string)
			if (initialName = "Conversation") then
				activate aWindow
				set theCheckbox to checkbox 5 of splitter group 1 of aWindow
				tell theCheckbox
					set checkboxStatus to value of theCheckbox as boolean
					if checkboxStatus is false then click theCheckbox
				end tell
			end if
		end repeat
	end tell
end tell

These scripts (and hopefully, others soon) are available on GitHub

Toggling the mute button in Microsoft Lync for Mac via Applescript

Through liberal use of the dictionary for Microsoft Lync, the Accessibility Inspector, and a few web links, I've come up with this script which toggles the mute button in Lync for Mac.

tell application "Microsoft Lync"
  activate
end tell
tell application "System Events"
  tell process "Microsoft Lync"
    repeat with aWindow in (get every window)
      set aName to get the name of aWindow
      set initialName to ((characters 1 through 12 of aName) as string)
      if (initialName = "Conversation") then
        activate aWindow
        click checkbox 5 of splitter group 1 of aWindow
      end if
    end repeat
  end tell
end tell

I still want to hook it up to a hotkey, and ideally, have a different hotkey for mute and unmute, but that will have to be left for another session. I will hopefully update this post with more details as I figure out how to explain them.

rspec-rails 3 deprecation warnings scripts and fixes

Upon upgrading to rspec 2.99.0, I began to receive deprecation warnings for several things that had issues, and to do a few updates:

Because the project was using its syntax and stub_model I needed to add that functionality back into rspec in the :test group of my Gemfile:

  # Support for its syntax
  gem 'rspec-its', '~> 1.0.1’
 
  # Support for stubbing model in view specs:
  gem 'rspec-activemodel-mocks', '~> 1.0.1'

On top of that I had to do substitutions for be_true, be_false, and_return with block syntax, and change pending to skip for a few pending tests.

I was able to run the following find + sed commands for each of these (note that the .original part is Mac-specific):

find . -name '*.rb' -exec sed -i .original 's/be_true/be_truthy/g' {} +
find . -name '*.rb' -exec sed -i .original 's/be_false/be_falsey/g' {} +
find . -name '*.rb' -exec sed -i .original 's/and_return[ ]*{[ ]*[^} ]*[ ]*}/and_return(\1)/g' {} +
find . -name '*.rb' -exec sed -i .original 's/^[ ]*pending /skip /g' {} +

I haven't completely foolproofed the last two regexes, so I'd make sure to have your work committed for each set of substitutions (and to make sure rspec still passes your tests, of course.)

And the cleanup:

find . -name '*original' -exec rm {} +

Lastly, to quiet the remaining deprecation warnings that I had, I added this to my spec_helper.rb:

Rspec.configure do |config|
# other config code
#
  config.mock_with :rspec do |mocks|
    mocks.yield_receiver_to_any_instance_implementation_blocks = true
  end
 
  config.infer_spec_type_from_file_location!
  config.raise_errors_for_deprecations!
#
# other config code
end

This configuration, as I understand it, will be standard with 3.0:

  mocks.yield_receiver_to_any_instance_implementation_blocks = true

This setting is required for 2.99 because you will unconditionally get a deprecation warning even if you set the type...

  config.infer_spec_type_from_file_location!

And I wanted to raise an error for any other deprecation warnings:

  config.raise_errors_for_deprecations!

After all the dust had settled from 2.99, I upgraded rspec-rails to 3.0.0 and did a bundle update:

  gem 'rspec-rails', '~> 3.0.0' # Test framework

I've unearthed a few deprecation warnings about :should syntax, which I expect to update later.

One misleading deprecation warning:

Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /Users/tpowell/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'.

...was actually due to having require 'rspec/autorun' in my spec_helper.rb

mkdir with intermediate directories and rails generate view spec

I've been running into a lot of cases where I need to build intermediate directories for a path. Apparently, the correct option is -p

mkdir -p dir/tree/to/make

From the mkdir man page:

     -p      Create intermediate directories as required.  If this option is not specified, the full path prefix of each operand must already exist.  On the
             other hand, with this option specified, no error will be reported if a directory given as an operand already exists.  Intermediate directories
             are created with permission bits of rwxrwxrwx (0777) as modified by the current umask, plus write and search permission for the owner.

I've assigned it an alias in my .zlogin:

alias mkdirtree='mkdir -p'

Of course, this all came about because I needed to an generate rspec file for a view, which can be done with:

rails g rspec:view name/of/controller action another_action

Results in the following files in the spec/name/of/controller directory:

action.html.erb_spec.rb
another_action.htl.erb_spec.rb