Skip to content

Instantly share code, notes, and snippets.

@jgdoncel
jgdoncel / exception_error_handler.php
Created September 23, 2016 14:59
Error handler para convertir cualquier warning, notice etc. en una excepción
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
@jgdoncel
jgdoncel / new_gist_file.bat
Created September 23, 2016 14:33
Reunir todos los ficheros de texto de un directorio en un único fichero
copy /b *.txt newfile.txt
<?php
function tailCustom($filepath, $lines = 1, $adaptive = true) {
// Open file
$f = @fopen($filepath, "rb");
if ($f === false) return false;
// Sets buffer size
if (!$adaptive) $buffer = 4096;
// http://www.tehplayground.com/#qhRHh31Lj
$codigos = array(
"12454"=>"98",
"75489"=>"45",
"36985"=>"12"
);
$lista_codigos_string = implode(",",array_keys($codigos));
@jgdoncel
jgdoncel / dates.php
Created May 10, 2016 12:28
Parsear una fecha y sumarle horas
$fecha = date_create_from_format('d/m/Y H:i:s', '08/09/1969 15:32:21');
echo "Fecha: " . $fecha->format('Y-m-d H:i:s') . "<br/>";
$horas = 24;
echo "Fecha+24h: " . $fecha->add(new \DateInterval('PT' . $horas . 'H'))->format('Y-m-d H:i:s') . "<br/>";
@jgdoncel
jgdoncel / new_gist_file_0
Created April 12, 2016 12:59
MYSQL SET UTC
mysql> SELECT CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2016-04-12 14:31:59 |
+---------------------+
1 row in set
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
@jgdoncel
jgdoncel / single_redirect.php
Created March 29, 2016 19:04
Redirección de página con htaccess
RewriteRule ^loquesea$ http://www.otrodominio.com/otrodirectorio [R=301,NC,L]
@jgdoncel
jgdoncel / bootstrap-modal.html
Last active November 30, 2016 11:14
Boostrap modal fullscreen
<div class="modal fade" id="modal-id" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4>Título</h4>
</div>
<div class="modal-body" style="max-height: calc(100vh - 212px);overflow-y: auto;">
<div class="list-group">
</div>
@jgdoncel
jgdoncel / partition_by_month.sql
Last active August 29, 2015 14:22
Particionar tabla Ejemplo suponiendo una tabla test (id,fecha) que pretendemos particionar por meses. Conviene crear el campo para el HASH debido a que MySQL filtra las consultas por particiones siempre que se incluya el HASH en el filtro. https://dev.mysql.com/doc/refman/5.6/en/partitioning-pruning.html
-- Crear nuevo campo
ALTER TABLE `test` ADD COLUMN `ts_year_month` int(11);
-- Insertar valores en el campo para los registros actuales
UPDATE `test` SET ts_year_month = DATE_FORMAT(fecha,'%Y%m');
-- Actualizar la definición de la nueva columna
ALTER TABLE `test` MODIFY `ts_year_month` int(11) NOT NULL;
-- Añadir el nuevo campo al índice
@jgdoncel
jgdoncel / custom_order.sql
Created December 11, 2014 09:59
Orden personalizado en MySQL
SELECT * FROM tabla ORDER BY FIELD(tipo,'ANTES','DURANTE','DESPUES') ASC