Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@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 April 12, 2024 08:51
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')
@kamermans
kamermans / ios_models_map.json
Last active April 8, 2016 21:17
Parse iOS model names into mapping file
{
"AppleTV2,1": "Apple TV 2G",
"AppleTV3,1": "Apple TV 3",
"AppleTV3,2": "Apple TV 3 (2013)",
"AppleTV5,3": "Apple TV 4 (2015)",
"iPad1,1": "iPad 1",
"iPad2,1": "iPad 2 (WiFi)",
"iPad2,2": "iPad 2 (GSM)",
"iPad2,3": "iPad 2 (CDMA)",
"iPad2,4": "iPad 2 (Mid 2012)",
@kamermans
kamermans / fcgi_get.sh
Last active January 24, 2018 13:50
Dead-simple FCGI client with minimal dependencies
#!/bin/sh -e
# This cgi-fcgi and Perl-based, dead simple FGCI client works out-of-the-box with just
# a stock Perl installation and cgi-fcgi (apt-get install libfcgi0ldbl)
# It was made as a simple FCGI client for health-checking FCGI daemons, for example, in
# a minimal Debian-based Docker image. It is tested against PHP-FPM and HHVM
# By: Steve Kamerman
#
# Usage: ./fcgi_get.sh <fcgi_ip>:<fcgi_port> <script_path> <document_root> [GET|HEAD|POST|PUT|DELETE]
# If invalid arguments are passed, exit code 1 is returned
# If the connection succeeds, exit code 0 is returned and the HTTP Headers are output on STDERR