You can close all running Tmux sessions with:
You can close all running Tmux sessions with:
You can use
git shortlog to get a quick summary of committers and their commits on a project.
$ git shortlog Andrew Vogel (10): Initial commit Add local zshrc, vimrc, and tmux.conf Add README Remove unneeded stuffs Fix Markdown links Add installation info and image to README Update local zsh config Add local vim plugins Add lightline to vimrc Update README
Ever needed to install a package under an alias? Or maybe you need to install 2 versions of the same dependency.
You can handle this on install with yarn:
yarn add email@example.com yarn add react-select-next@npm:react-select@next
Now you can import your aliased dependency with:
import Select from 'react-select-next'
You can list your running tmux sessions with:
[prefix] + s
If you have a large or complex test suite, running Jest on CI can make your build especially slow or cause timeouts. Luckily, Jest has an option cut out for this.
runInBand runs all tests serially inside the current process instead of creating a bunch workers.
Using this option, we were able to trim suite time above 20mins down to less than 4 mins. 🏎️😎
Sometimes you need to inspect or debug a gem in your project. You can open a gem in editor with:
bundle open GEM_NAME
You can change the name of the parameter used by rails resource routing by specifying the
param option to the resource route.
For example, if we have a show endpoint:
resources :pages, only: :show
rake routes will return the
pages#show url as:
We can change the
id param to
slug by doing:
resources :pages, only: :show, param: :slug
rake routes will yield our new
pages#show route as:
Pass a string to
File.expand_path to generate the path to that file or directory. Relative paths will reference your current working directory, and paths prepended with
~ will use the owner’s home directory.
File.expand_path('example.rb') => "/Users/avogel/My/Working/Directory/example.rb" File.expand_path('~/example.rb') => "/Users/avogel/example.rb"
Rails provides a simple interface to pass an array as a query string.
Lets say we have an array:
platforms_ids = [0, 1, 2]
We can pass that to our endpoint as follows:
And in our controller action, we can access those
params[:platform_ids] => [0, 1, 2]
You can quickly go to a tab in Chrome by using:
Cmd + n # Go to the nth tab in the current window
If you ever need to search your commits for a pattern, you can use the following command to return the logs containing that pattern.
git log --grep pattern
Sometimes, it is nice to know what migrations you have before running them. You can get a list of migrations and their status with:
Sometimes, it’s useful to know what exactly a NPM package depends on before installing it. You can list that package’s dependencies by using NPM:
npm info react-native peerDependencies
Optionally, you can target a specific release with:
npm info react-native@latest peerDependencies
As a recent vim convert, I learn new commands everyday from my fellow rocketeers. Here’s some cool ones for deleting words:
dwto delete word. Cursor placement is important! If your cursor is not on the first character, it will only delete from your cursor to the end of the word.
diwto delete inside word. Deletes the entire word that your cursor resides in.
dt<char>to delete to character. Deletes from your cursor to the specified character.
By default, the BetterErrors gem only works for localhost. If you’re using ngrok to access your rails server and you want to have access to BetterErrors, you’ll need to whitelist the IP of the machine that ngrok is running on.
Add the following to
BetterErrors::Middleware.allow_ip!(NGROK_MACHINE_PUBLIC_IP) # - or - # Use an IP finding service to grab your public IP each time you start the server: # (ipecho.net, api.ipify.org, etc.) BetterErrors::Middleware.allow_ip!(open('http://api.ipify.org').read)
You can explicitly set the
domain with Rails URL Helpers:
app.root_url => "http://www.example.com/" app.root_url(domain: 'www.customdomain.org') => "http://www.customdomain.org"
If we include the protocol in our domain argument, this brings up an interesting gotcha. Check it out:
app.root_url(domain: 'http://www.customdomain.org') => "http://www.http://www.customdomain.org/"
Thankfully, Rails gives us the
host option. Host will use a Regex to remove the protocol from the argument:
app.root_url(host: 'https://www.customdomain.org') => "http://www.customdomain.org/"
Notice the output in the last example; our protocol was replaced removed and replaced with http. You can use the
protocol argument to enforce your protocol on a given
app.root_url(host: 'http://www.customdomain.org', protocol: 'https') => "https://www.customdomain.org/"
You can rename or optionally move a file under the cursor by using
R then specifying the new name/path.
You can delete, or at least attempt to delete, a file or directory under the cursor by using
If you need to override the name of a model method or field in a GraphQL type, you can use the
Let’s say we have a model called Message:
class Message < ApplicationRecord def bar "bar" end end
We can then make an alias to the bar method by specifying a property in our MessageType:
Types::MessageType = GraphQL::ObjectType.define do field :foo, types.String, property: :bar end