Friday, August 17, 2018

Cleaning up your global NPM packages

Sooner or later when you're working with any web app, you'll have to deal with nodejs because frontend requirements will force you to do so. And sooner or later, you'll have a mess of npm packages in your global space. You'll want to clean it up but when you issue the command npm list you get a whole mess of packages with their dependencies.

However there's a useful trick you can do that will make npm only list the top level packages without their dependencies.


$ npm list -g --depth 0


Here's a sample result:

The trick is the --depth 0 parameter. It suppresses the listing of a package's dependencies.

We can now tame our unruly global npm packages.

Ha!

Wednesday, July 25, 2018

Pyenv folder (.venv) with Pipenv

Pipenv, by default will use your virtualenv folder location if you set that environment variable - which probably be a .virtualenv or .env folder in your home directory.

But sometimes you would like to have the virtualenv folder within the project folder - ie. project/.venv No sweat, pipenv supports this workflow if set the PIPENV_VENV_IN_PROJECT environment variable.

For Macs: $ export PIPENV_VENV_IN_PROJECT=1

For Windows: > set PIPENV_VENV_IN_PROJECT=1

Do note that in Windows, you can also use setx.

Then we can run either a: pipenv install or pipenv --three to get started.




Friday, May 25, 2018

Cleaning up your local repo from too many dead branches

You'll eventually have too branches in your local that's untracked - ex. Not in origin or Github. This gets annoying since too many of these branches are often dead. So time to prune them:

git remote prune origin

You would assume that would work but nope. This only works on the remote repo and not your local. But you can to do this:

git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d

This is uncomplicated since this just soft deletes all branches that are already merged - the -d flag in git branch.

But if you need to check against the remote repo then a more complex command is called for:

git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

The only rub here that is only works on bash or zsh shells. Also you need to run git fetch --prune first because using this.


Reference:

  • https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore/16906759#16906759