Skip to content

Instantly share code, notes, and snippets.

@siran
siran / aws-mfa-cli.sh
Last active February 6, 2020 02:27
Script to authenticate the CLI with MFA, adds AWS environment variables.
#!/bin/bash
set -e
# specify your MFA_DEVICE_ARN
MFA_DEVICE_ARN=YOUR_MFA_ARN
if [ MFA_DEVICE_ARN=YOUR_MFA_ARN ]; then
echo "Please specify the MFA_DEVICE_ARN"
exit 1
fi
@siran
siran / collections.php
Last active May 13, 2017 00:31
working with collections
<?php
$list = $this->Transacciones->find()
->distinct(...)
->select(...)
->contain(...)
->order(...)
->reject(...)
->sortBy(...);
@siran
siran / queryLogger.php
Last active May 8, 2017 15:27
How to get complete sql query with values replaced in the placeholders (CakePHP 3.4)
<?php
use Cake\Database\Log\QueryLogger;
use Cake\ORM\Query;
class myLog extends QueryLogger
{
public function toStatement(Query $query)
{
$sql = $query->sql();
$registros = $source_table->find()->order('id');
$inicio = time();
$diff = time();
foreach ($registros as $registro) {
//for ($n = 0; $n < 500000; $n++) { //<-------------- see the difference when iterating over a for(0..500k) than over a foreach($registros)
$num++;
if ($num % 100 == 0) {
$memoria_usada = number_format(memory_get_usage(true), 0);
$to_log = __("used memory: ".$memoria_usada."\t$num records processed (time ".(time() - $inicio)."; diff: ".(time() - $diff).")");
<?php
/**
* @package Joomla.Platform
* @subpackage Database
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;