Miyamura80 / Useful-Commands

For personal note-taking of useful commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Useful-Commands

For personal note-taking of useful commands

Git

Standard

  • New branch: git checkout -b [name_of_your_new_branch]
  • List branches: git branch
  • Stage files: git add <filename>
  • See changes: git diff <branchname>
  • Create PR: git push
  • Delete branch: git branch -d <branchname>
  • Commit Modified File: git commit -am "commit message"
  • See modified files: git status

Merge Conflicts

  • Catch up with master on a feature branch: git merge master
  • Get rid of modification on file: git reset <filename>
  • Undo 1 commit: git reset HEAD~1
  • See commit log & hashes: git log
  • Unstage but keep all changes after this hash: git reset <commithash>
    • --hard to unstage + discard changes also

NextJS Sprint

  • npx create-next-app --example with-tailwindcss scrypto-bond-frontend
  • git init

Python Module

  • Sibling directory: 1) Single Method

    import os, sys
    currentdir = os.path.dirname(os.path.realpath(__file__))
    parentdir = os.path.dirname(currentdir)
    sys.path.append(parentdir) 
    1. Modularization: Create __init__.py in the sibling_directory with the following
    from sibling_script import sibling_method

    In the main.py do:

    from sibling_directory import sibling_method

Python set

  • Add
    my_set = {1,3,5,7}
    my_set.add(8)
    my_set.remote(8)

Python DefaultDict

from collections import defaultdict
def_dict = defaultdict(<DATA_TYPE OF DEFAULT VAL>)

# Defaultdict of defaultdict
defaultdict(lambda: defaultdict(int))

Python functional

  • Dictionary: Doesn't exist. Use comprehension
    my_dictionary = {k: f(v) for k, v in my_dictionary.items()}
  • Filter list:
    filtered_list = filter(input_list, boolean_func)

Python Typing

  • Set the same type as class in method's parameter:
    class Foo:
      def foo_method(self, other_foo: "Foo"):
          return "Hello World!"
    Using forward declarations it is evaled after the whole module is loaded, so it can evaluate to the Foo class.

Using requirements.txt with pip

  • Create requirements.txt: pip freeze > requirements.txt
  • Install all dependencies: pip install -r requirements.txt

Python Environment

  • Use Environment:
    • Linux: source env/bin/activate
    • Windows: .\env\Scripts\activate.bat
  • Anaconda:
    • conda env create -n <envName> --file requirements.txt
    • conda activate <envName>

About

For personal note-taking of useful commands


Languages

Language:Jupyter Notebook 99.0%Language:Python 1.0%