Image

Debian Linux Tutorial

Collection of snippets to help you getting started with Debian Linux

```md

# Disable root user

create admin user

```sh

/sbin/useradd -m -s /usr/bin/bash admin

/sbin/usermod -aG sudo admin

passwd admin

```

disable root login

```sh /etc/passwd

root:x:0:0:root:/root:/sbin/nologin

```

# Setup apt

remove cdrom line from /etc/apt/sources.list

```sh

apt update

apt upgrade

```

# apt

## Setup all debian apt repos

### preferences

to downgrade to a specific release use 1001 as the Pin-Priority.

```/etc/apt/preferences.d/testing.pref

Package: *

Pin: release a=testing

Pin-Priority: 900

```

```/etc/apt/preferences.d/stable.pref

Package: *

Pin: release a=stable

Pin-Priority: -10

```

```/etc/apt/preferences.d/unstable.pref

Package: *

Pin: release a=unstable

Pin-Priority: -20

```

### list

Setup debian stable, change bullseye for current stable version, or use stable for rolling release

```/etc/apt/sources.list.d/stable.list

deb http://deb.debian.org/debian bullseye main contrib non-free

deb-src http://deb.debian.org/debian bullseye main contrib non-free

deb http://deb.debian.org/debian-security/ bullseye-security main contrib non-free

deb-src http://deb.debian.org/debian-security/ bullseye-security main contrib non-free

deb http://deb.debian.org/debian bullseye-updates main contrib non-free

deb-src http://deb.debian.org/debian bullseye-updates main contrib non-free

```

Setup debian testing, change bookworm for current next-stable version, or use testing for rolling release

```/etc/apt/sources.list.d/testing.list

deb http://deb.debian.org/debian/ bookworm main contrib non-free

deb-src http://deb.debian.org/debian/ bookworm main contrib non-free

```

Setup debian unstable

```/etc/apt/sources.list.d/unstable.list

deb http://deb.debian.org/debian/ unstable main contrib non-free

deb-src http://deb.debian.org/debian/ unstable main contrib non-free

```

comment everything out in /etc/apt/sources.list

### Refresh repos

```sh

sudo apt update

sudo apt full-upgrade

/sbin/reboot

```

# Install software

install latest firmware, drivers and kernel

```sh

#apt install intel-microcode # optional intel microcode

#apt install amd64-microcode # optional amd microcode

apt install firmware-linux-nonfree

apt install linux-image-generic

#apt install nvidia-driver # optional nvidia driver

#apt install libnvoptix1 # optional nvidia optix

#apt install nvidia-cuda-dev nvidia-cuda-toolkit # optional nvidia cuda

#apt install firmware-iwlwifi # optional intel wifi

#apt install firmware-realtek # optional realtek wifi

/sbin/reboot

```

install gnome

```sh

apt install task-gnome-desktop

/sbin/reboot

```

install openbox

```

apt install openbox

```

install XFCE

```sh

apt install task-xfce-desktop

/sbin/reboot

#xfconf-query -c xfwm4 -p /general/use_compositing -s false # disable compositor

#xfconf-query -c xfwm4 -p /general/use_compositing -s true # enable compositor

```

install cursor theme, apply in Tweaks > Apperance > Cursor > Breeze_cursors

```sh

apt install breeze-cursor-theme

```

install system utils

```sh

apt install htop curl wget lshw git nmap python3-full neofetch virt-manager build-essential cmake dnsutils

```

install applications

```sh

apt install chromium firefox-esr keepassxc

```

install regular firefox

```sh

apt install -t unstable firefox

```

fix firefox high refreshrate

- about:config:

- layers.acceleration.force = True

# install vs code

```sh

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg

sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/microsoft-archive-keyring.gpg

sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

apt install apt-transport-https

apt update

apt install code

```

## Setup vs code

- Extensions

- hediet.vscode-drawio

- streetsidesoftware.code-spell-checker

- rust-lang.rust-analyzer

- vadimcn.vscode-lldb

- dbaeumer.vscode-eslint

- ms-python.python

- vscodevim.vim

- ms-dotnettools.csharp

# Install Rust

install rust with rustup

```sh

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

```

configure cargo path in fish

```~/.config/fish/config.fish

export PATH="$HOME/.cargo/bin:$PATH"

```

install rust-analyzer

```sh

rustup component add rust-analyzer

```

symlink rust-analyzer

```sh

sudo ln -s $(rustup which rust-analyzer ) /usr/local/bin/rust-analyzer

```

update rust toolchain

```sh

rustup update

```

# cargo clippy

## Default

```sh

cargo clippy --all-targets --all-features

```

## CI

```sh

cargo clippy --all-targets --all-features -- -Dwarnings

```

## Through

```sh

cargo +nightly clippy --all-targets --all-features -- -Wclippy::pedantic -Aclippy::too-many-lines -Aclippy::default_trait_access -Aclippy::must-use-candidate -Aclippy::doc_markdown -Aclippy::manual_assert -Aclippy::redundant-closure-for-method-calls

```

# cargo fmt

## Default

```sh

cargo +nightly fmt --all

```

# Setup git

```sh

git config --global user.email "${YOUR_EMAIL}"

git config --global user.name "${YOUR_NAME}"

git config --global credential.helper 'cache --timeout=86400'

```

# Install fish

```sh

sudo apt install fish

chsh -s $(which fish)

```

relog to change default shell, and open new terminal and run the command, which should print /usr/bin/fish

```sh

echo $SHELL

```

## Install fisher, fish package / plugin manager

```sh

curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher

```

## Install z, fuzzy directory navigation

```sh

fisher install jethrokuan/z

```

## Configure fish

```~/.config/fish/config.fish

if status is-interactive

# Commands to run in interactive sessions can go here

end

set fish_greeting

fish_add_path ~/.local/bin

fish_add_path ~/.cargo/bin

export HELIX_RUNTIME="/home/user/pro/github/helix/runtime"

if type -q exa

alias ll "exa -l -g --icons"

end

starship init fish | source

fnm env --use-on-cd | source

```

## Cheatsheet

Navigate to previous and next directories

```fish

ALT+LeftArrow

ALT+RightArrow

```

or use command

```fish

prevd

nextd

```

Prepend / rerun last command with sudo

```fish

ALT+S

```

Execute inline sh / shell scripts

```fish

sh -c 'ps aux | awk \'{sum+=$6} END {print sum / 1024}\''

```

# Install zsh

install and change default shell to zsh

```sh

sudo apt install zsh

chsh -s $(which zsh)

```

relog to change default shell, and open new terminal and run the command, which should print /usr/bin/zsh

```sh

echo $SHELL

```

install ohmyzsh

```sh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

```

install fish style plugins

```sh

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-history-substring-search $ZSH_CUSTOM/plugins/zsh-history-substring-search

git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

```

add plugins

```~/.zshrc

plugins = (git zsh-autosuggestions zsh-history-substring-search zsh-syntax-highlighting)

```

# install starship

```sh

cargo install starship --locked

```

## configure

```~/.config/starship.toml

format = """

\\[$time\\] - \

$username@\

$hostname:\

$directory\n\

\\$

"""

add_newline = false

[username]

show_always = true

format = '$user'

[hostname]

ssh_only = false

format = "$hostname"

[directory]

format = "$path"

truncation_length = 8

truncate_to_repo = false

truncation_symbol = "…/"

[time]

disabled = false

format = '$time'

time_format = "%H:%M:%S"

```

## enable in fish

```~/.config/fish/config.fish

starship init fish | source

```

## enable in bash

```~/.bashrc

eval "$(starship init bash)"

```

## enable in zsh

```~/.zshrc

eval "$(starship init zsh)"

```

# Install fnm

https://github.com/Schniz/fnm

```sh

cargo install fnm --locked

```

## enable in fish

```~/.config/fish/config.fish

fnm env --use-on-cd | source

```

## enable in bash

```~/.bashrc

eval "$(fnm env --use-on-cd)"

```

## enable in zsh

```~/.zshrc

eval "$(fnm env --use-on-cd)"

```

## install node version 14 and 16

```sh

fnm install 16.14

fnm install 14.20

```

# Next.js disable telemetry

```sh

npx next telemetry disable

```

# Install CascadiaCode

# Install Alacritty

install alacritty

```sh

sudo apt install alacritty

```

alacritty config

```~/.config/alacritty/alacritty.yml

window:

dimensions:

columns: 104

lines: 28

font:

normal:

family: CaskaydiaCove Nerd Font

size: 12.0

cursor:

style:

shape: Beam

blinking: On

colors:

primary:

background: '#1e1e1e'

foreground: '#ffffff'

normal:

black: '#232627'

red: '#ed1515'

green: '#11d116'

yellow: '#f67400'

blue: '#1d99f3'

magenta: '#9b59b6'

cyan: '#1abc9c'

white: '#fcfcfc'

bright:

black: '#7f8c8d'

red: '#c0392b'

green: '#1cdc9a'

yellow: '#fdbc4b'

blue: '#3daee9'

magenta: '#8e44ad'

cyan: '#16a085'

white: '#ffffff'

dim:

black: '#31363b'

red: '#783228'

green: '#17a262'

yellow: '#b65619'

blue: '#1b668f'

magenta: '#614a73'

cyan: '#186c60'

white: '#63686d'

```

Set Alacritty as default terminal emulator

```sh

sudo update-alternatives --config x-terminal-emulator

```

# Install exa, ls alternative

```sh

sudo apt install exa

```

## setup fish alias

```~/.config/fish/config.fish

if type -q exa

alias ll "exa -l -g --icons"

end

```

# Install dotnet, .NET, csharp, C#, mono and OmniSharp

https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian

```sh

wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

sudo dpkg -i packages-microsoft-prod.deb

rm packages-microsoft-prod.deb

sudo apt-get update && \

sudo apt-get install -y dotnet-sdk-7.0

sudo apt install apt-transport-https dirmngr gnupg ca-certificates

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

echo "deb https://download.mono-project.com/repo/debian stable-buster main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

sudo apt update

sudo apt -t stable-buster install mono-devel

```

install vscode exteinsion ms-dotnettools.csharp

# Install Unity

https://gigi.nullneuron.net/gigilabs/using-visual-studio-code-with-unity3d-on-linux/

```sh

sudo sh -c 'echo "deb https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list'

wget -qO - https://hub.unity3d.com/linux/keys/public | sudo apt-key add -

apt update

apt -t stable install unityhub

```

# Install KXStudio Zyn-Fusion zynsubaddfx sfizz

```sh

# Update software sources

sudo apt-get update

# Install required dependencies if needed

sudo apt-get install apt-transport-https gpgv wget

# Download package file

wget https://launchpad.net/~kxstudio-debian/+archive/kxstudio/+files/kxstudio-repos_11.1.0_all.deb

# Install it

sudo dpkg -i kxstudio-repos_11.1.0_all.deb

sudo apt -t bionic install zynaddsubfx fabla calf-plugins

echo 'deb http://download.opensuse.org/repositories/home:/sfztools:/sfizz/Debian_Testing/ /' | sudo tee /etc/apt/sources.list.d/home:sfztools:sfizz.list

curl -fsSL https://download.opensuse.org/repositories/home:sfztools:sfizz/Debian_Testing/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_sfztools_sfizz.gpg > /dev/null

sudo apt update

sudo apt install sfizz

```

# Utility

clear apt cache

```sh

apt clean && apt autoclean

```

clear logs

```sh

sudo truncate -s 0 /var/log/*log

```

```

Image

VS Code Settings

Sensible settings for VS Code

settings:

{

"editor.fontSize": 16,

"editor.tabSize": 2,

"editor.insertSpaces": true,

"editor.detectIndentation": false,

"editor.autoClosingOvertype": "never",

"extensions.ignoreRecommendations": true,

"editor.minimap.enabled": false,

"telemetry.enableTelemetry": false,

"telemetry.enableCrashReporter": false,

"editor.autoClosingBrackets": "never",

"editor.autoClosingQuotes": "never",

"editor.autoSurround": "never",

"javascript.updateImportsOnFileMove.enabled": "never",

"typescript.updateImportsOnFileMove.enabled": "never",

"workbench.enableExperiments": false,

"update.showReleaseNotes": false,

"extensions.autoCheckUpdates": false,

"workbench.settings.enableNaturalLanguageSearch": false,

"editor.fontFamily": "Cascadia Mono, Consolas, 'Courier New', monospace",

"explorer.compactFolders": false,

"debug.console.fontSize": 15,

"markdown.preview.fontSize": 15,

"terminal.integrated.fontSize": 15,

"editor.renderControlCharacters": false,

"editor.folding": false,

"update.enableWindowsBackgroundUpdates": false,

"telemetry.telemetryLevel": "off",

"window.titleBarStyle": "custom",

"diffEditor.ignoreTrimWhitespace": false,

"workbench.layoutControl.enabled": false,

"security.workspace.trust.enabled": false,

"files.defaultLanguage": "${activeEditorLanguage}",

"editor.cursorSmoothCaretAnimation": "on",

"editor.smoothScrolling": true,

"workbench.list.smoothScrolling": true,

"editor.accessibilitySupport": "off",

"git.postCommitCommand": "sync",

"git.autofetch": true,

"git.enableSmartCommit": true,

"git.autofetchPeriod": 30,

"git.inputValidationLength": 150,

"git.inputValidationSubjectLength": null,

"git.timeline.date": "authored",

"terminal.integrated.rightClickBehavior": "default",

"editor.lineNumbers": "relative",

"vim.useSystemClipboard": true,

"editor.cursorSurroundingLines": 999,

"editor.wordWrap": "on",

"rust-analyzer.inlayHints.enable": false,

"rust-analyzer.lens.implementations": false,

"rust-analyzer.lens.run": false,

"rust-analyzer.lens.debug": false

}

keybinds:

// Place your key bindings in this file to override the defaultsauto[]

[

{

"key": "ctrl+`",

"command": "workbench.action.terminal.toggleTerminal"

},

{

"key": "ctrl+alt+t",

"command": "workbench.action.terminal.toggleTerminal"

},

{

"key": "ctrl+shift+j",

"command": "workbench.action.terminal.toggleTerminal"

},

{

"key": "ctrl+shift+a",

"command": "editor.action.blockComment",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "shift+alt+a",

"command": "-editor.action.blockComment",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "ctrl+shift+z",

"command": "workbench.action.toggleZenMode"

},

{

"key": "ctrl+k z",

"command": "-workbench.action.toggleZenMode"

},

{

"key": "f5",

"command": "workbench.action.debug.run"

},

{

"key": "ctrl+f5",

"command": "-workbench.action.debug.run"

},

{

"key": "ctrl+f5",

"command": "workbench.action.debug.start",

"when": "!inDebugMode"

},

{

"key": "f5",

"command": "-workbench.action.debug.start",

"when": "!inDebugMode"

},

{

"key": "alt+b",

"command": "workbench.action.tasks.build"

},

{

"key": "ctrl+shift+b",

"command": "workbench.action.tasks.build"

},

{

"key": "shift+alt+down",

"command": "editor.action.copyLinesDownAction",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "ctrl+shift+alt+down",

"command": "-editor.action.copyLinesDownAction",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "shift+alt+up",

"command": "editor.action.copyLinesUpAction",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "ctrl+shift+alt+up",

"command": "-editor.action.copyLinesUpAction",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "alt+down",

"command": "workbench.action.terminal.focusNext",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "alt+up",

"command": "workbench.action.terminal.focusPrevious",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "shift+ctrl+right",

"command": "workbench.action.terminal.split",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "shift+alt+j",

"command": "workbench.action.toggleMaximizedPanel",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "shift+ctrl+down",

"command": "workbench.action.terminal.new",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "ctrl+shift+`",

"command": "-workbench.action.terminal.new"

},

{

"key": "shift+ctrl+up",

"command": "workbench.action.terminal.new",

"when": "terminalFocus && terminalProcessSupported"

},

{

"key": "alt+h",

"command": "-testing.toggleTestingPeekHistory",

"when": "testing.isPeekVisible"

},

{

"key": "alt+l",

"command": "-toggleSearchEditorContextLines",

"when": "inSearchEditor"

},

{

"key": "alt+l",

"command": "-toggleFindInSelection",

"when": "editorFocus"

},

{

"key": "alt+k",

"command": "-keybindings.editor.recordSearchKeys",

"when": "inKeybindings && inKeybindingsSearch"

},

{

"key": "alt+l",

"command": "workbench.action.terminal.focusNextPane",

"when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"

},

{

"key": "alt+k",

"command": "workbench.action.focusActiveEditorGroup"

},

{

"key": "alt+j",

"command": "workbench.action.terminal.focus"

},

{

"key": "alt+h",

"command": "workbench.action.terminal.focusPreviousPane",

"when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"

},

{

"key": "ctrl+k",

"command": "editor.action.commentLine",

"when": "editorTextFocus && !editorReadonly"

},

{

"key": "ctrl+tab",

"command": "workbench.action.nextEditor"

},

{

"key": "ctrl+shift+tab",

"command": "workbench.action.previousEditor"

},

]

Image

Style Guide

Sensible Style Guide

Use C# xml function headers to document exceptions thrown

/// <exception cref="ArgumentNullException">when things go wrong.</exception>

Prefer to use explicit types for assigning variables e.g.:

List<int> myVar = new();

Only use type inference for assigning variables, when the type is explicitly stated on the right hand side e.g.:

var myVar = new List<int>();

Image

prompt

Think in step by step, write a Memory Mapped Log Structured Hash Table implementation that implements the IDatabase trait in Rust. The implementation should use the crate following crates: ``` serde = "1.0" serde_json = "1.0" memmap2 = "0.9" ``` You may use any number of other crates if you see it fit Implement the data structure in the memmap2 byte array, such that it is propperly mapped to disk, and uses incremental append operations to take full advantage of memory mapped file io. ```rs /// IDatabase trait abstracts the underlying Database implementation /// ``` pub trait IDatabase: Send + Sync { /// Checks if the sensor with id exists in the Database fn contains(&self, id: &str) -> bool; /// Get the record with rec_id from the sensor with id in the /// Database /// /// May load data from disk, if it is not in-memory, /// as such it is mutable, even though a get normaly /// is immutable. fn get(&mut self, id: &str, rec_id: usize) -> Vec<u8>; /// Post a record with value to the sensor with id in the Database fn post(&mut self, id: &str, value: &[u8]); /// Get metadata from the sensor with id in the Database fn get_meta(&mut self, id: &str) -> Vec<u8>; /// Post metadata with value to the sensor with id in the Database fn post_meta(&mut self, id: &str, value: Vec<u8>); /// Get aggregates from the sensor with id in the Database fn get_aggregates(&self, id: &str) -> Vec<u8>; /// Get the latest record from the sensor with id in the Database fn get_latest(&mut self, id: &str) -> Vec<u8>; /// Get the latest limit number of records from the sensor with id /// in the Database /// /// May load data from disk, if it is not in-memory, /// as such it is mutable, even though a get latest limit normaly is /// immutable. fn get_latest_with_limit(&mut self, id: &str, limit: usize) -> Vec<Vec<u8>>; /// Get a range from start to end of records from the sensor with /// id in the Database /// /// May load data from disk, if it is not in-memory, /// as such it is mutable, even though a range scan normaly is /// immutable. fn get_range(&mut self, id: &str, start: usize, end: usize) -> Vec<Vec<u8>>; /// Get metadata from all sensors in the Database fn get_all_meta(&mut self) -> std::collections::HashMap<&str, Vec<u8>>; /// Get aggregates from all sensors in the Database fn get_all_aggregates(&self) -> std::collections::HashMap<&str, Vec<u8>>; /// Get the latest record from all sensors in the Database fn get_all_latest(&mut self) -> std::collections::HashMap<&str, Vec<u8>>; /// Get the latest limit number of records from all sensors in the /// Database /// /// May load data from disk, if it is not in-memory, /// as such it is mutable, even though a get latest limit normaly is /// immutable. fn get_all_latest_with_limit( &mut self, limit: usize, ) -> std::collections::HashMap<&str, Vec<Vec<u8>>>; } ```