Skip to content

Instantly share code, notes, and snippets.

@pbowyer
pbowyer / nuffield.js
Created July 17, 2011 20:07
Sample (non-working) node.io scraper
var nodeio = require('node.io');
exports.job = new nodeio.Job({max: 1, retries: 1, auto_retry: false, jsdom: true }, {
input: ["http://www.nuffieldtheatre.co.uk/events/category/C81/"],
run: function (search_page) {
this.getHtml(search_page, function(err, $) {
//Handle any request / parsing errors
if (err) this.exit(err);
@pbowyer
pbowyer / RelDate.php
Created December 5, 2011 08:55 — forked from arnaud-lb/RelDate.php
4 lines relative date formatter with DateInterval and Symfony2 Translator
<?php
use Symfony\Component\Translation\TranslatorInterface;
function format(\DateTime $date, TranslatorInterface $translator)
{
$diff = date_create()->diff($date);
$seconds = $diff->days * 86400 + $diff->h * 3600 + $diff->i * 60 + $diff->s;
$format = $translator->transChoice('reldate', $seconds);
@pbowyer
pbowyer / gist:1485532
Created December 16, 2011 10:28 — forked from lazymanc/gist:1485516
api routing
# artist api
artist:
url: /artist/*
param: { module: artist, action: methodSwitch }
# info api
info:
url: /info/*
param: { module: info, action: methodSwitch }
@pbowyer
pbowyer / gist:1485534
Created December 16, 2011 10:29 — forked from lazymanc/gist:1485485
symfony 1.4 api action class
<?php
/**
* Extended action class for adding json rendering functionality.
*
* @author Phil Moorhouse <phil@ticketline.co.uk>
* @package tlv4
* @subpackage api
*/
class tlApiActions extends sfActions
{
@pbowyer
pbowyer / gist:1485535
Created December 16, 2011 10:29 — forked from lazymanc/gist:1485490
basic symfony html5 layout
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php echo $sf_content ?>
</body>
@pbowyer
pbowyer / gist:1485537
Created December 16, 2011 10:29 — forked from lazymanc/gist:1485493
debug template
<?php var_dump($data); ?>
@pbowyer
pbowyer / gist:1486179
Created December 16, 2011 14:12 — forked from lazymanc/gist:1486168
sfWebBrowser cached version
<?php
/**
* Extended version of sfWebBrowser to provide caching functionality
*/
class tlCachedBrowser extends sfWebBrowser
{
protected $cache_expiration = 86400; // 1 day default cache
/**
class ProjectConfiguration extends sfProjectConfiguration
{
public function configureDoctrine(Doctrine_Manager $manager)
{
require_once sfConfig::get('sf_lib_dir') . '/../lib/cache/gyDoctrineCacheApc.class.php';
$cacheDriver = new gyDoctrineCacheApc();
$cacheDriver->setNamespace(md5(sfConfig::get('sf_root_dir')));
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
<?php
set_time_limit(0);
error_reporting(E_ALL);
define("_MPDF_TEMP_PATH", '/tmp/');
/*
My composer.json
{
@pbowyer
pbowyer / functions.php
Last active August 29, 2015 13:57
To show where one Wordpress template begins and another finishes, open wp-includes/template.php and replace function `load_template` with the one below. Then add the contents of `functions.php` to the end of your theme's custom functions file.
<?php
add_filter( 'template_include', 'mysite_template_include', 1000 );
function mysite_template_include( $template ){
$comment_template = str_replace(array(TEMPLATEPATH, STYLESHEETPATH), '', $template);
echo "<!-- Template: $comment_template -->\n";
include( $template );
echo "<!-- End Template: $comment_template -->\n";
return false;