Thursday, May 29, 2014

I could say this is a classic. I know that a lot of people already know this, but I think that beginners will find it very, very useful.

When learning any programming language it's vital to have good code as example for our own creations. Also, Python is a great way to learn programming, I think better than Java, without messing your brain up with anti-patterns in your code.

Having that in mind, one of the best challenges for beginners is to create a program that solves a Sudoku game. For those who don't know the game, you can read about it here. It's basically a mathematical game that consists on sorting numbers. I'm sure you've seen some Sudokus in the news papers. Now, for programming, the different solutions for this problem lead to some interesting mental exercises, and it looks like Peter Norvig thought the same.

Norvig is a computer scientist now working for Google. he has a lot of articles, presentations, speeches, etc., available online. You should check his webpage, it has some interesting material.

However, what really got my attention was this article. It's a comprehensive manual on how to beat any Sudoku puzzle with a simple application in Python. What is interesting about this article is that he explains how he did it with full details. It begins with the algorithm, and goes on to finish with the complete code.

My advise:

a) Read the whole article very carefully.

b) Download the code and modify it. For example, you could add a graphical interface with Jython.

Of course, you should have some basic programming skills, but I'm sure that you'll learn a lot from this great article.

Monday, May 26, 2014

There are some situations on which you'll need to share internet from PC to your Android. For example, there are some security policies in certain offices that restrict WiFi connections severely. So, if you need to perform any operation in your phone and don't want to spend money with the cellular connection, you can use this trick.

7. Click "Connect". You'll be prompted to gran some permissions in your phone. Just accept them. If everything's fine, you should see something like this:

Notice the data statistics. Now, if you go to any browser in your phone, it should have access to internet. Job's done!

Troubleshooting:

The first time I used this tool I couldn't reach any site from my phone. I tried to use the tools from the tool to kill the ADB service, but it didn't work.

I also tried to kill the process with the Task Manager, but it doesn't work. At least the first time, I think it's better to reboot your PC. For some reason, killing the service manually worked on later tests. Remember that this is a unstable process.

Sunday, May 25, 2014

Some time ago I wrote about TDD, and you may have realized that writing test cases is a big part of it. Playing a little bit with Java I realized that there are some practical problems with JUnit, which is the library used to run test cases. For example, you cannot choose the order of the test cases. I know that the test cases should be independent between each other, but this is not always applicable in the real world, especially when there are really big test cases.

A simple solution for this particular problem is using TestNG. It's just another library with its own functionality, that allows specify the order of the test cases in Java. Here's how to use it.

3. Select TestNG and click Next>Finish.
4. Open the testools.java file and enter the following code:

Here comes some explanation about this:

a) In this part:

public class Testools {

You may have noticed that the class does not extend TestCase. That's because we are not using JUnit anymore.

b) There are annotations on the methods:

@Test (priority = 3)public void first_test() {

These annotations are part of TestNG. They tell the methods what to do. If you remember, in JUnit you have to put the "test" word before the method name to indicate that this is a test, but this has obvious disadvantages (e.g. you can't add more tags for different frameworks). Annotations provide advantages such as flexibility, naming the methods without restrictions, additional parameters in the annotations, etc.

In this case, an additional parameter sets the order in which the test cases will be executed:

priority = 1 --> This is the first to be executed.
priority = 2 --> The second to be executed
priority = 3 --> The third.

5. Run the test cases. Open the menu in the "Play" button>Run As>TestNG Test

6. This simple test cases shouldn't take too much to finish. After that, check the console in the lower part of the Eclipse dashboard. It should look like this:

Notice that the execution order for the test cases is the same than the order in the script. Well, this is just a glimpse of what TestNG can do. You can check the official website here. It's worth giving it a try!

Monday, May 19, 2014

As I'm using elementary OS more and more, I installed VMware Workstation 10 to start my regular work, but I noticed that the whole machine was getting slower. I tried to limit the memory for the VMs, but that didn't work. I even installed a new Lubuntu machine, which is supposed to be very light. However, that didn't solve the overall slow down, so I had to finish my work in Windows.

This is actually a big issue that I think deserves more attention from the eOS developers, sin VMware is (let's say it) the best virtualization platform available. And there's no too much information about it in Internet. However, here's an approach to solve this problem.

If you are wondering why this works, the "max_cstate" value represents a level of "energy saving" for the processor. So, if the value is slower, the processor will be faster and consume more energy resources. As far as I tested it, there is not much difference, so I think it's a safe workaround for the problem with VMware. I hope this helps all the newbie Linux enthusiasts!!

Saturday, May 10, 2014

I know the title for this article is even offensive to some people. I know some friends that identify quality with brads directly. Just like that: Brand = Quality. I know this can be true for a lot of buyers, but when you studied just a little bit about the subject, or if you stop and think about it once in a while, you realize that brands are just an strategy for marketers to sell their products.

I mean, sometimes you buy the brand just to show off. That's good sometimes, but it can get ridiculous when you buy a piece of junk with a "jewel" label. It makes me think that buyers (I'm included) are very likely to be brainwashed maybe too easily. And that gives the prize not to the best in the market, but to the brightest brand. Sometimes we're just eager for some fool's gold.

I recently heard about the last acquisition of Apple: Beats Electronics, the creators of the famous Beats By Dre headphones. It drove me nuts. I could understand that from any other company, but Apple? The Steve Jobs' company buying some overpriced headphones just for the brand? Where is the quality they always claimed as the basis? (just in case, you can read this article to check some other opinion on this subject)

It got even worse. It makes me think that I myself was brainwashed for a while too. Who knows if the iPhone is really the best phone in the market? How much does it take to make a single iPhone? Does it have all the features you can find in other devices? This also apply for the iPad, the Macbook Air and all the other iProducts. Who knows if Apple is more brand than quality at the end of the day?

Marketers at Apple are superb...that is a tradition since Jobs' great presentations some years ago. But remember this: When the iPhone got into trouble with the antenna, Steve Jobs manipulated everyone (again, including me) into thinking that this was a universal problem. It's like justifying my writing mistakes showing some statistics of bad orthography in internet. It is all part of a marketing plan.

I'll wait until I see what happens with new acquisition by Apple. For now, I don't like.

Wednesday, May 7, 2014

Jenkins has proven to be a great and useful tool. You can do virtually anything with Jenkins, as long as you are familiar with it details and some other tools, like Ant. I've written a couple of articles about Jenkins (you can read them here), and as the time went on, I realized that you can improve the performance of Jenkins as well, just making some changes in the structure.

For example, when you need to perform silent operations in a computer, theoretically you don't need to add it as a node. It is enough with a ssh connection and some ant files. I'll show you how I do it in this article.

Requirements:

A computer where the actions of Jenkins will take place with Cygwin+ssh installed (you can install it offline if you need it) and Ant (ANT_HOME must me added to the path). I'll assume you are using a Windows machine, but if you are using a Linux one the steps are identical.

A computer with Jenkins installed.

Steps:

First, I'll try to have things automatized as much as I can. So, I'll try to avoid installing things in the "client" computer every time I can.

1. From the Jenkins main dashboard, got to: Manage Jenkins>Manage Plugins.
2. Open the "Available" tab and enter: publish over ssh

3. Select it and press Install without restart. Wait until the plugin is installed and you'll see something like this:

Click on "Go back to the top page". If you have to install any other plugin, just follow these steps again.

4. From the Jenkins main dashboard, go to: Manage Jenkins>Configure System. There, look for the "Publish over SSH" section. There click on "Add".

5. You have to register a SSH Server for every machine you want to manage with this method. Fill the field as follows:

Name: A name for you to use. This can be anything, but I suggest to put something descriptive, like "DB Server".

Hostname: the name or the IP number of the machine you will manage.

Username: The username registered in Cygwin.

Remote Directory: This is the directory that will be used as base by Jenkins. You have to use the Cygwin format for this. For example: /cygdrive/c/ for C:\.

Now, click "Advanced".

Select "Use password authentication, or use a different key" and enter the password you use for Cygwin in the corresponding field. Finally, test the connection pressing "Test Configuration".

Then press "Save".

6. You need to create a build.xml file in the "client" machine to perform the actions you want. You can use this example and place it in C:\.