How to view documents using Visual Studio

View documents in Visual Studio with an amazing tool

Xpath Axes

A very useful trick for automation

Review: Spire.DataExport for .NET

A great tool for exporting data in .NET

How to install Arch Linux, step by step, for VMware Workstation (Part I)

First part of a installation tutorial for this beloved OS

How to setup a local repository in Ubuntu

The steps to have a local repo in Ubuntu

Wednesday, January 29, 2014

How to backup and deploy a new instance of Jenkins (Linux)

Note: All the steps specified here were performed on a machine with Lubuntu 12.04.

I thought I should write an introduction for the use of Jenkins before writing about its features, but I think there's plenty of it in Internet (if this is the first time you read about Jenkins, you can check this and this). Instead, I'll tell you how to backup and deploy a new instance of Jenkins. In other words, this can be used to migrate Jenkins with all the created jobs to another server, or to deploy a new Jenkins in the same machine without losing done work.

First of all, Jenkins in a continuous integration tool. This kind of tool is very useful when developing and testing. Basically, what Jenkins does is to trigger automatic tasks in different machines from a central "Master". These tasks can consist in running programs, copying files, or whatever is needed to make and test new builds.

Once you have worked on Jenkins, you'll have a bunch of jobs and slave machines.
If you want to preserve all that configuration when doing a backup or to deploy it somewhere else, you could take the following steps:

Backup Jenkins

1. If you are using Lubuntu (or Ubuntu, but I haven't tested it yet), go to: /var/lib/jenkins/
Once there, copy all the folders and files to another location. You could create a folder named "Jenkins_backup" and paste all the files there. And that's it for the backup. There's nothing else to do! Jenkins is portable, which is a great feature.

Deploy Jenkins

1. Go to: /usr/share/jenkins. This is the path by default in Lubuntu. There you'll find the file jenkins.war.
2. Press F4 to open a Terminal there, and enter:

export JENKINS_HOME=<jenkins_backup_folder>

In my case:

export JENKINS_HOME=/var/lib/Jenkins_backup

That sets the JENKINS_HOME to the new Jenkins location.

3. In the same Terminal console, enter:

java -jar jenkins.war --httpPort=8083

Take into account that the port number must be different than the one you used in the original Jenkins instance. By default, that port is 8080, so you can use any other number.

4. Leave the console open and open a browser. There, enter the server IP number followed by the port you chose. And there you have it! Another instance of Jenkins already running.

Troubleshooting

When I first did this I noticed that there is a problem when launching a slave machine through Java Web Start. There is a dialog with this message:

Unable to launch the application

In order to solve this problem, I recommend you to take the following steps:

1. Go to Manage Jenkins>System Configuration>Jenkins Location

2. In Jenkins Location, enter the IP number of the machine where Jenkins is installed and the port you are currently using. Then click on Save.

3. Open the Jenkins Dashboard in the Slave machine you want to activate. In order to avoid some permissions problems, I recommend to use the command Jenkins gives you instead of pressing the Launch button. Just remember to modify the port if it is necessary. With this, you shouldn't have any more problems.
Have fun!

Monday, January 27, 2014

How to create test suites with Python

Some posts ago I wrote about Coverage for Python. As you may have noticed, coverage works for each module that contains test cases. But what happens if you have several modules for different parts of a program? The point here is to have the total percentage of coverage for all the code. In order to do that, you need to create a test suite.

A test suite is just a file that groups all the test cases in one. There are a lot of ways to achieve this, but I'll explain the method that worked best for me.

Note: If you have doubts about what I'm writing about here, you should read this article, about TDD.

Scenario:

You have a program in Python. For that program, you have some test cases grouped in 3 files:

test_sudoku_config.py
test_sudoku_game.py
test_sudoku_generator.py

Now, you can use this template:


Maybe you'll need to import some other things of modify some lines, but this is the basic form. Then, you can use Coverage on this single file to measure the total coverage percentage for the whole code. I hope this helps you!

Saturday, January 25, 2014

Kim Dotcom, the musician

Kim Dotcom is a famous guy. He's the founder of Megaupload, and whatever are your beliefs about copyright, I'm pretty sure you all have used that site at least once in your life (I myself did it many times). As you might know, Megaupload has a successor, Mega. However, Kim Dotcom is a classic antihero: The hacker, the entrepreneur, the rebel and...the singer!! Yes, he's also a singer. He recently released an album: Good Times. You can download it in iTunes. I can't help it, I'll give it a try. It's kinda weird to write about this, but it got my attention.
You can download the album in iTunes.
If you want, follow Dotcom in Twitter.


Friday, January 24, 2014

Auto execute VMware tools at startup in Lubuntu 13.10

I noticed that Lubuntu 13.10 has problems starting VMware tools when it is installed as a VM. When you restart the machine, VMware tools are not loaded automatically. So, here's a brief tutorial on how to do that.

Requirements:

A VMware VM with Lubuntu 13.10 (VMware tool work normally in previous versions as far as I saw)
VMware tools already installed. To do that, read this.

Steps:

1. Go to a folder where you'll save a script. I created a folder named "scripts" at /home/jorge:
2. Inside that folder, right click>Create New>Blank File
3. Enter a name for the new file and add the extension ".sh". My file is startvmwaretools.sh
4. Open the file and enter the following lines:

cd /etc/vmware-tools
vmware-user

With that, you are accessing a path and then executing a file that initiates VMware tools. This is the default path. However, if for any reason you installed VMware tools somewhere else, this is the file you are looking for:
5. Once you have your script, you have to make it executable. Go to the folder that contains your script in the UI and then press F4. A terminal will be open there:
Now enter:

sudo chmod +x <filename.sh>

In my case:

sudo chmod +x startvmwaretools.sh

6. In you Lubuntu Desktop go to Start>Preferences>Default applications for LXSession
You'll see the following dialog. Click Autostart:
7. In the textbox below "Manual autostarted applications" enter the full path to your script. Then click Add:
8. Reboot the machine and that's it! Now you should be able to use the clipboard in the VM and other features provided by VMware tools. By the way, this work for any other file that you may want to run at startup.

Thursday, January 23, 2014

Tip: Create a shortcut in LXDE (Lubuntu)

Here's a quick tip: Sometimes you need shortcuts in the desktop, especially in Linux, where the paths are not intuitive at all. For example, I noticed that VMware tools is not initiated automatically in Lubuntu 13.10, which is the latest version of this OS. So, a quick solution for that is to create a shortcut in the Desktop. Unfortunately, there is always something to write in the command line when using Linux. This is what you have to do to create a shortcut in Lubuntu:

Navigate to the folder or file for which you'll create a shortcut. For example:

/var/lib/jenkins/userContent
I access that path a lot, so it is a good candidate for the example. Now, open a Terminal. You can do it with: Control+Alt+T. There enter this:

ln -s <file or folder path> /home/user/Desktop

In my case:

ln -s /var/lib/jenkins/userContent /home/jorge/Desktop

And that's it. Once you hit enter, you'll see the new shortcut in the Desktop. I hope this is useful for you!

Tuesday, January 21, 2014

Unlock folders or files to delete or modify them with Unlocker

I'm aware that a lot of people already know the tool I'm writing about in this post, but it's worth repeating it for those who don't know it.

Sometimes, you have to erase a folder that you just used, but when you try that you get this message:
Or some other message that indicates that the folder is locked by a process or a program. Of course, the first approach is to use the some CMD commands or other tricks, but 99.9% of the times this didn't work for me. The only way to get rid of hidden processes was to use Unlocker.

This is a tool for Windows Explorer that helps to unlock files and folders when they are being accessed by other programs or processes. You can download it here.

Note: The following steps are performed in a Windows 7/8 machine. It should work almost in the same way for other Windows versions.

The installation is a classic "next, next, next":
Once you have installed Unlocker, you can test it with the following steps:

1. Create a folder in the C drive named "test".
2. Open a CMD console and go to the "test" folder.
3. Leave CMD open and try to erase the "test" folder. You'll get an error message like this: The action can't be completed because the folder or a file in it is open in another program.
4. To unlock it, right click "test">Unlocker
5. That action opens a dialog with the Unlocker options:
Here you can see the process that is using the particular folder or file. Take into account that sometimes these processes are not present in Task Manager, so you won't be able to see them there. In this case, you can unlock the folder by pressing Unlock. Now you can delete the folder "test".

Other details

If you need to use Unlocker in an automated way, for example in a batch file, you need to perform some steps:

1. Disable UAC. Unlocker can be used from the command line, but its execution gets interrupted if UAC is enabled. To disable this, go to Control Panel. In the search box in the upper-right part of the dialog, enter: User Account Control. You should see something like this:

Click on "Change User Account Control settings".
Now set level to "Never notify" and click OK. Reboot the machine.

2. Add Unlocker to the Windows path. Right click My Computer>Properties>Advanced system settings>Environment Variables
In System variables open "Path". In Variable value enter a semicolon (if that is not already there) and the path for the Unlocker installation. In my case, that looks like this:
Press OK in all dialogs. Open a CMD console and type unlocker -h. If everything is correct, you should see this:
Now you can use Unlocker in batch files and automation processes. Enjoy it!

Thursday, January 9, 2014

Check coverage percentage in Python

When I wrote about TDD I mentioned that it ensures that you have a high coverage percentage. But how to actually see that? I'll show you one tool to do that in Python. Very useful to have all the code tested.

Note: This tutorial is for Windows. I used Windows 8. There is no much difference with other versions of Windows.

Requirements:

Python installed.

Steps:

1. Install Coverage. Coverage is a tool for Python that you can download and user for free. To install it:
   1.1 Install Setuptools. You have to download setuptools-2.1.tar.gz.
   1.2 Extract that file somewhere you can access easyly.
   1.3 Open a CMD console and go to the extracted folder.
   1.4  For this step you should already have Python in path. Enter:

python setup.py install

It's the same with mnost of Python components. Whenever you have to install something in Python, try this method.

   1.5 Download coverage-3.7.1.tar.gz.
   1.6 Install it with the same steps you took to install Setuptools.

2. Add Coverage to the Path.
   2.1 Go to: <Python installation folder>\Scripts. In my case, it's: C:\Python27\Scripts.
   2.2 Copy that path.
   2.3 Right click on Computer > Properties > Advanced system settings > Environment Variables
   2.4 Double click Path
   2.5 At the end of the text line, paste the path you copied in step 2.1. There must be a semicolon between the last entry and the new one. Like this:
Then press OK in all the dialogs.
   2.6 To check if Coverage is available, open a CMD console and enter: coverage. You should see this:
3. Use Coverage!
   3.1 Now you'll need a Python program and it corresponding tests. You can use the code I showed in this article.
   3.2 Save the application and the test cases in a folder.
   3.3 Open a CMD window and go to the folder with the scripts.
   3.4 Enter:

coverage run test.py
In this case, the name of the module that contains the test cases is "test.py". Then, enter:

coverage html

Go to the folder with the scripts and you'll see a new folder called "htmlcov". Open it.
Open index.html. Now, you'll see the report in a browser:
This report contains useful information. For example, here I can see which lines are not tested yet. This will help you to correct or adjust your test cases (not just in TDD).

Enjoy it!

Monday, January 6, 2014

Connect as 2 different users at the same time with Cygwin

A couple of days ago I had to execute an installer with 2 different accounts at the same time in the same Windows machine. Of course, there is no easy way to do this in this environment, and I had to do it remotely. So I figured out a way to do it with Cygwin. This is what I did:

Requirements:

- A Windows machine with Cygwin. You can see some instructions about it here. Also, you can download it here.
- Cygwin must have ssh enabled.

You may have noticed that you connect to Cygwin with the account you installed ssh. In order for this to work, you have to create another user with administrative privileges in Windows (I won't give instructions for that :P ) and give it a password.
Steps:

1. Update the users data for Cygwin.
   1.1 Open Cygwin
   1.2 Enter the following command:
 
   mkpasswd -l > /etc/passwd

   With that, you'll update the Windows users in Cygwin.
2. Press Windows + R to execute a command. Then enter this:

runas /user:testools_user cmd

Replace "testools_user" with the user you created. Hit Enter. Then enter the password for the user and a command console will be opened.
3. From the CMD console, go to the Cygwin folder and execute cygwin.bat.
4. Enter:

ssh-user-config

Enter "no" for all the following requests.

5. Repeat steps 2-4 with another user.
6. From another machine, use Putty to access the first machine with one of the users, and then with the other.
7. That's it. Now you can make actions as 2 different users at the same time. This is useful for many things. I had to install an application twice at the same time, but the installer cannot be executed more than once at a time. I hope it is useful for you too!

Sunday, January 5, 2014

Random image slideshow in Ubuntu


I recently wrote an article on how to make executable scripts in Linux. Here's a small tutorial that goes along well with that article. We'll see how to create a random slideshow with the images on a folder.

1. Install FEH. It's just a command line tool to make slideshows. Open a terminal and enter:

sudo apt-get install feh

Say Yes to everything after that.
2. Create a script. Create an empty file in the Desktop (or wherever you want). Fill it with the following command:

feh -F -D 5 -z /home/slideshow_folder

Of course, you can change the options for feh. The path is for the folder containing the images you want to see in the random slideshow. Now save the script with a .sh extension (e.g. slideshow.sh).

3. Make the script executable. In a terminal go to the place where you have the script. Then, enter this:

chmod +x slideshow.h

That will allow you to double click the script to run it.

4. Start the slideshow! Double click the script and you'll see a slide show just like the one with the Windows Photo Viewer!

Saturday, January 4, 2014

Create executable scripts in Linux

I had a question in this article, asking how to create scripts to run double clicking them. It's pretty easy actually:

1. Create a .sh file with some commands. You could use the following as an example:

mkdir /home/<user_name>/Desktop/example_folder

That will create a folder in the desktop. Don't forget to replace <user_name> with your actual user name. Name the file like this: example_file.sh. You have to use the .sh extension.
Open a terminal and go to the Desktop. There, enter the following command:

chmod +x example_file.sh

Now double click example_file.sh. You'll see a dialog:
Click Execute. A folder will be created in the Desktop. And that's it!

What is TDD? Is it useful?

TDD: Test-driven Development

As the name suggests, TDD is a programming "style" that depends on test cases for its structure and development process. TDD is related to the extreme programming concept. It has basically the following steps:

1. Write automated test cases
2. Check if the test fails. The result will guide the production code
3. Run the test cases again
4. Clean up the code

Of course, it not very easy to understand this concept just with theorical explanations. Taking that into account, here we have a practical example in Python:

Requirements:

1. Python installed. Download it here.

Note: This article assumes that you know the basics for Python. If you want to know some more about it, read this.

Steps:

For this example, we'll create a simple Python program to check if a number is prime.

Using some text editor like notepad++, open a new file and copy the following code. Then save the file as "prime_test.py".

If you run this, you'll obviously have errors, since there is no "prime_numbers" module to import. But this shows how TDD works: You write the test before anything. Basically, the error messages tell you what to do next. In this example, the error is: ImportError: No module named prime_numbers. So, the first thing to do is to create the prime_numbers module. Let's do it. Create another Python file and copy the following code:

Now run the test again. Of course, it's going to fail again. We don't have the methods working yet. The trick with TDD is to make the test pass. So, in order to do that, we have to write the check_prime method:


Run the test again. Check the message and you'll know what to do next. The error message says: AssertionError: True is not false. So, you need the method to return false when a number is not prime. You can do that this way:

Run the test cases again and you'll see that they all pass. That's how you know that you are finished. As you can see, the code is driven by the test cases.

One interesting point about TDD is that you may en up writing more code in the test cases than in the actual program. Of course, there are some advantages in this programming style (from my point of view):

- You have your code very well structured.
- The coverage is often higher than 90%.
- It prevents the developer from making some mistakes.
- Once you get used to it, TDD helps you to develop in an easier way.

Among the disadvantages I could mention:

- The quantity of code for test cases can be huge in large projects.
- It can be distracting to focus on the test cases.
- You have to worry about writing the tests well. Test cases have bugs too.
- You might feel that you are wasting your time writing too many test cases...

Thursday, January 2, 2014

Tip: Connect to Virtual Machine through VNC

Here's a quick tip. In a work environment, such an office, it's always necessary to control Virtual Machines remotely. There are options for this, like Remote Desktop. However, sometimes those options are not available, especially when you are using something else than Windows.

This works only when using VMware:

1. You'll need a remote control software. I recommend TightVNC. Download it here and install it.
2. Go to your Virtual Machine.

3. Go to VM > Settings
4. Open Options > VNC Connections
5. Check "Enable VNC connections" and choose a port. You can set a password too. Then click OK.
6. Open TightVNC Viewer. On Remote Host enter the IP number from your Real Machine, followed by the port you selected. For example:
7. Click Connect and enter the password (in case you set it before) and click OK.
8. That's it, now you have access to the VM. Hope this was useful!
Just in case, this works with any OS.