first commit

This commit is contained in:
ZennDev1337 2023-12-20 16:30:40 +01:00
commit d47f1dc602
9 changed files with 1247 additions and 0 deletions

122
Code/Bash/Bash-Basics.md Normal file
View file

@ -0,0 +1,122 @@
# Bash scripting basics
Kommt immer zu begin eines neuen Scripts
```
#!/bin/bash
```
Berechtigung um ausgeführt zu werden
```
chmod +x FILENAME
```
## Description Numeric Comparison String Comparison
```
Shell comparison example: [ 100 -eq 50 ]; echo $? [ "GNU" = "UNIX" ]; echo $?
less than -lt <
greater than -gt >
equal -eq =
not equal -ne !=
less or equal -le N/A
greater or equal -ge N/A
boolean
true=0
false=1
```
```
Operator Description
! EXPRESSION The EXPRESSION is false.
-n STRING The length of STRING is greater than zero.
-z STRING The lengh of STRING is zero (ie it is empty).
[ -a FILE ] True if FILE exists.
[ -b FILE ] True if FILE exists and is a block-special file.
[ -c FILE ] True if FILE exists and is a character-special file.
[ -d FILE ] True if FILE exists and is a directory.
[ -e FILE ] True if FILE exists.
[ -f FILE ] True if FILE exists and is a regular file.
[ -g FILE ] True if FILE exists and its SGID bit is set.
[ -h FILE ] True if FILE exists and is a symbolic link.
[ -k FILE ] True if FILE exists and its sticky bit is set.
[ -p FILE ] True if FILE exists and is a named pipe (FIFO).
[ -r FILE ] True if FILE exists and is readable.
[ -s FILE ] True if FILE exists and has a size greater than zero.
[ -t FD ] True if file descriptor FD is open and refers to a terminal.
[ -u FILE ] True if FILE exists and its SUID (set user ID) bit is set.
[ -w FILE ] True if FILE exists and is writable.
[ -x FILE ] True if FILE exists and is executable.
[ -O FILE ] True if FILE exists and is owned by the effective user ID.
[ -G FILE ] True if FILE exists and is owned by the effective group ID.
[ -L FILE ] True if FILE exists and is a symbolic link.
[ -N FILE ] True if FILE exists and has been modified since it was last read.
[ -S FILE ] True if FILE exists and is a socket.
STRING1 = STRING2 STRING1 is equal to STRING2
STRING1 != STRING2 STRING1 is not equal to STRING2
INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
```
## Example if then else in bash
```
#!/bin/bash
num_a=400
num_b=200
if [ $num_a -lt $num_b ]; then
echo "$num_a is less than $num_b!"
else
echo "$num_a is greater than $num_b!"
fi
```
## IF ELSE && CASE
```
if Perform a set of commands if a test is true.
else If the test is not true then perform a different set of commands.
elif If the previous test returned false then try this one.
&& Perform the and operation.
|| Perform the or operation.
case Choose a set of commands to execute depending on a string matching a particular pattern.
fi End of if
```
## Variabeln
```
name='Someone' -Nur Text kann man in einem String speichern.
username=$(whoami) -funktionen werden mit $() angegeben
day=$(date +%A) -parameter können ohne Probleme in die Klammer schreiben.
```
## Command Exec
der befehl kommt ohne syntax einfach auf eine leere zeile z.b.
```
fortune
cowsay hallo
```
ich kann die beiden commands aber auch zusammensetzen
```
fortune | cowsay
```
## stderr stdout
The difference between stdout and stderr output is an essential concept as it allows us to a threat, that is, to redirect each output separately. The > notation is used to redirect stdout to a file whereas 2> notation is used to redirect stderr and &> is used to redirect both stdout and stderr. The cat command is used to display a content of any given file

13
Code/CPP/CPP-Basics.md Normal file
View file

@ -0,0 +1,13 @@
# Structure of a Program
Every C++ program must have a function named **main** (all lower case letters). When the program is run, the statements inside of _main_ are executed in sequential order.
```
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
```

View file

@ -0,0 +1,35 @@
# Visual Studio Dependencies
## Install dependencies
For developing C++ in Visual Studio 2022 on Windows 11 you have to install the _Desktop development with C++._ If you don't do this, the C++ capabilities will not be available.
![](/vsessentials.png)
## C++ Console Application
To create a C++ Console Application you have to create a new Project. In Visual Studio you select _Windows Desktop Wizard._ After naming the project the IDE opens the _Windows Desktop Project_ window. Make sure the Application type is on _Console Application (.exe)_ and that the _Precompiled Header_ option is unselected.
## Compiler Extensions
> **Best Practice**
>
> Disable compiler extensions to ensure your programs (and coding practice) remain compliant with C++ standards and will work on any System.
To do this you have to right click on your project name in the _Solution Explorer_ window, then choose _Properties_. First make sure the configuration is set to _All Configurations_. Then, click _C/C++ > Language tab,_ and set _Conformance mode _ to _Yes(/permissive-)._
## Warning and Error levels
> **Best Practice**
>
> Don't let warnings pile up. resolve them as you encounter them (as if they were errors). Otherwise a warning about a serious issue may be lost amongst warnings about non-serious issues.
You IDE can support you by handling the warnings. In the Solution Properties you can turn up your warning levels. To increase them, go to the _Properties_ of your solution and then you have to set for _All Configurations_ in _C/C++ > General _ then _Warning levels_ to _Level4 (/W4)_ and for more support the _Treat Warnings As Errors_ to _Yes (/WX)._
## Language standard
To select a language standard, open your solution properties, then open _C/C++ > Language._ Make sure the Configuration is set to _All Configurations._ From there, you can set the _C++ Language Standard_ to the version of C++ you wish to use.
> **Warning**
>
> With Visual Studio, you will need to reselect your language standard every time you create a new project.

89
Code/CSharp/Basics.md Normal file
View file

@ -0,0 +1,89 @@
# C# basics
## Dokumentation
```
/// <summary>
/// Was Macht diese Klasse / Methode / constante
///
/// Unten kommt immer der Name des Developers welcher diese class programmiert hat
/// </summary>
/// <param name="NameDesParameters"></param>
/// <returns>Was wird mit return zurückgegeben</returns>
```
if (Expression) Genau so auch bei While und for etc. { }
## Namespaceaufbau
```
1 2
namespace NameDesNamespaces
{
1: Das ist immer gleich. einfach namespace
2: das ist der name des namespace dieser wird eigentlich durch die ordnerstrucktur erstellt
}
```
## Classaufbau
```
1 2 3 4
public/privat partial/nichts class NameDerKlasse
{
1: Ist die class nur für diesen Namespace gedacht oder auch für auserhalb
2: Wenn partial geschrieben wird kann innerhalb des selben Namespace mehr zu der classe geaddet werden
wird eigentlich nur in grossen projeckten verwendet.
3: das keyword class ist immer gleich.
4: Der Klassen name dieser wird gross geschrieben wenn es eine public class sein soll.
}
```
## variablen einer class
```
1 2 3 4
public/privat string/int VariablenName { get; set; }
1: Ist die variable nur für diesen Namespace gedacht oder auch für auserhalb
2: Type der variable.
3: Name der variable wenn gross dann public sonst klein für privat.
```
## Constructor einer class
```
public class Person
{
private string last;
private string first;
1 2 3
public Person(string lastName, string firstName)
{
last = lastName;
first = firstName;
}
1: public/privat um es öffentlich zu machen
2: Name der class ist immer gleich wie vom costructor
3: alle parameter welche von anfang an initalisiert werden sollen.
}
```
## Funktionsaufbau
```
1 2 3 4 5
public/privat static/nichts void/string/int Name(string/int Args)
{
1: Ist die funktion nur für diesen Namespace gedacht oder auch für auserhalb
2: muss diese funktion mit new initialisiert werden oder nicht
3: was wird aus der funktion returnt
4: Der Name der funktion klein bei privaten gross bei public
5: Die Args weilche Mitgegeben werden. immer mit dem type im vorfeld.
}
```

255
Code/CSharp/Interface.md Normal file
View file

@ -0,0 +1,255 @@
# C# basics
## Dokumentation
```
/// <summary>
/// Was Macht diese Klasse / Methode / constante
///
/// Unten kommt immer der Name des Developers welcher diese class programmiert hat
/// </summary>
/// <param name="NameDesParameters"></param>
/// <returns>Was wird mit return zurückgegeben</returns>
```
if (Expression) Genau so auch bei While und for etc. { }
## Namespaceaufbau
```
1 2
namespace NameDesNamespaces
{
1: Das ist immer gleich. einfach namespace
2: das ist der name des namespace dieser wird eigentlich durch die ordnerstrucktur erstellt
}
```
## Classaufbau
```
1 2 3 4
public/privat partial/nichts class NameDerKlasse
{
1: Ist die class nur für diesen Namespace gedacht oder auch für auserhalb
2: Wenn partial geschrieben wird kann innerhalb des selben Namespace mehr zu der classe geaddet werden
wird eigentlich nur in grossen projeckten verwendet.
3: das keyword class ist immer gleich.
4: Der Klassen name dieser wird gross geschrieben wenn es eine public class sein soll.
}
```
## variablen einer class
```
1 2 3 4
public/privat string/int VariablenName { get; set; }
1: Ist die variable nur für diesen Namespace gedacht oder auch für auserhalb
2: Type der variable.
3: Name der variable wenn gross dann public sonst klein für privat.
```
## Constructor einer class
```
public class Person
{
private string last;
private string first;
1 2 3
public Person(string lastName, string firstName)
{
last = lastName;Interface
=========
Ein Interface kann man sich vorstellen, wie ein Bauplan. Dieser wird meistens einer Mutterklasse vererbt.\
Es gibt diverse Gründe warum man ein Interface benutzt.
- Man kann ein Interface als Parameter Type einbauen.
- Man hat eine Verpflichtung alle Eigenschaften einzubauen in eine Klasse.
Schauen wir uns doch einmal an wie ein Interface aussehen kann.\
In diesem Beispiel gehen wir von einem Zoo mit Tieren aus und die Tiere haben dann Tochter Klassen welche die Gattung darstellen.
Interface erstellen
-------------------
Ein Interface wird mit dem Keyword interface erstellt und hat immer ein grosses I vor dem Namen. 
```
namespace Zoo.Interfaces
{
interface IAnimal
{
}
}
```
Das Interface wurde innerhalb des Interfaces Unterverzeichnis erstellt.
Wir bauen jetzt quasi einen Bauplan für die Animal Klasse.
Properties einbauen
-------------------
Im nächsten Schritt fügen wir die angeforderten Properties hinzu.
Beachte, dadurch das nicht jedes Prop ein set hat, kann dies später nicht geändert werden.
```
namespace Zoo.Interfaces
{
interface IAnimal
{
string name { get; set; }
string foodType { get; }
string habitat { get; }
}
}
```
Wie du sehen kannst ist es nicht notwendig, das Keyword virtual zu verwenden. Es handelt sich ja auch nicht um eine Klasse sondern um ein Interface.
Methoden einbauen
-----------------
Fügen wir doch jetzt noch einige Methoden ein.
```
namespace Zoo.Interfaces
{
interface IAnimal
{
string name { get; set; }
string foodType { get; }
string habitat { get; }
void MakeNoise();
void Eat();
void Move();
Image GetImage();
string GetARandomName();
}
}
```
Wie du sehen kannst, haben die Methoden keine Funktionalität eingebaut. Wir geben lediglich an welchen Rückgabe Wert und welche Parameter verwendet werden müssen.
Klasse mit Interface
--------------------
Jetzt können wir eine neue Klasse hinzufügen welche das Interface beinhaltet. Es wird gleich eingebunden wie eine Vererbung. Animal : IAnimal
Ignoriere erstmal das Keyword abstract. [Du findest hier mehr dazu.](/Code/CSharp/Keyword/abstract)
```
namespace Zoo.Animals
{
public abstract class Animal : IAnimal
{
}
}
```
Der Code wird so nicht kompilierbar sein. Das Interface zwingt dich dazu die Properties und Methoden einzubauen.
Fangen wir mit den Properties an.
```
namespace Zoo.Animals
{
public abstract class Animal : IAnimal
{
public virtual string name { get; set; } = "animal";
public virtual string foodType { get; } = "Animalfood";
public virtual string habitat { get; } = "Cage";
}
}
```
Zu beachten ist, dass die Props genau so eingebunden werden, wie im Bauplan beschrieben. Achte dabei auf die get und set Keywords.
Jetzt fügen wir alle Methoden ein.
```
namespace Zoo.Animals
{
public abstract class Animal : IAnimal
{
public virtual string name { get; set; } = "animal";
public virtual string foodType { get; } = "Animalfood";
public virtual string habitat { get; } = "Cage";
public virtual void MakeNoise()
{
Debug.Write($"{this.name} makes a Noise:");
}
public void Eat()
{
Debug.WriteLine($"The {this.GetType().Name} Named {this.name} Eats: {this.foodType}.");
}
public virtual void Move()
{
Debug.WriteLine($"The {this.GetType().Name} Moves around.");
}
public virtual Image GetImage()
{
return AnimalsRes.Lion;
}
public string GetARandomName()
{
// Code für einen random Namen.
return "randomName"
}
}
}
```
Jetzt sollte der Code Kompilierbar sein.
first = firstName;
}
1: public/privat um es öffentlich zu machen
2: Name der class ist immer gleich wie vom costructor
3: alle parameter welche von anfang an initalisiert werden sollen.
}
```
## Funktionsaufbau
```
1 2 3 4 5
public/privat static/nichts void/string/int Name(string/int Args)
{
1: Ist die funktion nur für diesen Namespace gedacht oder auch für auserhalb
2: muss diese funktion mit new initialisiert werden oder nicht
3: was wird aus der funktion returnt
4: Der Name der funktion klein bei privaten gross bei public
5: Die Args weilche Mitgegeben werden. immer mit dem type im vorfeld.
}
```

View file

@ -0,0 +1,89 @@
# Heredity
Die Vererbung ist wohl das mächtigste Tool für C#.\
Es bedeutet, dass man von Mutter klassen zu Tochter klassen alle Eigenschaften weitergeben kann.
In meinem Beispiel, werde ich dass aufzeigen anhand eines Zoo's mit Tieren und den Kategorien welche es da gibt.
## Mutter Klasse
Wir haben ein Tier, dieses kann ein Geräusch machen mit der Methode `MakeNoise()`.\
Wenn ich nun ein Säugetier erstellen will, macht dieses ja ein anderes Geräusch als ein Vogel.
Wichtig ist: Bei einer Mutter klasse schreiben wir immer da das Keyword `virtual` hin, wo wir die Möglichkeit haben wollen, in der Tochter klasse dies zu bearbeiten oder ganz zu verändern.
```
namespace Zoo.Animals
{
public abstract class Animal
{
public virtual string name { get; set; } = "animal";
public virtual string foodType { get; } = "Animalfood";
public virtual string habitat { get; } = "Cage";
public virtual void MakeNoise()
{
Debug.Write($"{this.name} makes a Noise: ");
}
}
}
```
Wir lassen jetzt das Säugetier von Animal erben.\
Dies geht, indem wir nach dem Klassennamen die zu erbende Klasse nach einem : einfügen. Hier mit: `Mammal : Animal`
```
namespace Zoo.Animals
{
public abstract class Mammal : Animal
{
}
}
```
Nun können wir einige der Properties und Methoden verändern bzw. überschreiben.\
Wir ändern `foodType` & `habitat` so wie die Methode `MakeNoise()`.\
Mit dem Keyword `override`.
```
namespace Zoo.Animals
{
public abstract class Mammal : Animal
{
public override string foodType => "Mammalfood";
public override string habitat => "Cage";
public override void MakeNoise()
{
Debug.WriteLine($"{this.name} makes a Noise: Mammal Noise");
}
}
}
```
Wenn wir uns den Code der Methode `MakeNoise()` von Animal anschauen sehen wir, dass wir ein `Debug.Write` verwenden dies könnten wir weiterverwenden, mit `this.base()`
```
namespace Zoo.Animals
{
public abstract class Mammal : Animal
{
public override string foodType => "Mammalfood";
public override string habitat => "Cage";
public override void MakeNoise()
{
this.MakeNoise();
Debug.WriteLine("Mammal Noise");
}
}
}
```
Mit diesem Code wird erst die Methode `MakeNoise()` von Animal aufgerufen. Was dazu führt, dass in die Konsole `{this.name} makes a Noise: ` geschriben wird.\
Im nächsten Schritt wird mit `Debug.WriteLine("Mamal Noise")` Mamal Noise auf der gleichen Zeile ausgegeben und eine neue Zeile begonnen.
Die Ausgabe wird `{this.name} makes a Noise: Mamal Noise` sein.
Es sind 2 Wege zum gleichen Ziel.

88
Code/Powershell/Basics.md Normal file
View file

@ -0,0 +1,88 @@
Basics (WIP)
============\
PowerShell ist eine Objekt-Orientierte Shell. Sie wurde entwickelt um die antike CommandPrompt abzulösen.\
Man kann alle CMD-Commands in PowerShell ausführen, um jedoch PowerShell-Commands in CMD auszuführen muss man:\
 `powershell Get-ChildItem`\
PowerShell mit dem Command dem man ausführen möchte rufen.
**PowerShell ist Case-Insensitive** das heisst das auch Commands wie: `gEt-hElP GeT-lOcAlUsEr` problemlos ausgeführt werden können.\
Commands in PowerShell sind immer <Verb>-<Nomen>.
Hotkeys
-------\
`CTRL` + `L`  sendet der Shell den Clear-Command
`↑↓`                Erlaubt das durchsuchen der Command-History
`TAB`             AutoComplete des aktuellen Commands oder `SHIFT` + `TAB` um durch mögliche AutoComplete's durchzusuchen.
`CTRL` + `ALT` + `SHIFT` + `?`             Gibt eine Liste von allen Hotkeys im Terminal aus.
### Help\
Mit `Get-Help <command>`  bekommt man Hilfe zu einem spezifischen Command.\
Diese Liste kann mit `Update-Help` aktualisiert werden.
## Getting Around
### Get-Location\
Um herauszufinden wo wir uns gerade befinden benutzen wir den Command: `Get-Location`
![](/bild_2023-06-08_135841212.png)
### Get-ChildItem
Um Inhalte aus Ordner anzeigen zu lassen brauchen wir: `Get-ChildItem`\
Wir können uns Inhalte ausgeben die nicht im unserem aktuellen Ordner ist ausgeben: `Get-ChildItem <path-to-folder>`\
Dieser Command hat folgende Aliase: `gci`, `ls`
![](/powershell/bild_2023-06-08_140932224.png)
### Set-Location
Um uns schliesslich in ein anderes Verzeichnis zu bewegen verwenden wir: `Set-Location <path-to-folder>`\
Dieser Command hat folgende Aliase: `cd`
![](/powershell/bild_2023-06-08_141508119.png)
### Clear-Host
Um das Terminal-Fenster aufzuräumen oder wieder leer zu machen benutzen wir: `Clear-Host`\
Dieser Command hat folgende Aliase: `clear`, `cls`
## User- & Group-Management
### Get-LocalUser
Mit dem Command: `Get-LocalUser` werden uns alle Lokale-Benutzer angezeigt
![](/powershell/bild_2023-06-08_143131714.png)
### New-LocalUser
Um einen neuen Benutzer zu erstellen können wir: `New-LocalUser -Name "JLawrence" -NoPassword` brauchen.
![](/powershell/bild_2023-06-08_144944192.png)\
Danach können  wir eine Variable setzten: `$Password = Read-Host -AsSecureString`
Mit dem `$` sagen wir PowerShell das wir eine Variable erstellen.\
Der Command `Read-Host` sorgt dafür das PowerShell ein string entgegen nimmt.\
Schliesslich mit `-AsSecureString` können wir dafür sorgen das unsere Eingabe mit '\*' überdruckt wird.
![](/powershell/bild_2023-06-08_144112380.png)
### Set-LocalUser
Um Benutzer zu bearbeiten verwenden wir: `Set-LocalUser`\
Um also dem erstellten Benutzer ein Password hinzuzufügen werden wir den Command `Set-LocalUser -Name JLawrence -Password $Password` verwenden.
![](/powershell/bild_2023-06-08_150253157.png)
### Get-LocalGroup
`Get-LocalGroup` gibt uns alle lokale Benutzer im Terminal aus:
![](/powershell/bild_2023-06-08_150902546.png)
Next Adduser to local group