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
  • 13:39 (UTC +01:00)
View GitHub Profile
@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
@davidyell
davidyell / ElasticsearchQuestions.md
Last active November 9, 2015 10:40
A series of questions about Elasticsearch

#Preface These are a number of questions I've distilled over my first week of using Elasticsearch.

Should an application use a single index?

When ingesting data into Elasticsearch should you be using a single index for each application and then use types within that index to break up the data?

My current setup is like this, with a project index, users and leagues types within that index.

How to deal with document overlaps?

@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 / 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 / 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 / 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 / howto.md
Last active February 25, 2016 10:04
Hooking up Netbeans to CodeSniffer
@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
*/