RSSAmplifier

Blog

Codrut Constantin Gusoi

Recent content on Codrut Constantin Gusoi

codrut.proRSS feed ↗139 posts

Latest posts

Chroot in Linux with Encrypted Btrfs


 Prerequisites
 
 
 Link to heading 
 
 
 Go into root mode: 
 sudo -i
 Look for your drive: 
 lsblk -f
 
 # NAME FSTYPE LABEL 
 # nvme0n1 
 # ├─nvme0n1p1 vfat EFI 
 # └─nvme0n1p2 crypto_LUKS 
 You should have: 
 
 nvme0n1p1 → EFI partition 
 nvme0n1p2 → root LUKS 
 
 
 Usage
 
 
 Link to heading…

Generate QR Code from CLI

&#xA; Prereqisites&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo pacman -S qrencode&#xA; Also make sure you have a proper UTF8 font installed! &#xA; &#xA; Usage&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; From STDIN : &#xA; qrencode -t ansiutf8 <<< 'your_string_here' &#xA; From file: &#xA; qrencode -t ansiutf8 < ~/.ssh/id_ed25519.pub&#xA;

Terraform Format in CI

Install git and make in your terraform docker image: &#xA; # ------------------------------------------------------------------------------ &#xA; # Packages &#xA; &#xA; RUN set -exo pipefail && \&#xA; \&#xA; echo 'Installing packages' && \&#xA; apk add --update --no-cache \&#xA; git \&#xA; make &#xA; Create a Makefile in your terraform directory containing: &#xA; .PHONY : init&#xA; init : &#xA;…

Rails: install Administrate

&#xA; Gems&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add these to your Gemfile : &#xA; # Administration &#xA; gem 'administrate' , '~> 0.20.0' &#xA; &#xA; # Authentication &#xA; gem 'devise' , '~> 4.9' , '>= 4.9.3' &#xA; Then install your new gems: &#xA; bundle install&#xA; &#xA; Generate&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; bundle exec rails generate devise:install&#xA;…

Rails: install ActiveAdmin

&#xA; Gems&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add these to your Gemfile : &#xA; # Administration &#xA; gem 'activeadmin' , '~> 4.0.0.beta4' &#xA; &#xA; # Authentication &#xA; gem 'devise' , '~> 4.9' , '>= 4.9.3' &#xA; Then install your new gems: &#xA; bundle install&#xA; &#xA; Generate&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; bundle exec rails generate…

Create new Rails app through Docker

&#xA; Prerequisites&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Install Docker Here . &#xA; &#xA; Shell&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; You need the bigger Debian based docker image for installing Rails as it needs&#xA;to have gcc and make for building naitve extensions. &#xA; docker-here ruby:3.3.0 bash&#xA; &#xA; Rails&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA;…

Disallow GPT in robots.txt

Enable robots.txt in your hugo.toml (formerly config.toml ): &#xA; enableRobotsTXT = true &#xA; Add a file layouts/robots.txt with: &#xA; User-agent: GPTBot&#xA; Disallow: /&#xA; &#xA; User-agent: *&#xA; Allow: /&#xA;

Create a new Ruby gem

&#xA; Setup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add this to your ~/.bundle/config &#xA; ---&#xA; &#xA; BUNDLE_GEM__TEST : 'minitest' &#xA; BUNDLE_GEM__CI : 'gitlab' &#xA; BUNDLE_GEM__MIT : 'false' &#xA; BUNDLE_GEM__COC : 'false' &#xA; BUNDLE_GEM__CHANGELOG : 'false' &#xA; BUNDLE_GEM__LINTER : 'rubocop' &#xA; &#xA; Gem Name&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Use _ for…

RSpec Instance Double

Here is how you can make an assertion on a nested call to another class: &#xA; let( :double ) { instance_double( 'something' ) }&#xA; &#xA; before do &#xA; allow( SomeClass ) . to receive( :some_method ) . and_return(double)&#xA; allow(double) . to receive( :another ) . and_return( true )&#xA; end &#xA; &#xA; it 'does something useful' do &#xA; subject . call&#xA; &#xA; expect( SomeClass ) . to…

Easter Eggs: Pacman

&#xA; Open your pacman.cfg file: &#xA; &#xA; sudo vim /etc/pacman.conf&#xA; &#xA; Uncomment or add these instructions: &#xA; &#xA; Color&#xA;ILoveCandy&#xA; &#xA; Update your system with sudo pacman -Syyu . &#xA;

How to Use: sha256sum

&#xA; Prerequisites&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Create a basic file: &#xA; echo 'abc123' > test123.txt&#xA; &#xA; Digest&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Find the sha256sum of a file with: &#xA; sha256sum test123.txt&#xA; You will get the following result: &#xA; 5ecf8d2cc410094e8b82dd0bc178a57f3aa1e80916689beb00fe56148b1b1256 test123.txt&#xA; &#xA; NOTE:…

Extract text from page using XPath

let result = document. evaluate (&#xA; '/html/body/div/main/div[1]/div[3]/div' ,&#xA; document,&#xA; null ,&#xA; XPathResult . STRING_TYPE ,&#xA; null &#xA; ) ? . stringValue || '' &#xA; &#xA; return result &#xA;

Ansible noop, resume, and skip

Put one noop task at the beginning and end of your role: &#xA; ---&#xA; &#xA; - name : ToolInstall &#xA; ansible.builtin.meta : noop &#xA; &#xA; # ... &#xA; &#xA; - name : ToolInstallEnd &#xA; ansible.builtin.meta : noop &#xA; Now you can resume from where you left off with: &#xA; ansible-playbook playbooks/tool/install.yml --start-at-task = ToolInstall&#xA; And you can skip over that role and…

Evil Mode: silence movement warnings

If you&rsquo;re tired of seeing these: &#xA; evil-line-move: Beginning of buffer [81 times]&#xA;evil-line-move: End of buffer [32 times]&#xA;evil-forward-char: End of line [66 times]&#xA;evil-backward-char: Beginning of line [66 times]&#xA; Add these lines to your dotspacemacs/user-config : &#xA; (with-eval-after-load 'evil &#xA; (advice-add 'evil-line-move &#xA; :filter-args&#xA; (lambda (args) (…

Ruby Ractor: pass an arbitrary block

Let&rsquo;s say you have a piece of code: &#xA; class SomeThing &#xA; def initialize (thing)&#xA; @thing = thing&#xA; end &#xA; &#xA; def call &#xA; puts @thing . inspect&#xA; end &#xA; end &#xA; You want to execute this in parallel in a ractor: &#xA; Ractor . new { SomeThing . new( 1 ) . call }&#xA; This works if you have the block written within the Ractor. But it will fail&#xA;if the block is…

Git init without branch hint

If you run git init you will get this yellow hint: &#xA; hint: Using 'master' as the name for the initial branch. This default branch name&#xA;hint: is subject to change. To configure the initial branch name to use in all&#xA;hint: of your new repositories, which will suppress this warning, call:&#xA;hint:&#xA;hint: git config --global init.defaultBranch <name>&#xA;hint:&#xA;hint: Names commonly…

Git root empty commit

The best way to structure yout repository is to have an empty root commit and to&#xA;squash all the other commits periodically onto the second. This reduces the&#xA;repository size making it easier to clone in CI and for your end users. &#xA; &#xA; Empty root commit&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Create an empty commit: &#xA; git commit -m 'Initial commit' --allow-empty&#xA;…

Linux Bootable USB

&#xA; Usage&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo dd \&#xA; bs = 4M status = progress oflag = direct conv = fsync \&#xA; if = /path/to/linux.iso \&#xA; of = /dev/sda&#xA; &#xA; Details&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; &#xA; bs : Buffer size &#xA; status=progress : shows 3749707776 bytes (3.7 GB, 3.5 GiB) copied, 913 s, 4.1 MB/s &#xA; oflag=direct : actually…

Concatenate shell commands

&#xA; Steps&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Fetch a command with either: &#xA; &#xA; C-e C-u : go to end of line, cut until beginning of line. &#xA; C-a C-k : go to start of line, cut until end of line. &#xA; &#xA; Navigate to older command with: &#xA; &#xA; C-p : previous command. &#xA; C-r : search command (use fzf for better&#xA;results). &#xA; &#xA; Navigate to the end with…

Prepend to $PATH in bash

You should always check if the value is present in a list before adding it in. &#xA; function prepend_path () { &#xA; case ': ${ PATH } :' in&#xA; *: ' $1 ' :* ) &#xA; ;;&#xA; * ) &#xA; PATH = ' $1 : ${ PATH } ' &#xA; esac &#xA; } &#xA; &#xA; Usage&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; prepend_path ~/.local/bin&#xA; &#xA; Cleanup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA;…

Pretty print Linux $PATH

&#xA; &#xA; &#xA;&#xA;&#xA;&#xA; &#xA;&#xA; &#xA; Bash &#xA; &#xA; echo $PATH | sed 's/:/\n/g' &#xA; &#xA; &#xA;&#xA;&#xA;&#xA;&#xA;

Ruby Version Manager: rbenv

&#xA; Docker&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; The best way to manage ruby for your project is by using Docker: &#xA; &#xA; Docker Images: basic Ruby setup &#xA; Docker Projects &#xA; &#xA; If you don&rsquo;t have a Docker setup yet, you have to suffer, temporarily, by using&#xA; rbenv . There used to be another tool called rvm for this sort of thing but&#xA;it&rsquo;s been…

How to install Homebrew securely

The instructions at https://brew.sh/ are extremely dangerous! Here is how to&#xA;install homebrew properly. &#xA; &#xA; NOTE: we assume your homebrew path is: ~/Workspace/Hub/brew &#xA; &#xA; Code&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; &#xA; &#xA; Clone the repository: &#xA; git clone https://github.com/Homebrew/brew.git ~/Workspace/Hub/brew&#xA; &#xA; cd ~/Workspace/Hub/brew&#xA;…

Test for Emacs compiler warnings

&#xA; Setup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Your .gitignore : &#xA; *.elc&#xA; A Makefile containing: &#xA; .PHONY : compile&#xA; compile : &#xA; &#x9;@emacs -q -batch \&#xA; &#x9; --eval '(setq byte-compile-error-on-warn t)' \&#xA; &#x9; -f batch-byte-compile \&#xA; &#x9; *.el&#xA; &#xA; The first indentation is a tab, the following two are spaces. Makefiles just&#xA;work this…

Git refined diff output

&#xA; Package&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Find the location of your diff-highlight package: &#xA;&#xA;&#xA;&#xA;&#xA;&#xA; &#xA; &#xA; &#xA;&#xA;&#xA;&#xA; &#xA;&#xA; &#xA; Manjaro/Arch &#xA; &#xA; pacman -Ql git | grep diff-highlight&#xA; &#xA; &#xA;&#xA;&#xA;&#xA;&#xA; &#xA;&#xA;&#xA;&#xA; &#xA;&#xA; &#xA; Debian/Ubuntu &#xA; &#xA; dpkg -L git | grep diff-highlight&#xA;…

How to Use: ansible-lint

&#xA; Install&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; From package: &#xA; # Manjaro / Arch &#xA; sudo pacman -S ansible-lint&#xA; &#xA; # Alpine &#xA; apk add --update ansible-lint&#xA; From Docker (no official image so use mine): &#xA; docker run --rm -it -v ' $PWD ' :/work -w /work sdwolfz/ansible-lint:latest sh&#xA; &#xA; Configure&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA;…

Disable annoying Linux bell sound

&#xA; Basic&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo echo 'blacklist pcspkr' > /etc/modprobe.d/nobeep.conf&#xA; And restart your machine! &#xA; &#xA; Automated&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add this to an ansible role roles/os/configure/nobeep.yml : &#xA; # ------------------------------------------------------------------------------- &#xA; # Bell Sound &#xA; #…

HTML Tabs without Javascript

&#xA; HTML&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; < div class = 'tabs tab-right' >&#xA; < style >&#xA; . tabs input #tab1: checked ~ . tab-content-1 , &#xA; . tabs input #tab2: checked ~ . tab-content-2 , &#xA; . tabs input #tab3: checked ~ . tab-content-3 {&#xA; display : block ;&#xA; }&#xA; </ style >&#xA; &#xA; < input type = 'radio' name = 'tab-select' id = 'tab1' checked />&#xA; <…

Check for Git differences in CI

The command is: &#xA; git diff --exit-code&#xA; Prints the diff and exits with status code 1 . &#xA; &#xA; CI&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; generate :&#xA; image : ruby:3.1.2-alpine &#xA; script :&#xA; - apk add --update git make &#xA; - make generate &#xA; - git diff --exit-code &#xA;

Local packages in Spacemacs

Are you a hardcore elisp programmer? Add this to your ~/.spacemacs : &#xA; dotspacemacs-additional-packages ' (&#xA; (treemacs :location&#xA; (recipe :fetcher file&#xA; :path '~/path/to/treemacs/src/elisp' )&#xA; :update nil ))&#xA; Now you can hack on any emacs package in your live editor! &#xA; &#xA; Notes&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; &#xA; You will need to manually delete…

How to Use: esbuild

&#xA; Install&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; npm init&#xA; npm install --save-dev esbuild&#xA; &#xA; Setup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add this to your esbuild.js file: &#xA; const esbuild = require ( 'esbuild' )&#xA; &#xA; const targets = [ 'chrome58' , 'firefox57' , 'safari11' ]&#xA; &#xA; esbuild . build ({&#xA; entryPoints : [ 'src/main.js' ],&#xA;…

Ruby Benchmarking

&#xA; Tips&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Disable garbage collection when benchmarking for more accurate results. &#xA; GC . disable&#xA; &#xA; # ------------------------------------------------------------------------------ &#xA; # Code goes here &#xA; &#xA; # ------------------------------------------------------------------------------ &#xA; &#xA; GC . enable&#xA; &#xA;…

How to Use: Minitest Mocks

&#xA; Prerequisite&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; &#xA; Ruby Minitest and Simplecov starter &#xA; &#xA; &#xA; Usage&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; # Create a mock &#xA; mock = Minitest :: Mock . new&#xA; &#xA; # Add expectations. &#xA; # &#xA; # Arguments: &#xA; # 1. Method name &#xA; # 2. What to return when called &#xA; # 3. Expected inputs &#xA; mock .…

Ruby HTTP calls

&#xA; Setup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Use the basic, standard, bundled, ruby HTTP library, no other gem needed. &#xA; require 'net/http' &#xA; &#xA; url = 'https://www.codrut.pro' &#xA; headers = { 'X-HELLO' => 'world' }&#xA; use_ssl = true &#xA; &#xA; GET&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; params = { 'a' => 1 }&#xA; result = nil &#xA; &#xA; uri = URI…

Edit linux application shortcuts

Locations: &#xA; # System &#xA; /usr/share/applications/&#xA; /usr/local/share/applications/&#xA; &#xA; # Flatpak &#xA; /var/lib/flatpak/exports/share/applications/&#xA; &#xA; # Snap &#xA; /var/lib/snapd/desktop/applications/&#xA; &#xA; # Local &#xA; ~/.local/share/applications/&#xA; Search for your application in those directories and edit the files, using&#xA; root privileges where necessary.…

JournalCTL cheatsheet

&#xA; History&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; View history: &#xA; journalctl -b&#xA; Tail history: &#xA; journalctl -b -f&#xA; &#xA; Cleanup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo journalctl --vacuum-size = 100M&#xA;

Ruby: pass around a block

You have the following: &#xA; callable = proc { puts 'Hello' }&#xA; Pass it to a function like this: &#xA; def pass_me_something &#xA; yield if block_given?&#xA; end &#xA; &#xA; pass_me_something( & callable)&#xA; Or be explicit: &#xA; def pass_me_something ( & block)&#xA; block . call if block_given?&#xA; end &#xA; &#xA; pass_me_something( & callable)&#xA; You can also be weird: &#xA; def…

Emacs Lisp macro to evaluate arguments

One argument: &#xA; (defmacro macro-evaluates-arg (arg)&#xA; 'Evaluate `ARG' .' &#xA; ` (when (not ( null arg))&#xA; , arg))&#xA; Multiple arguments: &#xA; (defmacro macro-evaluates-args ( &rest args)&#xA; 'Evaluate `ARGS' .' &#xA; ` (when (not ( null args))&#xA; ,@ args))&#xA;

Git branch names

&#xA; Rules&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Here are my rules for git branch names: &#xA; &#xA; Don&rsquo;t start with the letter m , that&rsquo;s reserved for master or main . &#xA; No prefixes! &#xA; No ids inside branch names. &#xA; Use english words, more than one&hellip; &#xA; Pick either - or _ for separator, but be consistent, never mix. &#xA; Use common sense! &#xA;…

Remove node package funding spam

JavaScript developers have no dignity! Here is how you can restore it: &#xA; npm config set fund false&#xA; &#xA; Docker&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Add this to your Dockerfile : &#xA; # ------------------------------------------------------------------------------ &#xA; # NPM &#xA; &#xA; RUN set -ex && \&#xA; \&#xA; echo 'Restore dignity to the jacascript community' &&…

Check if a port is open

&#xA; Install&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo pacman -S openbsd-netcat&#xA; &#xA; Use&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; With an IP: &#xA; nc -v 127.0.0.1 5432 &#xA; Or a URL: &#xA; nc -v www.codrut.pro 443 &#xA;

List all open ports

netstat -atun&#xA; Now either grep or browse to see if you accidentally exposed your database to&#xA;the world.

Shell script infinite loop

Useful for all sorts of things: &#xA; while true; do echo 'Inside the loop' ; sleep 5; done &#xA;

Webpack and Babel setup for Javascript

Setup package.json by running: &#xA; npm init -y&#xA; Add packages: &#xA; npm install --save-dev \&#xA; @babel/core \&#xA; @babel/preset-env \&#xA; babel-loader \&#xA; webpack \&#xA; webpack-cli&#xA; Create webpack.config.js with index.js as your main, and bundle.js as&#xA;output: &#xA; const webpack = require ( 'webpack' );&#xA; const path = require ( 'path' );&#xA; &#xA; const config = {&#xA;…

Ruby CSV manipulation

&#xA; Read&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; file = CSV . open( 'path/to/file.csv' , col_sep : ',' )&#xA; file . each do | line | &#xA; pp line&#xA; end &#xA; &#xA; Write&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; header = [ 'A' , 'B' , 'C' ] &#xA; content = [[ 1 , 2 , 3 ] , [ 4 , 5 , 6 ]] &#xA; &#xA; csv = CSV . generate do | output | &#xA; output << header&#xA; &#xA;…

Remove metadata from images and documents

Every image or document you create has built in spyware, remove it like this: &#xA; &#xA; Install&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo pacman -S perl-image-exiftool&#xA; &#xA; Usage&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; exiftool -overwrite_original_in_place -all = path-to-file&#xA;

Convert PDF to PNG and back

&#xA; Prerequisites&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; sudo pacman -S gimp imagemagick poppler&#xA; &#xA; PDF to PNG&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Create a directory with your INITAIL.pdf then execute this inside of it: &#xA; pdftoppm INITIAL.pdf prefix-for-images -png&#xA; &#xA; Do whatever&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Edit your images in…

Enable systemd-oomd

&#xA; Prerequisites&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Make sure you have systemd installed with at least version 248 : &#xA; pacman -Ss systemd | grep 'core/systemd ' &#xA; &#xA; # core/systemd 248.2-1.1 [installed] &#xA; &#xA; Setup&#xA; &#xA; &#xA; Link to heading &#xA; &#xA; &#xA; Check if the service is active: &#xA; systemctl status systemd-oomd.service&#xA; Enable and start…

Emacs Lisp interactive debugging

&#xA; &#xA; Navigate to your function. &#xA; &#xA; &#xA; Instrument it with C-u M-x eval-defun , or C-u , e f in Spacemacs. &#xA; &#xA; &#xA; Execute that function. &#xA; &#xA; &#xA; Debug with these shortcuts: &#xA; &#xA; &#xA; &#xA; Key &#xA; Action &#xA; &#xA; &#xA; &#xA; &#xA; s &#xA; Next sexp. &#xA; &#xA; &#xA; i &#xA; Step in. &#xA; &#xA; &#xA; o &#xA; Step out. &#xA; &#xA; &#xA; d &#xA;…

Replace string in all files with sed

find . -type f -exec sed -i 's/STRING GOES HERE/REPLACEMENT HERE/g' {} +&#xA; Make sure to escape brackets ( \[\] ): &#xA; find . -type f -exec sed -i 's|Click \[here\](/here/)!|Click HERE!|g' {} +&#xA;