Skip to content

Instantly share code, notes, and snippets.

View fullybaked's full-sized avatar

David Baker fullybaked

View GitHub Profile

Keybase proof

I hereby claim:

  • I am fullybaked on github.
  • I am fullybaked (https://keybase.io/fullybaked) on keybase.
  • I have a public key whose fingerprint is 9919 C36F D1FD E4E5 CB0A E92F 8B05 EE06 F9EF 3B39

To claim this, I am signing this object:

@fullybaked
fullybaked / example.php
Last active August 29, 2015 14:07
Scoped CakePHP Models
<?php
class Person extends AppModel
{
// must explicitly set the useTable so child classes
// use this not the CakePHP conventions based on their
// class name
public $useTable = 'people';
// table people exists in the database with schema
// id int(11) PK
// type varchar(20) default 'contact' not null
<?php
/**
* This is a _very_ rough draft of an idea to create a composable field in a model
* by which, the Model::find methods would return a value object rather plain data
* for a given field.
*
* Value Objects would be created in the /Lib directory of the application
*
* This is a work in progress hence being a Gist.
*/
@fullybaked
fullybaked / raw.sql
Created June 17, 2015 10:27
SQL Snippet
select count(DISTINCT project_id), sum(amount), user_id
from payments
group by user_id
order by sum(amount) desc;
<?php
public function findByFullName($search_term) {
$users->find()
->where(['CONCAT(UserProfiles.first_name, " ", UserProfiles.lastname)' => $search_term]);
->contain(self::$applicant_contain)
->order(['Users.primary_role' => 'DESC', 'Users.modified' => 'DESC'])
->limit(25);
}
@fullybaked
fullybaked / data_view.php
Created July 22, 2015 19:29
JSON out from views
<?php
// data controller
public function get_data()
{
$data = [
'item' => $this->getDataFromSomewhere(),
'min' => 0,
'max' => 10
];
@fullybaked
fullybaked / example.php
Last active August 29, 2015 14:27
Cakephp date format issue
// open athens dates come from a date picker text input in the view, in the format dd-mm-yyyy
<?= $this->Form->input('openathens_start_date, [
'type' => 'text',
'class' => 'datepicker']);?>
<?= $this->Form->input('openathens_end_date, [
'type' => 'text',
'class' => 'datepicker']);?>
// in the Table
public function beforeMarshal(Event $event, \ArrayObject $data, \ArrayObject $options)
@fullybaked
fullybaked / test.scss
Created January 9, 2012 14:43
Test file for SCSS parsing based on 4 examples on http://sass-lang.com
/* Test SCSS File */
/* Variables & Calculations */
$blue: #3bbfce;
$margin: 16px;
.content-navigation {
border-color: $blue;
color:
darken($blue, 9%);
@fullybaked
fullybaked / HtmlHelper.php
Created January 14, 2012 12:25
Enhanced HtmlHelper::getCrumbs() from CakePHP 2.x to allow custom first link url and passing of images
<?
/**
* Returns the breadcrumb trail as a sequence of &raquo;-separated links.
*
* @param string $separator Text to separate crumbs.
* @param string $startText This will be the first crumb, if false it defaults to first crumb in array
* @param mixed $startPath Url for the first link in the bread crumbs, can be a string or array
* @param boolean $escape Escape the content of the link text, set to false if passing an image in
* @return string Composed bread crumbs
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
@fullybaked
fullybaked / UploadComponent.php
Created March 6, 2012 14:18
Upload Component for CakePHP 2.0
<?php
/**
* Component handles various types of file upload
*
* @author Dave Baker
* @copyright Dave Baker / Fully Baked 2012
* @link www.fullybaked.co.uk
*/
class UploadComponent extends Component {