Skip to content

Instantly share code, notes, and snippets.

@marcghorayeb
marcghorayeb / gulpfile.js
Created June 25, 2018 12:57
Gulp + TSC hack
let isWatching = false;
gulp.task('ts', () => {
return new Promise((resolve, reject) => {
const cmd = 'npx';
const args = ['tsc'];
if (isWatching) {
args.push('-w', '--preserveWatchOutput');
}
@marcghorayeb
marcghorayeb / RouterTest.php
Created July 23, 2013 12:08
Li3 RFC concerning Route parsing.
/**
*
*/
public function testRouteMatchWithControllerParsed() {
Router::reset();
Router::connect('/{:controller:lists}/{:action:add}');
$this->assertIdentical(
'/lists/add',
Router::match(array('controller' => 'lists', 'action' => 'add'))
@marcghorayeb
marcghorayeb / gist:5644257
Last active December 17, 2015 17:09
Filter Lithium's SQL describe method so that the schema can be cached and retrieved quickly
<?php
// I have this in my bootstrap/cache.php file
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
foreach (Connections::get() as $connection) {
$connection = Connections::get($connection);
$connection->applyFilter('describe', function($self, $params, $chain) {
if (!empty($params['fields'])) {
$fields = $params['fields'];
return $self->invokeMethod('_instance', array('schema', compact('fields')));
}
@marcghorayeb
marcghorayeb / gist:2788415
Created May 25, 2012 14:26
Lithium timestamp fix
<?php
case 'timestamp':
if ($value === 'CURRENT_TIMESTAMP') {
return 'NULL';
} else if (is_numeric($value)) {
return $this->connection->quote(date('Y-m-d H:i:s', $value));
} else if (is_string($value)) {
return $this->connection->quote(date('Y-m-d H:i:s', strtotime($value)));
} else {
throw new InvalidArgumentException('given value for date is invalid');
@marcghorayeb
marcghorayeb / gist:1731092
Created February 3, 2012 16:52
Lithium subquery
public function allParameters($product) {
$conditions = array('subtype_id' => $product->subtype_id);
$order = array('pos' => 'ASC');
$with = array(
'ParametersIndexes' => array(
'conditions' => array(
'product_id_key' => $product->id
)
)
);