Skip to content

Instantly share code, notes, and snippets.

View aeinbu's full-sized avatar

Arjan Einbu aeinbu

View GitHub Profile

Linux users/groups/permissions cheatsheet

Add user

sudo useradd -m peter
sudo passwd peter

groupadd myAppUsers

sudo usermod -a -G peter myAppUsers
@aeinbu
aeinbu / running-docker-images-cheatsheet.md
Last active February 19, 2024 23:26
docker cheat sheet

Running docker images cheatsheet

Download a docker image

Download the image called debian:

docker pull debian

Create a container (and start it)

The container in the samples will be named "debby"

@aeinbu
aeinbu / .zshrc
Last active November 8, 2023 19:54
`la` and `mkcd` commands
alias la="ls -a"
mkcd() {
mkdir $1 && cd $1
}
@aeinbu
aeinbu / array-helpers.js
Last active October 28, 2023 22:36
Array operations for useReducer or Redux with ES6+
// Returns a new array, with the element at pos replaced with replacement item or calling the replacement function on arr[pos]
function changeAtIndex(arr, pos, replacement) {
if (typeof replacement == "function") {
replacement = replacement(arr[pos]);
}
return [...arr.slice(0, pos), replacement, ...arr.slice(pos + 1)];
}
// Returns a new array, with the first element matching the predicate function replaced with replacement item or calling the replacement function on arr[pos]
@aeinbu
aeinbu / ArjansJsTsDebugHelpers.code-snippets
Last active October 28, 2023 21:37
Snippets to aid debugging collections transformations (map/filter/reduce) and promises
{
"console.log(\"***\", ...)": {
"prefix": "conso",
"scope": "javascript,typescript,typescriptreact",
"body": [
"console.log(\"*** $1\", $0)",
""
]
},
"debug-map":{
@aeinbu
aeinbu / adhoc.js
Last active January 8, 2023 10:48
Quick queries over json files...
const {
chain,
filter,
count,
groupBy,
map
} = require("./chaining")
const transforms = [
public abstract record StronglyTypedId<TValue>(TValue Value)
where TValue : notnull
{
public override sealed string ToString() => $"{Value}";
}

How to add a new disk in Linux

This post takes you through creating a partition, formatting it and finally mount it in the filesystem.

These procedures where tested on Linux Mint 19

List disks and partitions

$ sudo fdisk -l

The result will vary depending on the number of disk you have. On my computer I got these three entries:

@aeinbu
aeinbu / .gitconfig
Last active July 29, 2021 13:39
Some practial aliases for Git
[alias]
refresh = !git fetch --all --prune && git checkout master && git pull --rebase && git lastbranch
amend = commit --amend --no-edit
lastbranch = checkout @{-1}
ql = log -10 --oneline --decorate --graph
qb = "!qb(){ git refresh && git checkout -b aei/PPN-$@; }; qb"
qc = "!qc(){ git checkout aei/PPN-$@; }; qc"
qa = "!qa(){ git refresh && git branch --remote | grep $@ | sed 's/origin\\///' | xargs git checkout && git pull --rebase && git rebase master; }; qa"
function round(value, precision) {
return Number(Math.round(value + "e" + precision) + "e-" + precision)
}
function strictCompare(left, right) {
console.log(`strictCompare(${left}, ${right})`);
return left === right;
}