lunes, 5 de diciembre de 2016

LED is my new Hello World - Rust time

As I'm currently learning Rust, I need to publish my LED app again -;)

Please take in mind...that..."I'm learning Rust" my code might be buggy, long and not idiomatic...but...enough to showcase the language and allow me to learn more -;)

Here's the code...
use std::io;
use std::collections::HashMap;

fn main(){
 let mut leds:HashMap<&str, &str> = HashMap::new();

 leds.insert("0", " _  ,| | ,|_| ");
 leds.insert("1", "  ,| ,| ");
 leds.insert("2", " _  , _| ,|_  ");
 leds.insert("3", "_  ,_| ,_| ");
 leds.insert("4", "    ,|_| ,  | "); 
 leds.insert("5", " _  ,|_  , _| ");
 leds.insert("6", " _  ,|_  ,|_| ");
 leds.insert("7", "_   , |  , |  ");
 leds.insert("8", " _  ,|_| ,|_| ");
 leds.insert("9", " _  ,|_| , _| ");

 println!("Enter a number : ");
 let mut input_text = String::new();
 io::stdin().read_line(&mut input_text)
            .expect("failed to read");

 let split = input_text.split("");
 let vec: Vec<&str> = split.collect();
 let count = &vec.len() - 2;
 for i in 0..3{
  for j in 0..count{
   match leds.get(&vec[j]){
    Some(led_line) => { 
     let line = led_line.split(",");
     let vec_line: Vec<&str> = line.collect();
    None => println!("")

And here's the result...

Hope you like and if you can point me in more Rusty way of doing it...please let me know -:D


Development Culture.

My first post on Rust

Again...I'm learning a new programming language...and this time is the turn for Rust.

Rust is very nice and have some really interesting features like ownership and borrowing...and the syntax really reminds me of OCaml...which is really cool as well...

Right now I'm reading the official documentation, that it's pretty well of course I did my Fibonacci numbers app...
use std::io;

fn fib(num: i64, a: i64, b:i64) -> String{
 let mut result: String = "".to_string();
 let sum: i64 = a + b;
 let sum_str: &str = &sum.to_string();
 let a_str: &str = &a.to_string();
 let b_str: &str = &b.to_string();
 if a > 0 && num > 1 {
  result = result + sum_str + " " + &fib((num - 1), (a + b), a);
 }else if a == 0{
  result = "".to_string() + a_str + " " + b_str + " " + 
           sum_str + " " + &fib((num - 1), (a + b), b); 

fn main(){
 println!("Enter a number : ");
 let mut input_num = String::new();
 io::stdin().read_line(&mut input_num)
            .expect("failed to read");

 let trimmed = input_num.trim();
    match trimmed.parse::() {
        Ok(i) => { let result: String = fib(i, 0, 1); print!("{}", result);}
        Err(..) => println!("Please enter an interger, not {}", trimmed)

The code is a little bit long for my taste...but that might be simply because I haven't learned enough Rust...or because their ownership/borrowing system sacrifices length to add security...which is actually a pretty good thing...

Here's the result...

My LED Numbers app is ready of it's coming right after this post -;)


Development Culture.

jueves, 1 de diciembre de 2016

Unity3D and Alexa working together

This post was originally posted on Unity3D and Alexa working together.

Since a long time...I had the idea of making Unity3D and Alexa work together...however...other project kept me away for actually doing couple of days ago...a conversation with a friend made me remember that I actually really wanted to do I did :)

At first...I wasn't exactly sure how to do it...but then slowly the main idea came into my mind...what if Unity read a webservice that gets updated by Alexa? When the right command is parsed, then Unity will create the object and problems is solved...seems easy? actually is...

First things first...we need to create a small NodeJS webserver on Heroku...then...we need to install the Heroku Toolbelt...

Now...create a folder called node_alexa and inside create the following files...

  "dependencies": {
    "express": "4.13.3"
  "engines": {
    "node": "0.12.7"

web: node index.js
var express = require('express')
    ,app = express()

app.set('port', (process.env.PORT || 5000));

app.get('/', function (req, res) {
  if(req.query.command == ""){
 res.send("{ \"command\":\"" + last_value + "\"}");
 if(req.query.command == "empty"){
  last_value = "";
  res.send("{ \"command\":\"" + req.query.command + "\"}");
  last_value = req.query.command;

app.listen(app.get('port'), function () {
  console.log("Node app is running on port', app.get('port')");

Once you have that...log into your Heroku Toolbelt and write the following...

Heroku Toolbelt
cd node_alexa
git init .
git add .
git commit -m "Init"
heroku apps:create "yourappname"
git push heroku master
heroku ps:scale = web 0
heroku ps:scale = web 1

Your webservice is ready to rock :) You should be able to find by going to ""

Now...this simple NodeJS powered webservice will serve as a simple Echo server...meaning...whatever you type will be returned as a json response...of course...if you type "empty" then the response will be a empty the main idea here is that we can keep the last entered value...if you pass a command it will be called again when you don't pass any commands at by calling it once...we can cal it multiple times without disrupting its value...
Next in line...will be to create our Unity app...

Create a new app and call it "WebService" or something like that...project name doesn't matter too much...

If the Hierarchy window select "Main Camera" and change the "Tranform" details like this...

Now, create a new "3D Object" -> "Cube" and name it "Platform" with the following "Transform" details...

After that, we might need to create four wall that will go around the create 4 "3D Object" -> "Cube" and name them "Wall 1", "Wall 2", "Wall 3" and "Wall 4"...

When everything is ready, your workspace should look like this...

Go to the project tab and create a new folder called "plugins" and then create a new C# file called "SimpleJSON"...inside copy the source code from here...this will allow us to use SimpleJSON to parse the JSON...

Now...create another folder called "Script" and inside create a new C# file called "MetaCoding"...or whatever you like...

using UnityEngine;
using System.Collections;
using System.Net;
using System.IO;
using SimpleJSON;

public class MetaCoding : MonoBehaviour {

    int counter = 1;

    IEnumerator DownloadWebService()
        while (true) { 
            WWW w = new WWW("");
            yield return w;

            print("Waiting for webservice\n");

            yield return new WaitForSeconds(1f);

            print("Received webservice\n");

            print("Extracted information");

            WWW y = new WWW("");
            yield return y;

            print("Cleaned webservice");

            yield return new WaitForSeconds(5);

    void ExtractCommand(string json)
        var jsonstring = JSON.Parse(json);
        string command = jsonstring["command"];
        if (command == null) { return;  }
        string[] commands_array = command.Split(" "[0]);
        if(commands_array.Length < 3)
        if (commands_array[0] == "create")
            CreateObject(commands_array[1], commands_array[2]);

    void CreateObject(string color, string shape)

        string name = "NewObject_" + counter;
        counter += 1;
        GameObject NewObject = new GameObject(name);

        switch (shape)
            case "cube":
                NewObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            case "sphere":
                NewObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            case "cylinder":
                NewObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            case "capsule":
                NewObject = GameObject.CreatePrimitive(PrimitiveType.Capsule);
        NewObject.transform.position = new Vector3(0, 5, 0);
        switch (color)
            case "red":
                NewObject.GetComponent().material.color =;
            case "yellow":
                NewObject.GetComponent().material.color = Color.yellow;
            case "green":
                NewObject.GetComponent().material.color =;
            case "blue":
                NewObject.GetComponent().material.color =;
            case "black":
                NewObject.GetComponent().material.color =;
            case "white":
                NewObject.GetComponent().material.color = Color.white;

        // Use this for initialization
    void Start () {
        print("Started webservice import...\n");

 // Update is called once per frame
 void Update () {

Once you have the code...simply attach the script to the Main Camera...

The basic concept for this script is pretty simple...We're creating "DownloadWebService" as an IEnumerator method so we can call it as a Coroutine...and that allow us to have a sleep as we want to give some time between calls...

This method will fetch our Heroku WebService looking for a "create" command...once it has will parse the JSON response and split in we can have..."create", "blue" and "sphere"...this will call CreateObject which will then create a blue sphere...after we have done that...the coroutine will continue as simply send a new command to our WebService to clean the make this work nicely...we want to give 5 seconds after we clean the webservice before trying to see if there's another "create" call...

And this call be will be done by our Alexa basically when saying "create blue sphere" on Alexa...she will be send the command to the WebService...update the message and our Unity app will grab its work...and clean up the Webservice...the wait for Alexa to provide the next command... kind of wrap up...we need to create our Alexa skill...

First, we're going to create a Lambda log in here...

Of course...I have everything already I'm going to create a dummy function just to show the steps...

Click on "Create Lambda Function" and you will be presented with this...

There's a bunch of type in "Color" in the filter box...

Choose "alexa-skills-kit-color-expert"

Leave this as it is and press "Next"

Choose a name and a description...

Choose an existing role if you have it already...otherwise just create a lambda_basic_execution...then raise up Timeout to 10 seconds and leave everything else as it "Next"...a confirmation window will just press "Create function"...

You will be presented with a screen where you can upload your source code (which will be doing later on) and an ARN number...which we need for the next step...

The following part deals with create the Alexa please follow along...and log in here...

Choose "Alexa Skills Kit"...and create a new skill...

Choose a name for you skill and the most important...choose an "Invocation Name"...which is what you're going to use tell Alexa to open you application...something like..."Alexa, open Sandbox" next...

On the Interaction Model tab we have two windows...fill this on "Intent Schema"...

Intent Schema
  "intents": [
      "intent": "GetUnityIntent",
      "slots": [
          "name": "color",
          "type": "LITERAL"         
          "name": "shape",
          "type": "LITERAL"
      "intent": "HelpIntent",
      "slots": []

This are basically the parameters that we can use when asking Alexa to do something...

And fill this on "Sample Utterances"...

Sample Utterances
GetUnityIntent create {red|color} {sphere|shape}
GetUnityIntent create {yellow|color} {sphere|shape}
GetUnityIntent create {green|color} {sphere|shape}
GetUnityIntent create {blue|color} {sphere|shape}
GetUnityIntent create {black|color} {sphere|shape}
GetUnityIntent create {white|color} {sphere|shape}

GetUnityIntent create {red|color} {cube|shape}
GetUnityIntent create {yellow|color} {cube|shape}
GetUnityIntent create {green|color} {cube|shape}
GetUnityIntent create {blue|color} {cube|shape}
GetUnityIntent create {black|color} {cube|shape}
GetUnityIntent create {white|color} {cube|shape}

GetUnityIntent create {red|color} {cylinder|shape}
GetUnityIntent create {yellow|color} {cylinder|shape}
GetUnityIntent create {green|color} {cylinder|shape}
GetUnityIntent create {blue|color} {cylinder|shape}
GetUnityIntent create {black|color} {cylinder|shape}
GetUnityIntent create {white|color} {cylinder|shape}

GetUnityIntent create {red|color} {capsule|shape}
GetUnityIntent create {yellow|color} {capsule|shape}
GetUnityIntent create {green|color} {capsule|shape}
GetUnityIntent create {blue|color} {capsule|shape}
GetUnityIntent create {black|color} {capsule|shape}
GetUnityIntent create {white|color} {capsule|shape}

GetUnityIntent {thank you|color}

This are all the commands that Alexa can understand...and yes...we could have used "Custom Slot Types" to make the code shorter...but...I have had the problems of not working pretty well with more than one slot...simply hit next...

Here, choose AWS Lambda ARN...and pick either North America or Europe depending on your physical location...the on the text box...simply copy and paste the ARN that you received from your Lambda function...

This will send you to the "Test" tab...but we don't want to and actually we can't use that go back to the "Skill Information" tab and you will find that a new field has appeared...

And that should be "Application Id"...copy this number and let's move on to the final step...

Create a folder called "Unity" and inside a folder called "src"...inside that folder copy this file "AlexaSkills.js"

We're going to use the "request" module of install it locally on the Unity folder like this...

sudo npm install --prefix=~/Unity/src request 

This will create a node_module folder with the request module on it...

Then, create a new file called "index.js"

var request = require("request")
  , AlexaSkill = require('./AlexaSkill')
    , APP_ID     = 'yourappid';

var error = function (err, response, body) {
    console.log('ERROR [%s]', err);

var getJsonFromUnity = function(color, shape, callback){

var command = "create " + color + " " + shape;

if(color == "thank you"){
 callback("thank you");
var options = { method: 'GET',
  url: '',
  qs: { command: command },
   { 'postman-token': '230914f7-c478-4f13-32fd-e6593d8db4d1',
     'cache-control': 'no-cache' } };

var error_log = "";

request(options, function (error, response, body) {
 if (!error) {
  error_log = color + " " + shape;
  error_log = "There was a mistake";

var handleUnityRequest = function(intent, session, response){
  getJsonFromUnity(intent.slots.color.value,intent.slots.shape.value, function(data){
 if(data != "thank you"){
 var text = 'The ' + data + ' has been created';
 var reprompt = 'Which shape would you like?';
    response.ask(text, reprompt);
  response.tell("You're welcome");

var Unity = function(){, APP_ID);

Unity.prototype = Object.create(AlexaSkill.prototype);
Unity.prototype.constructor = Unity;

Unity.prototype.eventHandlers.onSessionStarted = function(sessionStartedRequest, session){
  console.log("onSessionStarted requestId: " + sessionStartedRequest.requestId
      + ", sessionId: " + session.sessionId);

Unity.prototype.eventHandlers.onLaunch = function(launchRequest, session, response){
  // This is when they launch the skill but don't specify what they want.

  var output = 'Welcome to Unity. Create any color shape by saying create and providing a color and a shape';

  var reprompt = 'Which shape would you like?';

  response.ask(output, reprompt);

  console.log("onLaunch requestId: " + launchRequest.requestId
      + ", sessionId: " + session.sessionId);

Unity.prototype.intentHandlers = {
  GetUnityIntent: function(intent, session, response){
    handleUnityRequest(intent, session, response);

  HelpIntent: function(intent, session, response){
    var speechOutput = 'Create a new colored shape. Which shape would you like?';

exports.handler = function(event, context) {
    var skill = new Unity();
    skill.execute(event, context);

This code is very simple...because it mostly a simply copy it...change a couple of things and you're ready to go...

Basically when you say "Alexa, open Unity"...she will listen for your you can say "create green cube" will call our Heroku WebService and the wait for another command...if you doesn't speak to her again...she will prompt you to say something...if you say "Thank you" she will politely deactivate herself...

And that's pretty much it...once Alexa send the command to the WebServer...our Unity App will read and act accordingly...creating whatever shape and color you requested...nice, huh?

But of don't believe, don't you? It can't be that simple...well...yes and's simple...but I took all the pain point and provide you with the nice and clean set of instructions...'s how it looks like when you run the Unity app...

And here the action video...

Hope you like it...and stay tuned...because for me this was only a proof of concept...the real thing will become my next full time project...


Development Culture.

LED is my new Hello World - Swift (for Linux) time

It took me some time to write this post...mainly because I'm now learning Rust and also because I just finished my latest demo...whose blog is coming later today -;)

This version of my LED Numbers app becomes the 25th language's a pretty nice milestone for me -:D Who knows? Maybe I will do something nice if I can ever reach 50 languages -:D I love to say..."Enough me the source code" -;)

let leds: [Character:String] = [
 "0" : " _  ,| | ,|_| ",
 "1" : "  ,| ,| ",
 "2" : " _  , _| ,|_  ",
 "3" : "_  ,_| ,_| ",
 "4" : "    ,|_| ,  | ",
 "5" : " _  ,|_  , _| ",
 "6" : " _  ,|_  ,|_| ",
 "7" : "_   , |  , |  ",
 "8" : " _  ,|_| ,|_| ",
 "9" : " _  ,|_| , _| "

print("Enter a number: ",terminator:"");
let num = readLine(strippingNewline: true);

var line = [String]();
var led = "";

for i in 0...2{
 for character in num!.characters{
  line = String(leds[character]!)!.
                       characters.split(separator: ",").map(String.init);
  print(line[i], terminator:"");

And here's the picture of it working its magic -:)


Development Culture.

lunes, 28 de noviembre de 2016

My first post on Swift (for Linux)

As Apple kindly released Swift for Linux...I had to learn about it -:)

Of's not fully most of the things that makes Swift awesome on IOS are not here yet...but's awesome! -:D

Swift is kind of you can see a lot from Haskell and Erlang...but it's also imperative and Object that makes it a really interesting language...

As's my Fibonacci numbers little app...

func fib(num:Int,a:Int,b:Int) -> String{
 var result: String = "";
 if a > 0 && num > 1{
  result = result + String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: a);
 }else if a == 0{
  result = String(a) + " " + String(b) + " " + 
           String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: b);
 return result;

print("Enter a number: ",terminator:"");
let number = Int(readLine(strippingNewline: true)!);

print(fib(num: number!, a: 0, b: 1));

And here's the result....

I already have the LED Numbers app just wait for it -;)


Development Culture.

martes, 15 de noviembre de 2016

LED is my new Hello World - Perl Time

As's my LED Numbers a la Perl...and as always...please keep in mind that I'm Perl newbie...I know that there are more efficient, short and concise way of doing this good is an introductory code that uses some obscure and arcane code? I don't want to scare people away from Perl...I want people to say "Hey...that doesn't look hard...I want to learn Perl"... it is...
use strict;
use warnings;
use diagnostics;

my %leds = (
 0 => ' _  ,| | ,|_| ',
 1 => '  ,| ,| ',
 2 => ' _  , _| ,|_  ',
 3 => '_  ,_| ,_| ',
 4 => '    ,|_| ,  | ',
 5 => ' _  ,|_  , _| ',
 6 => ' _  ,|_  ,|_| ',
 7 => '_   , |  , |  ',
 8 => ' _  ,|_| ,|_| ',
 9 => ' _  ,|_| , _| '

print "Enter a number: ";
my $num = <>;
my @numbers = ( $num =~ /\d/g );

for my $i (0 .. 2){
 for my $j (0 .. scalar(@numbers) - 1){
  my @line = split /\,/,$leds{$numbers[$j]};
  print $line[$i];
 print "\n";

And here's the output...

And just so you know...this is my 24th version of this code...yep...I have written my LED Numbers app in 24 languages so far -;) What's going to be my end point? Who knows...programming is the limit -;)


Development Culture.

My first post on Perl

So yes...I started to learn Perl...why? 3 simple reasons...

  1. I love programming.
  2. For me...Perl belongs to the whole trinity of Scripting Languages along with Ruby and Python (Sorry don't make the cut)
  3.'s Perl! Come on!

So...I have been reading Beginning awesome book by the way...

If you're using any flavor of Linux or should have Perl installed already...if you're using can always download it and install it -:)

So far...I love's pretty amazing...and now I can see why people say that both Python and Ruby heavily borrow stuff from Perl...and sure...PHP too...

I don't have of course much experience...but as always...I start doing a simple and small program to get me into the right here's my Fibonacci numbers app...
use strict;
use warnings;
use diagnostics;

sub fib {
 my ($num,$a,$b) = @_;
 my $result = '';
 if ($a>0 && $num>1){
  $result = $result . ($a+$b) . " " . fib($num-1,$a+$b,$a)
 }elsif($a == 0){
  $result = $a . " " . $b . " " . ($a+$b) . " " . fib($num-1,$a+$b,$b)
 return $result

print "Enter a number: ";
my $num = <>;


And here's the nice output...

By now...I already have my classic "LED Numbers" app ready...but that goes into another post -;)


Development Culture.

martes, 9 de agosto de 2016

Microsoft HoloLens on SAP’s d-shop

This post was originally posted on Microsoft HoloLens on SAP’s d-shop.

One of SAP’s d-shop main goals is to gather, learn and share knowledge on the latest technologies and Microsoft HoloLens haven’t been out of our radar -;)

But…what is HoloLens?

HoloLens is a Mixed reality device…which is basically a mix of Virtual (Oculus Rift) and Augmented (Google Glass) Realities.

One of the most important features on Mixed Reality is that it allows you to create Holograms that can be blended into the real world and interact with them.

HoloLens will map your room and recognize that you have a coffee table, a sofa, a lamp, and so on…when you place your Holograms on a table or sofa, the Hologram will not go through it, but instead sit on it…and this allows to do amazing things like creating a Hologram of a lamp to be placed next the sofa and see how it looks. And that’s just one of the many uses cases that HoloLens can provide.

At the d-shop Silicon Valley, we believe that using and coding the HoloLens is an awesome experience.

So…what you do need to start coding and creating amazing experiences?

In this page you will find all the tools that you need, which includes Visual Studio, a tailor made version of Unity3D and the HoloLens emulator.

Also, it would be really good for you to take a look at the Holographic Academy videos…which guide you through the basics notions of HoloLens coding…

But…with this blog what we really want to show you a video with some of the demos/projects that we have created at the d-shop Silicon Valley.

Word Clock With this app, you can literally read the time -;) This demonstrates text usage in Unity and it was adapted from a Python application.

d-shop Robot This app uses a d-shop robot model built using Blender. This demonstrate Spatial Mapping and simple voice commands.

SAP Puzzle Game This app displays a sliding puzzle game that has two modes…easy and hard…it demonstrates how to clip an image and distributed into multiple cubes, it also demonstrates basic voice commands and physics.

HoloHouse This app is a project built for a bank in Dubai to be used as a real state application. The models were build using 3ds Max by an external company. This app demonstrates how to use Unity scripting to rotate the houses, fade the lights, lift the roof and floors of the houses and display annotations.

Now that you have seen what can be done in a couple of weeks…why don’t you join us at the d-shop and show us what you can do! -:D


Development Culture.

domingo, 7 de agosto de 2016

d-shop's very first Hololens Hackaton

This post was originally posted on d-shop's very first Hololens Hackaton.

On August, Wednesday 3 we hosted our d-shop’s very first Hololens Hackaton. People who had never used Unity3D before and of course who had never code for the Hololens before gathered together to have a fun and exciting learning experience.

Thanks to the hard work and organization efforts from my team partners Aaron Williams and Julia Satsuta we had three awesome guys from Microsoft Vlad Kolesnikov, Petri Wihelmsen and Jaime Rodriguez.

The first day was spend with explanations of what Hololens is…a quick introduction to Unity3D and a design thinking / brainstorming part where the teams could develop their ideas.

The second day started with Hololens coding and coaching from our side. People were totally excited and pumped up…trying things out on the Unity3D editor…on the Hololens emulator and on the device itself.

As a way to include more people and leave the teams working without too many distractions, we had a session on Hololens on Building 7…open for anyone to join in…

After that, we went back to keep coaching and helping the teams. They needed to be fully ready by 3:30pm as we had the demo presentation at 4:00pm.

The demo presentation happened at the cafeteria on Building 8.

We had 5 teams presenting their awesome work…


Design your dream room

Order part on the go...don't waste your time filling sheets

Next Talent

Engage your newly hired talents by immersing them in your culture and history


Planning your next trip? Get the seat that it's more comfortable for you

The Wesley Crushers

Is your pipe broken? Check it...measure it and request a replacement

As you can see…all the teams put a lot of effort and created some really awesome demos…but…there’s always need to be only one winner…so the last team to present was the team who won…so…congratulations “The Wesley Crushers” team!

After this really nice experience…I’m sure we’re going to come back for more…Hololens is still a brand new technology, so there’s still a lot to learn, a lot to hack and a lot of possibilities.

If you’re in Palo Alto…come and visit us! Remember that the d-shop is located on the first floor of Building 9 on Deer Creek Road -;)


Development Culture.