Skip to content

Instantly share code, notes, and snippets.

View fullybaked's full-sized avatar

David Baker fullybaked

View GitHub Profile
@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 / 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 / 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;
<?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 / 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 / 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

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: