postgres

sudo -i -u postgres
psql enters the prompt
in the prompt, \l lists the databases
out of the prompt, psql -l does the same
psql "name" enters the prompt for that database
\dt (or \dt+) lists the tables

in psql you can:
CREATE DATABASE "name";
CREATE USER "name" WITH PASSWORD "password";
GRANT ALL PRIVILEGES ON DATABASE "name" TO "user";
\q to quit




tmux

pane splitting:
ctrl-b " (top/bottom)
ctrl-b % (side/side)
move between panes:
ctrl-b [ARROW_KEY]
windows:
ctrl-b c (create)
ctrl-b & (delete)
ctrl-b p (previous)
ctrl-b n (next)
ctrl-b [NUMBER] (skip to num)
sessions:
tmux new -s [NAME]
tmux ls
tmux attach -t [NAME]
tmux rename-session -t [OLD_NAME] [NEW_NAME]
ctrl-b d

git

Set up server to be able to push local project to it:
on server:
mkdir [REPO_NAME].git
cd [REPO_NAME].git
git init --bare
git branch -m [BRANCH_NAME]
branch name is usually master or main
cd hooks/
touch post-receive
chmod +x post-receive
#!/bin/sh
GIT_WORK_TREE=[/DESIRED/PATH] git checkout -f [BRANCH_NAME]
on local:
git remote add [CHOSEN_NAME] [USER]@[REMOTE]:[PATH/TO/REPO_NAME].git
name is of remote (e.g. origin)
git push [CHOSEN_NAME]

Revert working directory changes to file:
git checkout HEAD [FILENAME]
Unstage file changes:
git reset HEAD [FILENAME]
Revert working directory to previous commit in commit log:
git reset [COMMIT_SHA]



Misc:

ln -s [EXISTING] [LINK]

get key hash:
ssh-keygen -E sha256 -l -f [PATH_TO_PUBKEY] (or -E md5)

test github connection:
ssh -T git@github.com

chmod/chgrp/chown

When you run ls -al:
drwxr-xr-x    2    root  root  4096    Dec 3 16:09    .
  permissions     #hardlinks   owner   group   size(bytes)       LastModified      Filename

The permissions are formatted like this:
*#########
"*" is the special permissions flag. Marks things like if it is a symlink or directory.
"#########" is actually broken into three sets of three:
- The first set is for the user who owns it, "owner" (u)
- The second set is the permissions for "group" (g)
- The third set is the permission for "others" (o)
- Also: All three sets together are called "all" (a)

The letters refer to:
r : "read", 4
w : "write", 2
x : "execute", 1

chmod command:
Change the permissions of a file or directory:
chmod [permissions] [file]
[permissions] can be formatted two ways:
chmod 766 . (sum of numbers corresponding to r/w/x)
chmod u+rw,g=rw,a-x . (add, set, subtract permissions for specific user sets)

chown/chgrp command:
Change the owner or group of a file or directory:
Options include: recursive operation and only certain sources
chown [-r] [--from=CURRENT_OWNER:CURRENT_GROUP] NEW_OWNER
chgrp [-r] NEW_OWNER

netstat

A useful command for seeing if your servers really are listening on the ports:
mac : netstat -vanp tcp
linux: netstat -vlnt
-v : verbose
-n : numbers (e.g. 127.0.0.1 instead of localhost)
-p tcp : only tcp connections (mac)
-t : only tcp connections (linux)
-a : "all" sockets, normally servers are not shown (mac or linux)
-l : only listening sockets, normally not shown (linux)

Regex:
  • Regular expressions are special sequences of characters that describe a pattern of text that is to be matched
  • We can use literals to match the exact characters that we desire
  • Alternation, using the pipe symbol |, allows us to match the text preceding or following the |
  • Character sets, denoted by a pair of brackets [] , let us match one character from a series of characters
  • Wildcards, represented by the period or dot . , will match any single character (letter, number, symbol or whitespace)
  • Ranges allow us to specify a range of characters in which we can make a match
  • Shorthand character classes like \w, \d and \s represent the ranges representing word characters, digit characters, and whitespace characters, respectively
  • Groupings, denoted with parentheses () , group parts of a regular expression together, and allows us to limit alternation to part of a regex
  • Fixed quantifiers, represented with curly braces {} , let us indicate the exact quantity or a range of quantity of a character we wish to match
  • Optional quantifiers, indicated by the question mark ? , allow us to indicate a character in a regex is optional, or can appear either 0 times or 1 time
  • The Kleene star, denoted with the asterisk * , is a quantifier that matches the preceding character 0 or more times
  • The Kleene plus, denoted by the plus + , matches the preceding character 1 or more times
  • The anchor symbols hat ^ and dollar sign $ are used to match text at the start and end of a string, respectively