Skip to content

Instantly share code, notes, and snippets.

View jenkoian's full-sized avatar
👨‍💻
Works on my machine

Ian Jenkins jenkoian

👨‍💻
Works on my machine
View GitHub Profile
@jenkoian
jenkoian / gist:1111470
Created July 28, 2011 12:44
Some useful functions for use with dates
<?php
// Get array of months - useful for month dropdown for example
function getmonths() {
$months = array();
for ($m=1; $m<=12; $m++) {
$months[] = date('m', mktime(0,0,0,$m,1));
}
return $months;
@jenkoian
jenkoian / update_phpstorm.sh
Last active September 23, 2017 19:03
Small bash script to automatically install the latst PHPStorm EAP
#!/bin/bash
# Usage: ./update_phpstorm.sh http://download.jetbrains.com/webide/PhpStorm-EAP-126.36.tar.gz
echo "Downloading $1..."
sudo wget $1 -O phpstorm_eap.tar.gz
echo "Moving download..."
sudo mv phpstorm_eap.tar.gz /usr/local/bin/phpstorm_eap.tar.gz
@jenkoian
jenkoian / findLastModifiedThing.php
Last active December 11, 2015 22:09
Simple doctrine find last modified thing
<?php
/**
* @return null|\DateTime
*/
public function findLastModifiedThing()
{
$query = $this->createQueryBuilder('t')
->select('t.updated_at')
->orderBy('t.updated_at', 'desc')
@jenkoian
jenkoian / CacheControllerListener.php
Created January 29, 2013 21:40
Symfony2 listener to change the controller action based on whether it implements Cacheable or not
<?php
namespace Acme\DemoBundle\Listener;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Acme\DemoBundle\Controller\Cacheable;
class CacheControllerListener
{
/**
@jenkoian
jenkoian / Cacheable.php
Last active December 11, 2015 22:18
An interface used to implement caching on a controller
<?php
namespace Acme\DemoBundle\Controller;
/**
* Any controller that implements this interface will be eligible for caching. This works by an event
* listener that will look to see if the controller implements this interface and if it does, will call its
* getLastModifiedDate() method to check if the content has been modified or not. If not,
* then it will tell the controller to simply return the 304 response.
*
*/
@jenkoian
jenkoian / RestController.php
Created January 29, 2013 22:07
Abstract parent class for common rest controller methods.
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\View;
use Doctrine\ORM\EntityRepository;
abstract class RestController extends FOSRestController
{
@jenkoian
jenkoian / getLastModifiedDate.php
Created January 29, 2013 22:10
Simple example of getting the last modified date from a child controller
<?php
/**
* Find the last modified date
*
* @return \DateTime
*/
public function getLastModifiedDate()
{
$modifiedDate = $this->thingRepository->findLastModifiedThing();
@jenkoian
jenkoian / DateTimeType.php
Last active December 21, 2015 04:29
Doctrine2 DateTimeType to work around SQLServerPlatform compatibility issues between 2005/2008
<?php
namespace Acme\Bundle\DoctrineExtensions\DBAL\Types;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\DateTimeType as BaseDateTimeType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
class DateTimeType extends BaseDateTimeType
@jenkoian
jenkoian / bower.json
Last active December 30, 2015 13:09
bower.json sample
{
name: "acme",
version: "1.0.0",
description: "ACME demo application",
license: "MIT",
private: true,
ignore: [
"**/.*",
"node_modules",
"bower_components",
@jenkoian
jenkoian / layout.html.twig
Created December 6, 2013 23:16
bower twig setup
...
{% block javascripts%}
{% javascripts
'@AcmeDemoBundle/Resources/public/vendor/jquery/jquery.js'
'@AcmeDemoBundle/Resources/public/vendor/underscore/underscore.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}