Today I Learned

Code snippets, life lessons, and the like. By Nick Sheck.


December 16, 2021

To bulk revert a bunch of commits in Git (like, to redo your personal site from scratch) do this:

$ git revert -n <very first bad sha>^..HEAD
$ git commit

(the -n flag will squash the revert without committing, omitting it means you have to commit a revert for every. single. commit.)


March 05, 2020

If you’re trying to find files that contain two distinct strings, you can use ag (or grep) and unix to do it. So to find all files that have spec_helper AND stub_request:

$ ag -l spec_helper | xargs ag stub_request

March 04, 2020

If you’re using binding.pry in a delegator and (frustratingly) find yourself in the def method_missing context, you can use ::Kernel.binding.pry instead and it will place your context in the ⚡️right spot⚡️


September 17, 2018

Bulk renaming in Zsh

I needed to rename a bunch of React components inside of subdirectories from — for example — event.js.jsx to event.js. Instead of doing a loop or passing commands to find, you can do it easily with zmv.

autoload zmv
# Do a dry run to see how files would be renamed
zmv -n '(**/)(*).js.jsx' '$1$2.js'
# Do the actual renaming
zmv '(**/)(*).js.jsx' '$1$2.js'

October 12, 2017

Alphabetical sorting in Vim

This might be obvious, but it blew my mind today. Say you need to order something alphabetically, like propTypes on a react component. Just select the block of text in visual mode (Shift + v) and type :sort.


September 08, 2017

Quickly creating files and their parent directores in Vim

Creating new directories for brand new files in Vim can be a pain. When using ctrlp, you can type out the full name, including directories, and pressing control-y will create everything you just typed.


June 21, 2016

Testing credit card autofill locally

Recently worked on a project that needed to work with credit card autofill. Unfortunately, most browsers will not autofill unless the server uses https – a problem if you are trying to develop locally.

I found that if you use ngrok you can create a local tunnel that uses https. Also, it seems like it works with livereload as well.

$ gulp serve
$ ngrok http 9000
open the https tunneled URL

March 01, 2016

Unless you want to install hub, transferring commits from one similar repo to another is a pain.

  1. Add .patch to your github url for the commit, to download it as a formatted patch.
  2. Save to the folder of the other repo (and maybe rename it, too).
  3. In that folder run git am your_patch_name.patch

November 18, 2015

hirb is a nice replacement for the IRB used by rails console.

An example from their docs:

>> Tag.last
+-----+-------------------------+-------------+---------------+-----------+
| id  | created_at              | description | name          | namespace |
+-----+-------------------------+-------------+---------------+-----------+
| 907 | 2009-03-06 21:10:41 UTC |             | gem:tags=yaml | gem       |
+-----+-------------------------+-------------+---------------+-----------+
1 row in set

October 29, 2015

In the context of a larger organization, new software won’t always fix bad processes.


October 18, 2015

When using react to control checkboxes, Safari (and maybe Chrome) can have a weird flickering effect as you toggle their state. I tried changing the handler to onClick, tried doing preventDefault, and tried switching back to onChange — no luck.

Was finally able to get it to stop flickering by using custom styled checkboxes that are css only.


October 17, 2015

Getting your favorite editor color scheme as a pygments css file is difficult, but not impossible.

  1. seti.vim -> vim2pygments
  2. Download pygments tarball
  3. ./pygmentize -S seti -f html -a .highlight > seti.css