Kill rails that got stuck

I'd like to kill rails running w/specific port. (My laptop running several rails servers. )

kill -9 $(lsof -i :3000|grep ruby|head -1|awk '{print $2}')

Alyson

Automagical Intermediate-level Hashtables in Ruby

All intermediate-level hashtables will be created automagically

def autovivifying_hash
   Hash.new {|ht,k| ht[k] = autovivifying_hash}
end


Usage

response_builder = autovivifying_hash
response_builder['payment']['status'] = 'OK'
response_builder # => {"payment"=>{"status"=>"OK"}


Ali

Using Git's aliases feature

Git allows you to create aliases internally through the config. Your global config should be located here ~/.gitconfig

[alias]
  aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
  count = shortlog -sn
  l = log
  co = checkout
  ca = commit -C HEAD --amend
  c  = commit
  cm = commit -m
  a  = add
  s  = status
  b  = branch
  p  = push
  mt = mergetool
  dt = difftool
  o  = origin
  rc = rebase --continue
  rs = rebase --skip
  pd  = !git checkout develop && git pull origin develop && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d && git fetch --prune origin
  pm  = !git checkout master && git pull origin master && git branch --merged | grep -v '*' | grep -v 'develop' | xargs git branch -d && git fetch --prune origin
  pr = pull-request -c -m


Most are self explanatory...

git pd (prune develop) - checks out to develop, fetches latest changes, deletes all stale branches except develop (will delete master too)

git pm (prune master) - does the same as prune develop for master

Joe

See deleted files in previous commits [git]

$ git log --diff-filter=D --summary --oneline


Ali

Change VS Code Go to definition to Cmd+Click

Just open your user settings JSON file and use this option:

    "editor.multiCursorModifier": "cmd",


1
Ali

List your model names

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


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

1
Ali

Use Neovim as a git difftool

Just paste this into your ~/.gitconfig

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


5
Ali

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.

1
Const

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
        redraw!
    endif
endfunction
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.

Ali

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.

Ali