Frequently Used Snippets

1 minute read

I don’t know how many times I had to google for commands or code snippets I used before. People use differents methods to tackle this problem. Some people master the command line history search and others keep the most frequently used commands in a file to copy easily. Personally, I find it nice to have my favorite commands or snippets in one place. I want to share some of them here.


CLI

Snippets

Shortcuts


CLI

General

  • Create a virtual environment and install dependencies in your project
    python3 -m venv FILENAME
    source FILENAME/bin/activate
    pip install -r requirements.txt
    

Cloud

  • Authenticate to Google Cloud SDK and set your project
    gcloud auth login     # It redirects to browser, confirm to allow it
    gcloud config set project PROJECTID
    
  • Deploy your project to Google App Engine via Google Cloud SDK.
    gcloud app deploy app.yaml --project PROJECTID 
    
  • Monitor logs from your GAE app Google Cloud SDK.
    gcloud app logs tail -s default
    

Git

  • Change Git language to English (one time)
    LC_ALL=C git status
    

Snippets

Data Science

  • Select categorical columns with relatively low cardinality
    low_cardinality_cols = [cname for cname in X_train.columns if X_train[cname].nunique() < 10 and 
                            X_train[cname].dtype == "object"]
    
  • Select numeric columns

    numeric_cols = [cname for cname in X_train.columns if X_train[cname].dtype in ['int64', 'float64']]
    

Shortcuts

Jupyter Notebook

  • Insert a cell below: b (while the cell is blue)
  • Delete a selected cell: dd (while the cell is blue)