Skip to content

Instantly share code, notes, and snippets.

Steve Kamerman kamermans

Block or report user

Report or block kamermans

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
kamermans / hash_benchmark.php
Created Oct 21, 2018
Compute the performance of every hashing function in PHP
View hash_benchmark.php
$loops = 100000;
$str = "whois foobar";
$algos = hash_algos();
$algo_padding = array_reduce($algos, function($carry, $val) {
$len = strlen($val);
if ($len > $carry) {
$carry = $len;
kamermans /
Created Oct 19, 2018
Replace fancy-quotes / curly-quotes / smart-quotes with standard ASCII single- and double-quotes in bash
# Replaces annoying "fancy" quotes created by programs like Microsoft Word and everything in MacOS
# with normal ASCII single-quotes (') or double-quotes (")
# This script does NOT replace the GRAVE ACCENT (`) since it is commonly used in Markdown and as a bash command
# See:
SINGLE=$(echo -ne '\u00B4\u2018\u2019')
DOUBLE=$(echo -ne '\u201C\u201D')
sed -i "s/[$SINGLE]/'/g; s/[$DOUBLE]/\"/g" $1
kamermans / parse_elb_logs.php
Created May 4, 2018
AWS ELB Log Parsing Regex in PHP
View parse_elb_logs.php
// Cat your ELB logs into this script
$elb_regex = '#^(?<date>.+?) (?<elb>.+?) (?<client_ip>[\d\.]+):(?<client_port>\d+) (?<backend_ip>[\d\.]+):(?<backend_port>\d+) (?<request_processing_time>[\d\.]+) (?<backend_processing_time>[\d\.]+) (?<response_processing_time>[\d\.]+) (?<elb_status_code>\d+) (?<backend_status_code>\d+) (?<received_bytes>\d+) (?<sent_bytes>\d+) "(?<method>[A-Z]+) (?<https>https?)://(?<http_host>.+?):(?<port>\d+)(?<uri>/.*?) (?<protocol>HTTP/[\d\.]+)" "(?<http_user_agent>.+?)" (?<ssl_cipher>.+?) (?<ssl_protocol>.+?)$#';
while ($line = fgets(STDIN)) {
if (!preg_match($elb_regex, $line, $data)) {
kamermans /
Last active Apr 11, 2018
Bash functions for dealing with Docker containers in an unknown state (starting, stopping, removing, checking if they exist, etc)
# Helper functions for dealing with Docker containers
# Returns "missing", "stopped" or "running"
get_container_state() {
# Faster check to see if the container *might* exist
CONTAINER_MISSING=$(container_does_not_exist "$CONTAINER_NAME")
if [[ $CONTAINER_MISSING = "true" ]]; then
echo -n "missing"
kamermans / libwurfl_version.c
Created Nov 8, 2017
Get the version of libwurfl
View libwurfl_version.c
* libwurfl_version.c
* Compile with:
* gcc -o libwurfl_version libwurfl_version.c -lwurfl
#include <stdio.h>
#include <wurfl/wurfl.h>
int main(int argc, char **argv)
kamermans / curl-timing
Created Oct 21, 2017
Curl helper that adds detailed timing information
View curl-timing
#!/bin/bash -e
# Put this file in /usr/local/bin and use 'curl-timing' in place of 'curl'
# to get a detailed timing report with the response.
# You can customize the report below. For older versions of curl, some
# of the fields below will not be available.
url_effective: %{url_effective}
remote_ip: %{remote_ip}
kamermans / parse_identify.php
Last active Oct 13, 2017
ImageMagick identify -verbose JSON transformer
View parse_identify.php
#!/usr/bin/env php
<?php namespace kamermans\ImageMagick;
* Parser for the ImageMagick "identify" utility that takes "identify -verbose <file>"
* output on STDIN and outputs JSON on STDOUT.
* Example:
* identify -verbose foo.jpg | ./parse_identify.php
kamermans / url_cleaner.php
Created Jun 6, 2017
PHP function to cleanup/re-encode a URL
View url_cleaner.php
$url = ' with spaces/index.php?something=something else#foo-29 32';
$reencode_url = function ($url) {
$url_parts = parse_url($url);
// Add scheme
$scheme = array_key_exists('scheme', $url_parts)? $url_parts['scheme']: 'http';
$new_url = "$scheme://";
kamermans / python_fnmatch_translate.php
Created Apr 16, 2017
PHP port of the Python 2.7 `fnmatch::translate()` function to convert shell-expansion patterns to regular expressions.
View python_fnmatch_translate.php
* Direct port of the Python 2.7 fnmatch::translate(pat) function.
* Converts a shell-expansion pattern to a regular expression.
* by Steve Kamerman
* @see
function pythonFnmatchTranslate($pat, $delimiter=null) {
kamermans / zabbix_v3_2_template_percona_mysql_server.xml
Created Mar 24, 2017
Percona Monitoring Plugins MySQL Template for Zabbix 3.2
View zabbix_v3_2_template_percona_mysql_server.xml
<?xml version="1.0" encoding="UTF-8"?>
You can’t perform that action at this time.