Skip to content

Instantly share code, notes, and snippets.

View jessegreathouse's full-sized avatar

Jesse Greathouse jessegreathouse

View GitHub Profile
@jessegreathouse
jessegreathouse / gist:707195
Created November 19, 2010 21:19
php you vex me.
<?php
//a list of unknown size
$bars=array();
// I want to walk through the array and take the first one that isn't empty
//this code looks wierd but it's a compromise.
foreach ($bars as $bar) { if ($foo = $bar) { break 1; }
//this is what i wanted to do
while (!$foo = current($bars)) {
next($bars);
@jessegreathouse
jessegreathouse / index.php
Created April 6, 2011 19:25
how to use custom headers and footers with CDclient [theoretically]
<?php
/*
We've built in the ability to only select certain content by using CSS selectors. This may yield unexpected results if not used carefully and is subject to change. for example, you may wish to only select the body head and form, and you may wish to store those things in variables so you can mix in your own content. Here is how you'd do something like that:
*/
include('library.php');
$client = new cdClient();
$client->request();
$client->initHeaders();
<?php
//how to merge custom options into your client upon instantiation
$options = array(
'server' => 'http://staging.collegedegrees.com',
);
$client = new cdClient($options);
$client->request();
$client->initHeaders();
@jessegreathouse
jessegreathouse / fig1-1_MagicMethodsBefore.php
Created May 6, 2011 14:34
Before and After Magic Methods in entities. What originally I tried to do was using __get and __set but the implementation of that made my entities properties virtually public, which was something that's a no no with doctrine. So instead of using __get __
<?php
/** @MappedSuperclass */
class MagicMethods
{
public function __get($name) {
return $this->{strtolower($name)};
}
public function __set($name, $value)
@jessegreathouse
jessegreathouse / CustomerPurchaseControlTest.php
Created June 9, 2011 01:23
#Heres a quick mock up of an idea to use fixtures in a non-symfony way to aid in unit testing. The Unit testing fixtures wont get mixed up with application oriented fixtures.
<?php
#Tests/Service/CustomerPurchaseControlTest.php
namespace CodeMeme\CommerceBundle\Tests\Service;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use CodeMeme\CommerceBundle\Tests\Fixtures\Job\LoadJobQueueControlTestData;
use CodeMeme\CommerceBundle\Model\Cart\ActiveCart;
use CodeMeme\CommerceBundle\Entity\Purchase;
@jessegreathouse
jessegreathouse / SyncHosts.php
Created June 22, 2011 20:31
This is a class for one-time-engineering to reformat our login database to the new rendition. I needed to run this before I created the migration classes, otherwise there would be no data in the migration. I shouldn't need this engineering again but JUST
<?php
namespace CollegeDegrees\EdudirectBundle\Command\Util;
use CollegeDegrees\EdudirectBundle\Entity\Host;
use CollegeDegrees\EdudirectBundle\Entity\Login;
use CollegeDegrees\EdudirectBundle\Entity\Publishers;
use Doctrine\ORM\Query;
use Symfony\Component\Yaml\Yaml;
@jessegreathouse
jessegreathouse / JobExample.php
Created August 18, 2011 14:37
How to create a job in the NineThousandJobqueueBundle code
<?php
namespace MyApp\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use NineThousand\Jobqueue\Job\StandardJob as Job;
use NineThousand\Bundle\NineThousandJobqueueBundle\Vendor\Doctrine\Adapter\Job\Symfony2DoctrineJobAdapter as JobAdapter;
use NineThousand\Bundle\NineThousandJobqueueBundle\Entity\Job as JobEntity;