List your model names

$ RUBYOPT='-W0' rails runner 'Rails.application.eager_load!; puts ApplicationRecord.descendants.collect { |type| }'

NOTE: RUBYOPT=-W0 avoids verbosity when running rails command which suppresses warnnings.


Use Neovim as a git difftool

Just paste this into your ~/.gitconfig

    prompt = true
    tool = nvimdiff
[difftool "nvimdiff"]
    cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""


Improve Bundler performance

Level up your bundler performance by running bundler tasks concurrently in jobs:

$ bundle config --global jobs 4

See more options on the bundler website.


Rename files in VIM

Here's a handy function that I use to rename files in VIM (works in MacVIM and Neovim too)

function! RenameFile()
    let old_name = expand('%')
    let new_name = input('New file name: ', expand('%'), 'file')
    if new_name != '' && new_name != old_name
        exec ':saveas ' . new_name
        exec ':silent !rm ' . old_name
nnoremap n :call RenameFile()

NOTE: I've used which is mapped to comma in my config. but you can use whatever key combiniation you like.


Use capital letters in VIM mappings

" It means Ctrl-Shift-j
nnoremap  :echo "boom"

NOTE: @joe this solves your problem :D

UPDATED: You have to enable CSI code in your terminal; for example; in iterm you have to enable Use modern parser option.


Find a branch based on a commit

$ git log --oneline --all --grep=pretty

c198bb715 Make default expired description logic pretty

$ git branch --contains c198bb715

* deploy/staging


Check if command exists with shell script

if ! type gem > /dev/null; then
  echo 'gem command not found.'


Delete merged git branches

Handy git command for deleting all local git branches that already merged git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d


Simple Flux architecture with Vue.js

For a small app that only needs a simple state management pattern. I always use one component to hold the state of the app, a container. This act as a single source of truth for an app to refer to its states. Vue provides a mechanism to create a global event listener on the root level called EventBus which is a super simple way to mimic flux architecture.

All you need is one module that exports Vue as EventBus like so

// EventBus.js
import Vue from 'vue'
export const EventBus = new Vue()

Then you can use it inside your container to listen to event from any component inside the app. I normally add the listener on created life cycle.

EventBus.$on('event-name', callback)

Then you can import EventBus into any of your components and you can triggers my-custom-event from anywhere without having to emit the event to that component's parent and repeat the whole process in every component in between the component that triggers the change and the target container.

// Goes directly to the global listener and triggers callback

That's it. If it's getting too complex, consider using Vuex.


My most used slack shortcuts

⌘-K(or T) to open the channel switcher (I navigate channels solely with this shortcut and have my slack set to hide all channels without new messages)

⌘-F opens the search box. Can modify searches with from:@user and in:#channel for extra awesomeness

Up Arrow will edit you last message; perfect for when you hit Enter too early or mispell things

+:emoji: react to the last message. Have to be quick so nobody else replies before you react though or you'll react to the wrong message

/remind [someone usually myself] [to do something] [at this time in words] not really a shortcut but is great for not forgetting simple tasks

The channel switcher also supports fuzzy matching to some extent. If a channel is named foo-bar you can type fb to show it. It's doesn't work so well with multi-user-dm's though.