Skip to content

Instantly share code, notes, and snippets.

View bshaffer's full-sized avatar

Brent Shaffer bshaffer

View GitHub Profile
@bshaffer
bshaffer / Doctrine_Collection_Extra.class.php
Created July 20, 2010 18:15
order your result set by an array
<?php
/*
* Extended Doctrine Query class providing a few additional functions
* for wrapping your where clauses more efficiently
*/
class Doctrine_Query_Extra extends Doctrine_Query
{
public function addOrderBy($orderby, $values = null)
{
if ($values !== null)
#!/usr/bin/env ruby
while line = STDIN.gets do
line.sub!(/\d,\"/) {|s| s.sub(',"', ' - ')}
line.sub!(/\d,/) {|s| s.sub(',', ' - ')}
line.gsub!('""', '"');
line.sub!(/"$/, '');
puts line
end
<div class="sf_admin_pagination">
<?php $img = image_tag(sfConfig::get('sf_admin_module_web_dir').'/images/first.png', array('alt' => __('First page', array(), 'sf_admin'), 'title' => __('First page', array(), 'sf_admin'))) ?>
<?php echo link_to_current($img, array('page' => 1)) ?>
<?php $img = image_tag(sfConfig::get('sf_admin_module_web_dir').'/images/previous.png', array('alt' => __('Previous page', array(), 'sf_admin'), 'title' => __('Previous page', array(), 'sf_admin'))) ?>
<?php echo link_to_current($img, array('page' => $pager->getPreviousPage())) ?>
<?php foreach ($pager->getLinks() as $page): ?>
<?php if ($page == $pager->getPage()): ?>
<?php
function link_to_current($title, $params = array(), $options = array())
{
$currentRoute = sfContext::getInstance()->getRouting()->getCurrentRouteName();
$currentParams = sfContext::getInstance()->getRequest()->getParameterHolder()->getAll();
unset($currentParams['module'], $currentParams['action']);
#!/usr/bin/php
<?php
if (!isset($argv) || !count($argv))
{
throw new Exception("Please provide path of crons to flush");
}
foreach ($argv as $path)
{
@bshaffer
bshaffer / gist:472862
Created July 12, 2010 18:28
Sample Crontab
[email protected]
# run daily crons
5 1 * * 1 /path/to/project/cron.php --daily > /var/log/cron_prod.log
10 1 * * 1 /path/to/other-project/cron.php --daily > /var/log/cron_dev.log
# run weekly crons
0 0 * * * /path/to/project/cron.php --weekly > /var/log/cron_prod.log
5 0 * * * /path/to/other-project/cron.php --weekly > /var/log/cron_dev.log
<?php
class sfAdminRouteCollection extends sfDoctrineRouteCollection
{
protected function generateRoutes()
{
parent::generateRoutes();
if (!isset($this->options['with_export']) || $this->options['with_export'])
{
public function getExportFilename()
{
return "<?php echo isset($this->config['export']['filename']) ? $this->config['export']['filename'] : ucfirst($this->getModuleName()).'_Export' ?>_".date("Y-m-d_Hi");
<?php unset($this->config['export']['filename']) ?>
}
<?php
/**
*
*/
class sfFactory
{
protected static
$lastRandom = array(),
$lastIncrement = array();
@bshaffer
bshaffer / logdebug.sh
Created June 2, 2010 18:05
useful for traversing your symfony log files and debugging them
# The first argument is the application (default: frontend)
export app=$1
if [ ! -n "$app" ]; then
export app="frontend"
fi
# The second argument is the environment. (default: dev)
export env=$2