├── CICD
├── .gitlab-ci.yml
└── azure-pipelines.md
├── IaC
├── cloudformation.md
├── pulumi.md
└── terraform.md
├── LICENSE
├── LangLab
├── Go.md
├── JS.md
├── R.md
├── Rust.md
├── python
│ ├── Django.md
│ ├── Python.md
│ ├── sphinx.md
│ └── virtual_environments.md
└── typescript
│ ├── TS.md
│ ├── conditional_properties.md
│ └── installation.md
├── Linux
├── awk.md
├── cut.md
├── data_streams.md
├── file_and_dir_permissions.md
├── find.md
├── grep.md
├── history.md
├── logs.md
├── main_distros.md
├── passwd.md
├── ripgrep.md
├── sed.md
├── systemd.md
└── tr.md
├── README.md
├── SSH
├── commands.md
└── config
├── aws
├── cdk.md
├── certs
│ └── devops_engineer_pro.md
├── cli.md
├── containerization
│ └── ecr_ecs.md
└── ec2
│ ├── ec2_overview.md
│ └── ec2_startup_script.sh
├── code-vault.png
├── cyber_security.md
├── database
├── db.md
└── sql.md
├── docker
├── .dockerignore
├── Dockerfile
├── docker-compose.md
├── docker-compose.yaml
├── docker.md
└── docker_cheatsheet.pdf
├── dsa.md
├── git.md
├── k8s
├── k8s.md
└── minikube_notes.md
├── kerberos.md
├── markdown.md
├── networking.md
├── redis.md
├── regex.md
├── shell
├── bash.md
├── bash_scripting.md
├── cmd.md
├── nano.md
└── powershell.md
├── shortcuts.md
└── software-development
├── concepts.md
├── data-structures.md
└── design-patterns.md
/CICD/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 |
2 | ---
3 | stages:
4 | - build
5 | - test
6 | - deploy
7 |
8 | build-job:
9 | stage: build
10 | script:
11 | - echo "Compiling the code..."
12 | - echo "Compile complete."
13 |
14 | unit-test-job:
15 | stage: test
16 | script:
17 | - echo "Running unit tests... This will take about 60 seconds."
18 | - sleep 60
19 | - echo "Code coverage is 90%"
20 |
21 | lint-test-job:
22 | stage: test
23 | script:
24 | - echo "Linting code... This will take about 10 seconds."
25 | - sleep 10
26 | - echo "No lint issues found."
27 |
28 | deploy-job:
29 | stage: deploy
30 | environment: production
31 | script:
32 | - echo "Deploying application..."
33 | - echo "Application successfully deployed."
34 |
--------------------------------------------------------------------------------
/CICD/azure-pipelines.md:
--------------------------------------------------------------------------------
1 | # Azure pipelines (ADO)
2 |
3 | [YAML schema](https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/?view=azure-pipelines&viewFallbackFrom=azure-devops&tabs=schema%2Cparameter-schema)
4 |
5 |
6 | ```YAML
7 | variables:
8 | - template: vars/vars.yml
9 |
10 | parameters:
11 | - name: DIRECTORY
12 | type: string
13 | default: "."
14 |
15 | trigger:
16 | - main
17 | # - feature/*
18 | # TODO: add path(s)
19 |
20 | pool:
21 | vmImage: ubuntu-latest
22 |
23 | stages:
24 | - stage: CI
25 | jobs:
26 | - job: CIWork
27 | steps:
28 | - script: "Do CI work"
29 |
30 | - stage: Test
31 | jobs:
32 | - job: TestWork
33 | steps:
34 | - script: "Do test work"
35 | ```
36 |
--------------------------------------------------------------------------------
/IaC/cloudformation.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/IaC/cloudformation.md
--------------------------------------------------------------------------------
/IaC/pulumi.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/IaC/pulumi.md
--------------------------------------------------------------------------------
/IaC/terraform.md:
--------------------------------------------------------------------------------
1 | # Terraform
2 |
3 | Written in Go
4 |
5 | HCL: Hashicorp Configuration Language
6 |
7 | Install CLI
8 |
9 | # script naming
10 | `main.tf`
11 |
12 | ```terraform
13 | terraform {
14 |
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Gustav Rasmussen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/LangLab/Go.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/LangLab/Go.md
--------------------------------------------------------------------------------
/LangLab/JS.md:
--------------------------------------------------------------------------------
1 | # JavaScript
2 |
3 | ## resources
4 | * [Odin project](https://www.theodinproject.com/)
5 | * [RunJS](https://runjs.app/)
6 |
7 | ## node.js
8 | run JavaScript program locally
9 | `node programname.js`
10 | or
11 | `node .`
12 |
13 | ## data types
14 | * boolean
15 | * number
16 | * string
17 |
18 | ## branching
19 |
20 | ## loops
21 |
22 | Loop backwards through array:
23 | ```JavaScript
24 | for (var i = arr.length - 1; i >= 0; i--) {
25 | // do something with arr[i]
26 | }
27 | ```
28 |
29 | ## reverse array without reassigning
30 |
31 | ```JavaScript
32 | const arr = ['a', 'b', 'c'];
33 | const reversed = arr.toReversed();
34 | ```
35 |
36 | ## functions
37 |
38 | ## ternary statement
39 |
40 | ## string interpolation
41 |
--------------------------------------------------------------------------------
/LangLab/R.md:
--------------------------------------------------------------------------------
1 | # R
2 |
3 | ## rotate x-label in ggplot
4 |
5 | Given an ggplot, `q`:
6 | ```R
7 | q + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
8 | ```
9 |
--------------------------------------------------------------------------------
/LangLab/Rust.md:
--------------------------------------------------------------------------------
1 | # code example, main.rs:
2 |
3 | ```RUST
4 | fn main() {
5 | println!('hello, world!');
6 | }
7 | ```
8 |
9 | # program naming
10 | `main.rs`
11 |
12 | # compilation
13 | `rustc main.rs`
14 |
--------------------------------------------------------------------------------
/LangLab/python/Django.md:
--------------------------------------------------------------------------------
1 | # Django
2 |
3 | The Python-based Django framework is used by:
4 |
5 |
6 |
7 |
8 |

9 |

10 |

11 |

12 |

13 |

14 |
15 |
16 | Upcoming:
17 | - configuring URLs
18 | - database model creation
19 | - dynamic data in templates
20 | - admin panel
21 |
22 | ## Setup new Django project
23 |
24 | installation:
25 | `pip install django`
26 |
27 | start a new Django project
28 | `django-admin startproject workoutplans .`
29 |
30 | install the testing framework (interface between pytest and django, with additional features)
31 | `pip install pytest-django`
32 |
33 | start a new Django app
34 | `python manage.py startapp workoutapp`
35 |
36 | `cd - python manage.py startapp workoutapp`
37 |
38 | add html template:
39 | `mkdir templates && cd templates`
40 |
41 | `echo welcome page workout generator > index.html`
42 |
43 | Navigate to `project/myproject/settings.py`:
44 |
45 | add
46 | `import os`
47 |
48 | update `TEMPLATES[“DIRS”]` with:
49 | `os.path.join(BASE_DIR, "workoutapp/templates")`
50 |
51 | under `INSTALLED_APPS`,
52 | add an entry for the name of the new django app that was just created.
53 |
54 | ## Views
55 |
56 | A view is a function that receives a request and returns a response.
57 |
58 | example, `workoutapp/views.py`:
59 | ```Python
60 | from django.shortcuts import render, HttpResponse
61 |
62 |
63 | def home(request):
64 | return HttpResponse("Welcome to the workoutapp")
65 | ```
66 |
67 | then in `workoutapp/urls.py`:
68 | ```Python
69 | from django.urls import path
70 | from . import views
71 |
72 | urlpatterns = [
73 | path("", views.home, name="home")
74 | ]
75 | ```
76 |
77 | then in `workoutplans/urls.py`:
78 | ```Python
79 | from django.contrib import admin
80 | from django.urls import path, include
81 |
82 | urlpatterns = [
83 | path('admin/', admin.site.urls),
84 | path("workoutapp/", include("workoutapp.urls")),
85 | ]
86 | ```
87 |
88 |
89 | ## Development server
90 | Run app
91 | `python manage.py runserver`
92 |
93 | run Django app with the development server
94 | `python manage.py runserver (runs at local port 8000)`
95 |
96 | if you wish to change port:
97 | `python manage.py runserver 8080`
98 |
99 | then visit
100 | http://127.0.0.1:8000/workoutapp/welcome_view/
101 |
102 | ## Files
103 |
104 | the special configuration files `asgi.py` and `wsgi.py` allow django to communicate with the web server.
105 |
106 | the `settings.py` file:
107 | to install django apps, plugins, middleware,
108 | or modify database engines.
109 |
110 | the `urls.py` file: configure different url routes,
111 | that can then be directed / routed to different Django applications.
112 |
113 | the `manage.py` file acts as a command line tool,
114 | and can be used for running the django development server,
115 | do database migrations, create users and more.
116 |
117 | the `models.py` file:
118 | here the database models are placed.
119 |
120 | the `admin.py` file:
121 | register database models so they can be viewed on the admin panel.
122 |
123 | the `tests.py` file: adding automated tewst cases.
124 |
125 | the `views.py` file:
126 | create different views or routes, that can be accessed from the website.
127 |
128 | ## templates
129 |
130 | example, create `templates/base.html`,
131 | populate using emmet,
132 | then add blocks, e.g.
133 | ```HTML
134 | {% block title %}workoutplans{% endblock %}
135 | ```
136 |
137 | which uses the jinja templating engine, which allows displaying dynamic data.
138 |
139 | re-using template in `templates/home.html`:
140 | ```HTML
141 | {% extends "base.html" %} {% block title %} Home {% endblock %}
142 | {% block content %}
143 | welcome to the workoutplans home page
144 | {% endblock %}
145 | ```
146 |
147 | ## CSS
148 |
149 | - bootstrap
150 | - tailwind
151 |
152 | ## Run Django app with Docker
153 |
154 | ```BASH
155 | docker build --tag python-django .
156 | docker run --publish 8000:8000 python-django
157 | ```
158 |
--------------------------------------------------------------------------------
/LangLab/python/Python.md:
--------------------------------------------------------------------------------
1 | # Python
2 |
3 | ## Data types and methods
4 |
5 | list:
6 | - zip
7 | - enumerate
8 | - reverse list: `some_list[::-1]`
9 |
10 | dict:
11 | - get
12 | - setdefault
13 |
14 | example
15 | ```Python
16 | student_grades = {}
17 |
18 | spanish_grades = student_grades.setdefault("Roberto", {})
19 | spanish_grades["spanish"] = 90
20 | print(student_grades) # {"Roberto": {"spanish": 90}}
21 | ```
22 |
23 | ## for-else and while-else
24 |
25 | ```Python
26 | nums = [1, 2, 3, 4, 5,]
27 | find = 4
28 |
29 | for num in nums:
30 | if num == find:
31 | print(f"found {find} in the list.")
32 | break
33 | else:
34 | # This block will execute only if the loop completed without encountering a 'break'
35 | print(f"{find} was not found in the list.")
36 |
37 |
38 | count = 5
39 |
40 | while count > 0:
41 | print(count)
42 | count -= 1
43 | else:
44 | # This block will execute once the condition in the while statement is no longer true
45 | print("Liftoff!")
46 | ```
47 |
48 | ## print
49 |
50 | pretty printing
51 | ```Python
52 | from pprint import pprint as pp
53 |
54 | pp(some_dict)
55 | ```
56 |
57 | ```Python
58 | nums = [1, 2, 3, 4, 5,]
59 |
60 | print(*nums, sep="-", end="no new line after this string")
61 | ```
62 |
63 | ## walrus operator
64 |
65 | example
66 | ```Python
67 | numbers = [2, 8, 0, 1, 1, 9, 7, 7]
68 |
69 | description = {
70 | "length": (num_length := len(numbers)),
71 | "sum": (num_sum := sum(numbers)),
72 | "mean": num_sum / num_length,
73 | }
74 |
75 | print(description) # {'length': 8, 'sum': 35, 'mean': 4.375}
76 | ```
77 |
78 | ## comprehensions
79 |
80 | list, dict, set, generator
81 |
82 | e.g.
83 | `some_list = [a for a in b if some_condition]`
84 |
85 | ## Functional
86 |
87 | ### lambda functions
88 | anonymous functions
89 | `z = lambda x: x * 3`
90 |
91 | use lambda function to sort dictionary by specific key
92 | ```Python
93 | people = [
94 | {"name": "Oppenheimer", "age": 62},
95 | {"name": "Einstein", "age": 76},
96 | {"name": "Schubert", "age": 31},
97 | ]
98 |
99 | people.sort(key=lambda person: person['age'])
100 | ```
101 |
102 | ### map
103 | ```Python
104 | some_list = [1, 2, 4, 5, 6]
105 | new_list = map(lambda z: z + 5, some_list)
106 | ```
107 |
108 | ### filter
109 |
110 | ### reduce
111 |
112 | ## unknown number of function arguments
113 | ```Python
114 | def some_function(*args, **kwargs):
115 | print(args, kwargs)
116 |
117 |
118 | some_function(5, y='five')
119 | ```
120 |
121 | ## Swap values
122 | ```Python
123 | a, b = b, a
124 | ```
125 |
126 | ## Ternary / in-line if statement
127 | ```Python
128 | some_var = 0 if condition else 1
129 | ```
130 |
131 | ## Switch-case / structural pattern matching
132 |
133 | ## OOP dunder methods
134 |
135 | ```Python
136 | __init__
137 | __eq__
138 | __repr__
139 | __call__
140 | ```
141 |
142 | ## Decorators
143 | e.g. the built-in `@staticmethod`
144 |
145 | ## Generators
146 | e.g. if you only need access to a few items at a time,
147 | ```Python
148 | def firstn(n):
149 | num = 0
150 | while num < n:
151 | yield num
152 | num += 1
153 |
154 |
155 | sum_of_first_n = sum(firstn(1_000))
156 | ```
157 |
158 | ## context managers
159 | ```Python
160 | with open("some_file.txt", "r") as rf:
161 | data = rf.readlines()
162 | ```
163 |
164 | ## Metaclasses
165 |
166 | ## Concurrency and parallellism
167 | GIL.
168 |
169 | multi-processing / multi-threading
170 |
171 | ## Testing
172 | TDD with Pytest
173 |
174 | ## Collections
175 |
176 | ## Itertools
177 |
178 | ## Functools
179 |
180 | ## Timing
181 |
182 | ## Profiling
183 |
184 | ## Logging
185 |
186 | ## Pathlib
187 |
188 | ## Cookiecutter and Cruft
189 |
190 | ## build and publish package
191 |
--------------------------------------------------------------------------------
/LangLab/python/sphinx.md:
--------------------------------------------------------------------------------
1 | # Sphinx
2 |
3 | ```BASH
4 | mkdir docs && cd docs
5 |
6 | sphinx-quickstart
7 |
8 | # edit conf.py
9 |
10 | sphinx-apidoc -o ./ ../src
11 | # or:
12 | sphinx-apidoc -o ./source ../src
13 |
14 | make clean
15 |
16 | make html
17 | ```
18 |
--------------------------------------------------------------------------------
/LangLab/python/virtual_environments.md:
--------------------------------------------------------------------------------
1 | # Virtual Environments
2 |
3 | ## Poetry
4 | create new poetry project
5 | `poetry init`
6 |
7 | create virtual env inside project dir
8 | `poetry config virtualenvs.in-project true`
9 |
10 | create virtual env
11 | `poetry install`
12 |
13 | inspect
14 | `poetry env info`
15 |
16 | inspect path
17 | `poetry env info -p`
18 |
19 | activate virtual env
20 | `poetry shell`
21 |
22 | run tests
23 | `pytest`
24 |
25 | install django
26 | `poetry add django`
27 |
28 | uninstall
29 | `poetry remove some-package`
30 |
31 | close virtual env shell
32 | `exit`
33 |
34 | check which virtual env is active
35 | `poetry env list`
36 |
37 | close shell and deactivate virtual env
38 | `deactivate`
39 |
--------------------------------------------------------------------------------
/LangLab/typescript/TS.md:
--------------------------------------------------------------------------------
1 | # TypeScript
2 |
3 | ## Resources
4 |
5 | [book](https://basarat.gitbook.io/typescript/)
6 |
7 | [Doc](https://www.typescriptlang.org/)
8 |
9 | ## Language features
10 |
11 | Strongly typed.
12 | Superset of JavaScript.
13 |
14 | ## check type
15 |
16 | `typeof`
17 |
18 | ## ignore type
19 |
20 | ```TypeScript
21 | let z: number = 3
22 |
23 | // @ts-ignore
24 | z = "code-vault"
25 | ```
26 |
27 | ## compilation
28 | compilation (to JS, EcmaScript 3) with `tsc`.
29 |
30 | check version: `tsc --version`.
31 |
32 | example, `index.ts`:
33 |
34 | ```TypeScript
35 | console.log('hello code-vault')
36 |
37 |
38 | async function hello() {
39 | return 'code-vault'
40 | }
41 |
42 |
43 | const url = new URL('...') // . for auto-complete
44 | ```
45 |
46 | compile: `tsc index.ts`
47 |
48 | ## configuration
49 |
50 | create a configuration, `tsconfig.json`, for the compiler:
51 | `touch tsconfig.json`
52 |
53 | then add following content (specifying latest version of JS):
54 | ```JSON
55 | {
56 | "compilerOptions": {
57 | "target": "esnext",
58 | "watch": true,
59 | "lib": ["dom", "es2017"]
60 | }
61 | }
62 | ```
63 |
64 | `target`: version of JS to compile into.
65 | `watch`: automatically recompile for every file change (save)
66 | `lib`: automatically include typing for certain environments
67 |
68 | ## Third party libraries
69 | `npm i lodash`
70 |
71 | creates `node_modules` folder, with the source code for `lodash`.
72 |
73 | `index.ts`:
74 |
75 | ```TypeScript
76 | import * as _ from 'lodash';
77 |
78 |
79 | async function hello() {
80 | return 'code-vault'
81 | }
82 |
83 |
84 | _.pickBy()
85 | ```
86 |
87 | `lodash` comes without built-in types.
88 | install types:
89 | `npm i -D @types/lodash`
90 |
91 | ## Type annotations
92 |
93 | ```TypeScript
94 | // implicit type
95 | let lucky = 23;
96 |
97 | // opt out of the type system with the any keyword
98 | let also_lucky: any = 23;
99 |
100 | // then also_lucky can be re-assigned to any value (and the compiler won't type-check it)
101 | also_lucky = '23'
102 |
103 | // without value or type assignment, a new variable is assigned the any type:
104 | let very_lucky;
105 | very_lucky = '23'
106 | very_lucky = 23
107 |
108 | // if there is an implicit type, don't botherexplicitly typing it.
109 | // instead of:
110 | let super_lucky: number = 23;
111 | // do this instead:
112 | let super_lucky = 23;
113 |
114 | // built in types from JS are available, and we can also built our own types
115 | ```
116 |
117 | ## Custom types
118 |
119 | name commonly in PascalCase
120 |
121 | ```TypeScript
122 | // type Style = string;
123 | type Style = 'bold' | 'italic'; // union type
124 |
125 | let font: Style;
126 |
127 | font = 'bold'
128 |
129 | // Allow any additional fields with the any keyword
130 | interface Person {
131 | first: string;
132 | last: string;
133 | [key: string]: any
134 | }
135 |
136 | const person: Person = {
137 | first: 'John',
138 | last: 'Connor'
139 | }
140 |
141 | const person2: Person = {
142 | first: 'Jonas',
143 | last: 'Vingegaard',
144 | gc_cyclist: true
145 | }
146 |
147 | ```
148 |
149 | ## Types in functions
150 |
151 | ```TypeScript
152 | function pow(x: number, y: number): string {
153 | return Math.pow(x, y).toString();
154 | }
155 |
156 |
157 | function pow(x: number, y: number): void {
158 | Math.pow(x, y).toString();
159 | }
160 | ```
161 |
162 | ## Arrays
163 |
164 | ```TypeScript
165 | const arr: number[] = []
166 |
167 | arr.push(1)
168 | arr.push('23')
169 | arr.push(false)
170 |
171 | const arr: Person[] = []
172 |
173 | // Tuple with optional values
174 | type MyList = [number?, string?, boolean?]
175 | ```
176 |
177 | ## Generics
178 |
179 | allow for specifying internal type later in the code, by using ``
180 | ```TypeScript
181 | class Observable {
182 | constructor(public value: T) {}
183 | }
184 |
185 | let x: Observable;
186 |
187 | let y: Observable;
188 |
189 | let z = new Observable(23); // implicitly get number type
190 | ```
191 |
192 | ## using undefined
193 |
194 | ```TypeScript
195 | type Animal = {
196 | name: string
197 | legs?: number
198 | }
199 |
200 |
201 | const printAnimal = (animal: Animal) => {
202 | const x = (animal.legs ? animal.legs : 0)
203 | }
204 |
205 |
206 | const dog = {
207 | name = "kerberos"
208 | }
209 |
210 |
211 | printAnimal(dog)
212 | ```
213 |
214 | ## combining types
215 |
216 | ```TypeScript
217 | type Monkey = {
218 | diet: string
219 | } & Animal
220 | ```
221 |
222 | ## sets
223 |
224 | ```TypeScript
225 | const s: new Set();
226 |
227 | ```
228 |
229 | ## interfaces
230 |
231 | ```TypeScript
232 | type Fish = {
233 | name: string
234 | swim: () => void
235 | }
236 |
237 |
238 | type Dog = {
239 | name: string
240 | bark: () => void
241 | }
242 |
243 |
244 | // const printName = (animal: Dog | Fish) => {
245 | // console.log(animal.name)
246 | // }
247 |
248 | // Use interface to ensure something getting passed to certain function has certain properties on them
249 | interface Animal {
250 | name: string;
251 | }
252 |
253 |
254 | const printName = (animal: Animal) => {
255 | console.log(animal.name)
256 | }
257 | ```
258 |
259 | ## enums
260 |
261 | useful if the values change later (e.g. "Small" to "small"), only change in one place
262 | ```TypeScript
263 | enum ShirtSize = {
264 | Small = "Small",
265 | Medium = "Medium",
266 | Large = "Large"
267 | }
268 |
269 |
270 | const getShirtPrice = (shirtSize: ShirtSize) => {
271 | switch (shirtSize) {
272 | case ShirtSize.Small:
273 | return 10
274 | case ShirtSize.Medium:
275 | return 20
276 | case ShirtSize.Large:
277 | return 30
278 | }
279 | }
280 |
281 |
282 | const price = getShirtPrice(ShirtSize.Small)
283 | ```
284 |
285 | ## type guard / custom guard
286 |
287 | ```TypeScript
288 | const isFish = (animal: Fish | Dog): animal is Fish => {
289 | return (animal as Fish).swim() !== undefined
290 | }
291 |
292 |
293 | const callAnimalFunc = (animal: Fish | Dog) => {
294 | if (isFish(animal)) animal.swim()
295 | else animal.bark()
296 | }
297 | ```
298 |
--------------------------------------------------------------------------------
/LangLab/typescript/conditional_properties.md:
--------------------------------------------------------------------------------
1 | # Conditional properties
2 |
3 | ```TypeScript
4 | type Props = {
5 | name: string
6 | } & (CardioProps | StrengthProps)
7 |
8 | type CardioProps = {
9 | training: 'cardio'
10 | vo2_max: number
11 | }
12 |
13 | type StrengthProps = {
14 | training: 'strength'
15 | one_rm: number
16 | }
17 |
18 | const Child = (props: Props) => {
19 |
20 | if (props.training === 'cardio') {
21 | console.log(props.vo2_max)
22 | } else if (props.training === 'strength') {
23 | console.log(props.one_rm)
24 | }
25 |
26 | return child
27 | }
28 | ```
29 |
--------------------------------------------------------------------------------
/LangLab/typescript/installation.md:
--------------------------------------------------------------------------------
1 | # TypeScript Installation
2 |
3 | install, load and activate `nvm`
4 | ```BASH
5 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
6 |
7 | export NVM_DIR="$HOME/.nvm"
8 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
9 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
10 |
11 | . ~/.nvm/nvm.sh
12 | ```
13 |
14 | install `node.js` version 16 (compatible with `aws cdk`)
15 | ```BASH
16 | nvm install 16
17 | npm install -g npm@9.8.0
18 | ```
19 |
20 | check versions
21 | ```BASH
22 | node -v
23 | npm -v
24 | ```
25 |
26 | global typescript installation
27 | `npm i -g typescript`
28 |
29 |
--------------------------------------------------------------------------------
/Linux/awk.md:
--------------------------------------------------------------------------------
1 | # awk
2 |
3 | awk: scripting language to manipulate text
4 |
5 | example text file (with turtle name, banner-color, personality), `tmnt.txt`:
6 | ```TEXT
7 | leonardo blue leader
8 | raphael red hothead
9 | michelangelo orange party-animal
10 | donatello purple geek
11 | ```
12 |
13 | awk as default sees spaces as delimiters for fields.
14 |
15 | example, print everything:
16 | `awk '{print}' tmnt.txt`
17 | or (`0` represents the entire file),
18 | `awk '{print $0}' tmnt.txt`
19 |
20 |
21 | example, show specific (first) field only:
22 | `awk '{print $1}' tmnt.txt`
23 |
24 | example, show specific (third) field only:
25 | `awk '{print $3}' tmnt.txt`
26 |
27 | example, print multiple fields (`1` and `3`):
28 | `awk '{print $1,$3}' tmnt.txt`
29 |
30 | chaining commands into awk:
31 | `ls -l | awk '{print $1}'`
32 |
33 | example:
34 | `echo "Hello from code-vault" | awk '{print $1,$3}'`
35 |
36 | example: getting last field using number of fields `NF` (in this case 3):
37 | `awk '{print $NF}' tmnt.txt`
38 |
39 | example: no space delimiters
40 | this won't work:
41 | `awk '{print $2}' /etc/passwd`
42 | because, e.g.:
43 | `cat /etc/passwd | grep gus`
44 | instead, set a different field separator, `F`:
45 | `awk -F':' '{print $2}' /etc/passwd`
46 |
47 | to find out which shell each user of the system is using,
48 | `awk -F':' '{print $1,$7}' /etc/passwd`
49 |
--------------------------------------------------------------------------------
/Linux/cut.md:
--------------------------------------------------------------------------------
1 | # cut
2 |
3 | purpose: remove sections from lines within files
4 |
5 | example file, `message.txt`:
6 | ```TEXT
7 | TheNewThinkTank has recently reached 1,030 contributions in the last year! Wow!
8 | ```
9 |
10 | example, print the first character of a file:
11 | `cut -b 1 message.txt`
12 |
13 | `-b`: select by byte
14 | `-c`: select by character
15 | `-d`: select by delimiter
16 | `-f`: select by field
17 |
18 | example, print the first character of a file:
19 | `cut -b 7,8,9,10,11 message.txt`
20 | better, if the characters are sequential:
21 | `cut -b 7-11 message.txt`
22 |
23 | more consistently (to avoid if a character takes more than 1 byte),
24 | `cut -c 7-11 message.txt`
25 |
26 | example: choose multiple character intervals:
27 | `cut -b 7-11,56,57-61 message.txt`
28 |
29 | example, split a file by field:
30 | by default, tab `\t` is the delimeter.
31 | change the delimeter to space instead:
32 | `cut -d " " -f 1,2 message.txt`
33 |
34 | example: extract usernames
35 | `cat /etc/passwd`
36 |
37 | `cut -d ":" -f 1 /etc/passwd`
38 |
39 | cut is best used on files with multiple rows and fields
40 |
--------------------------------------------------------------------------------
/Linux/data_streams.md:
--------------------------------------------------------------------------------
1 | # Data Streams
2 |
3 | ## standard input, standard output, standard error
4 | `stdin` e.g. keyboard commands
5 | `stdout` screen printout
6 | `stderr` when an error is displayed on screen (failed commands, e.g. command not found)
7 |
8 | Distinguishing between `stdout` and `stderr`: `echo $?`
9 | returncode 1: `stderr`
10 | returncode 0: `stdout`
11 |
12 | example: following command will fail as it is not called with sudo:
13 | `find /etc -type f`.
14 | `echo $?` returns 1
15 |
16 | `stdin` is represented by the number 0, `stdout` by 1 and `stderr` by 2.
17 | example: split `stdout` from `stderr` and handle them differently:
18 | `find /etc -type f 2> /dev/null`
19 | `/dev/null` is a black hole; anything that is sent to `/dev/null` is never seen again.
20 |
21 | example: sent `stdout` to a file (it is implied):
22 | `find /etc -type f > ~/results.txt`
23 | displays only `stderr`, but newly created file has all `stdout`.
24 |
25 | example: send `stdout` and `stderr` to two different files (overwrite):
26 | `find /etc -type f > ~/results.txt 2> ~/errors.txt`
27 |
28 | example: append `stdout` and `stderr` to two different files:
29 | `find /etc -type f >> ~/results.txt 2>> ~/errors.txt`
30 |
--------------------------------------------------------------------------------
/Linux/file_and_dir_permissions.md:
--------------------------------------------------------------------------------
1 | # File and Directory Permissions
2 |
3 | `ls -l` shows the permissions string to the left.
4 | broken down into 4 groups, e.g. `drwxr-xr-x` or `-rw-rw-r--`.
5 | First group is a single character;
6 | `d`: directory
7 | `-`: file
8 | `l`: link
9 |
10 | next groups are 3 characters each. In order, they are:
11 | permissions for the user, the group and the other / world / everybody else
12 | `r`: read
13 | `w`: write
14 | `x`: execute
15 |
16 | ## Modify permissions
17 |
18 | Suppose file `testfile.txt` contains the command `ls -l`,
19 |
20 | make file executable for everybody:
21 | `chmod +x testfile.txt`
22 |
23 | remove execution permission for user:
24 | `chmod u-x testfile.txt`
25 |
26 | remove execution permission for group:
27 | `chmod g-x testfile.txt`
28 |
29 | remove execution permission for other:
30 | `chmod o-x testfile.txt`
31 |
32 | make file executable for user:
33 | `chmod u+x testfile.txt`
34 |
35 | remove read permission for group:
36 | `chmod g-r testfile.txt`
37 |
38 | remove read permission for other:
39 | `chmod o-r testfile.txt`
40 |
41 | remove write permission for group:
42 | `chmod g-w testfile.txt`
43 |
44 | example:
45 | `chmod u-w testfile.txt`
46 | will make the following command fail:
47 | `echo "https://github.com/TheNewThinkTank/code-vault" >> testfile.txt`
48 | `chmod u+w testfile.txt`
49 | `echo "https://github.com/TheNewThinkTank/code-vault" >> testfile.txt`
50 | now the content was appended to the file.
51 |
52 | ## Combining chmod commands
53 |
54 | Allow group to read and write with a single command:
55 | `chmod g+rw testfile.txt`
56 |
57 | ## Bit scores - numerical representations of r, w and x
58 |
59 | `r`: 4
60 | `w`: 2
61 | `x`: 1
62 |
63 | example
64 | `chmod 770 testfile.txt`
65 | results in permission string
66 | `-rwxrwx---`
67 |
68 | generally, `chmod ??? testfile.txt`
69 | with `???` equal to `ugo`, user, group and other.
70 |
71 | example
72 | `ls -l Downloads/`
73 |
74 | Recursively change permissions for all files in dir, without affecting the dir:
75 | `chmod 600 Downloads/*`
76 |
77 | Use with caution, applies to everything beneath the object:
78 | `chmod -R 700 Downloads`
79 |
80 | Or use `find` command for more granular controls
81 |
82 | ## Change ownership
83 |
84 | Change ownership of all files in `Downloads/` dir to `new-user` and `new-user-group`
85 | `sudo chown -R new-user:new-user-group Downloads/`
86 |
87 | Shorthand (leaving out group defaults to the user's group):
88 | `sudo chown -R new-user: Downloads/`
89 |
--------------------------------------------------------------------------------
/Linux/find.md:
--------------------------------------------------------------------------------
1 | # find
2 |
3 | search for any text file in home dir
4 | `find /home/gus -name *.txt`
5 |
6 | omit cache files
7 | `find /home/gus -name *.txt | grep -v .cache`
8 |
9 | only include files (from current dir)
10 | `find . -name Documents -type f`
11 |
12 | only include dirs (from current dir)
13 | `find . -name Documents -type d`
14 |
15 | delete files (from current dir)
16 | `find . -name Documents -type f -exec rm {} +`
17 |
18 | remove execution permission on files in `Pictures` dir
19 | `find Pictures/ -type f -exec chmod 600 {} +`
20 |
21 | set permissions on `Pictures` dir
22 | `find Pictures/ -type d -exec chmod 700 {} +`
23 |
24 | example, clear logs
25 | `ls -l /var/log`
26 |
27 | test / dryrun
28 | `sudo find /var/log -type f -name *.log`
29 |
30 | if results look ok, execute
31 | `sudo find /var/log -type f -name *.log -exec truncate -s 0 {} +`
32 |
33 | find any mp3 file in home dir and save to file
34 | `find . -name *.mp3 > music.txt`
35 |
--------------------------------------------------------------------------------
/Linux/grep.md:
--------------------------------------------------------------------------------
1 | # grep
2 |
3 | main purpose: search for text within files.
4 |
5 | `grep`: global regular expression print
6 |
7 | number of lines in file:
8 | `cat /etc/ssh/sshd_config | wc -l`
9 |
10 | seach for word in file:
11 | `cat /etc/ssh/sshd_config | grep Port`
12 |
13 | seach for lines without specific word in file:
14 | `cat /etc/ssh/sshd_config | grep -v Port`
15 |
16 | more directly:
17 | `grep Port /etc/ssh/sshd_config`
18 |
19 | generally, `grep what where` or `grep word file`
20 |
21 | exclusion:
22 | `grep -v Port /etc/ssh/sshd_config`
23 |
24 | add line numbers:
25 | `grep -n Port /etc/ssh/sshd_config`
26 |
27 | count, or number, of occurences:
28 | `grep -c Port /etc/ssh/sshd_config`
29 |
30 | grep is case-sensitive:
31 | `grep port /etc/ssh/sshd_config`
32 |
33 | remove case-sensitivity:
34 | `grep -i port /etc/ssh/sshd_config`
35 |
36 | seach for word in all files in current dir:
37 | `grep word *`
38 | `grep -n word *`
39 |
40 | recursive search (narrow `path` as much as possible):
41 | `grep -r word path`
42 | example with logs:
43 | `grep -ri Error /var/log`
44 |
--------------------------------------------------------------------------------
/Linux/history.md:
--------------------------------------------------------------------------------
1 | # History
2 |
3 | up / down arrows to cycle through previous commands
4 |
5 | `history`
6 |
7 | each previous command has a number, which can be used to execute that command, e.g.:
8 | `!123`, if the command had number 123
9 |
10 | ## avoid a command from showing up in the history
11 | add a space in front, e.g.
12 | ` groups`
13 | usefull if the command contains a password for example
14 |
--------------------------------------------------------------------------------
/Linux/logs.md:
--------------------------------------------------------------------------------
1 | # Logs
2 |
3 | text file with a lot of info about the system:
4 | `cat /var/log/syslog`
5 |
6 | `cd /var/log`
7 |
8 | message log:
9 | `dmesg`
10 |
11 | first 10 lines:
12 | `head /var/log/syslog`
13 |
14 | last 10 lines:
15 | `tail /var/log/syslog`
16 |
17 | last 50 lines:
18 | `tail -n 50 /var/log/syslog`
19 |
20 | follow (last 10 lines, and follow the file for changes):
21 | `tail -f /var/log/syslog`
22 | example:
23 | `sudo systemctl restart ssh`
24 |
25 | `journalctl`, part of `systemd`.
26 | example:
27 | `journalctl -u ssh`
28 | where `u`: unit
29 |
30 | example:
31 | `journalctl -u apache2`
32 |
33 | Alternatively,
34 | `cat /var/log/syslog | grep apache2`
35 |
36 | example, follow unit:
37 | `journalctl -fu apache2`
38 |
39 | obtionally,
40 | `sudo systemctl restart apache2`
41 |
--------------------------------------------------------------------------------
/Linux/main_distros.md:
--------------------------------------------------------------------------------
1 | # Main Linux Distributions
2 |
3 | Linux is an open-source operating system that comes in various distributions, commonly known as "distros." These distributions are developed and maintained by different organizations and communities, each with its own goals, design philosophies, and target audiences. Here are some major Linux distributions:
4 |
5 | ## Ubuntu
6 | Ubuntu is one of the most popular and user-friendly Linux distributions. It aims to provide an intuitive and accessible experience for desktop users. Ubuntu is known for its stability, extensive software repositories, and long-term support (LTS) releases.
7 |
8 | ## Debian
9 | Debian is a highly respected and influential Linux distribution known for its stability, security, and adherence to the principles of free software. It serves as a base for many other distributions, including Ubuntu. Debian follows a release cycle focused on stability and reliability.
10 |
11 | ## Fedora
12 | Fedora is a community-driven Linux distribution sponsored by Red Hat. It focuses on integrating the latest software and technologies, making it a good choice for users who want cutting-edge features and developments. Fedora follows a rapid-release cycle and offers a new version approximately every six months.
13 |
14 | ## CentOS
15 | CentOS (Community Enterprise Operating System) is a distribution built from the same source code as Red Hat Enterprise Linux (RHEL). It aims to provide a free and open-source alternative to RHEL, focusing on stability and long-term support. However, as of 2021, CentOS has undergone significant changes, transitioning to CentOS Stream, which is more aligned with RHEL development.
16 |
17 | ## Arch Linux
18 | Arch Linux is a lightweight and flexible distribution that follows a rolling-release model. It offers a minimalistic base system and a package manager called "pacman," allowing users to customize their installations according to their preferences. Arch Linux is known for its simplicity, flexibility, and extensive documentation.
19 |
20 | ## openSUSE
21 | openSUSE is a community-developed distribution sponsored by SUSE Linux GmbH. It focuses on stability, ease of use, and a polished desktop experience. openSUSE offers two main editions: Leap, which follows a regular release cycle, and Tumbleweed, a rolling-release edition with frequent updates.
22 |
23 | These are just a few examples of the major Linux distributions available. Each distribution has its own strengths and target audience, so it's worth exploring them further to find the one that best suits your needs and preferences.
24 |
25 | # built-in package managers of the above Linux distributions
26 |
27 | ## Ubuntu
28 |
29 | Package Manager: Ubuntu primarily uses the Advanced Package Tool (APT) as its package manager. APT provides a command-line interface and tools like apt-get and apt for managing packages.
30 | Practical Bash Commands:
31 | Update package lists: sudo apt update
32 | Install a package: sudo apt install
33 | Remove a package: sudo apt remove
34 | Search for a package: apt search
35 |
36 | ## Debian
37 |
38 | Package Manager: Debian also uses APT as its package manager, providing the same set of command-line tools.
39 | Practical Bash Commands: The commands are the same as those used in Ubuntu since Debian and Ubuntu share the same package management system.
40 | ## Fedora
41 |
42 | Package Manager: Fedora uses the DNF package manager (Dandified Yum) as its default package manager. DNF is the next-generation version of the Yum package manager.
43 | Practical Bash Commands:
44 | Update package lists: sudo dnf update
45 | Install a package: sudo dnf install
46 | Remove a package: sudo dnf remove
47 | Search for a package: dnf search
48 | ## CentOS
49 |
50 | Package Manager: Historically, CentOS used the Yum package manager, similar to Fedora. However, with the transition to CentOS Stream, it now uses DNF as its default package manager.
51 | Practical Bash Commands: The commands for CentOS are the same as those used in Fedora since CentOS Stream adopts many of Fedora's features.
52 | ## Arch Linux
53 |
54 | Package Manager: Arch Linux uses the Pacman package manager, which is known for its simplicity and speed.
55 | Practical Bash Commands:
56 | Update package lists: sudo pacman -Sy
57 | Install a package: sudo pacman -S
58 | Remove a package: sudo pacman -R
59 | Search for a package: pacman -Ss
60 | ## openSUSE
61 |
62 | Package Manager: openSUSE uses the Zypper package manager, which provides a command-line interface for managing packages.
63 | Practical Bash Commands:
64 | Update package lists: sudo zypper refresh
65 | Install a package: sudo zypper install
66 | Remove a package: sudo zypper remove
67 | Search for a package: zypper search
68 | These commands should help you get started with package management on these Linux distributions. Remember to use sudo before administrative commands to execute them with root privileges.
69 |
--------------------------------------------------------------------------------
/Linux/passwd.md:
--------------------------------------------------------------------------------
1 | # passwd
2 |
3 | ## Set or change password
4 | For logged in user: `passwd`
5 | other users: `sudo passwd username`
6 |
7 | ## Get password statistics
8 | `sudo passwd -S username`
9 |
10 | ## Lock password for user
11 | `sudo passwd -l username`
12 |
13 | ## Unlock password for user
14 | `sudo passwd -u username`
15 |
16 | ## Expire password after 30 days
17 | `sudo passwd -x 30 username`
18 |
19 | ## Expire password immediately
20 | `sudo passwd -e username`
21 |
22 | ## Delete password for user
23 | `sudo passwd -d username`
24 |
--------------------------------------------------------------------------------
/Linux/ripgrep.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/Linux/ripgrep.md
--------------------------------------------------------------------------------
/Linux/sed.md:
--------------------------------------------------------------------------------
1 | # sed
2 |
3 | `sed`: stream editor
4 | use it to filter and modify text, e.g. in-place within text-files.
5 |
6 | example file, `tonics.txt`:
7 | ```TEXT
8 | Delicious tonic combinations:
9 | 1. Ginger, Carrot, Apple
10 | 2. Orange, Ginger, Lime
11 | 3. Ginger, Pineapple, Blood orange
12 | 4. Whey protein, Banana, Ginger
13 | 5. Oat milk, Ginger
14 | ```
15 |
16 | example: replace `Ginger` with `Lemon` from `tonics.txt`, without overwriting the file
17 | `sed 's/Ginger/Lemon/' tonics.txt`
18 |
19 | example: replace file inplace:
20 | `sed -i 's/Ginger/Lemon/' tonics.txt`
21 |
22 | delete word
23 | `sed 's/Ginger//' tonics.txt`
24 |
25 | ## delimiters
26 | if one of the characters you want to replace is a forward slash, `/`,
27 | use a different delimiter.
28 |
29 | example:
30 | `find /etc -type f > paths.txt`
31 |
32 | `cat paths.txt`
33 |
34 | deletion:
35 | `sed 's./etc..' paths.txt`
36 |
37 | replacement:
38 | `sed 's./etc.something-else.' paths.txt`
39 |
40 | example:
41 | `echo "Code Vault" | sed 's/Vault/Hive/'`
42 |
--------------------------------------------------------------------------------
/Linux/systemd.md:
--------------------------------------------------------------------------------
1 | # systemd
2 |
3 | Most popular Linux init system.
4 | Controls units, e.g. services.
5 | Mostly interacted with through `systemctl`.
6 | Systemd is self-reliant and runs in the background.
7 |
8 | ## systemctl
9 | ```BASH
10 | sudo systemctl status service-name
11 | sudo systemctl start service-name
12 | sudo systemctl restart service-name
13 | sudo systemctl stop service-name
14 | sudo systemctl enable service-name
15 | sudo systemctl disable service-name
16 | ```
17 |
18 | ## Unit Directory Priority
19 | 1. /etc/systemd/system
20 | 2. /run/systemd/system
21 | 3. /lib/systemd/system
22 |
--------------------------------------------------------------------------------
/Linux/tr.md:
--------------------------------------------------------------------------------
1 | # tr
2 |
3 | tr - translate or delete characters.
4 |
5 | most often used together with other commands.
6 | example, make string all caps:
7 | `echo "Code Vault" | tr [a-z] [A-Z]`
8 | the first set `[a-z]` is replaced by the second set `[A-Z]`.
9 |
10 | alternatively,
11 | `echo "Code Vault" | tr [:lower:] [:upper:]`
12 |
13 | alternatively,
14 | `tr [a-z] [A-Z] < some-file.txt`
15 |
16 | deletion (delete all lower-case characters):
17 | `echo "Code Vault" | tr -d [a-z]`
18 |
19 | squeeze (`s`) out duplicate characters (e.g. k):
20 | `cat some-file.txt | tr -s "k"`
21 |
22 | delete every alphabet character:
23 | `cat some-file.txt | tr -d [:alpha:]`
24 |
25 | replace one character with another:
26 | `cat some-file.txt | tr "$" "#"`
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # code-vault
4 |
5 | [](https://github.com/TheNewThinkTank/code-vault/archive/refs/heads/main.zip)
6 |
7 | "Developers handbook" / "udviklerens ståbi"
8 |
9 | Welcome to the Snippet Hive / Tech Trove / Code Cabinet / Script Sanctuary.
10 |
11 | My personal collection of recipes for BASH, Git, Docker and more,
12 | intended primarily for my own daily work and as a quick reference.
13 |
14 | the main goal is quick access to a lot of relevant info
15 |
16 | Feel free to use these if you find them helpful,
17 | but don't expect any certain structure, explanation or consistency.
18 |
19 | ## Upcoming
20 |
21 |
22 |
23 | `aws/cdk`
24 | `aws/certs/devops_engineer_pro`
25 |
26 | `LangLab/JS`
27 | `LangLab/python/sphinx`
28 | `LangLab/typescript/TS`
29 |
30 |
31 |
32 | `Linux/lsof`
33 | `Linux/top`
34 | `Linux/ripgrep`
35 | `Linux/rsync`
36 | `Linux/scp`
37 | `Linux/etc_fstab`
38 |
39 | `software-development/data-structures`
40 |
41 | ## Reading list
42 | - [ ] "Continuous Delivery"
43 | - [ ] "Fluent Python"
44 | - [ ] "Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow"
45 | - [x] "Accelerate"
46 | - [x] "Creative Confidence"
47 | - [x] "Star Schema"
48 | - [x] "The Clean Coder"
49 | - [x] "The Pragmatic Programmer"
50 |
51 |
52 | ## Experts and useful resources
53 | This work could only have been possible thanks to the many excellent people and resources made available
54 | largely through the open source community and popular channels. To name a few,
55 |
56 | * Corey Schafer
57 | * Derek Banas
58 | * Learn Linux TV
59 | * Python Engineer
60 | * Tech With Tim
61 | * Fireship
62 | * Real Python
63 | * A Cloud Guru
64 |
--------------------------------------------------------------------------------
/SSH/commands.md:
--------------------------------------------------------------------------------
1 | ## SSH
2 | create ssh keypair:
3 | `ssh-keygen`
4 |
5 | ```BASH
6 | cat .ssh/id_rsa
7 | cat .ssh/id_rsa.pub
8 | mkdir projects & cd projects/
9 | cd ~/.ssh
10 | cp id_rsa.pub authorized_keys
11 | ```
12 |
--------------------------------------------------------------------------------
/SSH/config:
--------------------------------------------------------------------------------
1 | Host foo
2 | # Proxy command, ssm agent -> ec2 instance-id
3 | Hostname: |
4 | # port: # if not default (22)
5 |
6 | Host bar
7 | Hostname: some_domain
8 | User: john
9 |
--------------------------------------------------------------------------------
/aws/cdk.md:
--------------------------------------------------------------------------------
1 | # CDK
2 |
3 | ## useful commands
4 |
5 | ```BASH
6 | # installation
7 | npm install -g aws-cdk
8 |
9 | # start a new cdk app
10 | cdk init app --language typescript
11 |
12 | # synthesize cdk stack into CloudFormation
13 | cdk synth
14 |
15 | # deploy to aws
16 | cdk deploy
17 |
18 | # compare changes to previous deploy
19 | cdk diff
20 | ```
21 |
22 | ## useful resources
23 |
24 | [getting started](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)
25 |
26 | [cdk patterns](https://www.cdkpatterns.com/)
27 |
28 | [cdk day](https://www.cdkday.com/)
29 |
30 | ## terms
31 |
32 | `bootstrap` an AWS environment
33 | prerequisit for being able to deploy CDK stacks into said account.
34 | provisions certain AWS resources used during deployment.
35 | `cdk bootstrap ACCOUNT-NUMBER-1/REGION-1 ACCOUNT-NUMBER-2/REGION-2 ...`
36 |
37 | `environment`:
38 | An environment is the target AWS account and Region into which the CDK stack is intended to be deployed
39 | recommended to explicitly specify the environment for each stack in app:
40 | ```TypeScript
41 | const envEU = { account: '2383838383', region: 'eu-central-1' };
42 | const envUSA = { account: '8373873873', region: 'us-east-1' };
43 |
44 | new MyFirstStack(app, 'first-stack-us', { env: envUSA });
45 | new MyFirstStack(app, 'first-stack-eu', { env: envEU });
46 | ```
47 |
48 | ## deploy CDK stack to multiple environments:
49 |
50 | override the account and Region at synthesis time:
51 | ```TypeScript
52 | new MyDevStack(app, 'dev', {
53 | env: {
54 | account: process.env.CDK_DEPLOY_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
55 | region: process.env.CDK_DEPLOY_REGION || process.env.CDK_DEFAULT_REGION
56 | }});
57 | ```
58 |
59 | set the variables from command line arguments, `cdk-deploy-to.sh`:
60 | ```BASH
61 | #!/usr/bin/env bash
62 | if [[ $# -ge 2 ]]; then
63 | export CDK_DEPLOY_ACCOUNT=$1
64 | export CDK_DEPLOY_REGION=$2
65 | shift; shift
66 | npx cdk deploy "$@"
67 | exit $?
68 | else
69 | echo 1>&2 "Provide account and region as first two args."
70 | echo 1>&2 "Additional args are passed through to cdk deploy."
71 | exit 1
72 | fi
73 | ```
74 | execute `chmod +x cdk-deploy-to.sh` to make it executable.
75 |
76 | deploy to multiple environments, `cdk-deploy-to-prod.sh`:
77 | ```BASH
78 | #!/usr/bin/env bash
79 | ./cdk-deploy-to.sh 135792468 us-east-1 "$@" || exit
80 | ./cdk-deploy-to.sh 246813579 eu-central-1 "$@"
81 | ```
82 |
83 | ## projen
84 |
85 | ## constructs
86 |
87 | ## examples
88 |
89 |
--------------------------------------------------------------------------------
/aws/certs/devops_engineer_pro.md:
--------------------------------------------------------------------------------
1 | # DevOps Engineer Pro
2 |
3 |
4 |
5 |
6 | Domain 1: SDLC Automation
7 |
8 | ## Implement CI/CD pipelines
9 | - SDLC concepts, phases, and model
10 | - deployment patterns
11 | - CodeCommit
12 | - CodeBuild
13 | - CodeArtifact
14 | - Secrets Manager
15 | - Systems Manager Parameter Store
16 | - CodeDeploy
17 |
18 | ## Integrate automated testing into CI/CD pipelines
19 | - automated testing
20 | - unit tests, integration tests, acceptance tests, user
21 | interface tests, security scans
22 |
23 |
24 |
25 |
26 |
27 |
28 |
41 |
42 | ## Domain 2: Configuration Management and IaC
43 |
44 | ## Domain 3: Resilient Cloud Solutions
45 |
46 | ## Domain 4: Monitoring and Logging
47 |
48 | ## Domain 5: Incident and Event Response
49 |
50 | ## Domain 6: Security and Compliance
51 |
--------------------------------------------------------------------------------
/aws/cli.md:
--------------------------------------------------------------------------------
1 | # AWS CLI version 2
2 |
3 | ## Installation
4 |
5 | to install on macOS for all users:
6 | ```BASH
7 | curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
8 | sudo installer -pkg AWSCLIV2.pkg -target /
9 | ```
10 |
11 | verify that the shell can find and run the aws command in your $PATH:
12 | ```BASH
13 | which aws
14 | aws --version
15 | ```
16 |
17 | ## Configuration
18 |
19 | configure credentials:
20 | `aws configure`
21 | this creates a default user in the `.aws/credentials` file.
22 | for a non-default / named user:
23 | `aws configure --profile code-vault-member`
24 |
25 | ## Example commands
26 |
27 | S3:
28 | ```BASH
29 | # list buckets
30 | aws s3 ls
31 |
32 | # list objects in bucket
33 | aws s3 ls s3://foo target-filename
34 |
35 | # copy object
36 | aws s3 cp s3://foo
37 |
38 | # sync from local dir to bucket
39 | aws s3 sync . s3://mybucket
40 |
41 | # sync between buckets
42 | aws s3 sync s3://mybucket s3://mybucket2
43 |
44 | # sync from bucket to local dir
45 | aws s3 sync s3://mybucket .
46 |
47 | # sync from local dir to bucket and delete files that exist in destination but not in source
48 | aws s3 sync . s3://mybucket --delete
49 | ```
50 |
--------------------------------------------------------------------------------
/aws/containerization/ecr_ecs.md:
--------------------------------------------------------------------------------
1 | # ECR
2 |
3 | # ECS
4 |
5 | # Task
6 |
7 | # Task Definition
8 |
9 | # Cluster
10 |
11 | # Service
12 |
13 | # Fargate
14 |
--------------------------------------------------------------------------------
/aws/ec2/ec2_overview.md:
--------------------------------------------------------------------------------
1 | # EC2 overview
2 |
3 | ## Pricing Options
4 |
5 | `DORS`
6 | - Dedicated (most expensive)
7 | - On-Demand (pay by the hour or second)
8 | - Reserved (reserve for 1-3 years. up to 72% discount)
9 | - Spot (purchase unused capacity. up to 90 % discount)
10 |
11 | ## Instance Types
12 |
13 | - R: RAM
14 | - C: CPU
15 | - M: "medium", balanced
16 | - I: I/O
17 | - G: GPU
18 | - T2/T3: burstable
19 |
20 | [Instance overview](https://www.ec2instances.info)
21 |
22 | ## Related Services
23 |
24 | - ASG
25 | - ELB
26 | - EBS
27 | - EFS
28 |
29 | # Relevant Knowledge
30 |
31 | - SSH (e.g. `ssh ec2-user@ -i `)
32 | - User Data / bootstrapping
33 |
34 | ## Metadata
35 |
36 | Data about the EC2 instance. Inspect:
37 | `curl http:///latest/meta-data/`
38 | e.g. getting the IP:
39 | `curl http:///latest/meta-data/public-ipv4`
40 |
41 | Similarly, `user-data` can also be queried:
42 | `curl http:///latest/user-data`
43 |
44 | # TODO: AMI's
45 | # TODO: Image Builder
46 | # TODO: placement groups
47 |
--------------------------------------------------------------------------------
/aws/ec2/ec2_startup_script.sh:
--------------------------------------------------------------------------------
1 |
2 | #!/usr/bin/bash
3 |
4 | ## AMI: AL2023
5 | USERNAME="some_user"
6 | REPO_URL="some_repo"
7 | sudo -i
8 | useradd "$USERNAME"
9 | ## Grant sudo privileges
10 | echo "$USERNAME" ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/"$USERNAME"
11 | ## List users
12 | # awk -F: '{ print $1}' /etc/passwd
13 | ## Create ssh keypair
14 | ssh-keygen -t rsa -b 4096 # -C "$USERNAME"
15 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
16 | chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys && chmod 600 ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa.pub
17 | ## 600: (chmod a+rwx,u-x,g-rwx,o-rwx) sets permissions so that,
18 | ## (U)ser / owner can read, can write and can't execute.
19 | ## (G)roup can't read, can't write and can't execute.
20 | ## (O)thers can't read, can't write and can't execute.
21 | mkdir projects && cd projects
22 | sudo yum update -y
23 | ## Install git
24 | sudo yum install git
25 | ## Install docker AL2023
26 | sudo yum install -y docker
27 | ## Check Docker permissions
28 | # ls -la /var/run/docker.*
29 | # sudo chmod 666 /var/run/docker.sock
30 | sudo service docker start
31 | # sudo usermod -a -G docker ec2-user
32 | ## Install docker-compose
33 | # sudo yum install docker-compose
34 | # curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
35 | ## LOGGING
36 | systemctl enable sshd
37 | systemctl start sshd
38 | ## Check /var/log/dnf.log for package installation info
39 | ## Check binary file /var/log/wtmp for login info
40 | cat /var/log/wtmp | last
41 | ## Check /var/log/btmp for failed login attempts, needs to be run as root
42 | cat /var/log/btmp | lastb -adF
43 | ## a shows the hostname in the last column, d attempts to map DNS names to IP addresses, F displays the full times
44 | # systemctl enable docker.service
45 | # systemctl start docker.service
46 | # sudo service docker start
47 | # Clone repo
48 | # git clone "$REPO_URL"
49 | ## Install Node Version manager
50 | # curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
51 | ## Activate nvm
52 | # . ~/.nvm/nvm.sh
53 | ## Install node
54 | ## nvm install node
55 | ## nvm uninstall 20.3.1
56 | # nvm install 16
57 | ## Check versions
58 | # node -v
59 | # npm -v
60 | ## Install CDK (TypeScript)
61 | # npm install aws-cdk-lib
62 | npm install -g aws-cdk
63 | ## Upgrade npm
64 | npm install -g npm@9.8.0
65 | ## Install TypeScript 3.8 or later
66 | npm -g install typescript
67 | ## Check cdk version
68 | cdk --version
69 |
--------------------------------------------------------------------------------
/code-vault.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/code-vault.png
--------------------------------------------------------------------------------
/cyber_security.md:
--------------------------------------------------------------------------------
1 | # Cyber Security
2 |
3 | [PortSwigger](https://portswigger.net/)
4 |
5 | SCA - Software Composition Analysis
6 |
7 | SAST - Static Application Security Testing
8 |
9 | DAST - Dynamic Application Security Testing
10 |
11 | DevSecOps
12 |
13 | AuthN, AuthZ
14 |
15 | OWASP top 10
16 |
17 | ## SQLi
18 | escape characters
19 |
--------------------------------------------------------------------------------
/database/db.md:
--------------------------------------------------------------------------------
1 | # Database
2 |
3 | RDBMS / SQL
4 |
5 | NoSQL:
6 | - neo4j (graph)
7 | - mongoDB (document)
8 | - cassandra
9 | - redis
10 | - dynamoDB (key-value)
11 |
12 | ACID:
13 | - Atomicity (all-or-nothing)
14 | - Consistency
15 | - Isolation
16 | - Durability
17 |
18 | CRUD:
19 | - Create
20 | - Read
21 | - Update
22 | - Delete
23 |
24 | sharding vs replication
25 |
26 | CAP theorem:
27 | - Consistency
28 | - Availability
29 | - Partition (Network)
30 |
31 | PAC ELC theorem:
32 | Partition, yes (PAC):
33 | - Availability
34 | - Consistency
35 | no (ELC):
36 | - Latency
37 | - Consistency
38 |
--------------------------------------------------------------------------------
/database/sql.md:
--------------------------------------------------------------------------------
1 | # SQL
2 |
3 | ## Style guides
4 |
5 | [Gitlab](https://about.gitlab.com/handbook/business-technology/data-team/platform/sql-style-guide/)
6 | [IBM](https://www.ibm.com/docs/en/opw/8.2.0?topic=guide-sql-coding-guidelines)
7 | [Mozilla](https://docs.telemetry.mozilla.org/concepts/sql_style.html)
8 | [Simon Holywell](https://www.sqlstyle.guide/)
9 |
10 | ## DDL (Data Definition Language)
11 | - CREATE
12 | - ALTER
13 | - DROP
14 | - RENAME
15 | - TRUNCATE
16 | - COMMENT
17 |
18 | ## DML (Data manipulation Language)
19 | - SELECT
20 | - INSERT
21 | - UPDATE
22 | - DELETE
23 | - MERGE
24 | - CALL
25 | - EXPLAIN PLAN
26 | - LOCK TABLE
27 |
28 | ## DCL (Data Control Language)
29 | - GRANT
30 | - REVOKE
31 |
32 | ## TCL (Transaction Control Language)
33 | - COMMIT
34 | - ROLLBACK
35 | - SAVE POINT
36 | - SET
37 | - TRANSACTION
38 |
39 | ## Basic querying
40 |
41 | ```SQL
42 | SELECT *
43 | FROM table_a
44 | WHERE 1=1
45 | AND condition
46 | ```
47 |
48 | ## Joins
49 |
50 | ## SQL injections
51 |
--------------------------------------------------------------------------------
/docker/.dockerignore:
--------------------------------------------------------------------------------
1 | # Include any files or directories that you don't want to be copied to your
2 | # container here (e.g., local build artifacts, temporary files, etc.).
3 | #
4 | # For more help, visit the .dockerignore file reference guide at
5 | # https://docs.docker.com/engine/reference/builder/#dockerignore-file
6 |
7 | **/.DS_Store
8 | **/__pycache__
9 | **/.venv
10 | **/.classpath
11 | **/.dockerignore
12 | **/.env
13 | **/.git
14 | **/.gitignore
15 | **/.project
16 | **/.settings
17 | **/.toolstarget
18 | **/.vs
19 | **/.vscode
20 | **/*.*proj.user
21 | **/*.dbmdl
22 | **/*.jfm
23 | **/bin
24 | **/charts
25 | **/docker-compose*
26 | **/compose*
27 | **/Dockerfile*
28 | **/node_modules
29 | **/npm-debug.log
30 | **/obj
31 | **/secrets.dev.yaml
32 | **/values.dev.yaml
33 | LICENSE
34 | README.md
35 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1
2 |
3 | # Comments are provided throughout this file to help you get started.
4 | # If you need more help, visit the Dockerfile reference guide at
5 | # https://docs.docker.com/engine/reference/builder/
6 |
7 | ################################################################################
8 | # Pick a base image to serve as the foundation for the other build stages in
9 | # this file.
10 | #
11 | # For illustrative purposes, the following FROM command
12 | # is using the alpine image (see https://hub.docker.com/_/alpine).
13 | # By specifying the "latest" tag, it will also use whatever happens to be the
14 | # most recent version of that image when you build your Dockerfile.
15 | # If reproducability is important, consider using a versioned tag
16 | # (e.g., alpine:3.17.2) or SHA (e.g., alpine:sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff).
17 | FROM alpine:latest as base
18 |
19 | ################################################################################
20 | # Create a stage for building/compiling the application.
21 | #
22 | # The following commands will leverage the "base" stage above to generate
23 | # a "hello world" script and make it executable, but for a real application, you
24 | # would issue a RUN command for your application's build process to generate the
25 | # executable. For language-specific examples, take a look at the Dockerfiles in
26 | # the Awesome Compose repository: https://github.com/docker/awesome-compose
27 | FROM base as build
28 | COPY <
8 | `ARG [variable-name]=[default-value]`
9 |
10 | Modify ARG Value with docker build:
11 | If you did not provide a value for the ARG variable or want to modify the default value while building the image, use the --build-arg option.
12 |
13 | `docker build -t [image-name] --build-arg [arg-variable]=[value] .`
14 |
15 | Similarly,
16 | `ENV [variable-name]=[default-value]`
17 | (While the ARG variable is unavailable after the image-building process, ENV persists in the containers.)
18 |
19 | ## Images
20 | Build image:
21 | `docker build --tag python-django .`
22 |
23 | `--tag`: set a name for the image
24 |
25 | list images:
26 | `docker images`
27 |
28 | remove image:
29 | `docker rmi `
30 |
31 | ## Containers
32 | start container:
33 | `docker run --rm -ti --publish 8000:8000 python-django`
34 |
35 | `d`: background
36 | `t`: terminal (log messages)
37 | `i`: interactive
38 | `--rm`: remove previous containers with same name if they exist
39 |
40 | list running containers:
41 | `docker ps`
42 |
43 | stop container:
44 | `docker stop `
45 |
46 | list or remove stopped containers:
47 | ```BASH
48 | docker ps --filter status=exited -q
49 | docker rm $(docker ps -q)
50 | docker rm $(docker ps --filter status=exited -q)
51 | ```
52 |
53 | # TODO: add example with volume mount, in docker run command
54 |
--------------------------------------------------------------------------------
/docker/docker_cheatsheet.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheNewThinkTank/code-vault/add586e11a2d54c4204ed36d31ec3670675a81be/docker/docker_cheatsheet.pdf
--------------------------------------------------------------------------------
/dsa.md:
--------------------------------------------------------------------------------
1 | # Data Structures & Algorithms
2 |
3 | sorting
4 |
5 | searching
6 |
7 | graph algorithms
8 |
9 | dynamic programming
10 |
--------------------------------------------------------------------------------
/git.md:
--------------------------------------------------------------------------------
1 | # Git
2 |
3 | [Book](https://git-scm.com/book/en/v2)
4 |
5 | upcoming:
6 | - cherry-picking
7 | - force-with-lease
8 | - squash
9 |
10 | ## Basics
11 |
12 | initialize empty git repo
13 | `git init `
14 |
15 | push repo to remote:
16 | ```BASH
17 | git remote add origin
18 | git push origin master
19 | ```
20 |
21 | clone repo locally
22 | `git clone `
23 |
24 | configuration
25 | ```BASH
26 | git config --global user.email "user@gmail.com"
27 | git config --global user.name "user"
28 | ```
29 |
30 | repository status
31 | `git status`
32 |
33 | specific filechanges
34 | `git diff `
35 |
36 | get quick overview of last repo change
37 | `git log --oneline`
38 |
39 | undo changes
40 | `git revert `
41 |
42 | add file to staging area
43 | `git add `
44 |
45 | commit changes to repo
46 | `git commit -m ''`
47 |
48 | push changes to remote server
49 | `git push`
50 |
51 | get latest changes from remote
52 | `git pull`
53 |
54 | ignore files and dirs by adding their relative paths to the following file
55 | `.gitignore`
56 |
57 | ## Branching
58 |
59 | create new branch
60 | `git checkout -B ''`
61 |
62 | delete branch
63 | `git branch -D ''`
64 |
65 | upcoming:
66 | rebase
67 |
68 | ## Inspect recent changes
69 |
70 | e.g. for the `src` dir,
71 | `git whatchanged --since="last Sunday" -p -- src`
72 |
73 | ## Fixing detached HEAD, when on feature branch
74 | ```BASH
75 | git pull --rebase origin main
76 | git log
77 | git push --force
78 | ```
79 |
80 | ## Remove all git history from repo
81 | ```BASH
82 | #!/usr/local/bin/bash
83 |
84 | # prerequisites:
85 | # all tags deleted
86 | # main branch is the only branch that exists
87 |
88 | : '
89 | git checkout --orphan last
90 | git add -A
91 | git commit -am "feat: rewrite git history" --no-verify
92 | git branch -D main
93 | git branch -m main
94 | git push -f origin main -v
95 | cd .git
96 | git reflog expire --expire=now --all && git gc --prune=now --aggressive
97 | # check size:
98 | du -hs .
99 | du -hs .git
100 | '
101 | ```
102 |
--------------------------------------------------------------------------------
/k8s/k8s.md:
--------------------------------------------------------------------------------
1 | # Kubernetes
2 |
3 | ## Concepts
4 |
5 | - cluster
6 | - nodes (servers): control servers/master (hosts the k8s API) and worker nodes (running the application workloads)
7 | - pods: has 1 IP address, a bit of storage, and can contain 1 or more containers
8 | - (Docker) containers
9 |
10 | ## Tools
11 |
12 | etcd (pods) (data store for kubernetes controller/master server(s)):
13 | provides distributed synchronized data storage for the cluster state
14 |
15 | kube-apiserver
16 |
17 | kube-scheduler
18 |
19 | - KubeAdm
20 |
21 | - kubelet: runs as a service. Controls the pods
22 | e.g.
23 | `sudo systemctl status kubelet`
24 |
25 | - kubectl
26 |
27 | - kube-proxy (part of handling the virtual network of the cluster)
28 |
29 | `kubectl get pods -n kube-system`
30 | `kubectl get nodes`
31 | `kubectl get deployments`
32 | `kubectl describe deployment nginx-deployment`
33 |
34 | Get pod info (containers running inside etc.)
35 | `kubectl describe pod nginx`
36 | `kubectl delete pod nginx`
37 |
38 | - helmchart
39 | - Kustomize
40 | - Argo CD
41 | https://argo-cd.readthedocs.io/en/stable/
42 |
43 |
44 | services
45 |
46 | IaC: Pulumi or Terraform
47 |
48 | ## Networking
49 |
50 | Virtual network that spans the entire cluster (all nodes).
51 | Logically separate fromn the physical network that connects one node to another.
52 |
53 |
--------------------------------------------------------------------------------
/k8s/minikube_notes.md:
--------------------------------------------------------------------------------
1 | # MiniKube
2 |
3 | ## prerequisites
4 | Docker installed
5 |
6 | kubectl installed
7 |
8 | download minikube (macOS):
9 | https://github.com/kubernetes/minikube/releases/download/v1.32.0/minikube-darwin-arm64
10 |
11 | move it to: `/usr/local/bin/minikube`
12 |
13 | as the minikube binary is unnotarized,
14 | open it in finder, right-click, and manually open it first time.
15 |
16 | then `chmod +x minikube`
17 |
18 | ## useful commands
19 |
20 | start the Docker Daemon
21 | `open -a Docker`
22 |
23 | check it is running
24 | `docker ps`
25 |
26 | optionally, check the status of the Docker Daemon
27 | `docker info`
28 |
29 | start the minikube cluster
30 | `minikube start`
31 |
32 | inspect nodes and pods
33 | `kubectl get nodes`
34 | `kubectl get pods`
35 |
36 | get all pods:
37 | `kubectl get po -A`
38 |
39 | `minikube dashboard`
40 |
--------------------------------------------------------------------------------
/kerberos.md:
--------------------------------------------------------------------------------
1 | # Kerberos
2 |
3 | ## Terminology
4 |
5 | realms: systems Kerberos can authenticate users onto
6 | principal: unique identity of user or service (within realm)
7 | client: process that accesses service on behalf of user
8 |
9 | there can be multiple clients and users within realms
10 |
11 | service: resource provided to a client (e.g. file server, application)
12 |
13 | KDC: Key Distribution Center. Supplies tickets and generates temporary session keys, allowing a user to securely authenticate to a service. Stores secret symmetric keys for users and services. Has two servers:
14 |
15 | - authentication server: confirms that a known user is making an access request, and issues ticket granting tickets.
16 | - ticket granting server: confirms that a user is making an access request to a known service, and issues service tickets.
17 |
18 | during the authentication, multiple messages are sent.
19 | Two important types of messages:
20 |
21 | - Authenticators (allows mutual authentication between user and service)
22 | - Tickets (contains info such as client id, service id. All encrypted using server's secret key)
23 |
24 | ## Useful commands
25 |
26 | destroys Kerberos tickets
27 | `/usr/bin/kdestroy`
28 |
29 | obtains and caches Kerberos ticket-granting ticket
30 | `/usr/bin/kinit`
31 |
32 | displays current Kerberos tickets
33 | `/usr/bin/klist`
34 |
35 | changes a Kerberos password
36 | `/usr/bin/kpasswd`
37 |
38 | manages Kerberos keytab files
39 | `/usr/bin/ktutil`
40 |
--------------------------------------------------------------------------------
/markdown.md:
--------------------------------------------------------------------------------
1 | # Markdown
2 |
3 | ## Links
4 |
5 | [Link text Here](https://link-url-here.org)
6 |
7 | ## Collapsible MarkDown
8 | Source: https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab
9 |
10 |
11 | Click to expand!
12 |
13 | ## Heading
14 | 1. A numbered
15 | 2. list
16 | * With some
17 | * Sub bullets
18 |
19 |
20 | # A collapsible section containing code
21 |
22 | Click to expand!
23 |
24 | ```javascript
25 | function whatIsLove() {
26 | console.log('Baby Don't hurt me. Don't hurt me');
27 | return 'No more';
28 | }
29 | ```
30 |
31 |
--------------------------------------------------------------------------------
/networking.md:
--------------------------------------------------------------------------------
1 | # Networking
2 |
3 | OSI
4 |
5 | most common HTTP methods:
6 | - Get (read)
7 | - Post (create)
8 | - Put (update)
9 | - Delete (delete)
10 | these corresponds to each operation in CRUD
11 |
--------------------------------------------------------------------------------
/redis.md:
--------------------------------------------------------------------------------
1 | # REDIS
2 |
3 | `REDIS`: REmote DIctionary Server
4 |
5 | used by Twitter, Pinterest, craigslist etc.
6 |
7 | in-memory, multi-model database from 2009 (created by Salvatore Sanfilippo)
8 |
9 | READ / WRITE quickly by using main computer memory
10 |
11 | but stores data on disk, so can be reconstructed as needed,
12 | making the database durable, supporting snapshots and backups.
13 |
14 | support for graphs, JSON documents, full-text search, and more.
15 |
16 | sub-millisecond latency
17 |
18 | Interact using `SET` and `GET` commands
19 |
--------------------------------------------------------------------------------
/regex.md:
--------------------------------------------------------------------------------
1 | # Regular Expressions
2 |
3 | ## Resourses
4 | [rexegg](https://www.rexegg.com/)
5 | [regex101](https://regex101.com/)
6 |
7 | ## Quantifiers
8 | `*`: 0 or more
9 | `+`: 1 or more
10 | `?`: 0 or 1
11 | `{3}`: exact number
12 | `{3,4}`: range of numbers (minimum, maximum)
13 |
14 | ## Special characters
15 | `.`: any character except new line
16 | `\d`: digit (0-9)
17 | `\D`: not a digit (0-9)
18 | `\w`: word character (a-z, A-Z, 0-9, _)
19 | `\W`: not a word character
20 | `\s`: whitespace (space, tab, newline)
21 | `\S`: not whitespace (space, tab, newline)
22 | `\b`: word boundary
23 | `\B`: not a word boundary
24 |
25 | ## Anchors
26 | `^`: beginning of string
27 | `$`: end of string
28 |
29 | ## Character sets
30 | `[]`: matches characters in brackets
31 | `[^ ]`: matches characters NOT in brackets
32 | `|`: either or
33 |
34 | ## Capture groups
35 | `( )`: group
36 |
37 | ## Back referencing
38 |
39 | ## Positive / Negative Look-ahead / Look-behind
40 |
41 | ## Examples
42 | email:
43 | `[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+`
44 |
--------------------------------------------------------------------------------
/shell/bash.md:
--------------------------------------------------------------------------------
1 | # BASH
2 |
3 | ## BASH dir compression
4 |
5 | create an archive file called foo.tar.gz in current directory
6 | `tar -zcvf foo.tar.gz /home/jerry/tom`
7 |
8 | to restore/extract all files from archive in current directory
9 | `tar -zxvf foo.tar.gz`
10 |
11 | ## Basic commands
12 |
13 | clear screen: `Ctrl + l`
14 | change to home dir: `cd ~`
15 | change to previous dir: `cd -`
16 | change directory and swap back again:
17 | `pushd /some_dir`, then `popd`
18 | minimize program to the background (e.g. if working on file that's not ready to be saved): `Ctrl + z`
19 | then send it back to the foreground again:`fg`
20 | monitor system resources: `htop`
21 |
22 | ```BASH
23 | echo, cat, touch,
24 | whoami, pwd, ls -la
25 | mkdir, rmdir, rm, rm -rf
26 | sudo, su, sudo -i
27 | sudo apt update && sudo apt upgrade -y
28 | ```
29 |
30 | ```BASH
31 | echo $TERM
32 | visudo
33 | ```
34 |
35 | sudos
36 |
37 | logout user: Ctrl + d
38 |
39 | ```BASH
40 | man
41 | whatis
42 | which
43 | whereis
44 |
45 | wget
46 | curl
47 |
48 | zip
49 | unzip
50 |
51 | head
52 | tail
53 | less
54 |
55 | cmp
56 | diff
57 |
58 | tree -> tree.txt
59 |
60 | sort
61 |
62 | Pipe |
63 |
64 | find
65 | grep
66 | sed
67 | awk
68 |
69 | chmod
70 | chown
71 | ```
72 |
73 | ## Networking
74 | ```BASH
75 | ifconfig
76 | ip address | grep eth0
77 | ping -c 5 -s 500 url
78 | traceroute url
79 |
80 | netstat -tulpn
81 | ss -tulpn
82 |
83 | sudo ufw allow 80
84 | sudo ufw status
85 |
86 | uname -a
87 |
88 | sudo apt install neofetch
89 | ````
90 |
91 | ```BASH
92 | cal
93 |
94 | echo “4+5” | bc
95 |
96 | free
97 |
98 | df -H
99 |
100 | ps -aux
101 | top
102 | kill
103 | pkill -p name
104 | systemctl start
105 |
106 | history
107 | reboot
108 | shutdown -h now
109 | ```
110 |
111 | ## VS Code
112 |
113 | new terminal: `Ctrl + æ` (Win) | ```Shift + Ctrl + ` ``` (Mac)
114 |
--------------------------------------------------------------------------------
/shell/bash_scripting.md:
--------------------------------------------------------------------------------
1 | # Bash Scripting
2 |
3 | command interpreter / shell
4 |
5 | return to previous dir
6 | `cd -`
7 |
8 | move to `some-dir` and return at any moment
9 | ```BASH
10 | pushd
11 | popd
12 | ```
13 |
14 | move to background, and bring up again
15 | ```BASH
16 | Ctrl + Z
17 | fg
18 | ```
19 |
20 | reverse search through history
21 | `Ctrl + R`
22 |
23 | add timestamp to history. Ignore commands if started by whitespace
24 | ```BASH
25 | vim ~/.bashrc
26 | HISTTIMEFORMAT="%Y-%m-%d %T "
27 | HISTCONTROL=ignoreboth
28 | ```
29 |
30 | run 2 commands in a row
31 | `ls -l; echo "i am the second command"`
32 |
33 | only run second command if first succeeds
34 | `ls -l && echo "i am the second command"`
35 |
36 | follow log-file in real-time
37 | `tail -f `
38 |
39 | delete content of file
40 | `truncate -s 0 `
41 |
42 | ensure output is columnized
43 | `mount | column -t`
44 |
45 | find out which shell is used from a given terminal window
:
46 | `echo $SHELL`
47 |
48 | find the location of bash
:
49 | `which bash`
50 |
51 | create file
52 | `vim some_file.sh`
53 |
54 | add shebang to top of file
55 | `#!/usr/env/bin bash`
56 |
57 | make the file executable
58 | `sudo chmod +x some_file.sh`
59 |
60 | variables
61 |
62 | if statements
63 |
64 | while loops
65 |
66 | math functions
67 |
68 | exit codes
69 |
70 | for loops
71 |
72 | functions
73 |
74 | case statements
75 |
76 | scheduling jobs
77 |
78 | arguments
79 |
--------------------------------------------------------------------------------
/shell/cmd.md:
--------------------------------------------------------------------------------
1 | # CMD
2 |
3 | ## See command line history in cmd
4 | `F7`
5 |
6 | ## or, to see the command history in the command prompt itself:
7 | `doskey /history`
8 |
9 | ## and send to clipboard:
10 | `doskey /history | clip`
11 |
12 | ## Delete empty folder
13 | `rmdir folder_name`
14 |
15 | ## Delete non-empty folder
16 | `rmdir /S folder_name`
17 |
18 | ## Get IP address form server-name:
19 | `nslookup server-name`
20 |
--------------------------------------------------------------------------------
/shell/nano.md:
--------------------------------------------------------------------------------
1 | # Nano
2 |
3 | create file
4 | `nano some_file.txt`
5 |
6 | save file
7 | `Ctrl + O`
8 |
9 | exit file
10 | `Ctrl + X`
11 |
12 | cut line
13 | `Ctrl + K`
14 |
15 | undo / paste line
16 | `Ctrl + U`
17 |
18 | search for word
19 | `Ctrl + W`
20 | or line number
21 | `Ctrl + T`
22 |
23 | Spell-check specific line (needs the spell package)
24 | `Ctrl + T`
25 |
26 | open file at specific line
27 | `nano + some_file.txt`
28 |
29 | open file in view-only mode
30 | `nano -v some_file.txt`
31 |
--------------------------------------------------------------------------------
/shell/powershell.md:
--------------------------------------------------------------------------------
1 | # Powershell
2 |
3 | ## Networking
4 | `ipconfig /all | clip`
5 |
--------------------------------------------------------------------------------
/shortcuts.md:
--------------------------------------------------------------------------------
1 | # Shortcuts
2 |
3 |
4 | OS Shortcuts
5 |
6 | | action | macOS | Windows |
7 | | :----- | :---: | ------: |
8 | | run | | `Win + R` |
9 | | new explorer window | `Shift + Cmd + N` | `Win + E` |
10 | | toggle dock | `Cmd + Option + D` | |
11 |
12 |
13 |
14 |
15 | Terminal Shortcuts
16 |
17 | | action | macOS | Windows |
18 | | :----- | :---: | ------: |
19 | | clear terminal screen | `Ctrl + L` | `Ctrl + L` |
20 | | zoom in/out | `Cmd +/-` | `Ctrl +/-` |
21 | | delete line | `Ctrl + U` | `Ctrl + U` |
22 | | front of line | `Ctrl + A` | `Ctrl + A` |
23 | | end of line | `Ctrl + E` | `Ctrl + E` |
24 |
25 |
26 |
27 |
28 |
29 | VSCode Shortcuts
30 |
31 | | action | macOS | Windows |
32 | | :-------- | :------: | ----: |
33 | | zoom in / out | `Cmd + +/-` | `Ctrl + +/-` |
34 | | new integrated terminal | `Shift + Ctrl + ` ` | `Ctrl + Æ` |
35 | | multi-line cursor | `Shift + Cmd + L` or `Option + Cmd + UpArrow/DownArrow` | |
36 | | toggle file explorer | `Cmd + B` | `Ctrl + B` |
37 | | comment in/out line | `Shift + Cmd + 7` | `Ctrl + '` |
38 | | find next occurence | | `Ctrl + D` |
39 |
40 | playground
41 |
42 |
43 |
44 |
45 | Jupyter notebook
46 |
47 | | action | macOS | Windows |
48 | | :-------- | :------: | ----: |
49 | | new cell | | |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/software-development/concepts.md:
--------------------------------------------------------------------------------
1 | # Concepts
2 |
3 | monads (e.g. writer)
4 |
5 | memoization
6 |
7 | currying
8 |
9 | closures
10 |
11 | DRY
12 |
13 | SOLID:
14 | - Single responsibility
15 | - Open (for extention) / Closed (for modification)
16 | - Liskov substitution
17 | - Interface segregation
18 | - Dependency inversion
19 |
20 | LoD (Law of Demeter):
21 | principle of least knowledge
22 |
23 | Big-O
24 |
25 | OOP:
26 | inheritance, polymorphism, encapsulation, abstraction
27 |
28 |
29 | (semantic commits)[https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716]
30 |
31 | (conventional commits)[https://www.conventionalcommits.org/en/v1.0.0/]
32 |
33 |
34 | git bash integrations (aliases etc.)
35 |
36 |
--------------------------------------------------------------------------------
/software-development/data-structures.md:
--------------------------------------------------------------------------------
1 | # Data Structures
2 |
3 | Hash map
4 |
5 | linked list
6 |
7 | Queue
8 |
9 | Deque
10 |
11 | Graph
12 |
13 | Tree
14 |
--------------------------------------------------------------------------------
/software-development/design-patterns.md:
--------------------------------------------------------------------------------
1 | # Design Patterns
2 |
3 | ## Resources
4 |
5 | - (Refactoring.Guru)[https://refactoring.guru/design-patterns]
6 |
7 |
8 | GoF introduced 23 design patterns in 1994, falling into three categories:
9 | ## creational
10 | - Abstract Factory
11 | - Builder
12 | - Factory Method
13 | - Prototype
14 | - Singleton
15 |
16 | ## structural
17 |
18 |
19 | ## behavioral
20 | - Observer
21 | - Iterator
22 |
--------------------------------------------------------------------------------