Skip to content

Instantly share code, notes, and snippets.

View davidyell's full-sized avatar
🧙‍♂️
Weaving wondrous wisps

David Yell davidyell

🧙‍♂️
Weaving wondrous wisps
  • Senior Software Engineer
  • Southampton, Hampshire, UK
  • 14:33 (UTC)
View GitHub Profile
@davidyell
davidyell / howto.md
Last active February 25, 2016 10:04
Hooking up Netbeans to CodeSniffer
@davidyell
davidyell / required.scss
Created January 15, 2013 11:56
Adding required star to input
div.input{
&.required label:after{
content: "*";
}
&.error{
padding: 10px;
color: #B94A48;
background-color: #F2DEDE;
border: 1px solid #EED3D7;
border-radius: 4px;
@davidyell
davidyell / .htaccess
Last active December 11, 2015 03:28
.htaccess mod_rewrite utility rules
# Pass all the /forums stuff through the routing
RewriteCond %{REQUEST_URI} "/forums/"
RewriteRule (.*) $1 [L]
# If you need to lock down access to a folder, such as a CMS, then use the following
RewriteRule ^BusinessThing(.*)$ /maintenance.html [R=301,L]
# Redirecting everyone to maintenance
# Reference, http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/
RewriteCond %{REQUEST_URI} !/maintenance.html$
@davidyell
davidyell / cakepackages.nginxconf
Last active December 18, 2015 18:59
CakePHP on Nginx with php-fpm
server {
listen 80;
server_name cakepackages.ukwm157 cakepackages.dev;
# root directive should be global
root /Users/david/Sites/cakepackages/app/webroot;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$uri&$args;
@davidyell
davidyell / exampleFinds.php
Last active February 25, 2016 10:06
Find's in CakePHP
<?php
/*
These are some example files for CakePHP 2.x
Using containable
The problem with this is that if Group doens't match, then it will just return a blank array
dimension, because containable is just going to join the arrays in php
*/
@davidyell
davidyell / AppModel.php
Last active December 21, 2015 01:39
AppModel method to fix hasMany multi-select data
<?php
/**
* Transform a set of hasMany multi-select data into a format which can be saved
* using saveAll in the controller
*
* @param array $data
* @param str $fieldToSave
* @param int $deleteId
* @return array
*/
@davidyell
davidyell / php_if_statements.php
Last active February 25, 2016 10:08
The outcomes of testing things using just if() is.
<?php
/**
* As I never am quite sure the outcome of testing variables and arrays using
* just the plain if(), I thought I'd make a quick test so that I can refer to
* it when I next forget this!
*
* Manual ref: http://uk3.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
*/
$emptyArray = array(); // False
$filledArray = array('One','Two'); // True
@davidyell
davidyell / datetime.php
Created February 19, 2014 16:41
Using the PHP DateTime() object
<?php
date_default_timezone_set('UTC');
$deadline = '2013-09-13 13:00:00'; // UTC
$timezones = array(
'America/Los_Angeles',
'America/New_York',
'UTC',
'Europe/London',
@davidyell
davidyell / Cake3Finds.php
Created October 30, 2014 09:48
These two finds are equal in CakePHP 3, so which is better?
<?php
class ExamplesController extends AppController {
public function example($id) {
$match = $this->Matches->get($id, [
'contain' => [
'Venues',
'Formats'
]
]);
@davidyell
davidyell / LogFilenameListener.php
Last active October 17, 2015 12:19
Example CakePHP3 event listeners for the Proffer plugin.
<?php
/**
* Example listener class which will log the full absolute pathname for a Proffer upload
* to the logs.
*
* Should be in `src/Event`
*
* @category Example
* @package LogFilenameListener.php