Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
Fuck it.
| | |
)_) )_) )_)
)___))___))___)\
)____)____)_____)\
_____|____|____|____\\__
---------\ SHIP IT /---------
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
^^^^ ^^^^ ^^^ ^^
@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();
@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 / php_error_handling_closure.php
Created December 31, 2011 04:26
PHP Error Handling Closure
<?php
// A closure to store error information in an array
$errors = array();
$errorCallback = function($severity, $message, $file = null, $line = null, $context = null) use (&$errors) {
$normalizeSeverity = function() use ($severity) {
$severityMap = array(
Dear Prof. X,
I have serious concerns with some of the material that you covered in class in regards to browser sniffing and the use of http://www.w3schools.com/ as a reference guide.
Browser Sniffing
While there are occasions on the edge where browser sniffing may be necessary this is almost never the case when first starting out. I disagree that browser sniffing should be used as a means of determining functionality and so do a lot of other developers in the industry.
http://ryanmorr.com/archives/brower-detection-necessary-or-negligent
http://jibbering.com/faq/notes/detect-browser/
@cspray
cspray / gist:1822310
Created February 14, 2012 01:25
The code that generated the SO data for cspray.github.com/100-greatest-programming-books.html
<?php
$questionUrl = 'https://api.stackexchange.com/2.0/questions/1711/answers?site=stackoverflow&sort=votes&filter=withbody&page=1&pagesize=100';
$curl = curl_init($questionUrl);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
$response = curl_exec($curl);
$response = json_decode($response, true);
@cspray
cspray / gist:1833311
Created February 15, 2012 04:50
A snippet of code used to gather a SO Q&A that may be deleted soon
<?php
$questionUrl = 'https://api.stackexchange.com/2.0/questions/309300?page=1&pagesize=1&order=desc&sort=votes&site=stackoverflow&filter=!LP4hJGlAKQVCM-iPRmI8NA';
$curl = curl_init($questionUrl);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
$questionResponse = curl_exec($curl);
$answerUrl = 'https://api.stackexchange.com/2.0/answers/309622?order=desc&sort=activity&site=stackoverflow&filter=!akczUagg4t0rkU';
@cspray
cspray / gist:2040791
Created March 15, 2012 00:48
OOP storage benchmark omgz
<?php
error_reporting(-1);
class Tester {
protected $something;
public function __construct($something) {
$this->something = $something;
@cspray
cspray / why-xml-sucks.md
Created May 2, 2012 15:18
Why we don't like XML

I was recently working with the FogBugz XML API and I needed to get some attribute value from the response. Below is the perfectly legal call chain needed to get an attribute value from my preferred XML parser, DOMDocument:

$case_id = $dom_document->getElementsByTagName('case')->item(0)->attributes->getNamedItem('ixBug')->nodeValue;

Assuming FogCreek chose to go with a JSON API for FogBugz we could expect something along these lines to get the same value:

$case_id = $json-&gt;case-&gt;ixBug
@cspray
cspray / gist:2629749
Created May 7, 2012 19:07
Outlook Rant

Recently I started working on a Windows based system and, by extension, Outlook. I'm not really a power email user and I can get by with just about any email client...as long as I can provide rules for emails so that my inbox isn't chock-full of crap. Fortunately, Outlook 2010 fully supports a wide variety of rules that should be able to handle just about any weird email routing you want. Overall, I really like the rule support provided by Outlook.

However, the support provided for group based rules is absolutely horrendous and the complete opposite of a good user experience. You see, Outlook has the ability to store and manage contacts...to include creating a group of contacts. You can email everybody in the group or setup a rule to route emails from the group to a specific folder. But, if you create a group-based rule Outlook throws up all over itself and says that the group must be converted into a list of individual contacts. The rub comes when you add, or remove, a contact from a group. The asso