Skip to content

Instantly share code, notes, and snippets.

View nicklasfrahm's full-sized avatar

Nicklas Frahm nicklasfrahm

View GitHub Profile
@nicklasfrahm
nicklasfrahm / chroot.sh
Last active July 18, 2022 21:15
chroot helper
#!/bin/bash
if [ "$1" != "start" ] && [ "$1" != "stop" ]; then
echo "usage: ./chroot.sh <start|stop> <rootfs>"
exit 1;
fi
ACTION=$1
if [ ! -d "$2" ]; then
echo "error: invalid directory: $2"
@nicklasfrahm
nicklasfrahm / binsize-00-default
Last active November 9, 2021 23:51
Go Binary Compression
total 38M
drwxr-xr-x 2 nicklasfrahm nicklasfrahm 4.0K Nov 10 00:01 .
drwxr-xr-x 13 nicklasfrahm nicklasfrahm 4.0K Nov 10 00:12 ..
-rwxr-xr-x 1 nicklasfrahm nicklasfrahm 8.4M Nov 10 00:01 audit
-rwxr-xr-x 1 nicklasfrahm nicklasfrahm 13M Nov 10 00:01 gateway-http
-rwxr-xr-x 1 nicklasfrahm nicklasfrahm 9.0M Nov 10 00:01 mail
-rwxr-xr-x 1 nicklasfrahm nicklasfrahm 8.3M Nov 10 00:01 status
@nicklasfrahm
nicklasfrahm / README.md
Last active June 14, 2021 08:29
Linux configuration

Linux configuration

This document is a collection of useful commands and configurations to set up a Linux system, because I am lazy and I don't want to remember them by heart.

Set up passwordless sudo

Switch to the user, you would like to set passwordless sudo up for and run:

echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$(whoami)
@nicklasfrahm
nicklasfrahm / authorized_keys
Created February 1, 2021 18:40
The authorized public keys for my servers.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAEAQCrW8DZAi3pHs4KBIiC+PL63T87QzsVTvG03BqAwBIwr+4LPL0XTxn5JieSKM0gSxSXJfQdz7w/NJMbAUL6JuI8c1+7aUeqF5nTOse3mb6uYk4ty1MEJ7zyjFJV/uh5fQ5KuqztE4I7i7BGLTp2DJROgcrr7Nv53bUdyjYF5Izv0LSu8u4/54QkiiSzfdQ/yDpj946Oys3SYLt8ZKed/8tuLCM+ziozBlx8HzvRUnle5IS4PTSGGqrphsmAf4BKxipWtAtQ1JkcNkp0gqJ/J9j6BpAWKR3cir2mXj7vYRkOE6prEoXx1S2I0KEHnjK5HzbUlOo+CQOYCeK+zvV0Wv9x2UBtFLWP68z/IHkLOV2EO1qgHEJ2KIx6tyY1BFtGDScEgel+i8GCwspXmmYlpGAvRw7FEUEt6x+lCt0FIh9ok/HOvkNlRTwHDMdN70XJ1q8DIQrq9tQ8YgLfRMnsN33hjWvjs2FJ6DcgN6a2L39XGmsYN/UOGnkqmGCnxaFZxLeiA0o/QMzCmc2NIEDJqjWAkwVsH4vjchJNNxbF0nTMCMQ6bN29hh5JOhCcnvjFVfDZ8dwXyMZ/dr8CE0OT6gu9PxlAcCpKQkvEOPjY+2inMwH2tZYh0KFvoh5Q9BhUwqYuYNe3vrAvFjrqW+Uk1Ge1MFmpf63ZhwpOQFAKkVIeWW0N+e2NgDYAXYSCOZDx3nU1xlr7mJVPzuO0kYHj9XIxZVFMghRggsLRso1lFTq4cMkkCCHuh6daEEsr/opwW3CeepMEVvftRFXp1+xP6i32NNJC7sNK8GZS4XTR86JKtbDPGexxufbpgqooYDUzcaRzX+MIUl6vwvE6x4EcXTpmzB5dvfIhIqLp5lUA8arqrysKc/liPeDd0Yk4zud/QvkYXyVxynpZ0wQ+JbM53sB45Rm7TEwBd2sgaMRQx3hhZSj0gxUJkOBsfRVpgybEU93PpabAagzpyuLv3tGs+TranMmC
@nicklasfrahm
nicklasfrahm / debian-10-etc-os-release
Created January 20, 2021 11:49
OS release information for common operating systems
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
@nicklasfrahm
nicklasfrahm / hscod-exercise-cache-performance.js
Created March 30, 2020 10:19
HSCOD - Exercise - Cache Design
const spacer = '--------------------------------------------------';
const decToBin = (dec, paddingCount = 8) =>
dec.toString(2).padStart(paddingCount, '0');
const sliceBits = (dec, start, end) => {
const positiveMask = 2 ** (end + 1) - 1;
const negativeMask = 2 ** start - 1;
return (dec & (positiveMask - negativeMask)) >> start;
};
const round = (num, digits = 2) =>
+(Math.round(num + `e+${digits}`) + `e-${digits}`);
@nicklasfrahm
nicklasfrahm / hscod-exercise-cache-design.js
Last active March 30, 2020 10:18
HSCOD - Exercise - Cache Design
const spacer = '--------------------------------------------------';
const decToBin = (dec, paddingCount = 8) =>
dec.toString(2).padStart(paddingCount, '0');
console.log(`${spacer}\nExercise 1\n${spacer}`);
{
const addressSize = 8;
const addressReferences = [3, 180, 43, 2, 191, 88, 190, 2, 88];
const indexes = {};
@nicklasfrahm
nicklasfrahm / run.sh
Created November 20, 2019 12:10
A convenient script for automatic compiling and execution
#!/usr/bin/env bash
RED='\033[1;31m'
BLUE='\033[1;34m'
RESET='\033[0m'
# Select compiler.
# COMPILER=x86_64-w64-mingw32-g++
COMPILER=g++
@nicklasfrahm
nicklasfrahm / id3.js
Last active June 8, 2019 01:30
ID3 music tags
const { promisify } = require('util');
const fs = require('fs');
const path = require('path');
const jimp = require('jimp');
const mm = require('music-metadata');
const Id3Writer = require('browser-id3-writer');
const start = Date.now();
const writeFile = promisify(fs.writeFile);
@nicklasfrahm
nicklasfrahm / noop.sh
Created June 2, 2019 11:24
A script that does nothing
#!/usr/bin/env bash
echo "noop noop"