Skip to content

Instantly share code, notes, and snippets.

View miken32's full-sized avatar

Michael Newton miken32

View GitHub Profile
@miken32
miken32 / parser.php
Created May 14, 2023 18:38
PHP parsing for Nagios/Icinga threshold values
/**
* Return a normalized threshold value (floats are converted to ints)
*
* @param string $thresh The threshold specification
* @return string The normalized threshold
* @throws Exception In case of invalid format
*/
function parse_threshold(string $thresh): string
{
if (preg_match("/^[0-9]+$/", $thresh)) {
@miken32
miken32 / Cidr.php
Last active October 24, 2023 07:27
Laravel CIDR validation rule
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use const FILTER_FLAG_IPV4;
use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_INT;
// ==UserScript==
// @name Accept Rate
// @version 0.5
// @description Display a user's Stack Exchange question accept rate
// @namespace k0tFZXXD
// @author Michael Hampton, Michael Newton
// @license GNU GPL v3 or later (http://www.gnu.org/copyleft/gpl.html)
// @include https://stackoverflow.com/*
// @include https://serverfault.com/*
// @include https://superuser.com/*
#!/bin/bash
xml_head='<?xml version="1.0" charset="utf-8" standalone="yes"?>\n<directory>\n<itemlist>'
xml_tail='</itemlist>\n</directory>'
mysql -N -D asterisk -e 'SELECT name, extension FROM users ORDER BY extension' | \
awk -F"\t" -v "xh=$xml_head" -v "xt=$xml_tail" '
BEGIN {print xh}
{printf ("<item><fn>%s</fn><ln>%s</ln><ct>%d</ct></item>\n", substr($1,0,index($1," ")-1), substr($1,index($1," ")+1), $2)}
END {print xt}'
@miken32
miken32 / BlockCheck.class.php
Last active May 10, 2017 23:54
Verify if all characters of a string belong to a given Unicode character block
<?php
/**
* BlockCheck 1.0
*
* Copyright (C) 2017 Michael Newton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.