Skip to content

Instantly share code, notes, and snippets.

@jaywilliams
jaywilliams / csv_to_array.php
Created April 30, 2010 23:18
Convert a comma separated file into an associated array.
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active July 21, 2024 01:20
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@lisachenko
lisachenko / SplClassLoader.php
Created November 3, 2011 06:13 — forked from jwage/SplClassLoader.php
PSR-0 SplClassLoader
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@weierophinney
weierophinney / ViewLayerIdeas.php
Created February 9, 2012 18:09
Brainstorming for ZF2 view layer
<?php
// The default strategy would add a listener to Application::dispatch() at high
// priority. This would inject a ViewModel instance with the layout template set
// as the template, no capture_to value, and a false terminal flag.
// The default strategy would also listen to Dispatchable::dispatch() at low
// priority; a returned ViewModel instance would be injected into the MvcEvent
// as the ViewModel. At this time, we'd also check for a template on the
// ViewModel, and if none found, auto-determine it and inject it based on the
@shevron
shevron / Uri.php
Created June 18, 2012 18:18
Zend Framework 2.0 Uri validator
<?php
namespace Zend\Validator;
class Uri extends AbstractValidator
{
const INVALID = 'uriInvalid';
protected $_messageTemplates = array(
self::INVALID => "Provided input is not a valid URL"
@SocalNick
SocalNick / filterChain.php
Created June 27, 2012 18:23
ZF2 FilterChain Sample Configuration
<?php
// Convert "socalnick.dev.phantom.www.ign.com" or "www.ign.com" to "WwwIgnCom"
$filter = new Zend\Filter\FilterChain(array(
'filters' => array(
array(
'name' => 'pregReplace',
'options' => array(
'match' => '/^(.*phantom\.)?([^:]+)(:\d+)?$/i',
'replace' => '$2',
),
@noopable
noopable / Module.php
Created July 18, 2012 10:20 — forked from juriansluiman/Module.php
Set a default locale for your application in Zend Framework 2
<?php
namespace Application;
use Locale;
use Zend\EventManager\Event;
use Zend\ModuleManager\Feature;
class Module implements
Feature\BootstrapListenerInterface
{
@santouras
santouras / Unique.php
Created August 29, 2012 14:13
Failing ZF2 validator requiring Service Locator
<?php
namespace My\Validator;
use Zend\Validator\AbstractValidator;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Unique extends AbstractValidator
@weierophinney
weierophinney / listener.php
Created August 29, 2012 19:54
Example of triggering another dispatch event in ZF2
<?php
use Zend\Mvc\Router\RouteMatch;
// Listener on dispatch.error event
$listener = function ($e) {
$app = $e->getTarget();
$events = $app->getEventManager();
$event = clone $e;
$matches = new RouteMatch(array('controller' => 'Some\Controller\Alias'));
$event->setRouteMatch($matches);
<?php
// module/Album/src/Album/Model/Album.php:
namespace Album\Model;
use Zend\Form\Annotation as Form;
class Album{
/**
* @Form\Required(false)
* @Form\Attributes({"type":"hidden"})