lunes, 25 de mayo de 2015

El Libro del Día: Expert TSQL Window Functions in SQL Server

El Libro del Día: 2015-05-25

Titulo: Expert TSQL Window Functions in SQL Server
Autor: Kathi Kellenberger, Clayton Groom
Editorial: Apress
Nro Paginas: 140

Capítulos:
Chapter 1: Looking Through the Window
Chapter 2: Discovering Ranking Functions
Chapter 3: Summarizing with Window Aggregates
Chapter 4: Tuning for Better Performance
Chapter 5: Calculating Running and Moving Aggregates
Chapter 6: Adding Frames to the Window
Chapter 7: Taking a Peek at Another Row
Chapter 8: Understanding Statistical Functions
Chapter 9: Time Range Calculations and Trends

Descarga:
Expert_TSQL_Window_Functions_in_SQL_Server

viernes, 22 de mayo de 2015

El Libro del Día: Microsoft Azure SQL Database Step by Step

El Libro del Día: 2015-05-22

Titulo: Microsoft Azure SQL Database Step by Step
Autor: Leonard G. Lobel, Eric D. Boyd
Editorial: Microsoft Press
Nro Paginas: 401

Capítulos:
CHAPTER 1 Getting started with Microsoft Azure SQL Database
CHAPTER 2 Configuration and pricing
CHAPTER 3 Differences between SQL Server and Microsoft Azure SQL Database
CHAPTER 4 Migrating databases
CHAPTER 5 Security and backup
CHAPTER 6 Cloud reporting
CHAPTER 7 Microsoft Azure SQL Data Sync
CHAPTER 8 Designing and tuning for scalability and high performance
CHAPTER 9 Monitoring and management
CHAPTER 10 Building cloud solutions

Descarga:
Microsoft_Azure_SQL_Database_Step_by_Step

jueves, 21 de mayo de 2015

El Libro del Día: Custom SharePoint Solutions with HTML and JavaScript

El Libro del Día: 2015-05-21

Titulo: Custom SharePoint Solutions with HTML and JavaScript
Autor: Brandon Atkinson
Editorial: Apress
Nro Paginas: 240

Capítulos:
Chapter 1: Setting Up Your Environment
Chapter 2: Introduction to SharePoint Front-End Solutions
Chapter 3: Content Editor and Script Editor Web Parts
Chapter 4: Building Custom Web Parts Using HTML and JavaScript
Chapter 5: Using JSLink to Style List Web Parts
Chapter 6: Content Search Web Part and Display Templates
Chapter 7: Working with SharePoint’s Built-in JavaScript Functions and Properties
Chapter 8: Working with the JavaScript Object Model
Chapter 9: Working with the REST API

Descarga:
Custom_SharePoint_Solutions_HTML_JavaScript

miércoles, 20 de mayo de 2015

El Libro del Día: SignalR Blueprints

El Libro del Día: 2015-05-20

Titulo: SignalR Blueprints
Autor: Einar Ingebrigtsen
Editorial: Packt
Nro Paginas: 244

Capítulos:
Chapter 1: The Primer
Chapter 2: Overheating the Discussion
Chapter 3: Extra! Extra! Read All About It!
Chapter 4: Can You Measure It?
Chapter 5: What Line of Business Are You In?
Chapter 6: An Architectural Taste
Chapter 7: The Three Screens - Mobile First
Chapter 8: Putting the X in .NET - Xamarin
Chapter 9: Debugging or Troubleshooting
Chapter 10: Hosting and Deployment

Descarga:
SignalR_Blueprints

martes, 19 de mayo de 2015

El Demo del Día: Obtener el Tipo de Cambio de la Pagina de la SUNAT

Obtener el Tipo de Cambio de la Pagina de la SUNAT

Después de mucho tiempo de no publicar un Demo, vamos a compartir un pedido de una persona que necesitaba ingresar a la pagina de la SUNAT diariamente y copiar el tipo de cambio para ingresarlo en su sistema, lo ideal seria tener un Servicio Web de uso libre, pero ante la falta de este o si existe necesitaríamos las credenciales, les dejo esta solución.

Requerimiento

Obtener diariamente en forma automática el tipo de cambio de la SUNAT publicado en la siguiente dirección: http://www.sunat.gob.pe/cl-at-ittipcam/tcS01Alias

Solución

Vamos a crear una aplicación Windows en C# .NET que use la clase HttpClient para hacer una llamada asíncrona a la dirección de la pagina, bajarla a memoria, crear una cadena con el contenido y extraer la parte que corresponde al tipo de cambio del ultimo día: las 3 ultimas celdas de la ultima fila de la segunda tabla de la página.

Restricción

La aplicación podría fallar en un futuro si la SUNAT cambia su contenido agregando o quitando tablas y habría que hacer los ajustes respectivos al código, pero aun así es una ayuda por mientras.

Crear una Aplicación Windows Forms en C#

Abrir Visual Studio y crear una aplicación Windows Forms en C# llamada "TipoCambioSUNAT", cambiarle de nombre al formulario por "frmSUNAT" y realizar el diseño similar a la figura mostrada:


Hacer una referencia a la librería: "System.Net.Http.dll" y escribir el siguiente código en el formulario:

using System;
using System.Collections.Generic; //List
using System.Text; //Encoding
using System.Windows.Forms;
using System.Net.Http; //HttpClient, HttpResponseMessage
using System.IO; //File, MemoryStream

namespace TipoCambioSUNAT
{
    public partial class frmSUNAT : Form
    {
        public frmSUNAT()
        {
            InitializeComponent();
        }

        private void btnConsultar_Click(object sender, EventArgs e)
        {
            HttpClient cliente = new HttpClient();
            cliente.BaseAddress = new Uri("http://www.sunat.gob.pe/");
            HttpResponseMessage rpta = cliente.GetAsync("cl-at-ittipcam/tcS01Alias").Result;
            if (rpta != null&&rpta.IsSuccessStatusCode)
            {
                string contenido = "";
                using(MemoryStream ms= (MemoryStream)
                rpta.Content.ReadAsStreamAsync().Result)
                {
                    byte[] buffer = ms.ToArray();
                    contenido = Encoding.UTF8.GetString(buffer);
                    contenido = contenido.ToLower();
                }
                if (contenido.Length > 0)
                {
                    File.WriteAllText("Sunat.txt", contenido);
                    int posInicioT1= contenido.IndexOf("<table");
                    int posFinT1 = contenido.IndexOf("</table");                  
                    if (posInicioT1 > -1&&posFinT1>-1)
                    {
                        int posInicioT2 = contenido.IndexOf("<table",posInicioT1+1);
                        int posFinT2 = contenido.IndexOf("</table", posFinT1 + 1);
                        string tabla = contenido.Substring(posInicioT2, posFinT2 - posInicioT2 + 8);
                        File.WriteAllText("Tabla.txt", tabla);
                        posInicioT1 = 0;
                        tabla = tabla.Replace("</strong>", "");
                        List<string> valores = new List<string>();
                        for (int i = 1; i < 4; i++)
                        {
                            posInicioT1 = tabla.LastIndexOf("</td");
                            if (posInicioT1 > -1)
                            {
                                tabla = tabla.Substring(0,posInicioT1).Trim();
                                posFinT1 = tabla.LastIndexOf(">");
                                if (posFinT1 > -1)
                                {
                                    valores.Add(tabla.Substring(posFinT1 + 1,
                                    tabla.Length - posFinT1 -1).Trim());
                                }
                            }
                        }
                        if (valores.Count > 0)
                        {
                            txtVenta.Text = valores[0];
                            txtCompra.Text = valores[1];
                            txtFecha.Text = valores[2];
                        }
                    }                  
                }
            }
        }
    }
}

Nota: En este Demo los datos de la consulta van a 3 TextBoxs pero pueden ir directamente a la BD en vez de mostrarse en pantalla.

Ejecutar y Probar la Aplicación Windows Forms

Grabar la aplicación y pulsar F5 para ejecutarla, luego clic al botón "Consultar" y se mostrarán los datos del último día, el tipo de cambio compra y el tipo de cambio venta, tal como se muestra en la siguiente figura:


Comentarios

Muchas veces queremos obtener un cierto dato de una pagina y tenemos que entrar manualmente, en este post hemos visto como usando el método "GetAsync" de la clase "HttpClient" del Namespace "System.Net.Http" podemos hacerlo vía código.

En este caso lo hemos aplicado a la pagina de la SUNAT, la cual se analizó su HTML y se observó que tiene varias tablas, la segunda corresponde a la tabla con los datos de los tipos de cambios de la última semana, para lo cual se obtuvo la última fila y de esta las 3 últimas celdas.

No se hizo mediante XML porque el HTML estaba mal formado y no generaría bien el XML DOM, es por eso que trabajamos con texto puro y substrings.

Este Demo lo terminamos en colaboración con mis alumnos del Taller de los Domingos a los cuales les doy las gracias por estar siempre pendientes de aprender y querer mejorar.

Si alguien de ustedes tiene alguna URL de algún Servicio Web que consideren útil compartir por ejemplo el del Tipo de Cambio o Consulta de RUC de la SUNAT, DNI de la RENIEC, ONPE, etc. seria bueno hacer otro post pero ya usando Servicios.

Descarga del Código
DemoDia_TipoCambioSUNAT

El Libro del Día: Adaptive Code via C#

El Libro del Día: 2015-05-19

Titulo: Adaptive Code via C#
Autor: Gary McLean Hall
Editorial: Microsoft Press
Nro Paginas: 433

Capítulos:
PART I AN AGILE FOUNDATION
CHAPTER 1 Introduction to Scrum
CHAPTER 2 Dependencies and layering
CHAPTER 3 Interfaces and design patterns
CHAPTER 4 Unit testing and refactoring
PART II WRITING SOLID CODE
CHAPTER 5 The single responsibility principle
CHAPTER 6 The open/closed principle
CHAPTER 7 The Liskov substitution principle
CHAPTER 8 Interface segregation
CHAPTER 9 Dependency injection
PART III ADAPTIVE SAMPLE
CHAPTER 10 Adaptive sample: Introduction
CHAPTER 11 Adaptive sample: Sprint 1
CHAPTER 12 Adaptive sample: Sprint 2
Appendix A: Adaptive tools
Appendix B: GitHub code samples

Descarga:
Adaptive_Code_via_C#

viernes, 15 de mayo de 2015

Personajes de la Computación - Kyle Simpson

Personajes de la Computación - Kyle Simpson

Kyle Simpson es un especialista en JavaScript, HTML5 y Web Performance (Frontend). Es reconocido por ser uno de los principales Evangelistas de la Web Libre (Open Web).

Kyle es de Austin, Texas (USA) y trabaja en Getify Solutions. Es conferencista y autor de una serie de libros denominados: "You Don't Know JS" que se han convertido en un material indispensable para entender JavaScript.


A continuación les dejo mas información de su trabajo y aporte al Desarrollo de Software especialmente en JavaScript.

Libros

O'Reilly - 2014 You Don't Know JS. Scope & Closures


O'Reilly - 2014 You Don't Know JS. this & Object Prototypes


O'Reilly - 2015 You Don't Know JS. Types & Grammar


O'Reilly - 2015 You Don't Know JS. Async & Performance


Direcciones

You Don't Know JS (Github)

Google+

Blog de Getify

Videos de Entrevistas

Entrevista sobre OSCON 2013


Entrevista sobre Fluent 2014


Developer Roundtable: What does HTML5's future look like beyond the browser?


Entrevista sobre Fluent 2015: JavaScript Coercion's bad reputation


Videos de Conferencias

JS.everywhere( ) 2012: Browser Versions are Dead


HTML5DevConf 2013: New Rules For JS


Forward JS 2014: JavaScript, Choose Your Own Adventure


OSCON 2014: Syncing Async


E4E Developer Conf 2014: Syncing Async


GOTO 2014: New Linting Rules


Comentario Final

Son 6 libros publicados por Kyle de los cuales he subido 4 que son muy buenos y con información muy importante que todo programador JavaScript debe conocer. Recuerden que el Lenguaje de Programación del Futuro es JavaScript tanto en el cliente (CofeeScript, TypeScript, Dart, etc) como en el Servidor (Node.js), por tanto, hay que conocer mejor el lenguaje.