Skip to content

Instantly share code, notes, and snippets.

@csalgueiro
csalgueiro / template2xlsx.php
Created May 31, 2017 08:50
Cargar un Template XLSX y cubrir los valores
<?
require_once './lib/PHPExcel/Classes/PHPExcel.php';
$fileName = './templates/excel/plantilla.xlsx';
$objPHPExcel = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objPHPExcel->load($fileName);
$active_sheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $worksheet->getHighestRow();
@csalgueiro
csalgueiro / medirdistancia.php
Created May 10, 2017 08:34
Funcion para medir la distancia entre dos posiciones GPS
function distancia_gps ($punto1, $punto2) {
$metros = 6371000; //Circunferencia de la tierra
$coo1 = explode(',', $punto1);
$coo2 = explode(',', $punto2);
$distancia = $metros * acos(sin(deg2rad($coo1[0])) * sin(deg2rad($coo2[0])) + cos(deg2rad($coo1[0])) * cos(deg2rad($coo2[0])) * cos(deg2rad($coo1[1]) - deg2rad($coo2[1])));
return ((is_numeric($distancia)) ? $distancia : 0);
}
@csalgueiro
csalgueiro / scratch.php
Created December 28, 2016 09:52
diferencia de horas php con strtotime
$hora_ini = "08:15";
$hora_fin = "09:30";
$fecha = date("Y-m-d");
$ts_fin = strtotime($fecha." ".$hora_fin);
$ts_ini = strtotime($fecha." ".$hora_ini);
echo "TS_INI: ".$ts_ini."<br>";
echo "TS_FIN: ".$ts_fin."<br>";
echo "DIFF: ".($ts_fin-$ts_ini)/3600;
@csalgueiro
csalgueiro / eliminar_duplicados.sql
Created November 15, 2016 12:25
eliminar_duplicados MYSQL
CREATE TEMPORARY TABLE tabla_temporal AS
SELECT id
FROM tabla_original
GROUP BY campo_unico_1, campo_unico_2;
DELETE FROM tabla_original
WHERE id NOT IN(SELECT id FROM tabla_temporal);
@csalgueiro
csalgueiro / file_get_contents_curl.php
Created February 10, 2014 18:28
function url_get_contents ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close($ch); return $output; }
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
@csalgueiro
csalgueiro / datediff.js
Created January 28, 2014 10:03
Calcular diferencia de dias en JS con datepicker
var start = $("#form_expedientes input[name='fecha']").datepicker('getDate');
var end = $("#form_expedientes input[name='fecha_entrega']").datepicker('getDate');
if(!start || !end)
return;
var days = 0;
if (start && end) {
days = Math.floor((end.getTime() - start.getTime()) / 86400000); // ms per day
}
@csalgueiro
csalgueiro / filtro_fechas.sql
Created January 20, 2014 08:55
Filtrar en base a fechas utilizando intervalos desde la fecha actual.
// Obtener registros de la tabla con fecha superior a hace tres meses
SELECT * FROM tabla WHERE fecha >= DATE_ADD(NOW(),INTERVAL -3 MONTH)
// De otro modo:
SELECT * FROM tabla WHERE fecha >= (NOW() + INTERVAL -3 MONTH)
<?php
// Obtener el array
$myarray = glob("*.*");
// Ordenar por fecha ascendente
usort($myarray, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
$.validator.addMethod('require-one', function (value) {
return $('.require-one:checked').size() > 0; }, 'Please check at least one box.');
var checkboxes = $('.require-one');
var checkbox_names = $.map(checkboxes, function(e,i) { return $(e).attr("name")}).join(" ");
$("#itemForm").validate({
groups: { checks: checkbox_names },
errorPlacement: function(error, element) {
if (element.attr("type") == "checkbox")
@csalgueiro
csalgueiro / checktoggle.js
Created January 13, 2014 09:21
Toggle sobre un checkbox de la forma mas eficiente posible
$(this).find("input[type='checkbox']").prop("checked",function( i, val ) { return !val; });