Skip to content

Instantly share code, notes, and snippets.

@jgdoncel
jgdoncel / create_calendar_table.sql
Created March 22, 2024 11:53 — forked from vetali/create_calendar_table.sql
Calendar table for MySql
SET FOREIGN_KEY_CHECKS = 0;
/* Drop Tables */
DROP TABLE IF EXISTS calendar CASCADE;
/* Create Tables */
CREATE TABLE calendar (
id DATE NOT NULL,
year SMALLINT NOT NULL,
@jgdoncel
jgdoncel / fn_split_string.sql
Created January 12, 2023 15:18
MySQL: Function to split string based on a separator and an extraction index
/*
Usage:
SELECT fn_split_string('20156 2018-01-25',' ',1) AS one, fn_split_string('20156 2018-01-25',' ',2) AS two;
+-------+------------+
| one | two |
+-------+------------+
| 20156 | 2018-01-25 |
+-------+------------+
*/
CREATE FUNCTION `fn_split_string`(
@jgdoncel
jgdoncel / GoogleChart.cs
Last active January 28, 2019 10:39
Clase para generar objetos compatibles con Google Chart (https://developers.google.com/chart/interactive/docs/reference#dataparam)
using System.Collections.Generic;
namespace GoogleChart {
public class Col
{
public string id { get; set; }
public string label { get; set; }
public string type { get; set; }
}
@jgdoncel
jgdoncel / Module.js
Created January 21, 2019 11:37 — forked from sdd/Module.js
Javascript Module pattern template. Shows a class with a constructor and public/private methods/properties. Also shows compatibility with CommonJS(eg Node.JS) and AMD (eg requireJS) as well as in a browser.
/**
* Created with JetBrains PhpStorm.
* User: scotty
* Date: 28/08/2013
* Time: 19:39
*/
;(function(global){
"use strict";
var M = function() {
@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) {
@jgdoncel
jgdoncel / fn_remove_accents.sql
Last active April 19, 2024 12:20
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 / 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 / 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.
<img src="imagenotfound.gif" alt="Image not found" onerror="this.src='imagefound.gif';" />
@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");