Skip to content

Instantly share code, notes, and snippets.

View muhamadazmy's full-sized avatar
🤓

Muhamad Awad muhamadazmy

🤓
  • Threefold Tech
  • Ghent/Belgium
View GitHub Profile
@muhamadazmy
muhamadazmy / volstat.sh
Created April 4, 2024 08:39
Script to print size and available space on a subvol quota
#!/bin/sh
# this script is called as `volstat.sh <path/to/subvol>`
set -e
vol=$1
id=$(btrfs subvol show $vol | grep 'Subvolume ID:'| cut -f 4)
output=$(btrfs qgroup show --raw -r $vol| grep "^0/$id")
size=$(echo $output | cut -d ' ' -f 4)
@muhamadazmy
muhamadazmy / debug-image.sh
Last active March 11, 2024 13:40
Test a bootable tarball with cloud-hypervisor
#!env bash
socket="/tmp/virtiofs.sock"
# override this as well if u wanna change
# the vm entry point
init=/sbin/init
# pass to extracted tarball
dir=$1
@muhamadazmy
muhamadazmy / extract-image.sh
Created February 23, 2023 15:56
Extract a docker image into a directory, does not require a container
set -e
# you need to run `docker save <image> -o <file>.tar
# then run this script like `extrat-image.sh <file>.tar`
# it will create a directoyr `<file>.tar-root` which containers
# all files from the image extracted
input=$1
if [ ! -f "${input}" ]; then
echo "file does not exist"
use std::collections::HashMap;
struct Module;
struct Data {
modules: HashMap<String, Module>,
}
impl Data {
fn module<S: AsRef<str>>(&mut self, name: S) -> &mut Module {
if let Some(m) = self.modules.get_mut(name.as_ref()) {
@muhamadazmy
muhamadazmy / bluetoosh.sh
Created December 10, 2019 10:19
Fix bluetooth annoying issue on linux
#!env sh
set -e
sudo systemctl stop bluetooth
sudo modprobe -r btusb btrtl btbcm btintel
sudo modprobe btusb
sudo systemctl start bluetooth
pulseaudio -k
sleep 1s
bluetoothctl power on
@muhamadazmy
muhamadazmy / updatemirrors.sh
Created August 27, 2019 08:38
Update arch linux mirrors
#!env sh
# this file depends on rankmirrors package
tmp=$(mktemp)
trap "rm -f ${tmp}" EXIT
curl "https://www.archlinux.org/mirrorlist/?country=BE&country=FR&country=DE&country=IL&protocol=http&protocol=https&ip_version=4&use_mirror_status=on" | sed "s/#Server/Server/g" > $tmp
rankmirrors ${tmp} | sudo tee /etc/pacman.d/mirrorlist
@muhamadazmy
muhamadazmy / msgpack-go-rust-compatibility.md
Created August 7, 2019 13:04
Test msgpack compatibility accross go and rust.

Quick test for msgpack compatibility

The code below (data encoded in Go) and then decoded in Rust. works fine.

Rust decoder

extern crate rmp_serde as rmps;
extern crate serde;

#[macro_use]
extern crate serde_derive;
@muhamadazmy
muhamadazmy / borrow.rs
Last active March 5, 2019 09:37
No idea why this doesn't build
struct Cache {}
impl Cache {
fn new() -> Cache {
Cache {}
}
fn get(&mut self, key: &u32) -> Option<&str> {
None
}
#SET TO DESTINATION IP
DEST_IP='172.17.0.1'
#CHANGE IF NECESSARY (the dest ip should be reachable from eth0)
DEV=eth0
dmesg -n 7
modprobe configfs
@muhamadazmy
muhamadazmy / copy-chroot.sh
Created December 19, 2017 13:19
Copy binaries to a chroot
#!/bin/bash
if [ $# != 2 ] ; then
echo "usage $0 PATH_TO_BINARY TARGET_FOLDER"
exit 1
fi
PATH_TO_BINARY="$1"
TARGET_FOLDER="$2"