Skip to content

Instantly share code, notes, and snippets.

<?php
class Step extends AppModel
{
public $belongsTo = ["Translator"];
}
$results = model(Step::class)->find("first", [
"conditions" => [
"Step.translator_id IS NOT NULL",
@garethellis36
garethellis36 / Liskov breach.php
Last active February 25, 2019 12:38
LSP example in PHP
LSP: "Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program."
<?php
namespace App\User;
// imagine the following interface
interface Repository
{
public function getById($id);
@garethellis36
garethellis36 / .bashrc
Last active March 9, 2016 14:38
Disable XDebug when running composer in Git Bash for Windows - add this to ~/.bashrc
function composer()
{
COMPOSER="$(which composer)"
sed -i -e 's/zend_extension=C:\\php5.6\\ext\\php_xdebug-2.3.2-5.6-vc11-nts.dll/;zend_extension=C:\\php5.6\\ext\\php_xdebug-2.3.2-5.6-vc11-nts.dll/g' /c/php5.6/php.ini
$COMPOSER "$@"
sed -i -e 's/;zend_extension=C:\\php5.6\\ext\\php_xdebug-2.3.2-5.6-vc11-nts.dll/zend_extension=C:\\php5.6\\ext\\php_xdebug-2.3.2-5.6-vc11-nts.dll/g' /c/php5.6/php.ini
}
@garethellis36
garethellis36 / AppModel.php
Last active February 5, 2016 15:27
Possible improvement to CakePHP AppModel::updateAll() ?
//Add to app/Model/AppModel.php
public function updateAll($fields, $conditions = true)
{
$fields = array_map([$this, "quoteString"], $fields);
if (is_array($conditions)) {
$conditions = array_map([$this, "quoteString"], $conditions);
}
parent::updateAll($fields, $conditions);
}
@garethellis36
garethellis36 / bookmarklet
Last active February 5, 2016 15:28
Triboni bookmarklet
javascript:
var amountBK = prompt('Enter amount','');
void(document.getElementById('amount').value = amountBK);
void(document.getElementById('title').value = 'costs_description');
void(document.getElementById('office').value = '123');
void(document.getElementById('department').value = '12345');
void(document.getElementById('account').value = '1234567');
if (amountBK > 0) {
var blurEvent = new Event('blur');
void(document.getElementById('amount').dispatchEvent(blurEvent));