domingo, 21 de diciembre de 2014

generar json en php

<?php

$student = array("id"=>101,
"name"=>"John Doe",
"isStudent"=>true,
"scores"=>array(10, 20, 30, 40),
"courses" => array(
"major"=>"Finance",
"minor"=>"Marketing"
)
);

echo json_encode($student); //encoding the array into a JSON string
//and using echo to  print the output

?>

lunes, 1 de diciembre de 2014

Fusiones

Fusiones


Solución de conflictos

a) Fast-Forward
b) Manual Merge

Fast-Forward
Los gestores trabajaron archivos diferentes al repositorio

Manual Merge
¿Qué pasa cuando 2 desarrolladores trabajan el mismo archivo en la fusión?

RAMAS

2.2 Ramas


El concepto HEAD
¿En qué punto de la historia de nuestro proyecto nos encontramos?

git branch [nombre]
git log --oneline --graph --all
git config --global alias.nicelog 'log --oneline --graph --all'

Repositorios "forked"

Repositorios "forked"
Crear ó entrar a la carpeta del proyecto
$ git remote add origin [HTTPS ó SSH del proyecto forked]
$ git remote add upstream [HTTPS ó SSH del proyecto "main"]
$ git fetch upstream
$ git merge origin/upstream
$ git fetch origin
$ git merge origin/master
Hacer cambios en local
$ git fetch upstream
$ git merge origin/upstream
$ git push origin master

Ciclo final - Repositorios "forked"






Ciclo final - Repositorios "forked"

Subir cambios a GitHub

Subir cambios a GitHub

$ git init
$ git remote add origin [HTTPS or SSH]
$ git remote -v
Generamos cambios
$ git commit -am "[Mensaje]"
$ git push origin master

Git Fetch & Git Merge

Git Fetch & Git Merge

Creamos ó entramos a la carpeta de nuestro proyecto
$ git init (si apenas vamos a iniciar)
$ git remote add origin [HTTS or SSH]
$ git fetch origin
$ git merge origin/master
Hacen cambios
$ git fetch origin
$ git merge origin/master
$ git push origin master

domingo, 30 de noviembre de 2014

MENU DINAMICO EN YII

$baseUrl2 = YiiBase::getPathOfAlias("webroot");

$menus= $baseUrl2.'/menus/menus.json';

//echo $menus;
$datos = file_get_contents($menus);
$recuperar = json_decode($datos, true);

//echo json_encode($recuperar);
//die();

 $this->widget('application.extensions.eflatmenu.EFlatMenu', array(
    'items'=>$recuperar,
));

$this->widget('application.extensions.eflatmenu.EFlatMenu', array(
    'items' => array(
        array('label' => 'Home', 'url' => array('/site/index'), 'active' => true, 'icon-class'=>'fa-home'),
        array('label' => 'About', 'url' => array('/site/page', 'view' => 'about')),
        array('label' => 'Contact', 'url' => array('/site/contact')),
        array('label'=>'Level 2 Menu', 'url'=>'#', 'items' => array(
            array('label' => 'Sub-Menu 1', 'url' => '#', 'icon-class'=>'fa-home'),
            array('label' => 'Level 3 Menu', 'url' => '#', 'items' => array(
            array('label' => 'Sub-Menu 1', 'url' => '#', 'icon-class'=>'fa-home'),
            array('label' => 'Sub-Menu 2', 'url' => '#'),
            )),
        )),
        array('label' => 'Login', 'url' => array('site/login'), 'visible' => Yii::app()->user->isGuest),
        array('label' => 'Logout (' . Yii::app()->user->name . ')', 'url' => array('/site/logout'), 'visible' => !Yii::app()->user->isGuest)
    )
));

miércoles, 15 de octubre de 2014

Instalar Wireshark

Install WireShark 1.11.4
sudo add-apt-repository ppa:dreibh/ppa
sudo apt-get update
sudo apt-get install wireshark

sudo chmod a+x /usr/bin/dumpcap

jueves, 9 de octubre de 2014

directiva ng-repeat

Esta directiva hace un foreach de cada elemento de una variable de tipo array

(function () {
  var app = angular.module('pokedex', []);

  app.controller('PokemonController', function () {
    this.pokemon = {
      id: "001",
      name: "Bulbasaur",
      species: "Seed Pokémon",
      type: [ "Grass", "Poison" ],
      height: "2′4″ (0.71m)",
      weight: "15.2 lbs (6.9 kg)",
      abilities: [ "Overgrow", "Chlorophyll" ],
      stats: {
        hp: 45,
        attack: 49,
        defense: 49,
        "sp.atk": 65,
        "sp.def": 65,
        speed: 45,
        total: 318
      },
      evolution: [ "Bulbasaur", "Ivysaur", "Venusaur" ]
    };
  });

})();

<!DOCTYPE html>
<html ng-app="pokedex">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Pokédex</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/main.css">
  </head>
  <body>
    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">
            <img src="img/logo.png">
            Pokédex
          </a>
        </div>
      </div>
    </div>
    <div class="container">
      <!-- pokemon -->
      <div ng-controller="PokemonController as pkmCtrl">
        <div class="page-header">
          <h1>
            {{pkmCtrl.pokemon.name}}
            <small>{{pkmCtrl.pokemon.species}}</small>
            <span class="label label-primary pull-right">#{{pkmCtrl.pokemon.id}}</span>
          </h1>
        </div>
        <div class="row">
          <div class="col-md-6">
            <img class="avatar center-block" ng-src="img/pokemons/{{pkmCtrl.pokemon.name | lowercase}}.jpg">
          </div>
          <div class="col-md-6">
            <ul class="nav nav-tabs nav-justified">
              <li class="active"><a href="#">Pokédex</a></li>
              <li><a href="#">Stats</a></li>
              <li><a href="#">Evolution</a></li>
            </ul>
            <div class="tab-content">
              <!-- Pokedex -->
              <div>
                <ul class="list-group">
                  <li class="list-group-item">
                    <strong>Type</strong>
                    <span class="pull-right">
                      <span class="label type type-{{type | lowercase}}" ng-repeat="type in pkmCtrl.pokemon.type">
                        {{type}}
                      </span>

                    </span>
                  </li>
                  <li class="list-group-item">
                    <strong>Height</strong>
                    <span class="pull-right">{{pkmCtrl.pokemon.height}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Weight</strong>
                    <span class="pull-right">{{pkmCtrl.pokemon.weight}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Abilities</strong>
                    <ul>
                      <li ng-repeat="ability in pkmCtrl.pokemon.abilities">
                        {{ability}}
                      </li>

                    </ul>
                  </li>
                </ul>
              </div>
              <!-- Stats -->
              <div>
                <ul class="list-group">
                  <li class="list-group-item">
                    <strong>HP</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats.hp}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Attack</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats.attack}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Defense</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats.defense}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Special Attack</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats['sp.atk']}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Special Defense</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats['sp.def']}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Speed</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats.speed}}</span>
                  </li>
                  <li class="list-group-item">
                    <strong>Total</strong>
                    <span class="badge">{{pkmCtrl.pokemon.stats.total}}</span>
                  </li>
                </ul>
              </div>
              <!-- Evolution -->
              <div>
                <div class="text-center" ng-repeat="pokemon in pkmCtrl.pokemon.evolution">
                  <a href="#">
                    <img src="img/pokemons/{{pokemon | lowercase}}.jpg" width="160">
                    <p>
                      <strong>{{pokemon}}</strong>
                    </p>
                  </a>
                  <span ng-hide="$last" class="glyphicon glyphicon-arrow-down"></span>
                </div>

              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- /pokemon -->
    </div>
    <script src="js/lib/angular.min.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

Directiva ng-controller

Se crea app.js

(function () {
  var app = angular.module('pokedex', []);

  app.controller('PokemonController', function () {
    this.pokemon = {
      id: "001",
      name: "Bulbasaur",
      species: "Seed Pokémon",
      type: [ "Grass", "Poison" ],
      height: "2′4″ (0.71m)",
      weight: "15.2 lbs (6.9 kg)",
      abilities: [ "Overgrow", "Chlorophyll"]
    };
  });

})();


SE DEFINE EL MODULO pokedex

<!DOCTYPE html>
<html ng-app="pokedex">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Pokédex</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script>
    <script src="js/app.js"></script>
  </head>
  <body>
    <div ng-controller="PokemonController as pkmCtrl">
      <h1>{{pkmCtrl.pokemon.name}} #{{pkmCtrl.pokemon.id}}</h1>
      <h2>{{pkmCtrl.pokemon.species}}</h2>
      <img src="img/{{pkmCtrl.pokemon.name | lowercase}}.jpg">
      <h2>Pokédex</h2>
      <ul>
        <li><strong>Type</strong> {{pkmCtrl.pokemon.type.join(', ')}}</li>
        <li><strong>Height</strong> {{pkmCtrl.pokemon.height}}</li>
        <li><strong>Weight</strong> {{pkmCtrl.pokemon.weight}}</li>
        <li><strong>Abilities</strong> {{pkmCtrl.pokemon.abilities.join(', ')}}</li>
      </ul>
    </div>
  </body>
</html>

lunes, 6 de octubre de 2014

Posiciones en CSS










Elememntos por default estatic

http://www.virtuosimedia.com/includes/Files/Uploaded/Images/Articles/Content/css-positioning.jpg

Display block, inline-block, none

display:  block; /* estilo por defecto*/
 /*display: inline-block;
 display: none; /* lo desaparece de la pagina*/
background: lightgray; /*Pone el texto en la misma linea*/

Modelos de caja









Asi funcional culaquier tag html, todos tienen por defecto

CSS con http://suitcss.github.io/

header{
    background: blue;
}
.header {
    background: blue;
}


ul > li {
    background: blue;
}

section + section {
    background: red; /* estilo adyacente */
}

/*selector de atributos
*/

[href="#Yo"] {
    background: orange;
}

Convenciones

http://suitcss.github.io/

.MyComponent {}
.MyComponent.is-animating {}
.MyComponent--modifier {}

.MyComponent-part {}
.MyComponent-anotherPart {}
 
 

viernes, 3 de octubre de 2014

Instalar adobe air

sudo apt-get install libxt6:i386 libnspr4-0d:i386 libgtk2.0-0:i386 libstdc++6:i386 libnss3-1d:i386 lib32nss-mdns libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386

And you have to create a symbolic link to your gnome keyring:


sudo ln -s /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0 sudo ln -s /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0


wget http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRInstaller.bin
chmod a+x AdobeAIRInstaller.bin
./AdobeAIRInstaller.bin

miércoles, 3 de septiembre de 2014

crear un usuario y dar permisos

mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost;
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit;

jueves, 28 de agosto de 2014

CSS3: Box Model

Principales Propiedades
  1.  width
  2. height
  3. Padding
  4. Border
  5. Margin

Find all con parametros

  $data =Trimestres::model()->findAll((array(
    'condition'=>"id_periodo=$_POST[id_periodo]",
    'order'=>'id'
    )));

miércoles, 30 de julio de 2014

montar conexiones remotas

SSH
Para mapear/montar una carpeta de un servidor remoto como lo cal hay que utilizar sshfs, si no lo teneis instalado bastan con ejecutar en debian o derivados:
sudo apt-get install sshfs
Una vez instalado el programa tenemos que crearnos una carpeta en disco donde mapearemos el la ruta del servidor remoto, por ejemplo:
ruta local: /home/depruebas/www/servidor_remoto
En el servidor remoto queremos mapear la ruta:
/var/www/html/mi_proyecto_guay
La instrucción es la siguiente:
sshfs root@servidor.remoto.com:/var/www/html/mi_proyecto_guay /home/depruebas/www/servidor_remoto
Esto crea una carpeta en tu disco con los datos de la ruta del servidor remoto.

domingo, 27 de julio de 2014

Codigo de NodeBots

var keypress = require('keypress'),
    five = require("johnny-five"),
    board = new five.Board({
      //port: '/dev/cu.itead-DevB'
      port: '/dev/cu.usbmodem1411'
    });

board.on("ready", function() {

  console.log("Testint motors... ");

  // motor = new five.Motor({
  //   pins: {
  //     pwm: 4,
  //     dir: 5
  //   }
  // });
  motor1Fwd = new five.Led({
    pin: 5
  });

  motor1Rev = new five.Led({
    pin: 4
  });

  motor2Fwd = new five.Led({
    pin: 6
  });

  motor2Rev = new five.Led({
    pin: 7
  });


  board.repl.inject({
    motor1Fwd: motor1Fwd,
    motor1Rev: motor1Rev,
    motor2Fwd: motor2Fwd,
    motor2Rev: motor2Rev
  });

  // make `process.stdin` begin emitting "keypress" events
  keypress(process.stdin);

   // listen for the "keypress" event
  process.stdin.on('keypress', function (ch, key) {
    if (key && key.ctrl && key.name == 'c') {
      process.exit(0);
    }

    if ( key ){
      switch ( key.name ){
        case 'up':
          console.log(' => Up: ');
          motor1Fwd.on()
          motor2Rev.on()
          break;
        case 'down':
          motor2Fwd.on();
          motor1Rev.on();
          break;
        case 'left':
          motor1Fwd.off()
          motor2Rev.on()
          console.log(' => Left: ');          
          break;
        case 'right':
          motor1Fwd.on()
          motor2Rev.off()
          console.log('right');
          break;
        case 'space':
          console.log(' => Stoping...');
          motor1Fwd.off();
          motor2Fwd.off();
          motor1Rev.off();
          motor2Rev.off();
          break;
        default:
          console.log('Ignoring key: ' + key.name);
      }
    }

  });

  process.stdin.setRawMode(true);
  process.stdin.resume();
});

viernes, 13 de junio de 2014

Instalar smartgit en ubuntu


 1993  sudo add-apt-repository ppa:eugenesan/ppa
 1994  sudo apt-get update
 1995  sudo apt-get install smartgit
 1996  sudo apt-get install smartgithg

viernes, 6 de junio de 2014

Uso de GIT y github

Instalar GIT

cesar@developerWEB:/var/www$ sudo apt-get install git
cesar@developerWEB:/var/www$ sudo apt-get install git-core

Configuramos las variables

cesar@developerWEB:/var/www$ git config --global user.name 'Cesar Morones Sanchez'
cesar@developerWEB:/var/www$ git config --global user.email 'cesar.morones1@gmail.com'

Generamos un par de llaves

cesar@developerWEB:/var/www$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cesar/.ssh/id_rsa):
/home/cesar/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cesar/.ssh/id_rsa.
Your public key has been saved in /home/cesar/.ssh/id_rsa.pub.
The key fingerprint is:
34:51:aa:47:d2:02:74:d1:7c:dc:5d:bb:32:69:1a:f4 cesar@developerWEB
The key's randomart image is:
+--[ RSA 2048]----+
|   .o o+.o.. . ..|
|     o .ooo . . .|
|      o *. .   . |
|       * .. . . .|
|      . S  . E . |
|       .    + o  |
|           .     |
|                 |
|                 |
+-----------------+

Una vez que tenemos la llave hay que ponerla  en github en

Clonamos una carpeta de hithub a nuestra maquina


cesar@developerWEB:/var/www/clone$ sudo git clone https://github.com/cmorones/Sfotipy.git
[sudo] password for cesar:
Cloning into 'Sfotipy'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

checamos el status

cesar@developerWEB:/var/www/clone/Sfotipy$ git status
# On branch master
nothing to commit (working directory clean)

Creamos dos archivos 

cesar@developerWEB:/var/www/clone/Sfotipy$ touch hola.txt hola2.txt

checamos el sttaus y vemos que ya tenemos dos archivos nuevos

cesar@developerWEB:/var/www/clone/Sfotipy$ git status

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   README.md
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# hola.txt
# hola2.txt
no changes added to commit (use "git add" and/or "git commit -a")

Los agregamos 

cesar@developerWEB:/var/www/clone/Sfotipy$ git add --all
cesar@developerWEB:/var/www/clone/Sfotipy$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   README.md
# new file:   hola.txt
# new file:   hola2.txt

Con este comando desagregammos

cesar@developerWEB:/var/www/clone/Sfotipy$ git reset

Y le damos commit
#
cesar@developerWEB:/var/www/clone/Sfotipy$ git commit -m 'añadi dos archivos'
[master e3a7f8c] añadi dos archivos
 0 files changed
 mode change 100644 => 100755 README.md
 create mode 100755 hola.txt
 create mode 100755 hola2.txt

Este comando se usa solo la primera vez  que hacemos un push  y significa que vamos a subir los archivos a github

cesar@developerWEB:/var/www/clone/Sfotipy$ git push -u origin master
Username for 'https://github.com': cmorones
Password for 'https://cmorones@github.com':
To https://github.com/cmorones/Sfotipy.git
   a2b33ad..e3a7f8c  master -> master
Branch master set up to track remote branch master from origin.

Separar la logica de la aplicacion con templates

var source =$("#song-template").html();
undefined
source
" <span> {{name}} - {{author}} </span> <span class="right"> <a href="" class="action icon-add gray"></a> <a href="" class="action icon-love gray"></a> <a href="" class="action icon-share gray"></a> </span> "
var template = Handlebars.compile(source);
undefined
var song = new Sfotipy.Song ({ name:"Marinlyn Monroe", author : "Pharell Williams" });
undefined
song.toJSON();
Object {name: "Marinlyn Monroe", author: "Pharell Williams"}
var html = template(song.toJSON());
undefined



var song = new Sfotipy.Song ({ name:"Thuder", author : "ACDC" });
undefined
var song1 = new Sfotipy.Song ({ name:"One", author : "Metallica" });
undefined
var songs = new Sfotipy.Songs([song, song1]);
undefined
songs

child {length2modelsArray[2]_byIdObjectconstructorfunctionmodelfunction}
songs.at(0);

child {cid"c1"attributesObject_changingfalse_previousAttributesObjectchangedObject}
songs.at(0).toJSIN();

TypeError: undefined is not a function
songs.at(0).toJSoN();

TypeError: undefined is not a function
songs.at(0).toJSON();
Object {name: "Thuder", author: "ACDC"}
songs.at(1).toJSON();
Object {name: "One", author: "Metallica"}
song.forEach(function(s){console.log(s.toJSON());});

TypeError: undefined is not a function
songs.forEach(function(s){console.log(s.toJSON());});
Object {name: "Thuder", author: "ACDC"} VM6044:2
Object {name: "One", author: "Metallica"} VM6044:2
[
child
,
child
]

songs.where({name: "One"});


var song = new Sfotipy.Song ({ name:"Thuder", author : "ACDC" });
undefined
var songView = new Sfotipy.SongView({ model: song, el: $(".list")});
undefined
songView.render();
undefined
song.set({name: "Marilyn Monroe", author:"Pharrell Williams"});

child {cid"c1"attributesObject_changingfalse_previousAttributesObjectchangedObject}

jueves, 5 de junio de 2014

main.js

Sfotipy = {};

Sfotipy.Song = Backbone.Model.extend({});

Sfotipy.SongView = Backbone.View.extend({
tagName: 'li',
className: 'item border-bottom',

render: function(){
var song =this.model;
var name =song.get('name');
var author = song.get('author');

this.$el.html("<span>" + author + "</span - <span>" + name + "</span>");
}
});


window.Sfotipy = Sfotipy;

Vistas en Backbone.js

Crear una vista

var SongView = Backbone.View.extend({ tagName: 'li', className:'item border-bottom', id:'song1'});
undefined
var view= new SongView();
undefined
view.el
  1. <li id=​"song1" class=​"item border-bottom"></li>