Ansible uses YAML to define tasks, playbooks and handlers. If the files follow some conventions, it is easy to index them using Exuberant Ctags.

For example, following ctags options will index all the lines starting with - name: in .yml and .yaml files. Save it as .ctags in the playbook or role top directory.

--regex-ansible=/^[ \t]*-[ \t]*name:[ \t]*(.+)/\1/k,tasks/

It is assumed that playbook and task files use extention .yml or .yaml. And name field just follows -.

- name: name must be the first field just following the dash
  hosts: all
  roles: [ site ]

Now generate the tags

ctags -R .

And try it in vim

:tselect /keyword

To make it works with ctrlp CtrlPBufTag, add following config in vimrc

let g:ctrlp_buftag_types = {
  \ 'yaml'     : '--languages=ansible --ansible-types=k',
  \ }

It is a headache to find an available keyboard shortcuts in Mac OS X. I used Option + Letter and Shift + Option + Letter before, since they are preserved for inputting special characters. It has some problems:

  • Emacs and terminal require a modifier for Meta. I choosed Command. It means if I want to use application shortcut with Command in these applications, such as Command+Q to quit the application, I have to use the right one.
  • I always forget the shortcuts. Although I have listed them in a sheet, it is a pain to keep it synchronized with the shortcuts defined every where.

I switched to a new solution using keystroke sequence shortcuts recently. All my global shortcuts start with Command+M (⌘M). A menu is displayed when I typed prefix. If I forget the shortcut, I just need to glance through the menu.

Auto Toggle MacBook Internal Keyboard

I prefer using external keyboard with my MacBook. When no external monitors are used, a typical setup is placing the keyboard above the internal one, so I can still use the internal touchpad.

But sometimes the external keyboard may press some keys of the internal keyboard. There is a solution to disable the internal keyboard, but it is tedious to run the command manually.

# Disable, ignore the warning
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
# Enable
sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/

Fortunately, Keyboard Maestro supports executing scripts when a USB device is attached or detached.

ActiveRecord has two query methods to eager load associations, includes and preload. Although the documentation of preload says

Allows preloading of args, in the same way that includes does.

Indeed the two methods have some differences.

In simple words, prefer includes to eager load associations. Use preload only when

  • you want to customize select columns, or
  • you meet error “Can not eagerly load the polymorphic association”.

ActiveRecord has two methods to remove duplicates. Method uniq and option distinct: true in method count. I thought uniq.count and count(distinct: true) were identical. Indeed, uniq.count still counts duplicates, and count(distinct: true) must be used here.

In simple words, use uniq to get unique result set, use count(distinct: true) to count unique result.