Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View LubosRemplik's full-sized avatar

Luboš Remplík LubosRemplik

View GitHub Profile
public function findClient(Query $query, array $options)
{
$query->matching(
'OfferTypes', function ($q) use ($options) {
return $q->where(['OfferTypes.id' => $options['client']['offer_type_id']]);
}
);
$query->matching('Clients', function ($q) use ($options) {
return $q->where(['Clients.name' => $options['client']['name']]);
});
@LubosRemplik
LubosRemplik / gist:c79fc56571d00a403384785b94ec6e7d
Last active March 9, 2018 13:54
ServerRequest withAttribute / getParam fail in 3.6
<?php
namespace Admin\Test\TestCase\View\Cell;
use Admin\View\Cell\MenuCell;
use Cake\TestSuite\TestCase;
/**
* Admin\View\Cell\MenuCell Test Case
*/
class MenuCellTest extends TestCase
public function edit($id)
{
$this->Crud->on('beforeFind', function(\Cake\Event\Event $event) {
$event->getSubject()->query->contain(['Roles']);
});
$this->Crud->execute();
}
@LubosRemplik
LubosRemplik / gist:88b8dcfe0c26a25baa6af2d7c0a1f4b0
Created February 14, 2018 08:30
Crud many-to-many save issue - edit method + request data
/**
* Method: edit
*
* Amend user entity before save
*
* {@inheritDoc}
*/
public function edit($id)
{
if ($this->request->is('put')) {
SELECT `ShopProduct`.`id`, `ShopProduct`.`shop_category_id`, `ShopProduct`.`name`, `ShopProduct`.`slug`, `ShopProduct`.`meta_title`, `ShopProduct`.`meta_description`, `ShopProduct`.`meta_keywords`, `ShopProduct`. `heading`, `ShopProduct`.`overview`, `ShopProduct`.`excerpt`, `ShopProduct`.`content`, `ShopProduct`.`sorting`, `ShopProduct`.`upload`, `ShopProduct`.`status`, `ShopProduct`.`created`, `ShopProduct`.`created_by`, `ShopProduct`.`modified`, `ShopProduct`.`modified_by`, `ShopProduct`.`shop_order_item_count`, (`I18n__name`.`content`) AS `ShopProduct__i18n_name`, (`I18n__slug`.`content`) AS `ShopProduct__i18n_slug`, (`I18n__meta_title`.`content`) AS `ShopProduct__i18n_meta_title`, (`I18n__meta_description`.`content`) AS `ShopProduct__i18n_meta_description`, (`I18n__meta_keywords`.`content`) AS `ShopProduct__i18n_meta_keywords`, (`I18n__overview`.`content`) AS `ShopProduct__i18n_overview`, (`I18n__heading`.`content`) AS `ShopProduct__i18n_heading`, (`I18n__excerpt`.`content`) AS
$query->leftJoinWith('TicketExecutors');
$query->where(['TicketExecutors.id' => $options['request']['restrictByUserId']]);
$query->leftJoinWith('TicketOwners');
$query->orWhere(['TicketOwners.id' => $options['request']['restrictByUserId']]);
$(window).resize(function() {
$.each($('.blog-posts'), function(key, value) {
var height = 0;
$.each($('.item', value), function(key2, value2) {
if ($(value2).height() > height) {
height = $(value2).height();
}
});
console.log(height);
$.each($('.item', value), function(key2, value2) {
# backup all rsync projects, weekly
0 11 * * 5 nice -n 19 livedrive-backup golfmore >> /home/lubos/.livedrive 2>&1
# Daily backups (weekdays)
10 10 * * 1,2,3,4,5 nice -n 19 rsync-16x "-azv --exclude-from=/home/lubos/0rsync/.exclude" vmrates:httpdocs/01/ /home/lubos/0rsync/vmrates/ vmrates >> /home/lubos/0rsync/.log/vmrates`date +\%Y-\%m-\%d`.log 2>&1
# Weekly backups
10 10 * * 1 nice -n 19 rsync-3x "-azv --exclude-from=/home/lubos/0rsync/schillings/.exclude" schillings:httpdocs/ /home/lubos/0rsync/schillings/ schillings >> /home/lubos/0rsync/.log/schillings`date +\%Y-\%m-\%d`.log 2>&1
10 10 * * 3 nice -n 19 rsync-3x "-azv --exclude-from=/home/lubos/0rsync/.exclude" gcha:httpdocs/01/ /home/lubos/0rsync/gcha/ gcha >> /home/lubos/0rsync/.log/gcha`date +\%Y-\%m-\%d`.log 2>&1
10 10 * * 5 nice -n 19 rsync-3x "-azv --exclude-from=/home/lubos/0rsync/.exclude" fitzroviapartnership:httpdocs/02/ /home/lubos/0rsync/fitzrovia/ fitzrovia >> /home/lubos/0rsync/.log/fitzrovia`date +\%Y-\%m-\%d`.log 2>&1
@LubosRemplik
LubosRemplik / gist:7023701
Created October 17, 2013 12:04
Use of Makefile and make
LESS_SOURCE = ./app/webroot/frontpage/css/less/style.less
CSS_TARGET = ./app/webroot/frontpage/css/style.min.css
BOOTSTRAP_SOURCE = ./app/webroot/frontpage/js/bootstrap/
JS_TARGET = ./app/webroot/frontpage/js/app.min.js
build:
@recess --compress --compile ${LESS_SOURCE} > ${CSS_TARGET}
@cat \
./app/webroot/app/js/jquery/jquery-1.10.2.min.js \
./app/webroot/app/js/jquery/jquery.cookie.js \
@LubosRemplik
LubosRemplik / gist:7012852
Created October 16, 2013 18:55
Split tar files and cat them together again.
You can use split for this:
tar czpvf - /path/to/archive | split -d -b 100M - tardisk
This tells tar to send the data to stdout, and split to pick it from stdin - additionally using a numeric prefix (`-d`), a chunk size (`-b`) of 100M and using 'disk' as the base for the resulting filenames (tardisk00, tardisk01, etc.).
To extract the data afterwards you can use this:
cat tardisk* | tar xzpvf -