Skip to content

Instantly share code, notes, and snippets.

View bubba-h57's full-sized avatar

Bubba bubba-h57

View GitHub Profile
@bubba-h57
bubba-h57 / parallel_stub.php
Created September 10, 2019 15:29
Stub File for PHP extension parallel
<?php declare(strict_types=1);
/**
* A helper file for providing autocomplete information for your IDE.
*
* This file should not be included in your code, only analyzed by your IDE!
*
* @author Bubba Hines <bubba@stechstudio.com>
*/
@bubba-h57
bubba-h57 / phpbuild.sh
Created February 7, 2019 15:27
Build Similar PHP 7.2 & 7.3 Debug/Pthreaded Builds on the same system using phpbrew
#!/usr/bin/env bash
brew install openssl
brew install gd
brew install imagemagick
brew install libmemcached
brew services start memcached
phpbrew install --name 7.3-debug php-7.3 \
+zts \
+debug \
@bubba-h57
bubba-h57 / LockerRoom.py
Created May 1, 2018 20:18
Simple Distributed Advisory Locking Class for AWS Lambda
import os
import redis
import logging
import string
import random
from collections import namedtuple
from redis.exceptions import RedisError
Lock = namedtuple("Lock", ("valid", "resource", "key", "ttl"))
@bubba-h57
bubba-h57 / test.php
Created September 26, 2017 12:13
Have a function timeout on itself
<?php
try {
test();
} catch (TimeoutException $e) {
$e->handle();
} catch (Throwable $t) {
printf('Some other error occured. %s', $t->getMessage());
}
@bubba-h57
bubba-h57 / luthers_insults.js
Created August 25, 2017 14:25
Generate Random Citations of Martin Luther Insults
var insults = [
{
"work": "Heidelberg Disputation from Vol. 31 of Luther's Works.",
"quotes": [
{
"page": "51",
"quote": "Your sin smells to high heaven."
}
]
},
@bubba-h57
bubba-h57 / NonBreakableSnakeCase.php
Last active July 5, 2017 15:35
Convert studly, traditional snake, and kebob case strings into a non-breakable snake case string.
<?php
function non breakable snake case($value, $delimiter = ' ')
{
$value = ucwords(str_replace(['-', '_'], ' ', $value));
if (! ctype_lower($value)) {
$value = preg_replace('/\s+/u', '', $value);
$value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value), 'UTF-8');
}
@bubba-h57
bubba-h57 / .php_cs
Created June 21, 2017 14:05
My favorite Code Style Rules for php-cs-fixer
<?php
$rules = [
'@PSR2' => true,
// Additional Non-PSR2 rules
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_double_arrow' => true],
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
@bubba-h57
bubba-h57 / helpers.php
Created June 19, 2017 12:38
Various PHP Helper Functions I Regularly Use
<?php
if (!function_exists('human_filesize')) {
/**
* From http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
*
* @param int $bytes
* @param int $decimals
* @param string $separator
*
* @return string
@bubba-h57
bubba-h57 / times.sh
Created April 25, 2017 14:06
Run a command 100 times and get the average.
#!/bin/bash
rm -f /tmp/mtime.$$
for x in {1..100}
do
/usr/bin/time -f "real %e user %U sys %S" -a -o /tmp/mtime.$$ $@
tail -1 /tmp/mtime.$$
done
@bubba-h57
bubba-h57 / Homestead.yaml
Last active October 11, 2017 15:45
after.sh for Homestead
variables:
- key: STS_USER
value: "<your name>"
- key: STS_HOME
value: "<your customized home dir>"
- key: AWS_ACCESS_KEY_ID
value: "<your key>"
- key: AWS_SECRET_ACCESS_KEY
value: "<your secret>"
- key: AWS_DEFAULT_REGION