Skip to content

Instantly share code, notes, and snippets.

View teknoraver's full-sized avatar
🖥️
coding

Matteo Croce teknoraver

🖥️
coding
View GitHub Profile
@teknoraver
teknoraver / ghclone
Created August 8, 2024 11:06
Clone a GitHub repo and, if it's a fork, setup the upstream as remote
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <git-repo-url>"
exit 1
fi
url=$1
repo=$url
@teknoraver
teknoraver / cleanups.c
Last active July 11, 2024 16:26
C cleanups example
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#define BUFFER_SIZE 4096
int copy(const char *src_path, const char *dst_path)
{
*.o
sysctl_monitor
vmlinux.h
*.skel.h
@teknoraver
teknoraver / forkrepo.sh
Last active December 19, 2023 18:56
Fork repo locally
#!/bin/sh
if [ $# -ne 2 ]; then
echo "usage: ${0##*/} <source> <target>"
echo " clone 'source' to 'target' sharing objects"
exit 1
fi
src=$1
trg=$2
@teknoraver
teknoraver / mannaggia-ng.sh
Created October 25, 2023 16:00
Improved mannaggia.sh
#!/bin/bash
# Versione riveduta e corretta di mannaggia.sh
# problemi di mannaggia.sh:
# * scarica solo la prima pagina di ogni lettera dell'alfabeto
# * usa /dev/urandom per scegliere una lettera casuale (LOL!), quando Bash ha il supporto al random
# * inutilmente complesso, il parsing dei tag veniva fatto con CINQUE PIPE, quando basta un solo awk scritto bene
# released under GNU-GPLv3
prescegli() {
@teknoraver
teknoraver / parentdev.sh
Created July 13, 2023 13:17
Given a partitioned block device, return the device representing the whole disk
#!/bin/sh
dev=$1
dev=$(realpath "$dev")
dev=$(basename "$dev")
sys="/sys/class/block/$dev"
if [ -f "$sys/partition" ]; then
@teknoraver
teknoraver / linesplit.go
Last active November 29, 2021 12:10
split file by maximum size, but never break lines
package main
import (
"bufio"
"flag"
"fmt"
"os"
)
func main() {
@teknoraver
teknoraver / .gitignore
Last active December 17, 2021 16:17
eBPF CO-RE example
/core
*.o
*.lskel.h
vmlinux.h
*.pem
*.x509
@teknoraver
teknoraver / debianttyinstall
Created September 24, 2021 15:54
Install Debian via a serial console
#!/bin/sh
[ $# -eq 2 ] || exec echo "Usage: $0 <install.iso> <disk.img>"
for k in qemu kvm qemu-kvm; do
which $k 2>/dev/null >/dev/null && kvm=$k && break
done
[ -n "$kvm" ] || exec echo "error: KVM not found!"
cores=$(nproc)
@teknoraver
teknoraver / oediv
Created September 16, 2021 11:27
reverse an mp4 video
#!/bin/sh
[ $# -ne 2 ] && exec echo "Usage: ${0##*/} <input> <output>"
src=$1
dst=$2
dir=$(mktemp -d)
trap "rm -rf $dir" EXIT