Skip to content

Instantly share code, notes, and snippets.

View stefano-garzarella's full-sized avatar

Stefano Garzarella stefano-garzarella

View GitHub Profile
@stefano-garzarella
stefano-garzarella / root.sh
Last active August 29, 2015 14:06
Bash root privileges
# Make sure only root can run this script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
@stefano-garzarella
stefano-garzarella / rm_all_remote_branch.sh
Created September 11, 2014 12:57
[GIT] Remove all remote branches except master
#!/bin/bash
#Remove all remote branches except master
REMOTE_NAME="github"
MASTER_BRANCH="master"
git branch -r | grep ${REMOTE_NAME}/ | grep -v ${MASTER_BRANCH} | grep -v HEAD | cut -d/ -f2-10 | while read line; do git push ${REMOTE_NAME} ${MASTER_BRANCH} :$line; done;
@stefano-garzarella
stefano-garzarella / steshell.py
Last active November 3, 2015 16:00
execute schell command in python script
import subprocess
import sys
def sh(cmd, dbg = False):
if dbg:
print(cmd)
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
ret = process.communicate()[0]
@stefano-garzarella
stefano-garzarella / debug_k_printf.c
Last active January 22, 2016 11:27
Linux kprintf with some debug info
#define _dprintk(_fmt, ... )\
do { \
struct timeval _t0; \
do_gettimeofday(&_t0); \
printk(KERN_ERR "%03d.%06d %s():%d - " _fmt "%s\n", \
(int)(_t0.tv_sec % 1000), (int)_t0.tv_usec, \
__func__, __LINE__, __VA_ARGS__); \
} while (0);
#define sprintk(...) _dprintk(__VA_ARGS__, "")
#ifdef PDEBUG
@stefano-garzarella
stefano-garzarella / debug_c_printf.c
Last active March 4, 2016 10:50
C printf with some debug info
#define _DPRINTF(type, _fmt, ... )\
do { \
struct timeval _t0; \
gettimeofday(&_t0, NULL); \
fprintf(stderr, "%03d.%06d %s():%d - %s - " _fmt "%s\n", \
(int)(_t0.tv_sec % 1000), (int)_t0.tv_usec, \
__func__, __LINE__, type , __VA_ARGS__); \
} while (0);
#define EPRINTF(...) _DPRINTF("*ERROR*", __VA_ARGS__, "")
#define IPRINTF(...) _DPRINTF("INFO", __VA_ARGS__, "")
@stefano-garzarella
stefano-garzarella / client.sh
Created July 13, 2018 12:56 — forked from rroohhh/client.sh
gstreamer udp audio streaming
#!/bin/bash
gst-launch-1.0 -v udpsrc uri=udp://239.1.1.1:5000 caps="application/x-rtp,channels=(int)2,format=(string)S16LE,media=(string)audio,payload=(int)96,clock-rate=(int)44100,encoding-name=(string)L24" ! rtpL24depay ! audioconvert ! autoaudiosink sync=false
@stefano-garzarella
stefano-garzarella / sh_param.sh
Last active July 18, 2018 09:38
parse shell parameters
RED='\033[0;31m'
NC='\033[0m' # No Color
function usage
{
echo -e "usage: $0 [OPTION...]"
echo -e ""
echo -e "Simple description"
echo -e ""
echo -e " -s, --set X.Y set parameter"
@stefano-garzarella
stefano-garzarella / qemu_linux_pvh.md
Last active August 24, 2019 13:01
QEMU 4.0 is able to boot uncompressed Linux x86_64 kernel using the PVH entry point defined in the x86/HVM direct boot ABI https://stefano-garzarella.github.io/posts/2019-08-23-qemu-linux-kernel-pvh/

QEMU 4.0 boots uncompressed Linux x86_64 kernel

Read more

@stefano-garzarella
stefano-garzarella / vsock-get-cid.py
Created March 7, 2023 13:26
vsock: get local CID using the available ioctl
#!/usr/bin/env python3
import socket
import struct
import fcntl
with open("/dev/vsock", "rb") as fd:
r = fcntl.ioctl(fd, socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID, " ")
cid = struct.unpack("I", r)[0]
print("Local CID: {}".format(cid))
@stefano-garzarella
stefano-garzarella / vsock_connected_sock_issue.py
Created June 20, 2023 10:09
Script to debug a vsock issue. This happen when a connecting socket is bound to a port in the guest, the guest close the socket while the host still have it opened.
#!/usr/bin/python3
import argparse
import sys
import socket
def vsock_server(vsock, args):
vsock.listen()
while True: