Skip to content

Instantly share code, notes, and snippets.

View cosimo's full-sized avatar
🇳🇴

Cosimo Streppone cosimo

🇳🇴
View GitHub Profile
@cosimo
cosimo / proc-map-size.pl
Last active June 18, 2019 11:27
Shows process memory segment sizes
#!/usr/bin/env perl
=head1 NAME
map-size.pl - Shows process memory segment sizes
=head1 SYNOPSIS
cat /proc/[pid]/maps | ./map-size.pl
@cosimo
cosimo / quick-stats.pl
Created July 26, 2019 08:01
Calculate the basic statistical attributes of a numeric population
#!/usr/bin/env perl
=head1 NAME
quick-stats.pl - Calculate the basic statistical attributes of a list of numbers
=head1 SYNOPSIS
echo <list of numbers> | ./quick-stats.pl
@cosimo
cosimo / test-certificate-expiry.sh
Created October 16, 2019 09:14
Bash script to test for about-to-expire certificates
#!/bin/bash
#
# Test certificate file expire date
#
# Usage:
# test-certificate-expiry my.crt
#
#
# Emit an error/critical if the certificate expire date
@cosimo
cosimo / debian-safe-upgrade.sh
Created April 30, 2020 09:46
Safe upgrade of a debian system
#!/bin/sh
OLDDIST=lenny
NEWDIST=squeeze
BACKUP_DIR="/var/tmp/backup.$OLDDIST"
echo "+ Create backup directory"
mkdir -p "$BACKUP_DIR"
#!/usr/bin/env perl
use v5.014;
use warnings;
# Perl WebSocket test client
# Greg Kennedy 2019
# IO::Socket::SSL lets us open encrypted (wss) connections
use IO::Socket::SSL;
# IO::Select to "peek" IO::Sockets for activity
@cosimo
cosimo / cloudpassage_zone_update.py
Last active February 25, 2021 08:33
Automatic update of a Cloudpassage FirewallZone (python script)
#!/usr/bin/env python
# encoding: utf-8
"""
Update an existing Cloudpassage FirewallZone from an external list of IPs
Wanted to use this to block abusive IPs, then I made this work and
realized it only accepts max 6000 characters, which in practice translates
to ~400 IP addresses, so it's probably not worth using in any case.
Usage:
@cosimo
cosimo / inv.py
Last active October 1, 2021 10:19
Display ansible inventories with Python and the rich console library
"""
Display Ansible inventories as a tree of environments, groups and hosts as leaves.
A nice diversion/excuse to dive into the rich console library.
It will expand simple host ranges, allowing grep commands to find
group names for given hosts.
Usage:
./inv.py
./inv.py | grep -B10 some-hostname
@cosimo
cosimo / disable_cb_access_scanner.sh
Created June 24, 2021 13:24
Disable the Couchbase Bucket Access Scanner to avoid micro outages
#!/bin/bash
#
# Disables the Couchbase access scanner on a list of buckets
# Access scanner can cause short outages when buckets are very large.
#
set -e -x
USER='Administrator'
@cosimo
cosimo / nvidia-kernel-crash.log
Last active August 9, 2021 09:28
nvidia modeset kernel crash + screen freeze
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500704] nvidia-modeset/: page allocation failure: order:4, mode:0x40cc0(GFP_KERNEL|__GFP_COMP), nodemask=(null),cpuset=/,mems_allowed=0
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500709] CPU: 1 PID: 244 Comm: nvidia-modeset/ Tainted: P OE 5.4.0-72-generic #80~18.04.1-Ubuntu
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500709] Hardware name: MSI MS-7A71/Z270-A PRO (MS-7A71), BIOS 1.20 04/07/2017
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500710] Call Trace:
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500714] dump_stack+0x6d/0x8b
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500716] warn_alloc+0xfe/0x160
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500718] __alloc_pages_slowpath+0xe19/0xe50
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.500900] ? _nv032044rm+0x1e/0x30 [nvidia]
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.501066] ? os_release_spinlock+0x1a/0x20 [nvidia]
Aug 9 11:26:21 cosimo-desktop kernel: [8778506.501
@cosimo
cosimo / delete-unreferenced-charts.py
Created September 14, 2021 13:42
Clean up older versions of charts from chartmuseum
#!/usr/bin/env python3
import os
import yaml
import requests
CHARTMUSEUM_URL = 'https://your.chartmuseum.url'