Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / gist:6621030
Created September 19, 2013 09:17
Git repository install via Composer for dev-master
{
"name": "andrewkirkpatrick/sample",
"description": "Sample project",
"homepage": "http://www.andrew-kirkpatrick.co.uk",
"repositories": [{
"type": "package",
"package": {
"name": "andrewkirkpatrick/library",
"version": "dev-master",
"source": {
@magickatt
magickatt / gist:7608776
Last active December 29, 2015 03:39
Mocking an API for unit testing in Zend Framework 2
<?php
// Mock JSON
$json = <<< JSON
{
"timestamp": 1385150462,
"stuff": {
"this": 2,
"that": 4,
"other": 1
@magickatt
magickatt / gist:7870244
Last active December 30, 2015 18:49
Add user roles on register with ZfcUser in Zend Framework 2
<?php
class Module
{
public function onBootstrap(MvcEvent $e)
{
/*
* Other module code as usual...
*/
@magickatt
magickatt / gist:8397082
Created January 13, 2014 09:26
Wildcard VirtualHosts
NameVirtualHost *:80
<VirtualHost *:80>
VirtualDocumentRoot "/usr/local/zend/apache2/htdocs/%1/public"
<Directory "/usr/local/zend/apache2/htdocs/%1/public">
Allow From All
</Directory>
</VirtualHost>
@magickatt
magickatt / gist:8425277
Created January 14, 2014 20:40
Sports Points r/dailyprogrammer
<?php
if ($argc <= 1)
exit("No score was passed\n");
$inputScore = (integer) $argv[1];
$x = 0;
$validScores = array($x);
print "Input score: $inputScore\n";
while ($x <= $inputScore) { // Do until last valid score is higher than input score
$array = $validScores;
@magickatt
magickatt / gist:8427248
Last active January 3, 2016 07:09
Route-based parameters in Zend Framework 2 view helper
<?php
// Output the URL in the view
echo $this->url('somewhere',
array('controller' => 'company',
'action'=>'edit',
'id' => $company->id
)
);
@magickatt
magickatt / gist:8427282
Last active January 3, 2016 07:09
Query-based parameters in Zend Framework 2 view helper
<?php
// Output the URL in the view
echo $this->url('somewhere',
array('controller' => 'company',
'action'=>'edit'
),
array('query' =>
array('id' => $company->id)
)
@magickatt
magickatt / gist:8427376
Last active January 3, 2016 07:09
Sample segment route configuration in Zend Framework 2
<?php
return array(
'router' => array(
'routes' => array(
'somewhere' => array(
'type' => 'segment',
'options' => array(
'route' => '/company/edit/[/:id]',
),
@magickatt
magickatt / gist:8524328
Created January 20, 2014 17:14
Truncate a string to whole words for a given string length
<?php
$model = "Big ultra super car with mega turbo charger";
$limit = 10;
$words = explode(' ', $model);
$sentence = '';
foreach ($words as $word) {
$sentence .= $word . ' ';
@magickatt
magickatt / gist:8596331
Created January 24, 2014 12:24
Recursively delete the contents of a directory
<?php
/**
* Delete the contents of a directory (recursively by default)
* @todo Handle recursion when calls return false
* @param string $path Path to the directory
* @param boolean $recursive Whether to delete recursively (true by default)
* @return boolean Success or failure
*/
function deleteDirectoryContents($path, $recursive = true)