Posts

A collection of 45 articles

Keystroke Sequence Shortcuts in Mac OS X

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 chose 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.

Updated  •  3 min read

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.

Updated  •  1 min read

ActiveRecord includes and preload

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”.

Updated  •  2 min read