Skip to content

Instantly share code, notes, and snippets.

@zzhuolun
Last active August 30, 2023 10:26
Show Gist options
  • Select an option

  • Save zzhuolun/3ae3e0afd116ef6a13925560d75ef8bf to your computer and use it in GitHub Desktop.

Select an option

Save zzhuolun/3ae3e0afd116ef6a13925560d75ef8bf to your computer and use it in GitHub Desktop.
shortcuts

tmux

default prefix : Ctrl B

operation keyboard shortcut
create a window prefix c
delete a window prefix &
delete a pane Ctrl d
rename a window prefix ,
create a horizontal pane prefix %
create a vertical pane prefix "
attach to a session tmux attach -t <session-id>
move pane to a new window prefix !
kill current session prefix xkbmap us: kill-session
detach from currently attached session prefix d

conda

  • export the packages to a .yml file conda env export > environment.yml

  • install the package from the .yml file conda env create -f environment.yml

    • the firt line in .yml file sets the new environment's name
  • deactivate auto-loading of base environment since it is best-practice to not accidently install packages inside the base environment:

    conda config --set auto_activate_base false

jupyter notebook

command mode

operation keyboard shortcut
undo cell deletion Z
delete cell D D
markdown cell to code cell Y
code cell to markdown cell M
select multiple cell Shift Up/Down
merge selected cell Shift M
copy current cell C
cut currect cell X
paste cells below V
paste cells above Shift V
show all shortcuts H
enter edit mode Enter
scroll the notebook down Space
scroll the notebook up Shift Space

edit mode

operation keyboard shortcut
split cell at cursor Ctrl Shift -/+
exti edit mode Esc
show function arguments/documentation Shift-Tab
  • helper function: add a ? after the function and then run
  • Ctrl Shift C: show command pallette
  • %matplotlib qt: interactive plot mode
  • %matplotlib inline: normal charts inside notebook

vim

git

  • push local branch to a remote branch: git push <remote> <local_branch>:<remote_branch>

  • pull a remote branch to a local branch git pull <remote> <remote_branch>:<local_branch>

    Note: git pull will only work at fast-forward merge. For non-fast-forward merge:

    $ git fetch <remote> <remote_branch>
    $ git merge <remote>/<remote_branch>
    
  • show the difference of a file between current commit and one commit back: git diff HEAD^ HEAD main.c, between current commit and two commits back git diff HEAD^^ HEAD main.c

  • git branch description:

    Edit branch description: git branch --edit-description

    View branch description: git config branch.BRANCHNAME.description

    source

  • git tags:

    Add tags with message: git tag -a TAGNAME -m COMMENTS

    List tags: git tag -n99, note git tag will list tags without messages.

    Push all tags: git push --tags

PyCharm

Shift-Shift: open search bar

Alt-Enter: open pycharm suggestions

Ctrl-W: select the current word, press twice W select the current string, press more Ws futher to select wider scope; Ctrl-Shift-W to shrink selection.

Ctrl-Y: delete current line

Ctrl-D: duplicate selected line/ shortcut for copy-paste combined

Shift-UpperArrow: select from the current caret postion to one line above; press UpperArrow twince to select one more line

Shift-DownArrow: select from the current caret postion to one line below

Shift-LeftArrow or Shift-RightArrow: move the caret to left/right and select the text

Ctrl-Shift-UpperArrow: move current line up; if at the beginning of a block, the entire block wil be moved up.

Ctrl-Minus: collapse a code fragment

Ctrl-Equal: expand a code region

Ctrl-Shift-Minus: collapse all code regions

Ctrl-Shift-Equal: expand all code regions

Alt-J: select the symbol at the caret, press J agin to select the next occurence of this symbol.

Ctrl-Alt-Shift-J: select all occurences in the file (this is quite useful if you want to rename a variable and change its name in all occurences.

linux

  • print the owner of a pid: ps -o user= -p PIDHERE

  • zip a folder and exclude certain folders zip -r myarchive.zip dir1 -x dir1/ignoreDir1/\* dir1/ignoreDir2/\*

  • bash short cuts:

    • Ctrl-U: to clear line before the cursor. The deleted command will be stored into a buffer.
    • Ctrl-K to clear line after the cursor.
    • Ctrl-Y to paste the deleted command.
    • Ctrl-E to jump to the end of the input line.
    • Ctrl-A to jump to the start of the input line.
    • Ctrl-C to abort what you're typing.
    • Ctrl-W to delete word on the left.
    • Alt-D to delete word on the right.
    • Alt-F to move one word forward.
    • Alt-B to move one word back.
  • Search and run previous command:

    • Ctrl-r search for command
    • !{history-number} history number can be found at histrory command output
  • grep search + next/previous lines:

    grep -A1 "PATTERN" example.txt
    OPTIONS
           -A NUM, --after-context=NUM
           -B NUM, --before-context=NUM
           -C NUM, --context=NUM
    
  • show juyter notebook on server from local computer ssh -N -f -L localhost:$1:localhost:$2 user@server_ip

  • open a file or URL in default pplication xdg-open {file URL}

  • switch keyboard layout

    setxkbmap de switch to german keyboard

    setxkbmap us switch to us keyboard

  • print directory size

    du -h -d 1: -h stands for human-readable, -d 1 prints only 1 level below the current directory

    du -hs: -s stands for summarize the total size

  • report file system disk space usage: df -h

  • remove all files exclude certrain files:

    rm -rf !(*.py): remove all files except for .py files

    rm -rf !(index*).html: remove all .html files except for those named index*.html(* is a wildcard here)

  • pavucontrol: change volume above 100%

  • set brightness of a display:

    xrandr --output $Monitor --brightness 1.0

    Note: $Monitor is in the list of xrandr --listmonitors, set brightness to a float number will dim the selected display, e.g 0.5 is half the current brightness

  • change system font size

    gsettings set org.gnome.desktop.interface text-scaling-factor [scaling-factor-value]

  • print Linux version lsb_release -a

  • find my IP address: curl ifconfig.me

python tools

Run and profile the .py script:

kernprof -l script_to_profile.py

View the profiler results stored in .lprof

python -m line_profiler script_to_profiler.py.lprof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment