Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - :ohk<any>

#421
PHP / Re: SOlucionado
12 Noviembre 2009, 22:46 PM
Cita de: cΔssiΔni en 12 Noviembre 2009, 22:11 PM
esta bien, pero no borras el mensaje ni le cambias el titulo al post si lo has solucionado .. le posteas la respuesta por si a alguien mas le pasa mismo, ya tiene por donde ir luego de usar el buscador del foro..

asi ayudas a los demas  ;)

:xD
#422
PHP / Duda sobre nombre de archivo
12 Noviembre 2009, 14:40 PM
Hola, tengo una duda un tanto simbolica jeje
Si tengo un archivo hola.php y quiero otro archivo hola mundo.

Como es lo mas adecuado a la hora de nombrarlo.

Opcion 1: holamundo.php
Opcion 2: hola_mundo.php
Opcion 3: hola mundo.php


Creo que cuando uno nombra con espacios hay problemas, pero alguien me explica de que tipo y porque, o es solo un rumor.

Saludos
#423
xD

que conveniente, hay 3 que sobresalen y hay 3 votos :P
#424
Java / Re: Torres de hanoi con netbeans
10 Noviembre 2009, 16:20 PM
A perdón, la clase torre es esta:

Código (java) [Seleccionar]

//********************************************************************
// torre.java
// by @ohk
// para elhacker.net
//********************************************************************

import java.awt.*;
import java.util.Vector;

//********************************************************************

public class torre
{
    Graphics g;

    Vector v;

    int x;
    int y;
    int w;
    int d;

    //----------------------------------------------------------------

    torre (Graphics g)
    {
this.g = g;

v = new Vector ();
    }


    //----------------------------------------------------------------

    public void agregar (int i)
    {
Integer I = new Integer (i);

v.addElement (I);
    }


    //----------------------------------------------------------------

    public int pop ()
    {
int disco = ((Integer) (v.lastElement ())).intValue ();
int tamano = v.size ();

subir_disco (tamano, disco);
v.removeElementAt (tamano - 1);

return (disco);
    }


    //----------------------------------------------------------------

    public void push (int i)
    {
Integer I = new Integer (i);

v.addElement (I);

int tamano = v.size ();

bajar_disco (tamano, i);
    }


    //----------------------------------------------------------------

    public void paint (int _x, int _w, int h)
    {
x = _x;
w = _w;
y = h / 20;
d = w / 20;

dibujar_sujetadores (g);

int numero_de_discos = v.size ();

for (int i = 0 ; i < numero_de_discos ; i++)
{
    int j = ((Integer) (v.elementAt (i))).intValue ();
    dibujar_disco (x + j * d, y * (18 - i), w - 2 * j * d, y);
}
    }


    //----------------------------------------------------------------

    void dibujar_sujetadores (Graphics g)
    {
g.setColor (Color.green);
g.fillRect (x, y * 19, w, y / 5);
g.fillRect (x + w / 2 - w / 20, y * 15, w / 10, y * 4);
g.fillOval (x + w / 2 - w / 20, y * 11, w / 10, y * 8);
//g.setColor (Color.black);
g.setColor (Color.red);
g.drawString (" Torre 1 ", 120, 395);
g.drawString (" Torre 2 ", 325, 395);
g.drawString (" Torre 3 ", 530, 395);
    }


    //----------------------------------------------------------------

    void demora ()
    {
try
{
    Thread.sleep (hanoi.demora);
}
catch (InterruptedException e)
{
}
    }


    //----------------------------------------------------------------

    void subir_disco (int tamano, int disco)
    {
borrar_disco (x + disco * d, y * (19 - tamano), w - 2 * disco * d, y);

for (int i = y * (18 - tamano) ; i >= y + 180 ; i -= y)
{
    dibujar_disco (x + disco * d, i, w - 2 * disco * d, y);
    demora ();
    borrar_disco (x + disco * d, i, w - 2 * disco * d, y);
}
    }


    //----------------------------------------------------------------

    void bajar_disco (int tamano, int disco)
    {
for (int i = y + 180 ; i < y * (19 - tamano) ; i += y)
{
    dibujar_disco (x + disco * d, i, w - 2 * disco * d, y);
    demora ();
    borrar_disco (x + disco * d, i, w - 2 * disco * d, y);
}

dibujar_disco (x + disco * d, y * (19 - tamano), w - 2 * disco * d, y);
    }


    //----------------------------------------------------------------

    void dibujar_disco (int x, int y, int w, int h)
    {
g.setColor (Color.black);
g.fillOval (x, y, w - 1, h - 1);

g.setColor (Color.white);
g.drawOval (x, y, w - 1, h - 1);

g.setColor (Color.black);
    }


    //----------------------------------------------------------------

    void borrar_disco (int x, int y, int w, int h)
    {
Graphics g2;
g2 = g.create ();

g2.clipRect (x, y, w, h);

g2.drawImage (hanoi.fondo, 0, 0, hanoi.ancho, hanoi.alto, null);

dibujar_sujetadores (g2);
    }
}


La imagen la debes bajar con este nombre: egipto.gif
Saludetes ;D
#425
Porque siempre deben haber calaberas cuando se habla de hackers.
:¬¬
#426
Java / Re: Torres de hanoi con netbeans
9 Noviembre 2009, 23:15 PM
Mira, siendo sincero hace mucho que no veo java ni programo usando lógica  :xD :xD :xD :xD

Asi que te paso el ejercicio, mas una imagen que se requiere para que corra mas guapo  ;D

La imagen:



El codigo en java:

Código (java) [Seleccionar]

//********************************************************************
// hanoi.java
// aporte de @ohk
// para elhacker.net
//********************************************************************

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

//********************************************************************

public class hanoi extends Applet implements Runnable
{
    Graphics g;

    static public Image fondo;

    static public int ancho;
    static public int alto;

    static public int demora = 200;

    private boolean imagen_cargada = false;

    private int total_discos = 3;

    private Thread mi_hilo;

    private boolean hilo_iniciado = false;

    private Label label;

    private TextField resultado;

    String salida = "";
    int contador = 0;

    torre t [];

    int torre_origen = 0;
    int torre_destino = 2;

    //----------------------------------------------------------------

    public void init ()
    {

label = new Label ("Comportamiento de las Torres de Hanoi");
label.setFont (new java.awt.Font ("Georgia Ref", java.awt.Font.BOLD, 20));

resultado = new TextField (40);
resultado.setFont (new java.awt.Font ("Georgia Ref", java.awt.Font.BOLD, 15));
//Container contString = getContentPane ();
//contString.setLayout (new FlowLayout ());
resultado.setEnabled (false);
//contString.add (new ScrollPane (resultado));

g = getGraphics ();

String parametro;

parametro = getParameter ("TOTAL");
if (parametro != null)
    total_discos = Integer.parseInt (parametro);

parametro = getParameter ("DEMORA");
if (parametro != null)
    demora = Integer.parseInt (parametro);

ancho = size ().width;
alto = size ().height;

fondo = getImage (getCodeBase (), "egipto.gif");

Image imagenFueraPant = createImage (ancho, alto);
Graphics CGFueraPant = imagenFueraPant.getGraphics ();
CGFueraPant.drawImage (fondo, 0, 0, this);

t = new torre [3];

t [0] = new torre (g);
t [1] = new torre (g);
t [2] = new torre (g);

for (int i = 0 ; i < total_discos ; i++)
{
    t [0].agregar (i);
}
add (label);
add (resultado);

    }


    //----------------------------------------------------------------

    public boolean imageUpdate (Image img, int infoflags, int x, int y,
    int ancho, int alto)
    {
if (infoflags == ALLBITS)
{
    imagen_cargada = true;
    repaint ();
    return false;
}
else
    return true;
    }


    //----------------------------------------------------------------

    public void paint (Graphics g)
    {
if (!imagen_cargada)
    showStatus ("Torre de Hanoi:  cargando imagen");

else
{
    if (hilo_iniciado)
if (mi_hilo.isAlive ())
    showStatus ("Torres de Hanoi:  Corriendo");
else
    showStatus ("Torres de Hanoi:  Haga clic otra vez para reiniciar");
    else
showStatus ("Torres de Hanoi:  Haga clic para iniciar");

    ancho = size ().width;
    alto = size ().height;

    g.drawImage (fondo, 0, 0, ancho, alto, this);

    int x_inc = ancho / 10;

    t [0].paint (x_inc * 1, x_inc * 2, alto);
    t [1].paint (x_inc * 4, x_inc * 2, alto);
    t [2].paint (x_inc * 7, x_inc * 2, alto);
}
    }


    //----------------------------------------------------------------

    public boolean mouseDown (Event evt, int x, int y)
    {
if (!hilo_iniciado || !mi_hilo.isAlive ())
{
    mi_hilo = new Thread (this);
    mi_hilo.start ();
    showStatus ("Torre de Hanoi:  Corriendo");
    hilo_iniciado = true;
    resuelve_hanoi (total_discos, torre_origen + 1, torre_destino + 1);


}

return true;
    }


    //----------------------------------------------------------------

    public void run ()
    {
mover_torre (total_discos, torre_origen, torre_destino, 1);

int temp = torre_destino;
torre_destino = torre_origen;
torre_origen = temp;

showStatus ("Torre de Hanoi:  Haga clic otra vez para reiniciar");
    }


    //----------------------------------------------------------------

    private void mover_torre (int discos, int origen, int destino, int temporal)
    {
if (discos > 0)
{
    mover_torre (discos - 1, origen, temporal, destino);
    mover_disco (origen, destino);
    mover_torre (discos - 1, temporal, destino, origen);
}
    }


    //----------------------------------------------------------------

    private void mover_disco (int origen, int destino)
    {
int disco = t [origen].pop ();
t [destino].push (disco);
    }

    public void resuelve_hanoi (int n, int inicial, int finalizar)
    {
int libre = 0;
if (n == 1)
{
    resultado.setText (" Mover disco superior de la torre " + inicial + " a la torre " + finalizar);
}
else
{

    //Determinar cual es la aguja libre
    if (inicial != 1 && finalizar != 1)
libre = 1;
    else if (inicial != 2 && finalizar != 2)
    {
libre = 2;
    }
    else
libre = 3;

    //Primer subproblema:mover n-1 discos de inicial a libre
    resuelve_hanoi (n - 1, inicial, libre);
    //Transferir el disco grande a su posicion final
    try
    {
Thread.sleep (3200);
    }
    catch (InterruptedException e)
    {

    }
    ;
    resultado.setText (" Mover disco superior de la torre " + inicial + " a la torre " + finalizar);
    try
    {
Thread.sleep (3200);
    }
    catch (InterruptedException e)
    {

    }
    ;
    //Segundo subproblema: mover n-1 discos de libre a final
    resuelve_hanoi (n - 1, libre, finalizar);
}
    }
}


Espero te sirva.
Saludos
#427
Java / Re: Torres de hanoi con netbeans
9 Noviembre 2009, 21:49 PM
Te puedo hechar una mano con las torres de hanoi, pero no es por un método recursivo.
Esta en java, que dices...

saludos
#428
PHP / Re: comunicacion entre clase y formulario
9 Noviembre 2009, 20:47 PM
No veo ninguna variable que reciba los datos que envias...
#429
PHP / Re: Duda bastante nw con los select
9 Noviembre 2009, 16:28 PM
Cita de: cΔssiΔni en  9 Noviembre 2009, 16:26 PM
jejeje evitarla!!

:xD

Pues claro, no es una función para inyecciones sql, para eso no pones nada y eres vulnerable  :P :laugh:
#430
PHP / Re: Duda bastante nw con los select
9 Noviembre 2009, 16:18 PM
Citar
//Funcion que limpia las variables y asegura contra inyección SQL

function addslashes__recursive($var){
if (!is_array($var))
return addslashes($var);
$new_var = array();
foreach ($var as $k => $v)$new_var[addslashes($k)]=addslashes__recursive($v);
return $new_var;
}

Inyeccion SQL:

Citar
nyección SQL es una vulnerabilidad informática en el nivel de la validación de las entradas a la base de datos de una aplicación. El origen es el filtrado incorrecto de las variables utilizadas en las partes del programa con código SQL.

Seguir leyendo...

Saludos