Quick Notes

Notes
March 2, 2019

Print all the model fields withdjango_model._meta.get_fields()

When local branch and remote branch name is different, pushing something may be not be as simple as git push remote_name branch_name.

This command will help when remote and local branch have different names – git push origin local-name:remote-name.

Terminals – Ctrl+r allows reverse search in terminal. We can search for previously used commands. history command shows all the commands used till date. Check this.

Vim – Use %s/search_term/replace_term/g to perform search and replace in whole file. Check this.

NEVER EVER rebase a branch while a PR is open from it! (Remember how angry Oliver got when you rebased and his PR review was still pending! Still scares the hell out of me 😔)

Always prefer GIF over Video if voice is not an issue. People like me don’t like clicking on the play button. And keep things as short as possible.

Steps to add all changes to git except a few files and folder – git add –all and then git reset — folder/files or git reset — folder/*

 

Copying a git commit from one branch to another –

  1. git checkout detination_branch
  2. git cherry-pick commit_id

Find a file and delete it from terminal – Here we’re deleting all .pyc files and files inside a directory called migrations except a file with name __init__.py.

  1. find directory_to_find_in -path "*.pyc" -delete
  2. find directory_to_find_in -path "*/migrations/*.py" -not -name "__init__.py" -delete

Pythonic Magic✨

_ is the default variable in python. Look at this:

Whenever we need to run a loop, but not use the loop variable within the loop, we can use `_` as the loop variable instead.

_ can also used as a prefix for a function name, when the function needs to be kept private. For example, to make a function funcfun private, we can change it’s name to _funcfun.


We might’ve noticed `#noqa` at times while reading python code. Although it is a comment, it is an indicator to the linter that a particular must be ignored while formatting the code. Any `bad looking` code with `#noqa` might be intentionally bad as the developer put it.

 


ord(‘A’) returns ASCII character of ‘A’.

chr(65) returns character with ASCII value 65, i.e. ‘A’.

 


y{ – copying lines below in vim


y} – copying lines above in vim