Skip to content

Instantly share code, notes, and snippets.

View fullybaked's full-sized avatar

David Baker fullybaked

View GitHub Profile
@fullybaked
fullybaked / usort.php
Created September 1, 2015 12:05
Usort with PHP7 Spaceship vs PHP5.6
<?php
// PHP 5.6
usort($array, function($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
@fullybaked
fullybaked / File.php
Created November 27, 2014 11:16
Simple wrapper for PHP's file_(get|put)_contents methods
<?php
namespace Fullybaked;
use FileNotFound;
/**
* File class
*
* Simple wrapper for native methods file_get_contents and file_put_contents
* in an OOP context and with some useful methods for getting information about
* a given File
@fullybaked
fullybaked / bling.js
Created February 28, 2018 16:27 — forked from paulirish/bling.js
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
@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 {
@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 / 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 / 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 / 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
];
<?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 / 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;