# Handbook

# Git

## Remove files already added to git after you update .gitignore

```Bash
git rm -r --cached .
git add .
git commit -m "remove useless files"
```
## Push empty commit

```Bash
git commit --allow-empty -m "empty commit"
git push
```
## Set new remote origin

```Bash
git remote set-url origin new.git.url/here
```
## Revert commits from merged PRs

```Bash
git revert HEAD -m 1
```
# Linux

## List crontab for specific user

```JavaScript
# run crontab command for specific user
crontab -l -u <user>

# find crontab from spool 
cat /var/spool/cron/crontabs/<user>
```
## Find out size of directories in the /home directory

```Shell
 sudo du -sh /home/* | sort -h

```
- `s`: Display only a total for each argument.
- `h`: Print sizes in human-readable format (e.g., 1K, 234M, 2G).
## Edit files in terminal without nano, vim, vi, etc.

I was helping a friend fix some issues but didn’t have access to the code repository so I had to figure out how to edit files directly inside a deployed docker container with no nano or vim. This worked like a charm. Also, in order to apply the changes, I had to exit out of the container and run `docker restart container-id` so it would apply the updated configurations without triggering a new build so the changes are not lost.

```Bash
cat filename
```
Copy the entire text, change what you need to, then copy it again

```Bash
cat >filename
```
Paste the edited text and hit CTRL + D to save and quite

# Jupyter Notebook

## Using kernelspec

```Bash
jupyter kernelspec list
jupyter kernelspec install
jupyter kernelspec uninstall
```
## In notebook commands

```Bash
%pwd # print working directory
%cd # change directory
```


# Python

## Using secrets module

- To generate a random password you should use the `secrets` module


# PostgreSQL

## Backup & Restore Dockerized Postgres

### Backup your databases

```SQL
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql
```
### Restore your databases

```SQL
cat your_dump.sql | docker exec -i your-db-container psql -U postgres
```
## Show triggers

```Bash
select event_object_schema as table_schema,
       event_object_table as table_name,
       trigger_schema,
       trigger_name,
       string_agg(event_manipulation, ',') as event,
       action_timing as activation,
       action_condition as condition,
       action_statement as definition
from information_schema.triggers
group by 1,2,3,4,6,7,8
order by table_schema,
         table_name;
```
**Columns**

- **table_schema** - name of the table schema
- **table_name** - name of the trigger table
- **trigger_schema** - name of the trigger schema
- **trigger_name** - name of the trigger
- **event** - specific SQL operation: _Insert_, _Update_ or _Delete_
- **activation** - trigger activation time: _After_, _Instead of_ or _BEFORE_
- **condition** - trigger activation condition
- **definition** - definition of trigger - in postgreSQL it is always _EXECUTE PROCEDURE function_name()_
**Rows**

- **One row** represents one trigger
- **Scope of rows:** all triggers in a database
- **Ordered by** schema name, table name
# Strapi

## Running a project from your host machine

You can also use `strapi/strapi` to run a project you already have created (or cloned for a repo) on your computer.

First make sure to delete the `node_modules` folder if you have already installed your dependencies on your host machine. Then run:

```Plain Text
cd my-project
docker run -it -p 1337:1337 -v `pwd`:/srv/app strapi/strapi
```