Skip to content

Just a cheat sheet for various languages and technologies

Notifications You must be signed in to change notification settings

kevinkt1/CheatSheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 

Repository files navigation

CheatSheet

This repository is tailored for my personal use, but I want to make it public because I hope this repo will serve as a useful reference for all who come hither.

That said, I will probably exclude things that I already know to heart, such as Vim and Eclipse bindings.

Table of Contents

Confluence

Bullet List

CTRL + SHIFT + 8

Heading 1

CTRL + ALT + 0

Link text

CTRL + K

Numbered List

CTRL + SHIFT + 7


Doxygen

Quick Start

  1. doxygen -g
  2. Edit the newly generated Doxyfile to set the RECURSIVE tag to YES.
  3. To show private members, set EXTRACT_PRIVATE to YES.
  4. doxygen Doxyfile
  5. Open up html/index.html.

Notes

  • @file and @brief matters in the top-level comment at the start of the file.
  • @brief does not matter in classes and functions.
  • A doxygen comment is required at the top of a namespace to generate doxygen for the members within.
  • A doxygen comment is not required at the top of a class.
  • Add const to the end of @copydoc if const is part of the method signature.
  • @param[in] does matter.
  • @param [in] also works.
  • @throw and @throws both work. Be sure to specify the exception, e.g., @throw RuntimeError upon ....

Eclipse

Delete current line

CTRL + d


Emacs

Delete a word

ESC + d

Move to beginning of line

CTRL + a

Move to beginning of word

ESC + b

Move to end of line

CTRL + e

Move to end of word

ESC + f


Excel

Delete spreadsheet

ALT + H + D + S

Rename Excel

ALT + H + O + R


Fedora

Removing a package

  1. sudo dnf remove blah
  2. sudo dnf autoremove
  3. sudo dnf clean packages
  4. Check for leftover configuration files within these folders:
    1. /etc
    2. /usr/share
    3. ~/.local
    4. ~/.config

GDB

Define the user limit to allow for generation of core files with an unlimited maximum size

Command-line:

ulimit -c unlimited

Git

Auto-resolve merge conflicts on all unmerged files

Take our changes

grep -lr '<<<<<<<' . | xargs git checkout --ours

Take their changes

grep -lr '<<<<<<<' . | xargs git checkout --theirs

Branches

Create branch from another branch

git checkout -b new-branch old-branch

Create branch from current branch

git checkout -b new branch

Delete branch upstream

git push --delete origin branch-name

Checkout

Checkout another file from another local branch

git checkout local-branch-name -- local-file.txt

Checkout another file from another upstream branch

git checkout origin/upstream-branch-name -- upstream-file.txt

Cherry Pick

Grab commit from another branch

git cherry-pick commit-number-from-other-branch

View lost commits after using git reset

git reflog

Restore lost local commits

  1. git reflog

  2. git cherry-pick local-commit-number

  3. Merge the changes

  4. git cherry-pick continue

Changing a remote's URL

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

Reset

Reset to a commit as it was

git reset --hard commit-number

Reset to a commit but leave files staged

git reset --soft commit-number

Reset to a commit but leave files unstaged

git reset --mixed commit-number

Reset local branch to match upstream branch exactly

git pull
git reset --hard origin/branch-name

Status

Discard all untracked files

git clean -fdn

  • f is force
  • d is directory
  • n is to preview changes (remove the n flag to actually clean)
  • x is to remove ignored files

IntelliJ IDEA

Close current file

CTRL + F4

Delete current line

CTRL + X

Find a class

CTRL + N

Find a file

CTRL + SHIFT + N

Find text in all files

CTRL + SHIFT + F

Find usages

ALT + F7

Go back

CTRL + ALT + Left Arrow

Navigate to definition

Any of these keys will work:

  • CTRL + Left Click
  • CTRL + ALT + B

Settings menu

CTRL + ALT + S

Switch tab

  • ALT + Left
  • ALT + Right

Linux

find

Find a file

find ./ -name filename.txt

  • -iname can be used for case insensitivity

grep

Grep by file extension and sort by date

ls -rt *.txt | xargs grep -lr --include=\*.txt 'searchterm' ./

Grep for environment variables

env | grep ENV_VAR_NAME

ls

Sort all files by time

ls -lta

tar

Archive

Create archive without compression

tar -cvf sample.tar file1 file2

Compress files via gzip

tar -czvf sample.tgz file1 file2

Extraction

Preview tarball contents without extracting

tar -tvf file.tgz

  • -t is shorthand for --test

Extract tarball to current working directory

tar -xvf file.tar

  • -xvf is shorthand for --extract --verbose --file

Extract file to a target directory

tar -C target-directory file.tgz

  • -C changes to the target directory before extracting the tar file

A note on tarball file extensions

  • .tar is the conventional file extension to indicate the tarball is storing uncompressed data.
  • .tgz, .tar.gz, and .gz are the conventional file extensions indicating the tarball is storing compressed data.

zip

Zipping

Zip up multiple files

zip sample.zip file1 file2

Zip up a directory

zip -r sample.zip dir1/ dir2/

Unzipping

Unzip a file to the current working directory

unzip file.zip

Unzip a file to the target directory

unzip -d target-directory file.zip


Netcat

Connect to an address and port

nc -vv address port

Listen to a port

nc -vlp port


OpenSSL

Key Generation

Create a private key

openssl genrsa -out private_key.key 1024

Create a public key

openssl rsa -in /dev/shm/key/private_key.key -out public_key.key -pubout -outform PEM

Signing and Verification

Signing

openssl dgst -sha224 -sign /dev/shm/key/private_key.key -out sample.digest sample.tgz

Verification

openssl dgst -sha224 -verify /dev/shm/key/public_key.key -signature sample.digest sample.tgz


Outlook

Bullet list

* + <space>

Link text

CTRL + K


Python

Subprocess

subprocess.run()

# Python 3.5+
p = subprocess.run(fullCmdStr,
                   shell=True,
                   check=False,
                   executable='/bin/bash')

Arguments

  • executable defaults to sh instead of bash.
  • check throws an exception if the command failed.

Return Value

  • p.returncode is set to 0 if the command completed successfully.

Qt Creator Cheat Sheet

Go to function definition

F2

Go to line number

CTRL + L

Search with the Locator tool

CTRL + K

Switch between header and source files

F4


Regex

Syntax Table

Syntax Description
a Match 'a'
\. Match '.'
. Match any single character except newline
Character Class Description
[0-9] Digits within this range
\d Digits 0 through 9
\D Non-digits
[aeiou] Match one of the given characters
[^aeiou] Match any other character that is not given
[a-zA-Z] Letter within this range (a-ZA-Z or A-Za-z)
\s Whitespace [\r\n\t\f]
\S Non-whitespace
\w Word [a-z, A-Z, 0-9, underscores]
\W Non-word
Quantifier Description
[xy]{5} Match a string of length 5 consisting of characters {x,y}
f{1,3} Match 'f' 1, 2, or 3 times
\d{4,} Match at least 4 digit characters
c* Match 'c' 0 or more times
t+ Match 't' 1 or more times
Operator Description
[a|b] Match 'a' or 'b'
([A-Z]|[0-9]){2} Apply quantifier to grouping of [A-Z] or [0-9]
Anchor Description
^ Beginning of string
$ End of string
Grouping and Capturing Description
r'\b' Word boundary special character (r is needed in Python to avoid confusion with the backspace character)
() Capture a group
? Optionally capture this group
\1 Matches the same text as previously matched by the first capturing group
(?|regex1|regex2) Known as a 'branch reset group' that matches one of these groups or nothing
(\2two (one))+
Lookahead Description
a(?!b) Negative lookahead to notate that 'a' cannot be followed by 'b'
a(?=b) Positive lookahead to notate that 'a' must be followed by 'b'
(?<=a)b Positive lookbehind to notate that 'a' must precede 'b'
(?<!a)b Negative lookbehind to notate that 'a' cannot precede 'b'

Edge Cases

  • (b?)o\1
    • Successfully matches 'o' because the backreference matches the nothing captured by the group
  • (b)?o\1
    • In most regex flavors (excluding JavaScript), this regex pattern fails to match 'o' because the backreference references a group that did not participate in the match at all

PyTest

Loop a PyTest script

Add a loop inside the main.


Sublime

Keyboard Shortcuts

Command Palette

CTRL + SHIFT + P

Delete current line

CTRL + SHIFT + K

Wrap selected lines that exceed past the first ruler

ALT + Q

Packages

Anaconda package

Display signature tooltips (Anaconda: Display Object Docs)

CTRL + ALT + D

DocBlockr

Markdown Preview

Toggle NeoVintageous

CTRL + ALT + T


Vim

Command mode

" Determine the current file format
:set ff?

" If the current file format is DOS, change the file format to Unix
:set ff=unix
:%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g
:%s/\t/  /g
:retab

Jump to line number

" Jump to line 25
:25

Insertion Mode

Append by inserting after the cursor

a

Insert before the cursor

i

Append to the end of the line

A

Insert before the first word of the line

I

Normal Mode

Find all matches of word under cursor

*

Jump to line number

" Jump to line 25
25G

Movement

Center page around cursor

zz

Change/delete next instance of enclosed characters within double quotation marks

ci" di"

Change/delete next instance of enclosed characters within single quotation marks

ci' di'

Move cursor to the next instance of 'a'

fa

Move cursor to right before the next instance of 'a'

ta

Move cursor to the previous instance of 'a'

Fa

Move cursor to right after the previous instance of 'a'

Ta

Move to next match

;

Skip to previous blank line

{

Skip to next blank line

}

Visual Mode

Select characters

v

Select a whole line

V

Select a whole block

CTRL + v OR CTRL + q

Plugins

plantuml-syntax

python-syntax

vim-rainbow


Visual Studio Code

It should be noted that I rarely use Visual Studio Code these days.

Extensions

  • Bookmarks
  • Bracket Pair Colorizer 2
  • C/C++
  • CMake
  • CMake Tools
  • CSS Peek
  • Cython
  • Material Icon Theme
  • PlantUML
  • Python
  • Remote - WSL
  • Trailing Spaces
    • Currently, for a reason that I've long forgotten, I am not using this extension.

Keyboard Shortcuts

Code Navigation

Go back

CTRL + ALT + -

Navigate to function definition

F12

Views

Toggle fullscreen

F11

Setup Vim for Visual Studio Code

Note that the setup below is still not as preferable as using the original Vim.

Plugins


Windows

Close/minimize an application without an X button

  1. Click on the application to gain focus
  2. If you are confident that you have focus:
    • To close the application, press ALT + F4.
    • To minimize the application, press n.
  3. Otherwise, press ALT + SPACE to bring up the context menu.

XmlLint

Format an XML file

xmllint --format old_file.xml > new_file.xml

Validate an XML file against the schema

xmllint --noout --schema schema.xsd file.xml


YouTube

Disable suggested videos at the end of a video

Bring up the browser console (F12 on Chrome), and inject:

for(element of document.getElementsByClassName('ytp-ce-element')) {     element.style.display = 'none'; }  

About

Just a cheat sheet for various languages and technologies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published