Skip to content

Instantly share code, notes, and snippets.

@djfdyuruiry
djfdyuruiry / README.md
Last active April 28, 2024 08:34
WSL 2 - Enabling systemd

Enable systemd in WSL 2

NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)

This guide will enable systemd to run as normal under WSL 2. This will enable services like microk8s, docker and many more to just work during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

  • To enable systemd under WSL we require a tool called systemd-genie

  • Copy the contents of install-sg.sh to a new file /tmp/install-sg.sh:

[Unit]
Description=firewalld reload hook - run a hook script on firewalld reload
Wants=dbus-broker.service
After=dbus-broker.service
[Service]
Type=simple
ExecStart=/bin/bash -c '/bin/busctl monitor --system --json=short --match "interface=org.fedoraproject.FirewallD1,member=Reloaded" | while read -r line ; do [ -x /usr/local/sbin/firewalld-reload-hook ] && /usr/local/sbin/firewalld-reload-hook ; done'
[Install]
@russjones
russjones / run.sh
Last active September 23, 2022 14:57
A script to demonstrate Teleport Enhanced Session Recording.
#!/bin/bash
set -euo pipefail
RELEASE="teleport-v4.2.3-linux-amd64-bin.tar.gz"
if [[ $EUID -ne 0 ]]; then
echo "--> Please run this script as root or sudo."
exit 1
fi
@dianjuar
dianjuar / i3-shortcuts-screenshot.md
Last active April 24, 2024 15:10
My i3 shortcuts to take screenshots

Requirements

  • maim
  • xclip

Set-up

Set this on your i3 config file ~/.i3/config

# Screenshots
@iafisher
iafisher / bookmarks_from_sql.py
Created March 9, 2019 22:54
Programmatically access your Firefox bookmarks
"""
A script to automatically export bookmarks from Firefox's SQLite database.
There does not seem to be a programmatic way to get Firefox to export its bookmarks in
the conventional HTML format. However, you can access the bookmark information directly
in Firefox's internal database, which is what this script does.
Always be careful when working with the internal database! If you delete data, you will
likely not be able to recover it.
@maciej-lasyk
maciej-lasyk / ansible-pre-commit
Created June 27, 2018 12:15
git pre-commit hook for validating vault encryption and YAML syntax
#!/bin/sh
##############################################################################
# Check whether vault files are encrypted:
FILES_PATTERN='.*vault.*\.yml$'
REQUIRED='ANSIBLE_VAULT'
UNENCRYPTED_FILES=()
for f in $(git diff --cached --diff-filter=d --name-only | grep -E $FILES_PATTERN)
do
@mgeeky
mgeeky / collect-gpw.py
Last active February 22, 2024 21:44
Script that collects data from GPW (Warsaw Stock Exchange) and corellates it with stock details retrieved from Money.pl quotes. As the result two CSV files will be generated - one with full results, and second with results filtered by B. Graham conditions.
#!/usr/bin/python
#
# Skrypt pobierajacy obecne wskazniki spolek ze strony GPW,
# po czym dla kazdej spolki wczytujacy parametry jej notowan i akcji
# ze strony Money.pl. Rezultatem dzialania sa dwa pliki CSV gotowe do zaimportowania
# i obrobienia w Excelu. Pierwszy plik - out.csv zawiera wszystkie dane spolek, drugi
# csv_filtered zawiera dane odfiltrowane po restrykcyjnych kryteriach Benjamina Grahama,
# autora Inteligentnego Inwestora.
#
@fasiha
fasiha / README.md
Last active January 10, 2020 12:58
How Rust slays brittle indexing logic.

In writing one’s own Base64 codec for the Cryptopals Crypto Challenge in Rust, one gets to a point where every chunk of four adjacent elements in an input vector has to be transformed into a chunk of three elements in an output vector.

That is, the string SSdt containing four ASCII bytes becomes the string I'm containing three ASCII bytes, and IGtp becomes  ki, and so on, so that SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t is decoded to I'm killing your brain like a poisonous mushroom.

I had a function to do this four-to-three downconversion but looping over the two arrays, lining up the indexes, the keeping track of magic threes and magic fours in my code gave me a headache as I worked through writing the following:

pub fn decode(s: &[u8]) -> Vec<u8> {
    let mut out: Vec<u8> = vec![0; s.len() / 4 * 3];
    for i in 0..ou