Today I Learned
Inspired by jbranchaud/til.
aws cloudformation list-stacks --profile <profile-name-optional> | jq '.StackSummaries | .[] | {name: .StackName, status: .StackStatus}'
aws cloudformation delete-stack --stack-name place-indexer --profile <profile-name-optional>
Quick howto on installing and using the conda package manager.
brew install miniconda
Add to your shell:
conda init zsh
Create a new environment with a specific Python version:
conda create -n notebooks python=3.9
List available environments:
conda env list
Remove an environment:
conda env remove --name notebooks
Install a package to the current environment:
conda install jupyterlab=3
Pipe any list output to fzf
and get an interactive fuzzy selector.
This works as a shell function. Add it to your .zshrc
file.
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
As seen in fzf/wiki
git diff master..$(git branch --show-current) | grep TODO
Set main
as default branch:
git config --global init.defaultBranch main
Continue reading if you have older repos that need updating.
For older repos, update default branch:
git checkout -b main
git push -u origin main
On GitHub, you need to update the default too:
- Go to the repo settings
- Go to Branches
- In the Default branch section, click the Switch to another branch button
- Choose
main
and update
git add --update
Shorthand:
git add -u
gh repo list
gh pr create --title "The PR title"
If you use PROJ-XXX-slug
pattern for your branch names, and use PROJ-XXX: slug
for your PR title, you can do a little string munging with $(git branch --show-current)
and have the PR title generated from the branch name.
# insert bash one liner here
Sometimes you want to clone all the repos from an organization. You can do this using gh
, jq
and xargs
.
Here <username>
can be a GitHub user or organization.
gh repo list <username> --json nameWithOwner --jq ".[] | .nameWithOwner" | xargs -I REPO gh repo clone REPO -- REPO
Be aware that this may copy hundreds of repos to your machine, so you might want to check how many repos the user have with gh repo list <username>
first.
Use -L
or --limit
to specify the number of repos to clone.
brew install go
I can "get" a module like this:
go get github.com/user/repo
But where is it installed?
It's in ~/go/bin/
.
Using %%file
magic function, the cell contents will be saved in the specified file. For example:
%%file my_script.py
print('hello.py')
After executing the cell, you should see Writing my_script.py
as the cell output, and a new file is created with the contents print('hello.py')\n
Install jupyter_code_formatter extension. This adds a code format button in the notebook toolbar, and two new commands in the Edit menu.
Make sure you have black
and isort
installed.
pip install jupyterlab_code_formatter
pip install black isort
List available contexts:
kubectl config get-contexts
Show current context:
kubectl config current-context
Change context:
kubectl config use-context <context name>
pd.read_json(filepath, lines=True)
pyenv install --list
pyenv versions
pyenv global 3.9.0
When you want to set a Python version for a single workspace.
pyenv local 3.7.9
This will generate HTML docs of the current crate and its dependencies, and open it in the browser.
cargo doc --open
Extends cargo to have commands such as cargo add
, making Cargo.toml
management a breeze.
rustup toolchain install nightly
rustup toolchain list
rustup default <toolchain name>
# use nightly
rustup default nightly
# back to stable
rustup default stable
rustup update
This will update the everything included in the toolchain, such as rustc
, cargo
, rustfmt
.
rustup self update
Opens local copy of Rust documentation, including The Rust Programming Language.
rustup doc
$_
For example, create a directory and change into it:
mkdir /tmp/mydir && cd $_
ifconfig | grep ether | awk '{print $2}'
When filenames start with a hyphen and commands may interpret it as argument.
For example, you have a file called -test
and want to rename this to test
. This won't work:
mv -test test
mv: illegal option -- t
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
Use the --
signal to end option processing before typing the filename.
mv -- -test test
This works with other commands as expected:
touch -- -myfile
rm -- -myfile
Friendly reminder: imagemagick commands may contain hidden magic and can be destructive -- be sure to backup and work on the copy of your precious images.
montage -geometry 500x500 [input-file1 input-file2...] output-file
convert -rotate "90" original.gif rotated-output.gif
This will create a copy of the image with a new format:
convert input.heic output.jpg
If you have a bunch of HEIC files and want to convert all of them to JPG:
mogrify -format jpg *.heic
This will remove all metadata from the given photo file.
exiftool -all= photo.jpg
Here the photo.jpg
will be stripped of the metadata, and a copy of the original will be created. To overwrite the original without preserving a copy, use the -overwrite_original
option.
- Find file by name: cmd + p
- Go to symbol in the currently open file: cmd + shift + o
- Go to symbol: cmd + t
Enable code-insiders
command for the Insiders version
Within the editor, open command executor with cmd+shift+p and type "Install code-insiders command in PATH" and execute it.
code --list-extensions
Tap shift+enter. This will open a Python repl and execute the selected code.
This is also available via the command view (cmd+shift+p). Open the command view and type "python run line" (partial input works).