Skip to content

Instantly share code, notes, and snippets.

View peterjmit's full-sized avatar

Peter Mitchell peterjmit

View GitHub Profile
@peterjmit
peterjmit / indexing_columns_doctrine2.yml
Created February 16, 2012 16:00
Mapping Indexes with Yaml in Doctrine 2
# Example. A category entity with a url friendly 'slug'
# we want to index on this slug because we will be using it
# to query with.
Vendor\CategoryBundle\Entity\Category:
type: entity
table: category
indexes:
# the name of the index
category_slug_idx:
@peterjmit
peterjmit / host_exports
Created February 18, 2012 11:38
Settings for NFS and host only networking in vbox
# EXPORTS FILE (OSX)
#
# /etc/exports
#
# You can change the directory to wherever
# you store your project files
/Users/user_name/code -alldirs -mapall=501:501
# EXPORTS FILE (ubuntu 11.04)
#
@peterjmit
peterjmit / gist:1950591
Created March 1, 2012 15:41
Node.js Twitter/Facebook API JSONP Proxy
var express = require('express'),
graph = require('fbgraph'),
oauth = require('oauth');
var app = module.exports = express.createServer();
var twConfig = {
consumer_key: 'CONSUMER_KEY',
consumer_secret: 'CONSUMER_SECRET',
request_token_url: 'https://api.twitter.com/oauth/request_token',
@peterjmit
peterjmit / array_hyrdation.php
Created March 4, 2012 14:32
Array hydration Example
<?php
namespace Vendor\Prefix\Repository;
use Doctrine\ORM\EntityRepository;
class ProductRepository extends EntityRepository
{
public function find($id)
{
@peterjmit
peterjmit / doctrine_native_pagination.php
Created March 6, 2012 12:37
Helper function for paginating with native doctrine 2.2 class
<?php
function paginate(Doctrine\ORM\Query $query, $page, $limit, $fetchJoinCollection = true)
{
// If we don't have a page just return the result
if( ! $page && ! $limit)
{
return $query->getResult();
}
@peterjmit
peterjmit / doctrine_cache_driver.php
Created March 6, 2012 17:47
Get the Result Cache from the doctrine entity manager
<?php
class Foo
{
private $_em;
public function __construct($entity_manager)
{
$this->_em = $entityManager;
}
@peterjmit
peterjmit / dont-do-this.php
Created March 12, 2012 14:38
Some Doctrine 2 Best Practices
<?php
$articles = $article_repository->findAll();
foreach($articles as $article)
{
echo $article->getTitle();
echo count($article->getComments());
}
@peterjmit
peterjmit / SomeController.php
Created March 30, 2012 11:21
Global Symfony 2 Config without Config Parsing
<?php
// src/Vendor/SomeBundle/Controller/SomeController.php
namespace Vendor\SomeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request;
class SomeController extends Controller
@peterjmit
peterjmit / deploy.rb
Created April 10, 2012 13:45
Create a parameters.ini file interactively when deploying with capifony
# This custom task for deploying a Symfony 2 application is set to run after deploy:setup
# is executed. It interactively ask a user for database details to create a parameters.ini
# thus avoiding having to manually on to the server and create it
#
# Helper function from http://stackoverflow.com/a/1662001/1041885
#
# Interactive parameter.ini generation adapted from http://adurieux.blogspot.co.uk/2011/10/using-capistrano.html
# ...
# ... Your deployment settings/tasks
@peterjmit
peterjmit / application.ini
Created April 12, 2012 15:09
Profiling Doctrine 2 with Zend Framework
# ../application/configs/application.ini
resources.doctrine.dbal.connections.default.sqlLoggerClass = "Doctrine\DBAL\Logging\DebugStack"
ZFDebug = 1