Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
@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 / cv-ring-description.md
Created January 27, 2012 15:55
A brief description of cv-ring and cv-pls

What is 'cv-ring', 'cv-pls' and 'delv-pls'

In the Stack Overflow PHP chat you may notice the regulars using tags like cv-pls, cv-ring and delv-pls. These tags are used only in the chat room to communicate with other users that a question or answer may need more votes to be closed or deleted. The PHP tag has a lot of inferior quality and duplicative information on Stack Overflow. We feel that inferior quality questions bring down the site and make it harder to find good information, particularly about PHP. By closing and merging these questions as appropriate you'll find the information you need quicker.

  • cv-ring is just a 'funny name' we give to the group of regulars who use the tags
  • cv-pls is an in-chat tag that communicates "Hey, this question may be of inferior quality. Check it out and, if you feel appropriate, cast a close vote."
  • delv-pls is an in-chat tag that communicates "Hey, this question has alr
@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

@cspray
cspray / xdebug_ini_settings.php
Created May 14, 2012 14:04
Xdebug ini settings to show more info on var_dump
<?php
// Displays all array indices and object properties
ini_set('xdebug.var_display_max_children', -1);
// Displays all string data dumped
ini_set('xdebug.var_display_max_data', -1);
// Controls nested level displayed, maximum is 1023
ini_set('xdebug.var_display_max_depth', -1);