Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
@cspray
cspray / aysnc-test-example.php
Created February 9, 2019 15:52
AsyncTestCase example with amphp
<?php
// We assume that your PHPUnit bootstrap will include the appropriate class loader and setup your environment
use Amp\Delayed;
use Amp\Promise;
use Amp\PHPUnit\AsyncTestCase;
use function Amp\call;
<?php
abstract class AsyncTestCase extends \PHPUnit\Framework\TestCase {
public function runTest() {
Loop::run(function() {
$watcherId = Loop::delay(1500, function() {
Loop::stop();
$this->fail('The asynchronous test was expected to finish before the 1500 millisecond time limit');
});
@cspray
cspray / php-ds-stubs.php
Created June 26, 2016 01:23
A gist to create a PHP class for stubbing from a classname
<?php
declare(strict_types = 1);
/**
* @license See LICENSE file in project root
*/
require_once '/spraybot-app/vendor/autoload.php';
@cspray
cspray / route-handlers.php
Created August 23, 2015 00:32
Labrador HTTP - Possible Route Handlers
<?php
use Symfony\Component\HttpFoundation\Response;
// Have a simple enough Response? No fuss, no muss just pass a Response object
$engine->get('/', new Response('Hello World'));
// Need something a tad more advanced? How about an anonymous functions!
$engine->get('/', function() {
return new Response('Hello World');
@cspray
cspray / labrador-quick-start.php
Last active August 29, 2015 14:27
labrador.cspray.net quick-start example
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Cspray\Labrador\Services;
use Cspray\Labrador\Engine;
use Cspray\Labrador\Event\ExceptionThrownEvent;
/** @var Auryn\Injector $injector */
$injector = (new Services)->createInjector();
Fuck it.
| | |
)_) )_) )_)
)___))___))___)\
)____)____)_____)\
_____|____|____|____\\__
---------\ SHIP IT /---------
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
^^^^ ^^^^ ^^^ ^^
@cspray
cspray / insert-into-to-array.php
Last active December 28, 2015 03:09
A very rough implementation to convert an INSERT INTO SQL statement to an appropriate array structure for inserted values. There are caveats to the use of this function and full error handling has not yet been implemented.
<?php
function convertInsertIntoToArray($sql) {
$text = \explode(\PHP_EOL, $sql);
$data = array();
if (!empty($text)) {
$firstLine = \preg_replace('/\s+$/', '', $text[0]);
if ($firstLine === 'INSERT INTO') {
if (\preg_match('/\(.+\)/', $text[1], $cols)) {
$cols = \explode(',', \preg_replace('/\(|\)|\s|\`/', '', $cols[0]));
@cspray
cspray / 000-java-php-diff.md
Last active July 5, 2023 12:29
A list of differences I've noticed between PHP and Java.

Java vs. PHP

As is pretty obvious by my blog, GitHub repos and my job I'm a PHP developer. I'm also pretty adept with JavaScript and SQL. Lately I've been getting back into Java development a little more seriously. This gist is a series of short articles about some of the differences I've noticed between PHP and Java.

To be specific my Java development recently has been web development using Google App Engine. I am intending to create a RESTful API utilizing the language.

The differences discussed are not intended to be an indictment against either language. Some things about PHP I really like, some things about PHP I really dislike. The same goes for Java. Some things PHP is really good for and other things Java is really good for. This is not meant to be a religious war between languages.

I realize that in a way this is comparing apples and oranges. PHP is a dynamic, interpreted (althought yes it is still compiled) scripting language while Jav

@cspray
cspray / my-alabama-football-story.md
Last active October 13, 2015 11:37
My story of Alabama football

My story of Alabama football

I was born to the parents of SEC fans and, although I didn't move to the state of Alabama until 1992, Alabama football had been ingrained in me. From pictures of a baby me in a Bama bib or all the stories of Alabama football and the Bear, I was saying 'Roll Tide Roll' way before I actually lived in the state. SEC fans might notice that 1992 was a year that Alabama won an SEC and National Championship. Unfortunately it appears as if I was a harbinger of doom for Alabama football.

The 1993 year of Alabama football was the beginning of the end for the program. Once I entered the state Alabama football's program spiraled, truly hitting rock bottom. Auburn's current state of affairs is just the beginning of what the Alabama program endured. NCAA sanctions soon started rolling in and the slip down had begun. After a few reasonably successful seasons after the '92 Championship Mike DuBose came on board. Only more sanctions came against the program and we suffered one of the

<!--
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░░░░░░░░░░░░░░░░░░░░░
░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░░░░░░░░░░░░░░░░░░░░░
░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░░░░░░░░░░░░░░░░░░░░░
░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░░░░░░░░░░░░░░░░░░░░░
█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█░░░░░░░░░░░░░░░░░░░░
█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█░░░░░░░░░░░░░░░░░░░░
░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░░░░░░░░░░░░░░░░░░░░░