Skip to content

Instantly share code, notes, and snippets.

View josevh's full-sized avatar

Jose V Herrera Gallegos josevh

View GitHub Profile
sub alphanumeric_increment {
my $string = "" . shift;
my $position = @_ ? shift : -1;
if ($position == -1) {
$position = (length $string) - 1;
}
my $increment_str = substr $string, $position, 1;
@josevh
josevh / alphanumeric_increment.php
Last active May 9, 2018 15:42 — forked from lewayotte/alphanumeric_increment.php
Incrementing alphanumeric strings in PHP
function alphanumeric_increment( $string, $position=false ) {
if ( false === $position ) {
$position = strlen( $string ) - 1;
}
$increment_str = substr( $string, $position, 1 );
switch ( $increment_str ) {
case '9':
$string = substr_replace( $string, 'a', $position, 1 );
break;
case 'z':
@josevh
josevh / simulated-media-keys.au3
Created September 5, 2017 14:58
Simulate media key presses
#pragma compile(FileDescription, SimulatedMediaKeys simulates media keys)
#pragma compile(ProductName, SimulatedMediaKeys)
#pragma compile(ProductVersion, 0.1)
#pragma compile(FileVersion, 0.0.0.1)
HotKeySet("^!{NUMPAD8}", "MediaPlay")
HotKeySet("^!{NUMPAD6}", "MediaNext")
HotKeySet("^!{NUMPAD4}", "MediaPrev")
HotKeySet("^!{NUMPAD5}", "MediaStop")
<?php
/**
* Migration
*/
abstract class Migration
{
protected $db;
protected $dbName;
@josevh
josevh / define_app_root.php
Created March 20, 2017 15:24
handles app deployed top level or in subdirectory
<?php
define('APP_ROOT_ABS', realpath(__DIR__)); # /var/www/html/images
define('APP_ROOT_REL', preg_replace('/^' . preg_quote($_SERVER['DOCUMENT_ROOT'], '/') . '/', '', __DIR__)); # /images
@josevh
josevh / flight_remove_trailing_slashes.php
Last active April 23, 2022 15:00
Remove trailing slashes in FlightPHP url's
<?php
// before any other route
Flight::route('*', function () {
$request = Flight::request();
if ($request->url != '') {
list($base, $query) = array_pad(explode('?', $request->url, 2), 2, null);
if (substr($base, -1) == '/' && strlen($base) > 1) {
$url = rtrim($base, '/');
if ($query !== null) {
$url .= '?' . $query;
@josevh
josevh / JMXItemChecker.java
Last active August 30, 2016 08:42 — forked from Cromeshnic/JMXItemChecker.java
zabbix_java JMX LLD patch for 2.4.6. Usage example: jmx.discovery["org.apache.activemq:BrokerName=*,Type=Queue,Destination=*"]
/*
** Zabbix
** Copyright (C) 2001-2015 Zabbix SIA
**
** 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 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,