Thursday, December 11, 2014

[Pt-Br] Novo encontro de cloud e programação

Venha você também no novo encontro / meetup aprender e compartilhar conhecimento de tecnologias no dia 18 às 19h na Globalcode. mais informações no

Friday, October 31, 2014

Why I wanna try React.js in production


[DISCLAIMER - my personal impressions about some JS frameworks are described on this post. You may agree or not. I do not hate any of them, I just think all of them have good and bad parts, and each situation may have a different framework chose]

I have been using some JS frameworks in my projects - Angular.js, Backbone and Ember.js. Each of these have their own characteristics and advantages/disadvantages:

  • - Angular.js - Easy to use for very simple apps; hard to learn and maintain for more complex apps. It's easy to end up with giant controllers! (more here).
  • - Backbone.js - Beginners tend to many unnecessary XHR requests or mix some concepts between views and models. It's a little hard to learn, but (good part) besides these two points, it's hard to end up with a messed up code (more about Backbone impressions here) .
  • - Ember.js - I really like Ember, because I think it has a very simple convention and pretty easy to learn. But when your system gets big and complex, you end up with some problems described here.

A few days ago I was trying to decide which framework to use a new project. Someone mentioned: "Why not React?" I noticed I knew very few about it and didn't have anything in production with React yet. So... Why would React.js be cool?

At my first Google glances, I thought React was something like mustache.js or something, just a template library. One of the first articles I came across was this. So I thought I'd really need to use React only as the V layer, and maybe I'd still need to use Ember, Backbone or Angular.

After reading this post, I was convinced that it was not just that. This article describes that React could be used as something more than a template library, as it bring 3 main features: event and data binding, virtual DOM and components. This is more than just templating. IMHO it's something V+C, or maybe V+ part of C and part of M. Maybe for simple apps, React would be enough, but what about complex apps? This inconsistent definition and not conventioned use could make people use React under an inappropriate way.

Randomly and fortunately, I came across another Facebook tool: Flux. So yes, that was the missing piece for something more complex apps - Flux gives some pattern and structure for React.js. It organizes a clean MVC for the view through an element called Dispatcher. This is way different from the other MVC we have. In the other frameworks, we add logic to the controller layer:
(think about view as being a component or a single view)
Our controllers may bring us inconsistent states because the logic belong to them, not for the component itself! Example:
Oh no! See, we have sold and count on Controller. Count depends on sold, and the views need to render this information. With this, we lock one part of the view with the other, and we can end up with some trouble and weird code here - and worst, we may end up needing some explicit callback hell chain :( This is like a cascade effect that may harm us in some points of the system, especially the ones with a complex machine state.

What Flux do is introduce a pretty consistent data model, composed by a Dispatcher (that I have mentioned before) and a Store layer:

So see, this diagram is totally unidirectional - actions talk to dispatchers, dispatcher talks to store and views talk to actions! Now I won't be arrested to a callback cascade or something. Every time my view needs something, it will ask for an action, and not lock the controller layer. The dispatcher will handle the invokes.

React.js enters to give speed for the view - if we have a complex state machine on the system, the view will have to handle with frequent changes! And we can't loose performance! When store changes, React re-renders the entire component. Haaaa!! There it goes, the Virtual DOM! When the data changes, a new Virtual DOM is created. A diff (yes, a DIFF!) between the 2 versions of DOMs is created and TA-DA! The new real DOM is made with a diff! It gets view render pretty fast!

That's why Instagram and Facebook use this tool, Flux.

Well, I am not sure about the learning curve of this tool, but I think it's a pretty more complicated than Backbone or Ember. However, it's a very interesting tool IMHO! It brings a very decoupled model, and also seems easy to maintain the code.

All in all, theory is cool, but I need a production env to have my own conclusions. I already have a very dynamic environment with a complex state machine.

Do you have React or Flux in prod environment? Feel free to share your thoughts!

Sunday, August 31, 2014

Torquebox 3.1 - Injectable Resources demystified!

Hello, guys!

During the last week I had the chance to attend RubyconfBR, a great Ruby conference that happens every year here in Sao Paulo. I also could present a bit about Torquebox, a great tool to mix Java and Ruby languages into the same container. Torquebox is a pretty great tool IMHO, but it lacks of marketing and better examples. The first time I tried Torquebox was in 2011 and now in 2014 it is much more mature, fast and reliable.

Torquebox has a very interesting feature - you can deploy a JAR file inside a Ruby application and invoke a Java class inside Ruby code. Nothing new for JRuby users, but it makes a 'box' that makes the code much more simple:

 @m = TorqueBox.fetch(Java::test.torquebox.MemberRegistration)  

Well, a similar example is listed in the documentation. The problem is that it is not into a 'for dummies' format, so it gets pretty hard to execute. First thing we need to know is that Torquebox 3 has two operation modes:

  • A 'Slim' one - a format where you do not have all JBoss/JEE features embedded on it, turning the container lighter and faster, but incomplete in terms of JEE implementations. (Download here)
  • A 'Full' mode - You need to download JBoss AS 7.1 (or higher) or JBoss EAP (6.1 or higher - I am using JBoss EAP 6.3, that you can download here) and then download Torquebox Overlay Package (here). After that, you need to add Overlay files into JBoss AS or EAP, *respecting the proper directories*! Think about Overlay package as a JBoss Patch. This will give you all JEE implementations with full power of a Java Application Server. *THIS* is the only mode that Injectable resources will work properly, since CDI libs will be loaded here!
After that, another problem - I could not fin an example of Java application + Ruby application that I could deploy into Torquebox. Argh. So I created one example here. The only part that you should build with mvn clean install is the EJB project, that will generate a JAR for you. This project has a single Java class for test:

 package test.torquebox;  
 import javax.enterprise.context.ApplicationScoped;  
 import javax.inject.Inject;  
 public class MemberRegistration {  
      public MemberRegistration() {  
           // TODO Auto-generated constructor stub  
   public String minhaRegraDeNegocio() {  
        return "LOLOLOLOLOL";  

Clone the project from Github, go to ejb/ folder and run
mvn clean install

After that, you should obtain a JAR file with the class.

Then create your Rails application using JRuby (1.7.12 or higher). Paste the JAR into the lib/ folder of the Rails app. You should end up with something like this project.

Now you can call the Java classes inside the JAR just the way like the initial example in the post. You can also call the into the ERB files:
  <%= @m %>  
  <%= @m.minhaRegraDeNegocio %>  


Thursday, August 28, 2014

How to configure a JDBC driver on Wildfly / JBoss AS7

Hi guys! Welcome back to this series of blog post that aims to teach you something new  on every post =)

So in this post we are going to configure an JDBC driver on Wildfly / JBoss AS 7. I mention the JBoss AS as there still many people using it. Remember that Wildfly is the continuation of JBoss AS project, it just renamed it and now Wildfly is the upstream, having all the bleeding edge technologies and fixes.

I will try to make some very simple and specify steps how to do this with an example, drop a comment if you need any more help or if something went wrong, I will help you =)

For this tutorial, let's suppose we have a Oracle Database that we want to use in our WAR/EAR project. First things we need to know the specific version of the database (you can ask to the DBA or if you already have access to the database using a tool, just do a query like 'select * from v$version;' to check the Oracle DB version).

Now you need the JDBC Driver, which implements a many interfaces defined to abstract the database vendor to an easy to use API. So for this example, to get the JDBC driver from Oracle's website (which will require you to have an account) you will got to .

Now that we have the driver, it would be interesting to push that jar into your local maven repository (or you private repository), so if you need some classes from that JAR in your project and you use Maven (or some other technology that  can read the maven repository), that would help to control the JDBC version and type as well. To install it, run the following command (changing the parameters, like the 'ojdbc6.jar ' to the path of your JDBC jar file) and put it as dependency in the pom.xml with provided scope.
mvn install:install-file -Dfile=ojdbc6.jar -DartifactId=ojdbc6 -Dversion=11.2.0-4 -Dpackaging=jar

Now using Wildfly you have two options, you can drop the JDBC driver file into the deployment folder OR you can also create a module for this JDBC drive.

Then you have to setup the JDBC conection pool. Again, this can be done by two different ways, one you can use the web management console to create the connection (would look like this jdbc:oracle:thin:@HOST:PORT:SID ) or you can use the CLI (a command-line interface that comes with Wildfly) to connect to your remote server (or locally) and create the connection pool. Below an example of the CLI commands:    
[standalone@localhost:9990 /] data-source add --name=OracleDS --driver-name=ojdbc6.jar --connection-url=jdbc:oracle:thin:@HOST:PORT:SID --jndi-name=java:jboss/jdbc/OracleDS --user-name=u --password=p
[standalone@localhost:9990 /] reload
[standalone@localhost:9990 /] /subsystem=datasources/data-source=OracleDS:enable()
[standalone@localhost:9990 /] /subsystem=datasources/data-source=OracleDS:test-connection-in-pool()

Done! Now you can get your datasource using @Resource or configuring with your JPA or even using JNDI, for example:

InitialContext context = new InitialContext();
DataSource a = (DataSource) context.lookup("java:jboss/jdbc/OracleDS");

Well, hope it helped a bit to setup your JDBC driver and connection. I will put some useful links in the end of the post.

Thank for reading! Let me know any question.


Tuesday, June 3, 2014

Getting more secure with End-to-end and more advices for your privacy!

Hi, I would like to help people to install the end-to-end project (you can read the overview in the google security blog here). For those how want 10,000 feet overview, it basically it will make you encrypt your emails, which is much more secure, you can even put a password that only the recipients will be able to read.

To install, you need to get the contents from project wiki and use the following instructions (after resolving the dependencies (like git, svc, wget, java and etc) in case you don't have them installed before hand):

To install (get the source):
chmod a+x

To compile:
cd e2e_dev/
chmod a+x
shopt -s expand_aliases

Then just install the unpacked extension using the path  e2e_dev/end-to-end/javascript/crypto/e2e/extension/
(More details about it in )

Congratulations for the amazing project Google and  end-to-end project team =)

Guys, checkout other projects in ,so you can find things like disconnect that can help to avoid those advertisements and some undesired contents and other useful things to have more privacy.

Kindest regards,

Monday, June 2, 2014

PostgreSQL working on Mac OS Mavericks

Hello, all!

Installing PostgreSQL and make it up and running usually is a mess to me.
So, some simple and few steps worked pretty well to me.

1. Download and Install -
2. Install brew (
3. brew install postgresql

Fine! You have postgreSQL installed. However, it may generate the following error if you try to run a migration from Rails:

 Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?  

Now you have to follow these steps:

4. sudo mkdir /var/pgsql_socket/
5. ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
(steps described here - - on section named "No Socket" )

Almost there! Now it's time for (if it happens)

 rake aborted!  
 FATAL: role "postgres" does not exist  

So, finally,
6. Access PostgreSQL command Line (if is running, click on the elephant on the menu bar, then Open psql, as shown on the image below)
Click on "Open psql" option
7. Now, on the terminal, type
It will show you a list of SUPERUSERS. If you don't have postgres a SUPERUSER, simply add one:

And doonnee! Finally you have PostgreSQL up and running!

Saturday, May 17, 2014

Helios - iOS apps Backend made easy

Hi All!

Some time ago I found a precious tool to build backend apps for iOS world - Helios framework! . This guy is a ruby gem that allows you to do Data Mapping and Push Notifications in a very, very easy way.

If you like to build backends in Ruby and uses Heroku, this gem can be very useful if you need an iOS backend.

I have made some talks about it -  .

Warning - this guy is Beta yet. However, it's very stable - I have tried it with no disappointments!