Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / parse_storcli.py
Last active February 20, 2023 08:23
Script to parse storcli (replaced megacli) output for use in monitoring applications like Nagios, Zabbix, etc
#!/usr/bin/env python
#
# Parses the output of storcli:
# storcli /c0 show all J
import sys
import json
output_dir = "."
data = json.load(sys.stdin)
@kamermans
kamermans / parse_nginx_stats.py
Last active September 18, 2021 02:56
Simple nginx stats aggregation without NGINX Plus, Lua or NginScript - all you need is Python3!
#!/usr/bin/env python3
# Start this script before you start NGINX, so it is ready and waiting for log data.
# You should start it in the background with & or run it from supervisord or something.
# If the port is above 1024, you can run this script as a non-root user (recommended).
#
# It listens for raw Syslog data over UDP, parses is, aggregates it, and writes
# it to a file every flush_interval seconds. The output file format looks like this:
# key<TAB>value
# Here is an example (note that the delimiter is actually TAB, not a space):
@kamermans
kamermans / php-error-logstash.conf
Last active July 31, 2023 11:31
Logstash parser for PHP's error_log to combine multline stack traces / errors into one event
input {
stdin {
codec => multiline {
pattern => "^\[%{MONTHDAY}-%{MONTH}-%{YEAR} %{TIME} %{TZ}\]"
negate => true
what => "previous"
auto_flush_interval => 10
}
type => "php-error"
}
@kamermans
kamermans / DeleteThreadsInLabel.gs
Last active December 12, 2019 07:44
Delete all Gmail / Google Apps Email threads in a given label, even hundreds of thousands of emails.
/*
* Delete all Gmail / Google Apps Email threads in a given label.
* This is really only necessary when you have tons (read: hundreds
* of thousands) of messages to delete and the web interface crashes.
*
* Warning: if you don't understand this code, you might just delete
* all of your email!
*
* Author: Steve Kamerman, 2017
*
@kamermans
kamermans / test.php
Created January 13, 2017 03:18
Test showing the preservation of LF line endings via base64 encoding
<?php
if ($_POST) {
header("content-type: application/json");
$data = $_POST;
if (isset($data["encoded_data"])) {
$data["decoded_data"] = base64_decode($data["encoded_data"]);
}
@kamermans
kamermans / get_docker_host_ip.php
Created November 1, 2016 15:53
Example of retrieving the Docker host IP from within a container via PHP by parsing the Linux kernel's routing table
<?php
$gw = "Unknown";
// Get the Docker host IP from the routing table
$table = file("/proc/net/route");
foreach ($table as $row) {
// Split the fields out of the routing table
$fields = preg_split("/[\t ]+/", trim($row));
@kamermans
kamermans / generate_imei.py
Last active June 8, 2025 19:36
Generates a complete, valid IMEI from a TAC code or otherwise incomplete IMEI.
#!/usr/bin/env python2
from random import randint
def generate_imei(incomplete_imei):
luhn_sum = 0
imei_digits = []
for i in xrange(0,14):
# Pull each digit from the TAC, generate missing numbers with rand()
@kamermans
kamermans / list_varnish_includes.sh
Created August 9, 2016 16:59
# Recursively list all of the Varnish VCL config files that are included via "include" statements.
#!/bin/bash -e
# list_varnish_includes.sh
# Recursively list all of the Varnish VCL config files that are included via "include" statements.
# This scripts should work in Varnish 2-4+
# Author: Steve Kamerman
if [[ $# -ne 1 ]]; then
echo "Usage: ./$(basename $0) <path_to_config.vcl>" >&2
exit 2
fi
@kamermans
kamermans / exif_comment_to_lightroom.py
Created July 17, 2016 23:44
Windows Metadata Comments to Adobe Lightroom Sync
#!/usr/bin/env python2
#
# exif_comment_to_lightroom.py
#
# Windows Metadata Comments => Adobe Lightroom Sync
#
# This script will decode and copy the comment field from the Windows metadata details
# (when you right-click on an image and go to details in Windows Explorer) into the
# Adobe Lightroom compatible IPTC XMP caption field. After running, select all affected
# images and select Metadata -> Read Metadata from File.
@kamermans
kamermans / compute_milky_way.py
Last active June 14, 2016 04:31
Python script to compute optimal Milky Way photography dates and times
#!/usr/bin/env python2.7
from datetime import date, datetime
import ephem
mylocation = ephem.Observer()
mylocation.lat, mylocation.lon = '39.039502', '-77.486371'
min_alt = ephem.degrees('10:00')