Skip to content

Instantly share code, notes, and snippets.

@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/>";
// http://www.tehplayground.com/#qhRHh31Lj
$codigos = array(
"12454"=>"98",
"75489"=>"45",
"36985"=>"12"
);
$lista_codigos_string = implode(",",array_keys($codigos));
<?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;
@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
@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");
<img src="imagenotfound.gif" alt="Image not found" onerror="this.src='imagefound.gif';" />
@jgdoncel
jgdoncel / Function.Array-Group-By.php
Last active November 18, 2016 11:56 — forked from mcaskill/Function.Array-Group-By.php
PHP : Groups an array by a given key
<?php
if ( ! function_exists('array_group_by') ) :
/**
* Groups an array by a given key.
*
* Groups an array into arrays by a given key, or set of keys, shared between all array members.
*
* Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function.
@jgdoncel
jgdoncel / invalidhandler
Created December 20, 2016 12:22
jquery.validate - Focus bootstrap tab with firts invalid element
...
invalidHandler: function(e, validator){
if(validator.errorList.length)
$('a[href="#' + jQuery(validator.errorList[0].element, '#tabs').closest(".tab-pane").attr('id') + '"]').tab('show')
},
...
@jgdoncel
jgdoncel / fn_remove_accents.sql
Last active March 19, 2025 13:06
MySQL Function to remove accents and special characters
DROP FUNCTION IF EXISTS fn_remove_accents;
DELIMITER |
CREATE FUNCTION fn_remove_accents( textvalue VARCHAR(10000) ) RETURNS VARCHAR(10000)
BEGIN
SET @textvalue = textvalue COLLATE utf8_general_ci;;
-- ACCENTS
SET @withaccents = 'ŠšŽžÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝŸÞàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿþƒ';
@jgdoncel
jgdoncel / vanilla-js-plugin.js
Created May 10, 2018 09:08 — forked from cferdinandi/vanilla-js-plugin.js
My starter template for vanilla JavaScript plugins.
(function (root, factory) {
if ( typeof define === 'function' && define.amd ) {
define([], factory(root));
} else if ( typeof exports === 'object' ) {
module.exports = factory(root);
} else {
root.myPlugin = factory(root);
}
})(typeof global !== 'undefined' ? global : this.window || this.global, function (root) {