Skip to content

Instantly share code, notes, and snippets.

@sbz
sbz / aws_route53_detection.py
Last active May 7, 2019 10:30
Detect useless ResourceRecord with type 'A' on AWS R53 pointing to private IP which doesn't exist in the region anymore
#!/usr/bin/env python3
import ipaddress
import boto3
from pprint import pprint as pp
#
# This script iterate over our regions in order to collect all the private IPs
# and check if the ResourceRecord created has still an existing IPs
@sbz
sbz / pyflame.sh
Last active May 30, 2018 14:17
Run pyflame against your python code, to profile it and generate a flamegraph (here it's against singularity-monitor)
#!/bin/bash
sudo apt-get install -y autoconf automake autotools-dev g++ pkg-config python-dev python3-dev libtool make
[ ! -f ./flamegraph.pl ] && {
curl -O https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl
}
[ ! -f /usr/local/bin/pyflame -o ! -d pyflame ] && {
git clone https://github.com/uber/pyflame.git
cd pyflame
@sbz
sbz / tty-size.c
Created April 14, 2017 02:05
get terminal size using ioctl get win size (TIOCGWINSZ) in C
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int
main(void) {
struct winsize ws;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);
printf ("lines %d\n", ws.ws_row);
@sbz
sbz / tty-size.py
Last active March 28, 2025 06:58
get terminal size using ioctl get win size (TIOCGWINSZ) in Python
import termios
import fcntl
import os
import struct
with open(os.ctermid(), 'r') as fd:
packed = fcntl.ioctl(fd, termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0))
rows, cols, h_pixels, v_pixels = struct.unpack('HHHH', packed)
print rows, cols, h_pixels, v_pixels
@sbz
sbz / mz-tab-urls.py
Created February 4, 2015 21:57
mz-tab-urls: Get Mozilla Firefox tabs URLs on stdout
#!/usr/bin/env python
import ConfigParser
import json
import os
"""
Dirty script to get Mozilla Firefox tabs URLs on stdout
source: https://raymii.org/s/snippets/Get_the_current_or_all_Firefox_tab_urls_in_Bash.html
@sbz
sbz / freebsd.json
Created December 19, 2014 00:37
FreeBSD config file (base, localbase, kernel?, ...) backup as json in order to redeploy/backup config
{
"@base": {
"files": [
{
"make.conf": {
"filename": "make.conf",
"dirpath": "/etc/",
"@destination": "/etc/make.conf",
"@content": {
"svn_update": "yes",
@sbz
sbz / auxv.c
Last active August 29, 2015 14:02
auxv: dump elf auxillary vector information on freebsd
#include <stdio.h>
#include <elf.h>
/* /usr/include/x86/elf.h AT_* defs */
typedef struct {
const char *str_val;
int type;
} Elf_AuxStr;
@sbz
sbz / gitlab.py
Last active January 9, 2025 15:33
gitlab: list your groups and projects using api v4
#!/usr/bin/env python
import os
import requests
import subprocess
import sys
from pprint import pprint as pp
TOKEN = 'YOUR_TOKEN'
@sbz
sbz / pf_getrules.c
Last active May 25, 2018 16:11
pf: ioctl get rules call debugging
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#ifdef __FreeBSD__
#include <sys/endian.h>
#endif
#include <net/if.h>
#include <net/pfvar.h>
@sbz
sbz / list-sections.c
Created August 31, 2012 10:42
example to dump sections name using gelf(3) api on FreeBSD
#include <err.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>
static void