Skip to content

hluk/cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

This repository contains quick reference for various commands and configuration.

Ansible

Test command:

export ANSIBLE_DEBUG=1
ansible -vvvv --inventory=inventory host.dev.example.com --become-user postgres -k -K -m shell -a whoami

Install requirements and run a playbook:

export ANSIBLE_VAULT_PASSWORD_FILE=$PWD/../ansible-passwords.sh
# or --vault-password-file=...

ansible-galaxy install --force -r playbooks/dev/requirements.yml -p playbooks/dev/roles

ansible-playbook -vv --inventory=inventory --become --ask-pass --ask-become-pass --tags configure_users playbooks/dev/deploy.yml

Environment variables for k8s module:

export K8S_AUTH_API_KEY=$(shell oc whoami --show-token)
export K8S_AUTH_HOST=$(shell oc whoami --show-server)

Install different version of Ansible:

virtualenv -p python2 .venv
source .venv/bin/activate

#pip install ansible==2.4
pip install ansible<2.9

# make sure that system-installed version is not used
ansible --version

CMake

cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=$PWD/install ~/dev/copyq
ninja install

Containers

Remove old unnamed unused images:

podman image prune

Git

Remove parts from the latest commit:

git reset -p HEAD^
# select parts to remove ([y]es/[n]o/[s]plit)
git commit --amend --no-edit
git commit -a -m ...

gpg

gpg --edit-key $mail trust
gpg --verbose --encrypt --recipient $mail --output $file{.gpg,}

OpenShift

  • oc -n proj get pods
  • oc -n proj get dc
  • oc -n proj describe pod web-111-abcde
  • oc -n proj get events
  • oc -n proj rollout latest dc/web
  • oc -n proj rsh web-111-abcde
  • oc -n proj scale --replicas=0 dc web

Logs:

  • kail -- logs for all matching pods
  • kail -n proj -l deploymentconfig=web --since=1h
  • kail -n proj -l service=web --since=20m

Avoid using additional resources on deployment:

---
apiVersion: v1
kind: DeploymentConfig
spec:
  strategy:
    type: Rolling
    rollingParams:
      maxSurge: 0
# ...

PostgreSQL

psql "host=db.dev.example.com user=$user dbname=$db sslmode=require"

Python

Python 3 virtualenv:

python3 -m venv .venv
source .venv/bin/activate

Python 2 virtualenv:

virtualenv -p python2 .venv
source .venv/bin/activate

Breakpoint:

import ipdb; ipdb.set_trace()

Breakpoint in Python 3.7:

breakpoint()
export PYTHONBREAKPOINT=0
export PYTHONBREAKPOINT=pdb.set_trace
export PYTHONBREAKPOINT=ipdb.set_trace

Profiling decorator:

def profile(func):
    import cProfile
    import functools
    import io
    import pstats

    @functools.wraps(func)
    def wrap(*args, **kwargs):
        pr = cProfile.Profile()

        pr.enable()
        result = func(*args, **kwargs)
        pr.disable()

        s = io.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats(pstats.SortKey.TIME)
        ps.print_stats()
        print(s.getvalue())
        return result

    return wrap


@profile
def foo():
    pass

Vim

  • :windo difft -- diff open windows
  • :setl ar -- automatically reload file if changed
  • :read -- open file read only
  • q/ -- search history
  • q: -- command history
  • gf -- open file which filename is under cursor
  • gi -- go to last insert mode place
  • g; -- go to last change
  • g, -- go to next change
  • gq -- reformat
  • ~ -- change case of letter
  • :g/PATTERN/norm ... -- do something with each matched line (e.g. delete with dd)
  • :args **/*.h | vert sall -- open all matching files
  • https://www.reddit.com/r/vim/wiki/vimrctips

Zsh

  • Powerlevel10k -- fast status line
  • ALT-H -- show command help
  • C-x C-e -- edit command line

Other Tools

About

Various commands and configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published