Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / gist:5412216
Created Apr 18, 2013
Zend Server 6.0 default http (port 80) virtual host
View gist:5412216
Include "/usr/local/zend/etc/sites.d/http/__default__/0/*.conf"
<Directory "/usr/local/zend/var/apps/http/__default__/0/">
Allow From All
</Directory>
@magickatt
magickatt / gist:5412240
Created Apr 18, 2013
Zend Server 6.0 lighttpd (port 10088) virtual host
View gist:5412240
Include "/usr/local/zend/etc/sites.d/http/__default__/0/*.conf"
<Directory "/usr/local/zend/var/apps/http/__default__/0/">
Allow From All
</Directory>
@magickatt
magickatt / gist:5434032
Last active Dec 19, 2017
Safe __toString method
View gist:5434032
<?php
/**
* String representation of this object
* @return string
*/
public function __toString()
{
try {
return (string) $this->name;
@magickatt
magickatt / gist:5466324
Created Apr 26, 2013
Write data directly to FTP server without saving on the local filesystem
View gist:5466324
<pre>
<?php
// Host
$host = 'yourhostname.com';
$port = 21;
$timeout = 90;
// Credentials
$username = 'yourusername';
@magickatt
magickatt / gist:5590689
Created May 16, 2013
Concrete5 fixing missing uploaded files single page controller
View gist:5590689
<?php
class TestFixfilesController extends Controller
{
public function on_before_render()
{
$originalsDirectory = '/var/www/your-website.com/missing-files/';
$originalFilenames = scandir($originalsDirectory);
@magickatt
magickatt / gist:5985451
Created Jul 12, 2013
Zend Log MySQL CREATE TABLE query for Zend Framework 1 or 2
View gist:5985451
CREATE TABLE `log` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`priority` tinyint(1) NOT NULL,
`priorityName` varchar(5) CHARACTER SET ascii NOT NULL DEFAULT 'DEBUG',
`message` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
@magickatt
magickatt / gist:6040703
Last active Dec 20, 2015
Convert a directory of files into a directory of directories with the same names
View gist:6040703
<?php
$directories = scandir('/some_directory');
array_shift($dirs);
array_shift($dirs);
$baseDirectory = '/another_directory';
foreach($directories as $directory) {
$filename = current(explode('.', $directory));
@magickatt
magickatt / gist:6130199
Last active Sep 19, 2022
Output CSV to browser
View gist:6130199
<?php
// Headings and rows
$headings = array('ID', 'Name', 'Colour');
$array = array(
array(1, 'Apple', 'Green'),
array(2, 'Banana', 'Yellow'),
array(3, 'Orange', 'Orange'),
);
@magickatt
magickatt / gist:6223818
Created Aug 13, 2013
Late Static Binding namespace resolution in PHP
View gist:6223818
<?php
/*
* "Late Static Binding" namespace
*/
$class = get_called_class();
$lastSlashPosition = strrpos($class, '\\');
$namespace = substr($class, 0, $lastSlashPosition);
@magickatt
magickatt / gist:6621005
Created Sep 19, 2013
Git repository install via Composer
View gist:6621005
{
"name": "andrewkirkpatrick/sample",
"description": "Sample project",
"homepage": "http://www.andrew-kirkpatrick.co.uk",
"repositories": [{
"type": "package",
"package": {
"name": "andrewkirkpatrick/library",
"version": "0.1.0",
"source": {