viernes, 10 de enero de 2014

MeteorJS and SAP HANA

If you thought that I was going to learn MeteorJS and not try to link with SAP HANA...then you were dead wrong -;)

Of course...I'm far from being a good Meteor developer...so please bear with me -:( I'm also not very good at NodeJs...so...you know...this is just me playing around -:)

So...let's begin...there's a lot of ways that we can use to connect Meteor and SAP HANA...but...what if we can somehow do it with a native connection?

If you haven't visit SAP Developers on GitHub yet...I recommend you to do it...we have some really nice Open Source projects in there...

Anyway...in there you will find a hidden gem simply called node-hdb which is course...a NodeJS native connector for SAP HANA...awesome, huh?

Now...you will ask...why does NodeJS has to do with Meteor? Easy...Meteor uses NodeJs in the background...

Checking the web...I found this awesome Meteor Hack called Complete NPM integration for Meteor which is just great...basically...it allows us to include NodeJS packages in the underlying NodeJS service of our Meteor installation...

Simply do this...

Getting node-hdb into Meteor
npm install -g meteor-npm
cd "your_project"
meteor-npm

This will create an "npm" folder into your project...now...simply create a file called packages.json in your root folder...

Packages.json
{
 "hdb": "0.2.0"
}

With that...we're ready to rock with Meteor -;)

First...let's do the html part...

HANA_Test.html
<head>
  <title>SAP HANA and MeteorJS</title>
</head>

<body>
  {{> CallHANA}}
</body>

<template name="CallHANA">
<DIV ID'block' ALIGN='CENTER'>
<H1>Calling SAP HANA from MeteorJS</H2>
 <TABLE BORDER='1'>
 <TR><TH>Carrier</TH><TH>Connection</TH>
     <TH>Country From</TH><TH>City From</TH>
     <TH>Airport From</TH><TH>Country To</TH>
     <TH>City To</TH><TH>Airport To</TH>
     <TH>Distance</TH></TR>
 {{#each Spfli}} 
  <TR>
   <TD>{{CARRID}}</TD><TD>{{CONNID}}</TD>
   <TD>{{COUNTRYFR}}</TD><TD>{{CITYFROM}}</TD>
   <TD>{{AIRPFROM}}</TD><TD>{{COUNTRYTO}}</TD>
   <TD>{{CITYTO}}</TD><TD>{{AIRPTO}}</TD>
   <TD>{{DISTANCE}}</TD>
  </TR>
 {{/each}}
 </TABLE>
</DIV> 
</template>

Then...create two folders...one called "server" and the other called "client"...

Inside the "server" folder create a file called "HANA_TestServer.js"

HANA_TestServer.js
var myjson = [];

Meteor.methods({
    'CallHANA': function CallHANA() {
  hdb    = Meteor.require('hdb');
    client = hdb.createClient({
    host     : 'hanasvr-XX.sapdevcenter.com',
    port     : 30015,
    user     : 'SYSTEM',
    password : 'XXXXXX'
  });

  client.connect(function (err) {
     if (err) {
       return console.error('Connect error', err);
     } 
      client.exec('select top 10 * from SFLIGHT.SPFLI', function (err, rows) {
       client.end();
       if (err) {
          return console.error('Execute error:', err);
       }
        var count = Object.keys(rows).length
        for(var i=0;i<count;i++){
         myjson.push(rows[i]); 
        } 
      });
  });
  return myjson;
 }  
  });

Then inside the "client" folder create a file called ""HANAClient.js"...

HANAClient.js
 Meteor.startup(function () {
    Meteor.call("CallHANA", function (error, result) {
             Session.set("myjson", result);
            });
    });

    Template.CallHANA.Spfli = function () {
     row = Session.get("myjson");
     return row;
    };

With that ready...simply call up your meteor application and after you refresh your page...I need to work on the reactivity part -:( I'm sure a single button calling the function will do the trick...but I'm tired and I'm lazy...The result from the query will be shown -;)


Not that fancy I know...but for the first step...I guess it's good enough -;)

Greetings,

Blag.
Developer Empowerment and Culture.

lunes, 6 de enero de 2014

Machine Learning with R - Book Review

I have to admit it...I'm an R junkie...since the first time I started learning R...it has become an addiction to me...I try to solve every problem with R...which is obviously not the best way to go...but my rule of thumb is..."Try with R first...otherwise...just use something else and then go back to R" -;)

This time I was really excited to read a new R book (well...maybe not new...but new for me) called Machine Learning with R...


For me this book should be called "The Big Book for R nerds"...with 396 pages...this book is just beautiful, amazing and one of the best R books I have ever read...

Of course...keep in mind that is not a book for beginners...you need to have previous R experience to fully understand everything...so if you're not a R advocate...please help yourself and read the also awesome The R Inferno...

The book of course, contains a small introduction to R principles and most used commands like Vectors, Factors, Lists, Data Frames and data manipulation.

When the book really gets interesting is when the Machine Learning gets introduced...


It a nutshell...a Machine Learning algorithm will take input...learn something and the toss out a result that will help us make a decision...simply pure magic -:)

Some of the algorithms covered in this book...and covered in a really easy and digestible way with some of the best examples you could think of...are these...


  • Nearest Neighbor

  • naive Bayes 

  • Decision Trees 

  • Classification Rule Learners 

  • Linear Regression 

  • Regression Trees 

  • Model Trees 

  • Neural Networks 

  • Support Vector Machines 

  • Association Rules 

  • k-means Clustering

  • A little bit overwhelming, huh? Well...not really...R and it's plethora of packages makes your life easier....after reading this book...you will be able to apply each and everything single algorithm to your real life projects...but of course...you experience, trial and error and perseverance will be highly appreciated...

    Let's see some examples...

    Cross table for a Nearest Neighbor

    Decision Tree

    Neural Network Diagram

    Association Rules

    Random Forests

    Amazing isn't it? Of course...but the fun doesn't end there...the book helps us even more with chapters on...
    • Evaluation Model Performance
    • Improving Model Performance
    • Specialized Machine Learning Topics
    If you have played with R before and always wondered what the hell Machine Learning means and why you should learn it...this book is totally for you...I recommend it 100%...

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    martes, 31 de diciembre de 2013

    Getting Started with Meteor.js JavaScript Framework - Book Review

    Since I got this book I got some interest in reading it...mainly because with so many JavaScript Frameworks...I was skeptic...but...Meteor just totally blown my mind...this is my review...



    Two things comes to mind one when I think about this book...both Meteor.js and the book...totally rocks! Why? Simply because the book is really well explained...it's funny...yes...it's funny...and it comes with a real full blown application to build...I will show the screens later...

    If you're a Windows user like me...follow this link Meteor on Windows. Otherwise...just use the regular link...

    The book is not really long...as it's only 131 pages...but it covers everything you need to know to go out and build your first applications...really...after reading the book you just want to build stuff...and I already have a couple of things in mind -;)

    The book introduce you to the following themes...
    • Templates
    • Data, Meteor Style
    • Security and Accounts
    • Packaging and Deploying
    So...one cool thing about Meteor...is that it comes bundled with Minimongo...a minimized version of the document based MongoDB...which is course more than enough for simple applications...

    Now...I guess that you don't believe me...you still think that Meteor is just another JavaScript Framework...well...let me tell you...it has become for sure...my favorite JavaScript Framework...sorry AngularJS....


    This is the application that you build with the book...a simple "Lending" application...so you can keep track of your stuff...



    Not impressed yet? Well...Meteor comes with a Login UI package...



    So you don't have to deal with internal stuff...just create your user...and have fun -:)

    The only problem I see right now with Meteor...is that there are not enough books...but hopefully that's going to change while the framework becomes more popular and widely used -;)

    And of course...I would buy this book right away if I was you...

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    jueves, 26 de diciembre de 2013

    Mastering Web Application Development with AngularJS - Book Review

    I just finished reading Mastering Web Application Development with AngularJS and I gotta say...I have some mixed feelings -:P


    First things first...this book is huge...372 pages...and it covers a lot of things...but...there's always a downside...

    The book talks about building an SCRUM application...and it provides a lot of snippets that are related to that application...however...even when you download the book's source code...the application is nowhere to be found...meaning that either you figure out yourself...or just end with a bunch of nice but not very useful snippets...

    To be fair...this can be seen as either good or bad...good because it forces you to try it yourself and in the end...learn more...but also bad because without proper experience...there's no way you can build it and that leads to frustration...

    Anyway...there are some nice and complete examples that really make you keep going...also...the book covers many interesting aspects like...

    • Model transformations with filters
    • Advanced forms creation
    • Forms validation
    • Navigation
    • Application Security
    • Internationalization
    • Custom build directives

    It would say...if you really have AngularJS experience...then this book is for you...as it has some really nice tricks...otherwise...grab a more basic book...build applications...gain experience...and then read this one...otherwise...you will get lost more than once...

    Let's take a look at some pictures...





    What I like this book however is the fact that it introduces us to many "external" JavaScript libraries...without actually introducing us to them...which is funny...

    • Twitter's Bootstrap
    • Grunt.JS
    • Jasmine
    • Express
    • Passport
    • Restler
    At least...by knowing about them...we can explore them and make use of them -;)

    This said...I'm glad I read it...but...if I ever put myself on the situation where I actually need to build an AngularJS application...I would read it again...hopefully next time...I would be able to get more out of it...

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    Cookoo Watch - Product Review

    So...what do a geek like me get for Christmas?


    A Cookoo watch of course! -:D

    So...let's review it -;)


    The watch comes in a nice Birdhouse like case...that can be actually used as a real Birdhouse...or at least...that's what they propose...nice I should say -:)


    The watch is a little bit big but doesn't feel annoying when wearing it...after the first 5 minutes...you simply get used to it...also...but being able to link it with your phone...it couldn't be small...


    One of the things that I like about the watch is that it allows you to control the phone camera...this by using the Cookoo Life software that it's of course...available for free...actually...I obviously took the picture by using the "Command button" on the watch -;)

    Another cool thing...is that it allows you to control the music...one single click to Pause/Play...but longer to change the song and a bit long to actually stop it...

    Regarding the battery life...well...the watch connects to your phone by using Bluetooth Smart...so it really doesn't drain too much battery...I made a small experiment today...

    I charged my phone up to 100%...then leave home and walk to the office...which takes me around 40 minutes...I had the music on and was checking email, Facebook and Foursquare...when I hit the office...only 8% was drained...so we could say...around 1% every 5 minutes...something like 8 hours till the next recharge...of course...not taking into account "Phone calls"...that will drain your battery quickly...I gotta say...not bad at all...

    Also...the watch itself comes with a regular watch battery...so there's no need to charge it...it's supposed to last for at least a year and it's very easy to replace...it's water resistant as well -;)

    So...what else does this nice watch does?


    As you can see...it can tell you if you have a missing call...if you have new emails...if you have a calendar appointment...if you have a Facebook message...and if you're forgetting your phone...

    It's also supposed to allow you to do Facebook check-ins...but I haven't been able to make it work on the latest Cookoo Life update....as the current version is a new one designed specially for IOS 7...I guess they keep working on making it better...

    One thing that caught my attention was this....


    So...they will release an API to allow developers to create new way to connect the Phone with the watch...I already have some nice ideas but I prefer for now to wait for API to be released before I drop out something...

    So far...I love this watch...haven't got any "disconnect" problems...and it's working as promised...can't wait to see how this evolves in the future -:)

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    lunes, 23 de diciembre de 2013

    Instant AngularJS Starter - Book Review

    I have used AngularJS before when I wrote my blog AngularJS, PHP and SAP HANA. But of course...I only learnt what I need at that time...so I really wanted to learn a little bit more -;)

    Instant AngularJS Starter is the my first "Instant" book...and I can say...I couldn't be happier with it -:)



    Even when the book is fairly short...only 66 pages...it's just the kind of book I love...it comes with a quick introduction to AngularJS and what it's more important...the whole book guides you through the building of a complete application...so you can learn how to build it from the scratch and get a perfect base to build your own projects...

    The author explains everything is a nice and easy way...so it's easy to follow and understand...let's see some images of the application you will get to build...




    As you can see...it's just a simple application but in the end it uses all the AngularJS settings so you can quickly get use to them and learn them as well...

    If you haven't use AngularJS before...then this book is totally for you...if you have some experience...then just go for something more advanced...this book is aimed for the total newbie...and...even when I wasn't a total newbie...I learnt a lot from it...

    I got another AngularJS book that I just start reading...so stay tuned for more... -;)

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    jueves, 19 de diciembre de 2013

    Packt Publishing Book Bonanza!

    My friends at Packt Publishing had release a cool campaign!


    From December 19th, 2013 to January 3rd, 2014...all books and videos are just $5...without a limit!

    Cool, huh? Just follow this link http://bit.ly/1jdCr2W and fill your library -;)

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    miércoles, 18 de diciembre de 2013

    PhoneGap 3 Beginner's Guide - Book review

    This week...I read PhoneGap 3 Beginner's Guide which is a nice book, so here goes my review...


    To begin with...in my opinion...this is not a beginner's book at all...it's a book that will walk you through the new and cool things implemented on PhoneGap 3...so if you haven't used PhoneGap before, I will recommend you to choose another book like PhoneGap 2.x Mobile Application Development Hotshot...

    If you have previous PhoneGap experience...then this a good book for you...as it cover many cool things like:
    • App Templates
    • JavaScript compression
    • Web DB
    • Sensor
    • GeoLocation
    • Files
    • PhoneGap Plug-Ins.  
    There are many examples but they are used to achieve certain things, like using the Camera or dealing with GeoLocation...so no end to end examples are given...but if you have previous PhoneGap experience...that shouldn't be so much of a problem...

    One good thing about the book is that it takes care of showing how to achieve things on Mac OS, Linux and Windows, including alternatives when a certain tool can be used only on one of the Operating Systems...giving everyone the ability to try it out.

    Let's look at some pictures...




    The book also comes with exercises and pop up quizzes, so that's a good way to improve our knowledge and keep coding.

    In a overall...I have to say this again...if you're a newbie...be aware that this book is not meant for you...if you have previous experience...then this book is good enough to put you on the right track and show you some PhoneGap goodies...

    Greetings,

    Blag.
    Developer Empowerment and Culture. 


    viernes, 13 de diciembre de 2013

    Playing with schema flexibility on SAP HANA

    The other day, a colleague from the Labs asked me an interesting question..."Let's say you have a table with schema flexibility...with a lot of fields that might be empty...how do you know which are fields that have at least one value?"...of course...I didn't knew how to answer that...so of course...I put myself to work...as expected -;)

    First...let's create our table with a couple of values and some "missing" values...

    Create table Products
    DROP TABLE Products;
    
    CREATE COLUMN TABLE Products(
    PRODUCT_CODE VARCHAR(3),
    PRODUCT_NAME NVARCHAR(20),
    PRICE DECIMAL(5,2)
    ) WITH SCHEMA FLEXIBILITY;
    
    INSERT INTO Products values ('001','Blag Stuff', 100.99);
    INSERT INTO Products (PRODUCT_CODE,PRODUCT_NAME,PRICE,COLOR) 
    values ('002','More Blag Stuff',100.99,'Black');
    INSERT INTO Products (PRODUCT_CODE,PRODUCT_NAME,PRICE,COLOR,TYPES) 
    values ('003','More Blag Stuff',100.99,null,null);
    

    When we check the contents of the table we will have this...


    As we can see...the last field has no values at all...so we will need to retrieve the names of the other fields...for this...we're going to create a table to hold them...then...we're going to create a Procedure to retrieve them...

    Create table FIELDS_RECORDS
    DROP TABLE Fields_Records;
    
    CREATE COLUMN TABLE FIELDS_RECORDS(
    FIELD_NAME VARCHAR(256)
    );
    

    For the Procedure...we're going to read all the fields that compose the table...then we're going to count all the values that are not null for each field...for this...we're going to use the help of a temporal table and dynamic SQL as sadly...SQLScript doesn't support scarlar binding yet...

    GET_FIELDS_WITH_RECORDS
    DROP PROCEDURE GET_FIELDS_WITH_RECORDS;
    
    CREATE PROCEDURE GET_FIELDS_WITH_RECORDS(IN TableName VARCHAR(256))
    LANGUAGE SQLSCRIPT AS
    v_column_name VARCHAR(256);
    v_select VARCHAR(256);
    v_count INTEGER := 0;
    CURSOR c_cursor(v_column_name VARCHAR(256)) FOR
    SELECT COLUMN_NAME FROM SYS.CS_COLUMNS_ A inner join SYS.CS_TABLES_ B
    on A.table_oid = B.table_oid where schema_name = 'SYSTEM'
    and table_name = :TableName
    and internal_column_id > 200
    order by internal_column_id;
    BEGIN
    FOR cur_row AS c_cursor(v_column_name) DO
    create local temporary table #temptable(found INTEGER);
    
    v_select := 'INSERT INTO #temptable (SELECT COUNT(' || cur_row.column_name || ') 
                 FROM ' || :TableName || ' WHERE ' || cur_row.column_name || ' IS NOT NULL)'; 
    exec v_select;
    
    SELECT found INTO v_count FROM #temptable;
    IF v_count > 0 THEN
    v_select := 'INSERT INTO FIELDS_RECORDS VALUES(''' || cur_row.column_name || ''')';
    drop table #temptable;
    exec v_select;
    END IF;
    END FOR;
    END;
    

    When we call our Procedure, we simply need to pass the name of the table...and then read it's content...

    Call Procedure and get info
    CALL GET_FIELDS_WITH_RECORDS('PRODUCTS');
    
    SELECT * FROM FIELDS_RECORDS;
    

    Let's see what do we have on FIELDS_RECORDS -;)


    Just as expected -:) Nice, huh?

    Greetings,

    Blag.
    Developer Empowerment and Culture.

    miércoles, 11 de diciembre de 2013

    Learning jQuery, Third Edition - Book Review

    I started reading this book in order to learn JQuery...just because...

    I didn't had high expectations but this book really blown me away...

    Learning jQuery, Third Edition is just amazing...it's a really long book full with practical examples and things that you could use right away...


    The book starts with the very basics and slowly moves into more complex examples and external JQuery plug-ins...after reading it...I just love JQuery -;)





    With 13 chapters and 2 appendixes...this is a huge book that will have you both hook and entertained for a long time -:) 

    This book should be on your book shelve for sure! JQuery can really boost up your old HTML pages -;)

    Greetings,

    Blag.
    Developer Empowerment and Culture.