Noticias Weblogs Foros Wiki Código

RecorteX

» albin
303 usuarios y 202 recortes de código
Usuario

Contraseña
Crear cuenta
Estás viendo los recortes del usuario albin

RSS
Recortes: 29
Registrado: 6/8/2006
Web

Etiquetas:
php (13)
mysql (8)
JavaScript (5)
imagenes (5)
asp (3)
jpg (3)
JS (2)
Ajax (2)
fichero (2)
XMLHttpRequest (2)
MSSQLServer (2)
provincias (1)
clase (1)
forms (1)
elimina-ficheros (1)
sql (1)
importar (1)
existe-registro (1)
valor-minimo (1)
querystring (1)
connection (1)
leer (1)
genera-select (1)
eliminar (1)
svg (1)
onload (1)
aleatorio (1)
javascrip (1)
exportar (1)
variable (1)
recordset (1)
cuenta-registros (1)
link (1)
html (1)
escribir (1)
Transacciones (1)
antispam (1)
xhtml (1)
declarada (1)
registros (1)
MS-SQLServer (1)
imagen-flash (1)
etiqueta (1)
url (1)
plantilla (1)
flash (1)
duplicados (1)
scroll (1)
adodb (1)
event (1)
valor-maximo (1)

Busca URLs en un texto y las convierte en un enlace

Busca URLs en un texto y las convierte en un enlace con la URL como texto enlazable y sin title.


function SnTurls(texto)
	SnTurls = texto
	Set regx = New RegExp
	regx.Pattern = "http:\/\/[a-z]+\.[a-z]+\.[a-z]+\/"
	set matchs = regx.Execute(texto)
	for each match in matchs
		SnTurls = Replace(SnTurls, match, "<a href=""" & match & """>" & match & "</a>")
	next
end function

Compactar archivo transacciones

Cómo compactar el espacio de transacciones asociado a una base de datos.


USE master
BACKUP LOG DataBaseName WITH NO_LOG
GO
USE Cisa2005
DBCC SHRINKFILE(DataBaseName_log,1)
GO

Atender al evento "onload" de DOM

Quizás es un poco absurdo, en esta época de frameworks javascript, pero si alguien necesita suscribirse a este evento, sin anular otros posibles scripts que estén escuchándolo, aquí tiene una manera.


f_addEvent(window, "load", f_TuFuncion, false);

function f_TuFuncion() {
	...
}

function f_addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	}
}

Obtener registro aleatorio

Considerando que pueden haber identificadores que no corresponden ya a ningún registro, este stored procedure devuelve un registro al azar de una tabla


CREATE PROCEDURE getRandomRecord AS

	SET NOCOUNT ON

	DECLARE @id int			// del registro seleccionado
	DECLARE @max int		// total de registros
	DECLARE @rnd float		// número aleatorio
	DECLARE @sel int		// número aleatorio entero

	// Averiguamos cuantos registros hay
	SELECT @max = count(*) FROM t_TABLE

	// Obtenemos un aleatorio enterio entre 0 y @max
	SET @rnd = @max * DatePart(ms, GetDate()) / 1000
	SET @sel = cast(@rnd as int)

	// Obtenemos el identificador del registro en esa posición
	DECLARE crs SCROLL CURSOR FOR SELECT idRecord FROM t_TABLE
	OPEN crs
	FETCH ABSOLUTE @sel FROM crs INTO @id
	CLOSE crs
	DEALLOCATE crs

	// Selecionamos dicho registro
	SELECT * FROM t_TABLE WHERE idRecord = @id
GO

Plantilla SVG

Para comenzar facilmente desde cero un documento SVG.

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
     width="300" height="300">

  <script type="text/ecmascript">
    <![CDATA[
    ]]>
  </script>
  
</svg>

Comprobar si una variable ha sido declarada

No lo he testeado mucho, lo acabo de encontrar por ahí.

function isDefined(sVarName)
{
    return (typeof(window[sVarName]) == "undefined") ? false : true;
}

Volcar fichero en cadena de carácteres

Cómo volcar un fichero en un String

$file = fopen("filename.ext", "rb");
$text = '';
while (!feof($file)) {
  $text .= fread($file, 8192);
}
fclose($file);

Volcar cadena de carácteres en fichero

Cómo meter el contenido de un String en un fichero
 
$file = fopen("filename.ext", "w");
$bOk  = fwrite($file, $text);
fclose($file);
 

Etiqueta para insertar un flash

Cuidado con los "???"

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="???" height="???" VIEWASTEXT>
<param name="menu" value="false">
<param name="movie" value="???" />
<param name="quality" value="high" />
<embed src="???" menu="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="???" height="???"></embed>
</object>

Clase para manipular el QueryString

A veces tenemos que mantener el QueryString entre varias páginas, pero cambiar algún valor según en qué enlace pulses, pues esta clase lee el QueryString y te facilita variarlo y obtenerlo nuevamente como un String.

Es una lástima que PHP 4.x no tenga polimorfismo, "toStringWith" es una marranada.

class QueryString {

	var $aParams = array();

	function QueryString() {
	}

	function readURL() {
		$this->aParams = $_GET;
	}

	// Establece el valor $v del parámetro $k
	function setParam($k, $v) {
		$this->aParams[$k] = $v;
	}

	// Establece el valor de varios parámetros 
	// enviados en un array asociativo
	function setParams($pp) {
		while(list($k, $v)=each($pp)) {
			$this->aParams[$k] = $v;
		}
	}

	// Establece el valor $v del parámetro $k si este no existe
	function setDefault($k, $v) {
		if(!isset($this->aParams[$k])) {
			$this->aParams[$k] = $v;
		}
	}

	// Establece el valor de varios parámetros 
	// enviados en un array asociativo si estos no existen
	function setDefaults($pp) {
		while(list($k, $v)=each($pp)) {
			if(!isset($this->aParams[$k])) {
				$this->aParams[$k] = $v;
			}
		}
	}

        // Devuelve el QueryString como un String
	function toString() {
		$retval = "";
		while(list($k, $v)=each($this->aParams)) {
			$retval .= $k."=".$v."&";
		}
		return ($retval!=""? "?":"").substr($retval, 0, -1);
	}

        // Devuelve el QueryString con los parámetros indicados en el array $pp
        // pero no modifica el estado de la clase
	function toStringWith($pp) {
		$retval  = "";
		$aParams = $this->aParams;
		while(list($k, $v)=each($pp)) {
			$aParams[$k] = $v;
		}
		while(list($k, $v)=each($aParams)) {
			$retval .= $k."=".$v."&";
		}
		return ($retval!=""? "?":"").substr($retval, 0, -1);
	}

        // Devuelve el QueryString sin los parámetros indicados en el array $pp
        // pero no modifica el estado de la clase
	function toStringWithout($pp) {
		$retval  = "";
		$aParams = $this->aParams;
		while(list($a, $k)=each($pp)) {
			unset($aParams[$k]);
		}
		while(list($k, $v)=each($aParams)) {
			$retval .= $k."=".$v."&";
		}
		return ($retval!=""? "?":"").substr($retval, 0, -1);
	}

}
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin