My Code Snippets

My Code Snippets es una recopilación de pequeñas funciones (código) de php, javascript, actionscript, que pueden ser útiles en algún momento.

 

scanner de puertos en php

set_time_limit(0);
error_reporting(E_ERROR | E_PARSE);

if (isset($_GET['h']) && $_GET['h'] != '') {
    $host = $_GET['h'];
    for($i = 0; $i < 500; $i++) {
        $fp = fsockopen($host, $i, $errno, $errstr, 10);
        if($fp) {
            echo 'port ' . $i . ' open on ' . $host . '<br />' . "\n";
            fclose($fp);
        } else {
            echo 'port ' . $i . ' closed on ' . $host . ' : ' . $errstr . ' (' . $errno . ')<br />' .  "\n";
        }
        flush();
        sleep(1);
    }
} else {
    echo 'define the host first!';
}

Pop! es un menu desplegable no intrusivo desarrollado como plug-in para jQuery, de muy facil implementación.
Sitio oficial: http://pop.seaofclouds.com/

Pop! es un menu desplegable no intrusivo desarrollado como plug-in para jQuery, de muy facil implementación.

Sitio oficial: http://pop.seaofclouds.com/

Códigos randomicos

function getUniqueID($size) {
    srand ((double) microtime() * 1000000);
    //
    $raw_rand = md5(uniqid((rand() * time()) / rand()));
    $raw_size = strlen($raw_rand);
    $rand = rand(0,($raw_size - $size - 1));
    $rand_code = substr($raw_rand, $rand, $size);
    //
    $raw_uid = uniqid($rand_code, true);
    $raw_uid = str_replace('.', '', $raw_uid);
    $raw_uid_size = strlen($raw_uid);
    $rand_uid = rand(0,($raw_uid_size - $size - 1));
    return substr($raw_uid, $rand_uid, $size);
}

Códigos randomicos

function getRandomCode($size=6) {
    $raw_rand = md5(round((rand()*time())/rand()));
    $raw_size = strlen($raw_rand);
    srand ((double) microtime() * 1000000);
    $rand = rand(0,($raw_size – $size – 1));
    return substr($raw_rand, $rand, $size);
}

cambiar los nombres de las columnas en una tabla de uppercase a lowercase

$hostname = "localhost";
$database = "database";
$username = "login";
$password = "password";
$conexion = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);

$query = "SELECT * FROM parser";
mysql_select_db($database, $conexion);
$result = mysql_query($query, $conexion) or die(mysql_error());
$total_fields = mysql_num_fields($result);
$i = 0;
 
for($i; $i < $total_fields; $i++){
    $meta = mysql_fetch_field($result, $i);
    $old_name = mysql_field_name($result, $i);
    $new_name = strtolower($old_name);
    echo $old_name." ".$new_name." ".$meta->table."<br />";
    $update_query = sprintf("ALTER TABLE %s CHANGE %s %s VARCHAR(100)", $meta->table,  $old_name,  $new_name);
    $result_update = mysql_query($update_query, $conexion) or die(mysql_error());
}

Códigos randomicos

function generateurl($size=6) {
    $list = 'abcdefghijklmnopqrstuvwxyz0123456789';
    return str_shuffle(substr(str_shuffle($list),0,$size));
}

Debug en php

function debug($data) {
    var_dump($data);
}