Handy snippets I always forget

Handy snippets I always forget

This post is a place for useful snippets which I use semi-regularly, but not often enough to have them memorized, and regularly have to go back and find them.

How to activate conda environment with direnv

As you know, I like direnv to make things easier for me, by automatically setting things up whenever I enter a directory. There are a number of ways to get direnv to automatically activate a conda environment, but here's one of the simplest – just add this to your .envrc file:

eval "$(conda shell.bash hook)"
conda activate <env-name>

Source:

support for conda &gt;=4.4 · Issue #326 · direnv/direnv
With conda &lt;4.3 (Ubuntu 16.04.3), I&#39;ve been using: use_conda() { source activate &quot;$1&quot; } in my ~/.direnv file and use conda MY_CONDA_ENV in my .envrc files, which has worked great! ...

How to run a python module and automatically go into pdb on exceptions and breakpoints

ipython --pdb -m <module> -- <other args>

Source:

Starting python debugger automatically on error
This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let’s say an IndexError, python prints the line, locat...

How to push to a new branch without --set-upstream...

You create a new branch, and then go to push it, and get hit with "you can't do that, because we have no idea what you want us to do" one too many times?

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

:(

Run this command to set up your git config to automagically create a new remote branch to match the local one your pushing, and set your local branch to track the new remote one:

git config --global push.default current

Then, whenever you got to push a new branch, just do git push -u

Source:

Why do I need to do `--set-upstream` all the time?
I create a new branch in Git: git branch my_branch Push it: git push origin my_branch Now say someone made some changes on the server and I want to pull from origin/my_branch. I do: git pull ...

How to send a file/directory/message between computers

This one doesn't really fit with the others, because it's very easy to remember, but may not be well-known as it should be. Just use Magic Wormhole.

On one machine:

wormhole send <file/files/message>

For example:

$ wormhole send test.txt
Sending 6 Bytes file named 'test.txt'
Wormhole code is: 6-decadence-commence
On the other computer, please run:

wormhole receive 6-decadence-commence

One another machine, with no prior setup other than installing magic wormhole

$ wormhole receive 6-decadence-commence
Receiving file (6 Bytes) into: test.txt
ok? (y/N): y
Receiving (->relay:tcp:magic-wormhole-transit.debian.net:4001)..
100%|██████████████████████████████████████████████████████| 6.00/6.00 [00:00<00:00, 35.7kB/s]
Received file written to test.txt