Skip to content

Instantly share code, notes, and snippets.

View chadicus's full-sized avatar

Chad Gray chadicus

View GitHub Profile
@chadicus
chadicus / libraries.json
Created January 16, 2017 23:08
libraries collection for pholio db
This file has been truncated, but you can view the full file.
{ "_id" : "chadicus-csv", "owner" : "chadicus", "package" : "csv", "repository" : "chadicus/csv-php", "source" : "https://github.com/chadicus/csv-php", "stars" : 0, "watchers" : 1, "forks" : 0, "issues" : 0, "avatar" : "https://avatars.githubusercontent.com/u/1182337?v=3", "keywords" : [ "csv", "delimited", "file", "io" ], "description" : "Collection of classes to work with csv files", "tags" : [ "dev-master", "v1", "v0" ], "dev-master" : "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<project title=\"API Documentation\" version=\"2.8.5\"><partials/><file path=\"Reader.php\" generated-path=\"Reader.html\" hash=\"d7384edf73c636c87e502f7e2b63f3e1\" package=\"Default\"><docblock line=\"0\"><description/><long-description/><tag name=\"package\" line=\"0\" description=\"Default\"/></docblock><class final=\"false\" abstract=\"false\" namespace=\"Chadicus\\Csv\" line=\"8\" package=\"Default\"><extends/><implements>\\Iterator</implements><name>Reader</name><full_name>\\Chadicus\\Csv\\Reader</full_name><docblock line=\"
@chadicus
chadicus / xml_to_array_example.php
Last active November 5, 2015 21:26
Simple example showing XML to array functionality
<?php
//assumes "chadicus/dom" : "dev-master" requirement in composer.json
require_once 'vendor/autoload.php';
use Chadicus\Util;
$xml = <<<XML
@chadicus
chadicus / repository_pattern.php
Created October 5, 2015 19:53
Repository Implementation
<?php
interface UserFactoryInterface
{
/**
* Create a new instance of UserEntityInterface
*
* @param array $data The data for the new user
*
* @return UserEntityInterface
@chadicus
chadicus / explode_with_default.php
Last active August 29, 2015 14:26
Ensure all offsets exist when exploding a string.
<?php
//User input for a Name field
$input = 'John';
//Produces PHP Notice: Undefined offset: 1
list($firstName, $lastName) = explode(' ', $input);
//ensure offset 1 always exists
list($firstName, $lastName) = explode(' ', $input) + [1 => null];
@chadicus
chadicus / preg_grep.php
Created July 29, 2015 00:44
Use preg_grep and array_column to perform simple keyword searches on a data array
<?php
$json = file_get_contents('https://gist.githubusercontent.com/chadicus/aaa4714944a6340d8184/raw/22d8df40f0ab64b20ca54d08a1fa60308ea38278/books.json');
$books = json_decode($json, true);
$matched = preg_grep('/xml/i', array_column($books, 'description'));
@chadicus
chadicus / books.json
Created July 29, 2015 00:40
Books data array
[
{
"author": "Gambardella, Matthew",
"title": "XML Developer's Guide",
"genre": "Computer",
"price": 44.95,
"publishDate": 970372800,
"description": "An in-depth look at creating applications with XML."
},
{
@chadicus
chadicus / datetimezone.php
Created February 9, 2015 15:27
DateTimeZone Test
<?php
$timezone = new \DateTimeZone('HST');
assert($timezone->getName() === 'Pacific/Honolulu', 'Timezone name was not Pacific/Honolulu');
@chadicus
chadicus / getPaths.php
Last active August 29, 2015 14:01
Converts a multi-dimensional array to a single dimensional array with path keys
<?php
function getPaths($arrayOrScalar, $delimiter = '/', array $paths = array(), $string = '')
{
if (is_scalar($arrayOrScalar)) {
$paths[$string] = $arrayOrScalar;
return $paths;
}
if (!is_array($arrayOrScalar)) {
@chadicus
chadicus / build.php
Created May 12, 2014 20:50
Simple build script for Chadicus PHP projects (PHP >= 5.3)
#!/usr/bin/env php
<?php
chdir(__DIR__);
$returnStatus = null;
passthru('composer install --dev', $returnStatus);
if ($returnStatus !== 0) {
exit(1);
}
@chadicus
chadicus / db-mysql.php
Created April 15, 2014 15:38
Zend Mysql Connection
<?php
require_once 'vendor/autoload.php';
$datax = Zend_Db::factory('Mysqli', [
'host' => 'host',
'username' => 'username',
'password' => 'password',
'dbname' => 'database name',
]);