Update site

master
Spagnolo Gasper 2022-12-24 22:54:34 +01:00
parent 10c58980b3
commit 2938dc813c
57 changed files with 926 additions and 145 deletions

View File

@ -1,16 +1,16 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Clipboard"
description="click to read about Clipboard"
+++
# Clipboard
- `cat file.txt | xclip -selection clipboard -i` store file into clipboard
### On xorg
- `cat file.txt | xclip -selection clipboard -i` - store file into clipboard
### On wayland
- `cat file.txt | wl-copy` store file into clipboard
- `cat file.txt | wl-copy` - store file into clipboard

View File

@ -1,6 +1,6 @@
+++
date="2022-12-21"
date="2022-12-24"
author="spanskiduh"
title="Compression"
description="click to read about Compression"
@ -8,6 +8,7 @@ description="click to read about Compression"
# Compression
### Tar archives
- `tar -cf file.tar dir/` -archive using tar, extract `tar -xvf file.tar`
@ -26,3 +27,6 @@ description="click to read about Compression"
### 7zip archives
- `7z x <file.7z>` - unzip
## If you are super lazy
- `binwalk -e -M <file.zip>` - tries different extraction methods and recursively uznips

View File

@ -1,17 +1,16 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Curl"
description="click to read about Curl"
+++
# Curl
### Download any file
## Download any file
- `curl -o <file.extension> <url>` -download with new filename
- `curl -O <url>` - download with original filename
- `curl -X POST/GET/DELETE <url>` - different requests methods
useful flags:
- `-L` - use redirection

View File

@ -1,12 +1,10 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Dig"
description="click to read about Dig"
+++
# Dig
### Get all DNS records of a domain name

View File

@ -1,16 +1,15 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Find"
description="click to read about Find"
+++
# Find
### Examples of find command
- `sudo find / -type d -iname "gasper"` - search direcotry
- `sudo find /etc -type f -name "*.conf"` - display all configuration files, for more percison you should `|` into `grep`.
You can also add `szie` flag to narrow down results to expected filesize. Other useful flags: `user`, `group`.
You can also add `size` flag to narrow down results to expected filesize. Other useful flags: `user`, `group`.

View File

@ -1,12 +1,10 @@
+++
date="2022-12-21"
date="2022-12-24"
author="spanskiduh"
title="GIT"
description="click to read about GIT"
+++
# GIT
- If you want to revert changes made to your working copy, do this:

View File

@ -1,13 +1,12 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Locate"
description="click to read about Locate"
+++
# Locate
### Examples of locate command
use whatis/man locate for more info

View File

@ -1,6 +1,6 @@
+++
date="2022-12-01"
date="2022-12-24"
author="spanskiduh"
title="MPI"
description="click to read about MPI"

View File

@ -1,30 +1,11 @@
+++
date="2022-12-21"
date="2022-12-24"
author="spanskiduh"
title="Networking"
description="click to read about Networking"
+++
# Networking
### IP command
- `ip route show` -- display all routes `man ip | grep route` -- neat way to find more information about this command
- `ip a` -- display all interfaces
### Netstat command // by default use ss
- `netstat -r` -- show routes
- `netstat -t` -- display all current tcp connections, useful with grep command
- `netstat -ltnp / -lu` list local TCP or UPD connections
#### [netstat](https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/) is deprecated:
| Old command (Deprecated) | New command |
|:--:|:-:|
--:|:-:|
| ifconfig -a | ip a |
| ifconfig enp6s0 down | ip link set enp6s0 down |
| ifconfig enp6s0 up | ip link set enp6s0 up |

View File

@ -1,21 +1,16 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="SSH"
description="click to read about SSH"
+++
# SSH
### basic
- `/etc/ssh/ssh_config` - config location (client)
- `/etc/ssh/sshd_config` - config location (server)
It is *always* smart to disable root login!
--> uncomment `PermitRootLogin no`
### Enable encryption
- `ssh-keygen -t rsa` - generate private and public key
@ -26,11 +21,31 @@ It is *always* smart to disable root login!
### FAIL2BAN
- use it to secure ssh
- install a basic ubuntu vm and watch from 4:20 in video he he u get it, but it is actually there
### SCP
- `scp <filename> <user@server_ip:/destination_folder>` - copy file to server
- `scp <filename> <user@server_ip:/destination_folder>` - copy file to server, same goes for rsync
### SSH CONFIG FILE
example for github:
```bash
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519
```
exmaple for any server:
```bash
Host vpn.de
HostName vpn.de
IdentityFile ~/.ssh/keys/vpn_de
Port 22
User root
```
*note*: You should put your server's ip in `/etc/hosts/` for easier migrations.
### How to joke around with medic

View File

@ -1,12 +1,10 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="Tracks"
description="click to read about Tracks"
+++
# Tracks
- `/var/log` - Location of kernel and software logs

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="VFS"
description="click to read about VFS"

View File

@ -0,0 +1,23 @@
+++
date="2022-12-24"
author="spanskiduh"
title="address_space"
description="click to read about address_space"
+++
# Address space
## AS in C
```
[code ]
[init data ]
[uninit data]
[heap ]
[ | ]
[ . ]
[ free ]
[ . ]
[ | ]
[stack ]
[args + env ]
```

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="ansible"
description="click to read about ansible"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="bash"
description="click to read about bash"
@ -12,3 +12,112 @@ Gotta love those oneliners ;)
```bash
while read line; do printf "$line\n"; printf "other commands\n"; done < /etc/passwd
```
# SHELL SHORTCUTS
### Moving the cursor
```bash
Ctrl + a Go to the beginning of the line (Home)
Ctrl + e Go to the End of the line (End)
Ctrl + p Previous command (Up arrow)
Ctrl + n Next command (Down arrow)
Alt + b Back (left) one word
Alt + f Forward (right) one word
Ctrl + f Forward one character
Ctrl + b Backward one character
Ctrl + xx Toggle between the start of line and current cursor position
```
### Editing
```bash
Ctrl + L Clear the Screen, similar to the clear command
Alt + Del Delete the Word before the cursor.
Alt + d Delete the Word after the cursor.
Ctrl + d Delete character under the cursor
Ctrl + h Delete character before the cursor (Backspace)
Ctrl + w Cut the Word before the cursor to the clipboard.
Ctrl + k Cut the Line after the cursor to the clipboard.
Ctrl + u Cut/delete the Line before the cursor to the clipboard.
Alt + t Swap current word with previous
Ctrl + t Swap the last two characters before the cursor (typo).
Esc + t Swap the last two words before the cursor.
ctrl + y Paste the last thing to be cut (yank)
Alt + u UPPER capitalize every character from the cursor to the end of the current word.
Alt + l Lower the case of every character from the cursor to the end of the current word.
Alt + c Capitalize the character under the cursor and move to the end of the word.
Alt + r Cancel the changes and put back the line as it was in the history (revert).
ctrl + _ Undo
TAB Tab completion for file/directory names
```
### Special keys
Text Terminals send characters (bytes), not key strokes.
Special keys such as Tab, Backspace, Enter and Esc are encoded as control characters.
Control characters are not printable, they display in the terminal as ^ and are intended to have an effect on applications.
```bash
Ctrl+I = Tab
Ctrl+J = Newline
Ctrl+M = Enter
Ctrl+[ = Escape
Many terminals will also send control characters for keys in the digit row:
Ctrl+2 → ^@
Ctrl+3 → ^[ Escape
Ctrl+4 → ^\
Ctrl+5 → ^]
Ctrl+6 → ^^
Ctrl+7 → ^_ Undo
Ctrl+8 → ^? Backward-delete-char
Ctrl+v tells the terminal to not interpret the following character, so Ctrl+v Ctrl-I will display a tab character,
similarly Ctrl+v ENTER will display the escape sequence for the Enter key: ^M
```
### History
```bash
Ctrl + r Recall the last command including the specified character(s).
searches the command history as you type.
Equivalent to : vim ~/.bash_history.
Ctrl + p Previous command in history (i.e. walk back through the command history).
Ctrl + n Next command in history (i.e. walk forward through the command history).
Ctrl + s Go back to the next most recent command.
(beware to not execute it from a terminal because this will also launch its XOFF).
Ctrl + o Execute the command found via Ctrl+r or Ctrl+s
Ctrl + g Escape from history searching mode
!! Repeat last command
!n Repeat from the last command: args n e.g. !:2 for the second argumant.
!n:m Repeat from the last command: args from n to m. e.g. !:2-3 for the second and third.
!n:$ Repeat from the last command: args n to the last argument.
!n:p Print last command starting with n
!string Print the last command beginning with string.
!:q Quote the last command with proper Bash escaping applied.
Tip: enter a line of Bash starting with a # comment, then run !:q on the next line to escape it.
!$ Last argument of previous command.
ALT + . Last argument of previous command.
!* All arguments of previous command.
^abc­^­def Run previous command, replacing abc with def
```
### Process control
```bash
Ctrl + C Interrupt/Kill whatever you are running (SIGINT).
Ctrl + l Clear the screen.
Ctrl + s Stop output to the screen (for long running verbose commands).
Then use PgUp/PgDn for navigation.
Ctrl + q Allow output to the screen (if previously stopped using command above).
Ctrl + D Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT).
Ctrl + Z Send the signal SIGTSTP to the current task, which suspends it.
To return to it later enter fg 'process name' (foreground).
```

View File

@ -1,13 +1,16 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="binary-patching"
description="click to read about binary-patching"
+++
# Binary patching
firstly check in ghidra what hex value has function call. then open binary in vim, find that and replace all fucntion hex values with 90
### In vim :)
firstly check in ghidra what hex value has function call.
Then open binary in vim, find that and replace all fucntion hex values with 90
`:%!xxd` and `:%!xxd -r`

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="binary_vs_text_files"
description="click to read about binary_vs_text_files"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="burpsuite"
description="click to read about burpsuite"

View File

@ -1,10 +1,17 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="certs"
description="click to read about certs"
+++
# CERTS
https://stackoverflow.com/questions/66604487/how-do-i-generate-fullchain-pem-and-privkey-pem
## Generate self-signed certificate
[creds](https://stackoverflow.com/questions/66604487/how-do-i-generate-fullchain-pem-and-privkey-pem)
```bash
openssl genrsa > privkey.pem
openssl req -new -x509 -key privkey.pem > fullchain.pem
```

View File

@ -1,12 +1,10 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="disk-usage"
description="click to read about disk-usage"
+++
# Disk usage
### Very useful tool

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="disk-utils"
description="click to read about disk-utils"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="docker"
description="click to read about docker"
@ -21,3 +21,198 @@ docker container ls --filter "status=exited" | awk '{ print $1 }' | xargs docker
printf "Deleting all images\n"
docker image ls | awk '{print $3}' | xargs docker image rm --force
```
## Basic config example
```yml
# docker-compose.yml
version: '3'
services:
web:
build: .
# build from Dockerfile
context: ./Path
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redis
```
## Common commands
```bash
# Starts existing containers for a service.
docker-compose start
# Stops running containers without removing them.
docker-compose stop
# Pauses running containers of a service.
docker-compose pause
# Unpauses paused containers of a service.
docker-compose unpause
# Lists containers.
docker-compose ps
# Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose up
# Stops containers and removes containers, networks, volumes, and images created by up.
docker-compose down
```
## Config file reference
### Building
```yml
web:
# build from Dockerfile
build: .
# build from custom Dockerfile
build:
context: ./dir
dockerfile: Dockerfile.dev
# build from image
image: ubuntu
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry:4000/postgresql
image: a4bc65fd
```
### Ports
```yml
ports:
- "3000"
- "8000:80" # guest:host
# expose ports to linked services (not to host)
expose: ["3000"]
```
### Commands
```yml
# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]
# override the entrypoint
entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit]
```
### Environment variables
```yml
# environment vars
environment:
RACK_ENV: development
environment:
- RACK_ENV=development
# environment vars from file
env_file: .env
env_file: [.env, .development.env]
```
### Dependencies
```yml
# makes the `db` service available as the hostname `database`
# (implies depends_on)
links:
- db:database
- redis
# make sure `db` is alive before starting
depends_on:
- db
```
### Other options
```yml
# make this service extend another
extends:
file: common.yml # optional
service: webapp
volumes:
- /var/lib/mysql
- ./_data:/var/lib/mysql
```
## Advanced features
### Labels
```yml
services:
web:
labels:
com.example.description: "Accounting web app"
```
### DNS servers
```yml
services:
web:
dns: 8.8.8.8
dns:
- 8.8.8.8
- 8.8.4.4
```
### Devices
```yml
services:
web:
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
```
### External links
```yml
services:
web:
external_links:
- redis_1
- project_db_1:mysql
```
### Hosts
```yml
services:
web:
extra_hosts:
- "somehost:192.168.1.100"
```
### Network
```yml
# creates a custom network called `frontend`
networks:
frontend:
```
### External network
```yml
# join a preexisting network
networks:
default:
external:
name: frontend
```

View File

@ -1,6 +1,6 @@
+++
date="2022-12-21"
date="2022-12-24"
author="spanskiduh"
title="emacs"
description="click to read about emacs"
@ -8,12 +8,12 @@ description="click to read about emacs"
# Emacs
## Basics
`alt x` - show available commands
`space .` - show file search
`ctrl/space + w + v` - virtual split
`ctrl/space + w + w`- switch to next vsplit
`ctrl/space + w + c` - close virutal split
`space + b + k` - kill buffer
`space + b + b` - display opened buffers
`space + h + r + r` - `doom.d/init.el` reload plugins
`space + f + r` seaarch through reacently opened files
- `alt x` - show available commands
- `space .` - show file search
- `ctrl/space + w + v` - virtual split
- `ctrl/space + w + w`- switch to next vsplit
- `ctrl/space + w + c` - close virutal split
- `space + b + k` - kill buffer
- `space + b + b` - display opened buffers
- `space + h + r + r` - `doom.d/init.el` reload plugins
- `space + f + r` seaarch through reacently opened files

View File

@ -1,11 +1,13 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="exec"
description="click to read about exec"
+++
# EXEC
It is a family of functions that do the same thing but actually no.
When we call `exec()`, we never reutrn back to the callling program. The program
called by the `exec()` function replaces itself with the calling progam. The only way

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="ffmpeg"
description="click to read about ffmpeg"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="forensics"
description="click to read about forensics"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="fork"
description="click to read about fork"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="gcc"
description="click to read about gcc"
@ -12,3 +12,5 @@ description="click to read about gcc"
- `-Wall` ~ enable all warnings
- `-o binary` ~ output to binary file
- `-S` ~ also compile asm file
- `-ffast-math` ~ faster math operations but more inaccurate
- `-march=native` ~ Compile efficently for that CPU

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="gdb"
description="click to read about gdb"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="hydra"
description="click to read about hydra"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="lxc"
description="click to read about lxc"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="mosquitto"
description="click to read about mosquitto"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="mount"
description="click to read about mount"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="named_pipes"
description="click to read about named_pipes"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="nmap"
description="click to read about nmap"

View File

@ -1,17 +1,20 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="pdf"
description="click to read about pdf"
+++
# PDF MANIPULATION
## Cool tool
### PDFTK
Take individual pages out of pdf
```bash
thinkpad :: ~/Downloads » pdftk Document_2022-08-14_152049.pdf cat 1 output subvencija/karmen_spagnolo.pdf
thinkpad :: ~/Downloads » pdftk Document_2022-08-14_152049.pdf cat 2 output subvencija/brigita_spagnolo.pdf
thinkpad :: ~/Downloads » pdftk Document_2022-08-14_152049.pdf cat 3 output subvencija/darjo_spagnolo.pdf
```
### Pandoc
- `pandoc -o doc.pdf doc.md` - convert md to pdf

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="permissions"
description="click to read about permissions"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="pipewire"
description="click to read about pipewire"

View File

@ -1,12 +1,13 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="powerusage"
description="click to read about powerusage"
+++
# Check deatiled power usage on linux (common distros have it preinstalled)
# Check deatiled power usage on linux
## Upower (common distros have it preinstalled)
```bash
upower --monitor-detail
```

View File

@ -1,11 +1,11 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="proces_sorting_algorithms"
description="click to read about proces_sorting_algorithms"
+++
# Sorting algorithms
# Sorting algorithms (SL)
### FCFS
Basically a fifo

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="proxmox"
description="click to read about proxmox"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="pwn"
description="click to read about pwn"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="python_specifics"
description="click to read about python_specifics"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="qemu"
description="click to read about qemu"
@ -28,3 +28,9 @@ description="click to read about qemu"
-drive if=pflash,format=raw,file=QEMU_EFI.img \
-drive if=pflash,file=varstore.img \
-drive if=virtio,file=arm.img\`
### VIRT MANAGER
https://www.xmodulo.com/convert-ova-to-qcow2-linux.html

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="regex"
description="click to read about regex"
@ -8,4 +8,6 @@ description="click to read about regex"
# REGEX
### Reversing regex
[source](https://github.com/asciimoo/exrex)
`exrex "flag\{wa{0}e[^abcdrfghijknmopqrstuvwxyz]c(((o)))(?=[a-z])[^a-ln-z]e_to_dc{0}ctf{1}\}" -o out.txt` - you can list all possible words accepted by regex with this tool

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="rstudio"
description="click to read about rstudio"

View File

@ -1,15 +1,463 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="rust"
description="click to read about rust"
+++
# RUST
### Basic cli tools
## Basic cli tools
- `cargo init` ~ create new rust project
- `cargo run` ~ build & run
- `cargo build` ~ just build
- `cargo build --release` ~ minimal release version (optimized)
## Rust basics
### Arrays
```rust
// Arrays are allocated on stack just like in C
pub fn run() {
let mut numbers: [i32; 5] = [1, 2, 3, 4, 5];
numbers[2] = 20; // [1, 2, 20, 4, 5]
println!("Single value: {}", numbers[0]); // 1
println!("Array length: {}",numbers.len()); // 5
// Arrays are stack allocated
println!("Array occupies {} bytes", std::mem::size_of_val(&numbers)); // 20 bytes
// Get slice
let sliced: &[i32] = &numbers[0..2];
println!("Sliced: {:?}", sliced); // [1, 2]
}
```
### CLI arguments
```rust
use std::env;
pub fn run() {
let args: Vec<String> = env::args().collect();
let command = args[1].clone();
let name = "spanskiduh";
println!("Command: {}", command);
if command == "hello" {
println!("Hi {}, how are you?", name);
}
}
```
### Conditionals
```rust
// Conditionals - Used to check the condition of something and act on the result
pub fn run() {
let age: u8 = 18;
let check_id: bool = false;
let knows_person_of_age = true;
// If / Else
if age >= 21 && check_id || knows_person_of_age {
println!("bartender: What would you like to drink?"); // This gets printed
} else if age < 21 && check_id{
println!("bartender: Sorry, you have to leave.");
} else {
println!("bartender: I'll need to see your ID");
}
// Shorthand If (similar to terminary operator)
let is_of_age = if age >= 21 {true} else {false};
}
```
### Enums
```rust
enum Movement {
Up,
Down,
Left,
Right
}
fn move_avatar(m: Movement) {
match m {
Movement::Up => println!("Avatar moving up"),
Movement::Down => println!("Avatar moving down"),
Movement::Left => println!("Avatar moving left"),
Movement::Right => println!("Avatar moving right"),
}
}
pub fn run() {
let avatar1 = Movement::Left;
let avatar2 = Movement::Up;
let avatar3 = Movement::Right;
let avatar4 = Movement::Down;
move_avatar(avatar1);
move_avatar(avatar2);
move_avatar(avatar3);
move_avatar(avatar4);
}
```
### Functions
```rust
pub fn run() {
greeting("Hello", "Jane");
// Bind function values to variables
let get_sum = add(5, 5);
println!("Sum: {}", get_sum);
// Closure
let n3: i32 = 10;
let add_nums = |n1: i32, n2: i32 | n1 + n2 + n3;
println!("C Sum: {}", add_nums(3,3)); // 16
}
fn greeting(greet: &str, name: &str) {
println!("{} {}, nice to meet you!", greet, name);
}
fn add(n1: i32, n2: i32) -> i32 {
n1 + n2
}
```
### Loops
```rust
// Loops - Used to iterate until a condition is met
pub fn run(){
let mut count = 0;
// Infinite Loop
loop {
count += 1;
println!("Number: {}", count);
if count == 20 {
break;
}
}
// While loop (FizzBuzz)
while count <= 100 {
if count % 15 == 0 {
println!("FizzBuzz");
} else if count % 3 == 0 {
println!("Fiz");
} else if count % 5 == 0 {
println!("Buzz");
} else {
println!("{}", count);
}
count += 1;
}
// For range
for x in 0..100 {
if x % 15 == 0 {
println!("FizzBuzz");
} else if x % 3 == 0 {
println!("Fiz");
} else if x % 5 == 0 {
println!("Buzz");
} else {
println!("{}", x);
}
}
}
```
### Pointer references
```rust
// With non-privitieves, if you assign another variable to a piece of data, the
// first varaible will no longer hold that value. You'll need to use a reference
// (&) to point to the resource.
pub fn run() {
// Primitive array
let arr1 = [1, 2, 3];
let arr2 = arr1;
// Vector
let vec1 = vec![1, 2, 3];
let vec2 = &vec1;
println!("{:?}", (arr1, arr2)); // ([1, 2, 3], [1, 2, 3])
println!("{:?}", (&vec1, vec2)); // ([1, 2, 3], [1, 2, 3])
}
```
### Format strings
```rust
pub fn run() {
// Print to console
println!("Hello from print.rs file");
println!("{} se uci {}", "Gasper", "rust");
// Positional args
println!("{0} is from {1} and {0} likes to {2}", "Gasper", "SLovEniA", "program");
// Named args
println!("{name} likes to play {activity}", name = "John", activity = "Tennis");
// Placeholder traits
println!("Binary: {:b} Hex: {:x} Octal: {:o}", 10, 10, 10); // Binary: 1010 Hex: a Octal: 12
// Placeholder for debug trait
println!("{:?}", (12, true, "hello")); // (12, true, "hello")
// Basic math
println!("10 + 10 = {}", 10 + 10);
}
```
### String manipulation
```rust
// Primitve str = Immutable fixed-length string somewhere in memory
// String = Growable, heal-allocated data structure - Use when you need to modify
// or own strign data
pub fn run() {
let hello = "Hello"; // Primitve
let mut growale_hello = String::from("Hello "); // Growable
// Get string length, works for both types
println!("Length: {}", hello.len());
// Append, only Growable
growale_hello.push('W');
growale_hello.push_str("orld!");
// Capacity in bytes (work on both)
println!("Capacity: {}", growale_hello.capacity());
println!("Is Empty: {}", hello.is_empty());
println!("Is Empty: {}", growale_hello.is_empty());
// Substring??
println!("{} -> Contains 'World' {}", hello, hello.contains("World"));
println!("{} -> Contains 'World' {}", growale_hello, growale_hello.contains("World"));
// Replace
println!("Replace: {}", growale_hello.replace("World", "Bro"));
println!("Replace: {}", hello.replace("Hello", "Bye"));
// Loop through string by whitespace
for word in growale_hello.split_whitespace() {
println!("{}", word);
}
// Create string with predefined capacity
let mut s = String::with_capacity(10);
s.push('a');
s.push('b');
println!("{}", s); // ab
// Assertion testing
assert_eq!(2, s.len());
assert_eq!(10, s.capacity());
}
### Structs
```rust
// Traditional struct
struct Color {
red: u8,
green: u8,
blue: u8,
}
// Tuple struct
struct Color2(u8, u8, u8);
struct Person {
first_name: String,
last_name: String
}
impl Person {
// Construct person
fn new(first: &str, last: &str) -> Person {
Person {
first_name: first.to_string(),
last_name: last.to_string()
}
}
// Get full name
fn full_name(&self) -> String {
format!("{} {}", self.first_name, self.last_name)
}
// Set last name
fn set_last_name(&mut self, last:&str) {
self.last_name = last.to_string();
}
// Name to tuple
fn to_tuple(self) -> (String, String) {
(self.first_name, self.last_name)
}
}
pub fn run() {
let mut c = Color {
red: 255,
green: 0,
blue: 0
};
c.red = 200;
println!("color: {} {} {}", c.red, c.green, c.blue);
let mut c2 = Color2(255, 0, 0);
c2.0 = 200;
println!("color: {} {} {}", c2.0, c2.1, c2.2);
let mut p = Person::new("Marry", "Doe");
println!("Person {} {}", p.first_name, p.last_name);
p.set_last_name("Doee");
println!("Person {}", p.full_name());
println!("Person tuple {:?}", p.to_tuple());
}
```
### Tuples
```rust
// Max 12 elements, diffrent types allowed
pub fn run() {
let person: (&str, &str, i8) = ("Gasper", "NG", 22);
println!("{} is from {} and is {}", person.0, person.1, person.2);
}
```
### Types
```rust
pub fn run() {
// default is "i32"
let x = 1;
// default is "f64"
let y = 2.5;
// Add explicit type
let z: i64 = 33213123;
// Find max size
println!("Max i32: {}", std::i32::MAX);
println!("Max i64: {}", std::i64::MAX);
// Boolean
let is_active: bool = true;
// Get boolean from expression
let is_greater:bool = 10 > 5;
let a1 = 'a';
let face = '\u{1F600}';
println!("{:?}", (x, y, z, is_active, is_greater, a1, face)); // (1, 2.5, 33213123, true, true, 'a', '😀')
}
```
### Variables
```rust
// Variables hold primitive data or references to data
// Variables are immutable by default (u cannot reasign them)
// Rust is a block-scoped language
pub fn run() {
let name = "Gasper";
let mut age = 22;
let mut i_mutate: i128 = 42069;
println!("My name is {} and I am {}", name, age);
// Chage vaue
age = 23;
// Define constant
const ID: i32 = 001;
// Assign multiple vars
let (my_name, my_age) = ("Gasper", 200);
let mut i = 0;
while i < 10 {
i_mutate = i_mutate + 420;
println!("Value: {}", i_mutate);
i = i + 1;
}
}
```
### Vectors
```rust
// Vectors are resizable arrays stored on a heap
use std::mem;
pub fn run() {
let mut numbers: Vec<i32> = vec![1, 2, 3, 4, 5];
// Assign a value
numbers[2] = 20;
// Add on to a vector
numbers.push(5);
numbers.push(6);
// Pop off last value
numbers.pop(); // [1, 2, 20, 4, 5, 5]
println!("Single value: {}", numbers[0]); // 1
println!("Vector length: {}",numbers.len()); // 6
// Vectors are heap allocated
println!("Vector occupies {} bytes", mem::size_of_val(&numbers)); // 24
// Get slice
let sliced: &[i32] = &numbers[0..2];
println!("Sliced: {:?}", sliced); // Sliced: [1, 2]
// Loop through vector values
for x in numbers.iter() {
println!("Number: {}", x);
}
// Loop and mutate values
for x in numbers.iter_mut() {
*x *= 2;
} // [2, 4, 40, 8, 10, 10]
}
```

View File

@ -1,12 +1,10 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="services-and-process-management"
description="click to read about services-and-process-management"
+++
# Services and process management
### PS command

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="squid"
description="click to read about squid"

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="symlinks"
description="click to read about symlinks"

View File

@ -1,12 +1,10 @@
+++
date="2022-12-21"
date="2022-12-24"
author="spanskiduh"
title="tmux"
description="click to read about tmux"
+++
# Tmux
### Window operations

View File

@ -1,12 +1,10 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="uart"
description="click to read about uart"
+++
# Connect to uart
- `sudo dmesg | grep tty` - find uart device
- `sudo minicom -D /dev/ttyACM0 -b 115200` - connect to uart device

View File

@ -1,13 +1,11 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="ufw"
description="click to read about ufw"
+++
# ufw
# UFW
### Connections
- `sudo ufw status numbered verbose` - check ufw status

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="vim_tutor"
description="click to read about vim_tutor"

View File

@ -1,24 +1,23 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="wasm"
description="click to read about wasm"
+++
# Wasm
h39df71edfbdc6cfb
hffef93c8d94444c4
## Usage of wabt
- wat2wasm: translate from WebAssembly text format to the WebAssembly binary format
- wasm2wat: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
- wasm-objdump: print information about a wasm binary. Similiar to objdump.
- wasm-interp: decode and run a WebAssembly binary file using a stack-based interpreter
- wasm-decompile: decompile a wasm binary into readable C-like syntax.
- wat-desugar: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
- wasm2c: convert a WebAssembly binary file to a C source and header
- wasm-strip: remove sections of a WebAssembly binary file
- wasm-validate: validate a file in the WebAssembly binary format
- wast2json: convert a file in the wasm spec test format to a JSON file and associated wasm binary files
- wasm-opcodecnt: count opcode usage for instructions
- spectest-interp: read a Spectest JSON file, and run its tests in the interpreter
- `wat2wasm`: translate from WebAssembly text format to the WebAssembly binary format
- `wasm2wat`: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
- `wasm-objdump`: print information about a wasm binary. Similiar to objdump.
- `wasm-interp`: decode and run a WebAssembly binary file using a stack-based interpreter
- `wasm-decompile`: decompile a wasm binary into readable C-like syntax.
- `wat-desugar`: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
- `wasm2c`: convert a WebAssembly binary file to a C source and header
- `wasm-strip`: remove sections of a WebAssembly binary file
- `wasm-validate`: validate a file in the WebAssembly binary format
- `wast2json`: convert a file in the wasm spec test format to a JSON file and associated wasm binary files
- `wasm-opcodecnt`: count opcode usage for instructions
- `spectest-interp`: read a Spectest JSON file, and run its tests in the interpreter

View File

@ -1,11 +1,11 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="wl-mirror"
description="click to read about wl-mirror"
+++
# WL-mirror
# WL-mirror (wayland exclusive for managing displays)
## To list all outputs

View File

@ -1,6 +1,6 @@
+++
date="2022-11-30"
date="2022-12-24"
author="spanskiduh"
title="yaml"
description="click to read about yaml"