viernes, 27 de marzo de 2015

Resturar una base desde cosola en postgresql

1) Se crea la base de datos

template>  CREATE DATABASE  nombrebase owner="user"

2) Para cambiarse a la base

templaet>  \c

3) Restaurar base

template > \i  /home/ruta/basededatos.out


Listo......

martes, 24 de marzo de 2015

Ajax callback

<html>
    <head>
        <meta charset="utf-8">
        <title>Jquery Totorial</title>
    </head>
    <body>
        <input type="text" id="name"><input id="boton" type="button" value="Load">

        <div id="content"></div>

        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/ajaxcall.js"></script>
       
    </body>
</html>

$('#boton').click(function(){
var name = $('#name').val();
$.ajax({
    url:'php/send.php',
    data:'name='+name,
    success: function(data){
        $('#content').html(data);
    }
}).error(function(){
    alert('Error de pagina');
}).complete(function(){

    alert('Complete');
});

});

Ajax send

<html>
    <head>
        <meta charset="utf-8">
        <title>Jquery Totorial</title>
    </head>
    <body>
        <input type="text" id="name"><input id="boton" type="button" value="Load">

        <div id="content"></div>

        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/ajaxsend.js"></script>
       
    </body>
</html>

send.js

$('#boton').click(function(){
var name = $('#name').val();
$.ajax({
    url:'php/send.php',
    data:'name='+name,
    success: function(data){
        $('#content').html(data);
    }
});

});

Ajax load

index.html

<html>
    <head>
        <meta charset="utf-8">
        <title>Jquery Totorial</title>
    </head>
    <body>
        <input id="boton" type="button" value="Load">

        <div id="content"></div>

        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/ajax.js"></script>
       
    </body>
</html>


ajax.js

$('#boton').click(function(){
$.ajax({
    url:'page.html',
    success: function(data){
        $('#content').html(data);
    }
});

});

jueves, 19 de marzo de 2015

Sumar campos es en formulario con jquery

<?php
/* @var $this BaseController */
/* @var $model base */
/* @var $form CActiveForm */
Yii::app()->clientScript->registerScript('search', "



$('#importe_bruto').keyup(function(){
var iva = eval($('#iva').val());
var importe = eval($('#importe_bruto').val());

$('#subtotal').val(importe+iva);
});

$('#iva').keyup(function(){
var iva = eval($('#iva').val());
var importe = eval($('#importe_bruto').val());

$('#subtotal').val(importe+iva);
});

$('#iva_ret').keyup(function(){
var iva = eval($('#iva_ret').val());
var isr = eval($('#isr_ret').val());
var subtotal = eval($('#subtotal').val());

$('#importe_neto').val(subtotal-iva-isr);
});

$('#isr_ret').keyup(function(){
var iva = eval($('#iva_ret').val());
var isr = eval($('#isr_ret').val());
var subtotal = eval($('#subtotal').val());

$('#importe_neto').val(subtotal-iva-isr);
});

");

?>

lunes, 16 de marzo de 2015

function each en jquery

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fruit Basket</title>
<link rel="stylesheet" href="css/fruitBasket.css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function(){
// Array containing Objects with Fruit names & quantities
var fruitBasket = [ {title:'Apples', quantity:20},
{title:'Oranges', quantity:25},
{title:'Kiwis', quantity:50},
{title:'Strawberries', quantity:45},
{title:'Bananas', quantity:10},
{title:'Mangoes', quantity:5},
{title:'Tomatoes', quantity:30} ];

// Your jQuery code goes here

$.each( fruitBasket, function( index, element){
$('.fruits').append('<li>We have ' + element.quantity + " " + element.title + '</li>');
});

$('.fruits > li').each( function(index, element){
$(element).css('background-color','rgb(100,200,0)');
});

})
</script>
</head>
<body>
<div class="container">
<ul class="fruits">


</ul>
</div>
</body>
</html>

otro ejemplo

<html>
    <head>
        <title>Funcion each()</title>
        <script type = "text/javascript" src = "jquery.js"> </script>
        <script type = "text/javascript">
           $(document).ready(function()
           {
              $.each(["Lun","Mar","Mie","Jue","Vie"],function(idx,v) {
                 console.log('(' + idx + ') Tratando valor (' + v +')');
              });
           });
        </script>
    </head>
    <body>
    </body>
 </html>


otro ejemplo

<html>
    <head>
        <title>Funcion each(II)</title>
        <script type = "text/javascript" src = "jquery.js"> </script> 
        <script type = "text/javascript">
           $(document).ready(function()
           {
              $("p").each(function(idx,v) {
                 console.log('(' + idx + ') Tratando valor (' + $(this).html() +')');
              });
           });
        </script>
    </head>
    <body>
       <p>Parrafo 1</p>
       <p>Parrafo 2</p>
       <p>Parrafo 3</p>
    </body>
 </html>

chaining modules and namespaces

var ray = (function() {
  var DEFAULTS = {
    say: 'hello',
    speed: 'normal'
  }

  return {
    speak: function() {
      var myArguments = arguments[0] || '';
      var statement = myArguments.say || DEFAULTS.say;
      console.log(statement);
      return this;
    },
    run : function() {
      var myArguments = arguments[0] || '';
      var running = myArguments.speed || DEFAULTS.speed;
      console.log('running...'+ running);
      return this;
    }
  };
})();

 <script>
    ray.speak({ say: 'howdy' }).run().speak({ say: 'run faster' }).run({speed: 'faster'});
  </script>

Leer parametros como argumentos

var plus = function() {
  var sum =  0;
  for (var i = arguments.length - 1; i >= 0; i--) {
    sum += arguments[i];
  };
  return sum;
}

console.log(plus(2,2,2,3,2,3,4));

var socialMedia = {
  facebook : 'http://facebook.com/viewsource',
  twitter: 'http://twitter.com/planetoftheweb',
  flickr: 'http://flickr.com/planetotheweb',
  youtube: 'http://youtube.com/planetoftheweb'
};

var socialList = function() {
  var  output = '<ul>',
    myList = document.querySelectorAll('.socialmediaicons');

  for (var key in arguments[0]) {
    output+= '<li><a href="' + socialMedia[key] + '">' +
      '<img src="images/' + key + '.png" alt="icon for '+key+'">' +
      '</a></li>';
  }
  output+= '</ul>';
 
  for (var i = myList.length - 1; i >= 0; i--) {
    myList[i].innerHTML = output;
  };
}(socialMedia);

Invacando funciones con call y apply

Call

var speak = function(what) {
  console.log(what);

}

var saySomething = {normal: "meow", love: "purr"}
speak.call(saySomething, saySomething.normal);

Apply


var speak = function(what) {
  console.log(what);
  console.log(this.love);
}

var saySomething = {normal: "meow", love: "purr"}
speak.apply(saySomething, ['meouff']);

Expandir objetos con prototype herencia

var speak = function(saywhat) {
  console.log(saywhat);
}

var Dog = function() {
  var name, breed;
}

var Cat = function() {
  var name, breed;
}

Dog.prototype.speak = speak;
Cat.prototype.speak = speak;

firstDog = new Dog;
firstDog.name = "Rover";
firstDog.breed = "Doberman";
firstDog.speak('woof');

firstCat = new Cat;
firstCat.name = "Sniggles";
firstCat.breed = "Manx";
firstCat.speak('meow');

Funciones como objetos

var calc = {
  status: 'Awesome',
  plus: function (a,b) {
    return (
      console.log(this),
      console.log(a+b),
      console.log(arguments),
      console.log(this.status)
    )
  }
}

calc.plus(2,2);


/// Invocando atra ves de constructor

var Dog = function() {
  var name, breed;
  return console.dir(this);
}

firstDog = new Dog;  //crea una instancia
firstDog.name = "Rover";
firstDog.breed = "Doberman";

secondDog = new Dog;
secondDog.name = "Fluffy";
secondDog.breed = "Poodle"

viernes, 13 de marzo de 2015

Crear objetos en javascript

var person = {  //igual que arriba pero cn mayo performance
 
  nombre : "Cesar",
  apellido : "Morones",
  hola : function(){
  return "Hola Cesar";
  }
 
};

Clousure

Funciones clausura


Son funciones que reornan una funcion  con variables de un scope externo.


function testClosure(){

var x =4;  // solo es local esta  variable
return x;

}
/////  Es este ejemplo la funcion interior  puede accesar a las variables de la funcion exterior ya que las toma como variables globales, no es necesario pasarla como parametro.


function testClosure(){

var x =4;  // solo es local esta  variable
function closeX(){
  return x;
}

retun closeX;

}

var checkloalX = testClosure();
checkLocalX();

---> 4


function buildCoverTicketMaker( transport )
 {

  return function (name) {
   alert ("Here is your transportation ticket via the " + transport + ".\n" + "wlecome to the Cold Closures Cove" + name  + "!");

  }
}

var getSubmarineTicket = buildCoverTicketMaker( "Submarine");
var getBatleShipTicket = buildCoverTicketMaker( "Balteship");
var getGiantTicket = buildCoverGiantMaker( "Giant Seagull");

getSubmarineTicket ("cesar");


Invocar funciones inmediatamente

var parkRides = [["Birch Bumpers",40],["Pines Plunge",40],["Cedar Coaster",40],["Ferris wjhell of firs",40]];

var fastPassQueue = ["Pines Plunge", "Birch Bumpers", "Pines Plunge"];

var watsRide = "Pines Plunge";

buildTicket(parkRides, fastPassQueue, watsRide  )();


function buildTicket( allRides, passRides, pick){

if(passRides[0] == pick){
var pass = passRide.shift();
return function(){
  alert ("Quick! You've got a Fast Pass to " + pass + "!");
};

} else {

   for( var i = 0; i< allRides.length; i++){
     if(allrides[i][0]) ==pick ){
     resturn function(){
  alert("A ticket is printing for " + oick + "1\n" + "Your wait time is about " + allRides[i][1]"+ minutes.");
};

}

}
}

})
}

Funciones

var  diff = function diffOfSqueares(a, b){  // En este caso el nombre de la funcion es opcional
return a*a-b*b;
};

var  diff = function (a, b){  // esta hace lo mismo no es necesario el nombre
return a*a-b*b;
};

diff(9,5);

//funciones que reciben funciones como parametros


var greeting = function (){

 alert ("Gracias por tu visita\n" + "hola mundo");
}


function closeTerminal(mensaje ){

mesage();
}

closeTerminal ( greeting );


var numbers = [12, 4, 3 , 9 , 8 , 6 , 10 ,1];

var results = number.map( function (arrayCell){
  return arrayCell * 2;
}



);



jueves, 12 de marzo de 2015

Validar radiobuttons

<SCRIPT LANGUAGE="javascript">
<!--
<!--
var valor = 0;
function fullName(){
var form =document.forms[1]


for (var i =0; i<form.boton.length; i++){
if (form.boton[i].checked==false){
 valor++;
}
}


if (valor != form.boton.length) {
alert(document.form.boton.value)
document.form.submit();
}
else  {

alert("Es necesario que seleccione un registro!!!!")
valor = 0
}
}

//-->
</SCRIPT>

viernes, 6 de marzo de 2015

Levantar un servidor en Python

python -m SimpleHTTPServer 3333

y con eso se levanta un servidor de la parpeta en donde estemos ubicados.