Using jquery us map to Create a Map of States That Can Be Toggled

The us-map plugin was already in use elsewhere and I wanted to create a clickable map that would display an anchor state and allow for configuration of related states.

Also in use is the gon gem to allow passing of data directly into Javascript, included in a Rails 4.1 project.

Controller code:

  # assume @state is the current state
  gon.current_state_code = @state.state_code 
  gon.regional_states = @state.related_state_codes # returns ["AL", "AK", ...]

View code:

<%# this is inside a form and states_list maintains the current list of selected states%>
  <div id="map" style="width: 800px; height: 600px;"></div>
  <%= hidden_field_tag 'states_list' %>

Associated CoffeeScript:

 
states = ->
  # initialize the hidden field for states selected
  $('#states_list').val(JSON.stringify(gon.regional_states))
  $('#map').usmap(
    stateStyles:
      fill: 'lightGray'
    stateSpecificStyles: do ->
      # current state is red, selected states green
      specificStyles = {}
      specificStyles[gon.current_state_code] = fill: 'red'
 
      for state in gon.regional_states
        specificStyles[state] = fill: 'green'
 
      specificStyles
    click: (event, data) ->
      # don't allow current state to be selected
      if data.name != gon.current_state_code
        # add green as a specific style or delete to toggle state highlight
        if this.stateSpecificStyles[data.name]
          delete this.stateSpecificStyles[data.name]
        else
          this.stateSpecificStyles[data.name] = fill: 'green'
 
      # this could be more intelligent, but I'm just recalculating along the way
      regionalStates = []
      for key of this.stateSpecificStyles
        if this.stateSpecificStyles[key]['fill'] != 'red'
          regionalStates.push(key)
      $('#states_list').val(JSON.stringify(regionalStates))
  )
 
$(document).ready ->
  if gon? && gon.regional_states?
    states()

Sites That Have a Problem Working in Google Chrome

I’ve been hitting issues with site compatibility with Chrome lately, so I decided to start with a list of sites that I’ve had issues with in the last day, and I’ll build on from there.

As of Chrome 39.0.2171.71 (64-bit) on Yosemite:

  • panel.dreamhost.com – Rebilling edit does not allow you to check the checkbox to limit billing on one day or specify an amount.
  • Fidelity.com – Quicklinks dropdown after login collapses immediately instead of allowing you to select a menu item.
  • playstation.com – Password Reset password fields don’t register that you’re typing in any information (strength meter doesn’t change), and when you submit, you password hasn’t actually been changed. Same functionality worked in Firefox.

The story behind rspec kung fu hamster

rspec-kungfuhamster originated as a joke on a POS development team I worked on almost 10 years ago. In the battle of scope creep and requirements changes, we all got a bit loopy and a couple members of the team drew up an ASCII animated “kung fu hamster” as a terminal-based spinner while the credit card authorization (often by modem) was taking place.

Strangely, product ownership didn’t see the humor in so much time being spent on the animation.

I decided to revive kung fu hamster as an rspec formatter in honor of those days of solving technical problems on out-of-date SCO Unix boxes without access to anything but standard and home grown libraries, as well as the two team members that have passed away at far too young an age since.

 

Applescript to periodically raise unsent Outlook replies to the foreground

I’ve had a particular problem starting replies in Outlook for Mac and then losing track of them or forgetting about them.

This script is a fairly naive attempt at having such replies raised to the foreground. It doesn’t distinguish between a reply you’re reading and one you’re writing. It also won’t notice email that you’re composing that *doesn’t* have a ‘Re:’ as the start of the title. I imagine there’s a window property that I can look for to select those, I just didn’t want to go there yet.

The script also unintelligently repeats every 60 seconds, which I figure is better than leaving an email unsent for 2 hours.

I’m publishing updates to my “applefritters” project on GitHub if you want to keep up with further improvements to this script.

repeat
	tell application "System Events"
		tell process "Microsoft Outlook"
			repeat with aWindow in (get every window)
				set aName to get the name of aWindow
				set initialName to ((characters 1 through 3 of aName) as string)
				if (initialName = "Re:") then
					tell application "Microsoft Outlook"
						activate
					end tell
					activate aWindow
					set frontmost to true
					perform action "AXRaise" of aWindow
					exit repeat -- only activate one window
				end if
			end repeat
		end tell
	end tell
	delay 60
end repeat

Dollar Shave Club (Executive) Review as a Gillette Mach 3 User

I decided to try the Dollar Shave Club Executive (6 blade) model for a month. The subscription for 4 blades per month is $9.

The initial shipment came with their own shave butter, which I tried for my first shave. The shave butter broke down too quickly for my skin and facial hair thickness, and didn’t seem to do much for the shaving experience, but then again, I generally use a shave cream or hair conditioner while shaving.

The blade angles felt a bit too sparse–or maybe the space between them clogged too quickly, though I didn’t notice that this was the case. My first shave attempt was on about 3 days growth, and felt spotty irritation in my skin and notices several patches that had clearly been shaved, but had not been shaved particularly closely.

On my second shave attempt on about 2 days growth, I used my Gillette Sensitive Skin to try and alleviate the irritation and possibly get a bit closer with the shave. After shaving, I had a lot of spots in my facial hair that were about a half day’s worth of growth in length. Whether using the shave butter or my Gillette Sensitive Skin shaving cream, I experienced a small amount of irritation–not as much as a cheap disposable, but a little more than the Schick Quattro.

The closeness of the shave is ultimately as close as the Quattro, but with noticeably more irritation.

For comparison:

  • I use the base Gillette Mach 3 razor normally, usually with the Gillette Sensitive Skin shaving cream.
  • I generally shave twice a week, partly because my skin is too sensitive if I shave more frequently than that.
  • I have sparse and uneven facial hair.
  • Dollar store and disposable Bic razors break the skin for me.
  • The Schick Quattro razor didn’t irritate the skin any more than my Mach 3, but the shave isn’t that close for me.
  • Electric razors turn my skin red with irritation.

Hope this helps you decide if Dollar Shave is an option for you. Interestingly enough, the Executive blades are $2.25 per cartridge vs. the Gillette Mach3 Base Cartridges 15 Count(Amazon associates link) per-cartridge price of about $2.06 per cartridge.

Using a vimscript to run through a list of substitutions with dictionary pairs

I wanted to modify a test suite to call a method using ruby 2’s keyword arguments. There were several calls to the same initialization function that followed a pattern that made it a good candidate for a series of `%s` calls using key-value pairs in a dictionary.

Interesting how vimscript uses a leading slash as line continuation instead of a trailing slash at the end of the continued line.

Also, it took me a while to figure out that interpolating a variable in an Ex command required “execute” and string concatenation with periods.

let fields = { 'public_key' : 'public_pem_key',
              \'private_key' : 'private_pem_key',
              \'username' : 'username',
              \'password' : 'password',
              \'url' : 'url',
              \'ssl_verify_host' : 'ssl_verify_host'
            \}
 
for key in keys(fields)
  execute '%s/\([ \t]*\)\(.*TestCommon::' . fields[key] . '\)/\1' . key . ': \2/'
endfor

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.