Skip to content

Instantly share code, notes, and snippets.

@jgdoncel
jgdoncel / gist:f72176ceb58d3553dd7b
Created May 8, 2012 09:06
Contar páginas de un PDF
function getNumPagesInPDF($file)
{
//http://www.hotscripts.com/forums/php/23533-how-now-get-number-pages-one-document-pdf.html
if(!file_exists($file))return null;
if (!$fp = @fopen($file,"r"))return null;
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
@jgdoncel
jgdoncel / gist:2635022
Created May 8, 2012 13:32
MySQL INSERT o UPDATE si existe
INSERT INTO clientes_peticiones (
id_cliente,fecha,peticiones
) VALUES (
1,'2011-11-02',1
) ON DUPLICATE KEY UPDATE peticiones = peticiones+1;
@jgdoncel
jgdoncel / utf8.php
Created October 2, 2013 13:35
Eliminar caracteres no UTF8 de una cadena
// Supposing your want to be sure that $string is composed by valid UTF-8 characters:
$string = iconv("UTF-8","UTF-8//IGNORE",$string);
// If you want to remove none ISO-8859-1 characters from this string:
$string = iconv("UTF-8","ISO-8859-1//IGNORE",$string);
$string = iconv("ISO-8859-1","UTF-8",$string);
// If you still have characters you want to be ignored, try this:
$string = recode_string("us..flat", $string);
@jgdoncel
jgdoncel / ejemplo_01.sql
Created October 2, 2013 13:44
Numerar filas en una consulta
# La siguiente consulta añade un campo numerado a una consulta:
set @num=0;
select id, @num:=@num+1 AS contando FROM tabla;
@jgdoncel
jgdoncel / combine_folder.bat
Created October 2, 2013 13:45
Combinar archivos
REM Combinar los archivos js de un directorio
@echo off
pushd "%~1"
echo.>tmp.js
del tmp.js
for /r %%x in (*.js) do (
type "%%~x" >> tmp.js
)
popd
@jgdoncel
jgdoncel / order.sql
Created October 2, 2013 13:50
Ordenar en base a un campo En el ejemplo se ordenan las líneas de pedido en su orden natural pero manteniendo unidas las que son del mismo color.
Select * FROM pedidos_lineas
where id_pedido=33
order by find_in_set(color, (SELECT GROUP_CONCAT(DISTINCT(color)) FROM pedidos_lineas WHERE id_pedido=33));
@jgdoncel
jgdoncel / if.sql
Created October 2, 2013 13:52
IF en subconsulta Ejemplo de uso de una condición IF con una subconsulta en su interior
SELECT DISTINCT files.contentType, IF ((SELECT COUNT(id) FROM files_favoritos)=0,'si','no') FROM files
@jgdoncel
jgdoncel / update.sql
Last active December 24, 2015 11:58
Ejemplo de actualización de un campo de un tabla tomando el valor de un campo de una tabla diferente
UPDATE Hoja1 origen, clientes_acceso destino
SET destino.password = origen.NUEVA_CLAVE
WHERE destino.IDusuario = origen.CODIGO;
@jgdoncel
jgdoncel / .htaccess
Created October 2, 2013 21:46 — forked from pbougie/.htaccess
Set time zone to Coordinated Universal Time (UTC) for PHP in an .htaccess file.
php_value date.timezone UTC
@jgdoncel
jgdoncel / infoImagen
Created October 8, 2013 07:38
ImageMagick
identify archivo.ext