Skip to content

Instantly share code, notes, and snippets.

@csalgueiro
csalgueiro / insertorreplace.mysql
Created October 30, 2013 11:17
insertar o actualizar valores multiples
INSERT INTO contents_languages (
id_content,
id_language,
friendly,
title,
abstract,
text,
place
)
VALUES
@csalgueiro
csalgueiro / .htaccess
Created November 15, 2013 09:31
cambiar encoding por htaccess
AddDefaultCharset UTF-8
#Por defecto para todos
AddCharset ISO-8850-1 .js
#Cambiarlo para un conjunto de archivos
@csalgueiro
csalgueiro / selectinsert.sql
Created November 29, 2013 15:43
SelectInsert sencillo
INSERT INTO tabla ( id, nombre, activo, fecha ) SELECT $id, $nombre, $activo, now() WHERE NOT EXISTS ( SELECT id FROM tabla WHERE nombre = $nombre AND activo = $activo )
@csalgueiro
csalgueiro / generarMatricula.php
Created January 10, 2014 13:14
Funcion para generar aleatoriamente matriculas europeas
function generateMatricula() {
$numbers = '0123456789';
$characters = 'BCDFGHIJKLMNPQRSTVWXYZ';
$randomString = '';
for ($i = 0; $i < 4; $i++) {
$randomString .= $numbers[rand(0, strlen($numbers) - 1)];
}
for ($i = 0; $i < 3; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
@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; });
$.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")
<?php
// Obtener el array
$myarray = glob("*.*");
// Ordenar por fecha ascendente
usort($myarray, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
@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)
@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 / 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;