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

Sunday, April 21, 2013

An awesome calculator for iDevices

Yesterday I wanted to download a calculator for my iPad. I reviewed some apps from the App Store and found MyScript Calculator. This is coolest idea for a calculator.  You can write any mathematical calculation by hand in the screen, and the app will know what you want. This is exactly what you need if you want to solve, for example, something like this:
You would have to perform some different steps in a normal calculator, but with MyScript Calculator, all you have to do is this:
And what you get is this:
Awesome, isn't it?? Download the app here. It's free!

Friday, April 19, 2013

How to connect a SQL Server database with a DataGridView with C# (Visual Studio)

Note: Click the link if you want to know how to use a SQL Server database with a multiline textbox.

This tutorial will show you how to show data in a DataGridView from a SQL Server database. Pretty simple. Just in case, the screenshots show Visual Studio in Spanish. That's the only version I have, but I think you can deduce the names of the buttons in English. It's very easy watching the screenshots.

Requirements:
  • Visual Studio 2012 (it's what I used).  You can get the express version here.
  • SQL Server 2012.  Get the express version here.  This is not necessary, but I recommend to install SQL Server Management Studio. I'm more comfortable using that tools to manage my databases in SQL Server. To get SQL Server Management Studio along with the other components, download ENU\x86\SQLEXPRADV_x86_ENU.exe or ENU\x64\SQLEXPRADV_x64_ENU.exe, depending of the architecture of your computer.
Steps:

1. Create a new database and fill it with some data

1.1 Open SQL Server Management Studio and connect to it.
1.2 Expand [Server]>Databases
1.3 Right click Databases>New Database...
I'll call my new database "TestoolsDB". Press OK.
1.4 Create some a table with a couple of columns. Create 3 rows of data. Of course, this is just an example:
The was supoused to be called "dummy_data", with double m, but anyway...it doesn't matter for this example.

2. Create a Windows Form

2.1 Open Visual Studio
2.2 Click on New Project
2.3 Select "Windows Forms", set a name for the solution and press Accept.  I named mine "GridExample":
2.4 Add a DataGridView (look for it in the Tool Box) to the Form.
2.5 Give it a name you can recognize. For example, "testGrid".
3. Create a new connection

3.1 Go to Project>Add new data source...
3.2 Select Database and press Next twice.

3.3 Press New Connection
3.4 Press Browse and select the database you created. It is possible that it is located in the default folder: C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA






3.5 Select your database and press Open. If you have problems with permissions or messages saying that the database is in use, check this. Anyway, all you have to do is grant permission for the .mdf and .ldf files.  If you see a message indicating that the database is in use, just enable the "auto close" feature in the database properties with SQL Server Management Studio. You can see a detailed explanation in this video.
3.6 Press Accept
3.7 Press Next in this screen:
3.8 Now, you will see this (well, in English):
Press Yes to coy the database to the project folder, or No to use it where it is right now. It's up to you. In this example, I'll press Yes.

3.9 Press Next. Now just wait.
3.10 Check "Tables" and press Finish
3.11 Open Server Explorer.
3.12 Highlight your database.
3.13 Copy the connection string in the properties of the new connection.
4. Write the code

4.1 Double click on the form (not the grid). This means that the code will be executed when the form loads. If you want to use a button, double click the button.
4.2 Write the following code. I'm showing the complete code, just in case you have any doubt:

I'm not going to explain the code, but you can read the comments and I'm sure you'll understand what is all about.

Once you have written the code, press F5 to see the results:
And there you have it!!! This simple trick can lead you to make more complex programs.

Wednesday, April 17, 2013

Set an application to work with only one processor (Windows 8)

One of my favorite video games of all times is Silent Hill 2. As you might know, Silent Hill 2 for PC is full of bugs, and you occasionally have to deal with it.  For example, the classic sound loop bug causes the music to enter in an endless sound loop, ruining a major part of the experience, because the soundtrack of this game is magnificent.

I spent several hours searching for a solution to the sound loop glitch, until I finally found an almost permanent solution: Change the game to work only with one processor.

I don't know the technical details, but I guess Silent Hill 2 was programmed to work with just one processor, since it was created when computers had no more than one processor.

You can use this simple trick to troubleshoot problems with other old programs, or maybe when testing something.

Note: I'll use Silent Hill 2 as example in this article.

Requirements:

A Windows 8 machine.

Method 1:

1. Open the application. In this case, Silent Hill 2.

2. Press Alt+Tab or Control+Esc.  This will take you out of the program (or game).
3. Open Task Manager.
4. Open the "Details" tab.
5. Look for the program for which you want to set affinity. In this case, it's sh2pc.exe.
6. Right click the program.
7. Press on "Set affinity"
8. Select only CPU 0. Press OK.
9. Go back to the program or game and it will work with only 1 processor. This trick eliminates the sound loop most of the times in Silent Hill 2 for PC.

Method 2:

You can create a shortcut to start a program directly with the desired affinity:

1. Right click on the desktop>New>Shortcut
2. In "Type the location of the item" enter:

[path] /C start /affinity 1 [executable]

In my case:

"C:\Program Files\Konami\Silent Hill 2\sh2pc.exe" /C start /affinity 1 sh2pc.exe


Just in case, I'm using quotation marks because the path contains blank spaces. An error message will be displayed without the quotation marks.
3. Press Next
4. Give a name for the shortcut and press Finish.
5. To verify if this is working, double click the shortcut you just created.
6. Get out of the application by pressing Alt+Tab or Control+Esc.
7. Open the Task Manager and verify the affinity in the Details tab (just like in the first method).

I hope this is useful for everyone!

Monday, April 15, 2013

"Testing" Windows 8 on an iPad

If you want to develop for Windows 8, you'll notice that testing your app in a real tablet is essential. With this in mind, I found a great app a couple days ago. Its name is Win8 Metro Testbed.

What this app does is just amazing. It streams Windows 8 to the iPad, in order to get a real tablet impression with all the required details. The gestures work very smoothly in the iPad, and it feels like you have installed Windows 8 in your Apple tablet.

One of the best features of this app is that music, videos and everything work like you have the Microsoft OS in your hands. I tried some remote connectivity software before, like LogMeIn, but none of them works as you would wan them to.

For example, I wanted to watch some videos from my PC. I used LogMeIn, but the frame rate is lame. Then I tried VLC Streamer. The problem with this app is that video lose sound quality, so you have to convert your video to transfer them to the iPad anyway.

Unfortunately, Win 8 Metro Testbed only works with Windows 8.  But it's worth trying it, especially when you are developing some apps in Visual Basic or C#. Remember that you have to install a streamer in your PC. Get it here.

Sunday, April 14, 2013

Creating "batch" scripts for Linux (Ubuntu)

I'm sure that most of you have used a batch file at least once in Windows. They are simple but very convenient script files to automatize some tasks. Linux has an advantage: Its powerful bash. You can even make simple programs with it. And, since you have to write a lot of things all the time, a script is very, very useful as "shortcuts" for some tasks.

This tutorial will show you how to create bash scripts for Ubuntu, but I'm sure these can be used with other Linux distros too.

Requirements:

A Ubuntu machine. I'm using Ubuntu 12.10.
Before using the script that I'll use as an example, you need to install some packages. To do that, open a  terminal and type:

sudo apt-get install --no-install-recommends gnome-panel

Then press enter.

Steps:

1. Prepare a script you would like to use. I'll use a script to make shortcuts on the desktop:

gnome-desktop-item-edit --create-new ~/Desktop

2. Click on Dash Home
3. Type "gedit"
4. Click on "Text Editor"
5. The Text Editor will be opened.  Enter the following text in the Text Editor:


#!/bin/bash  
command

In my case, I typed:

#!/bin/bash  
gnome-desktop-item-edit --create-new ~/Desktop
As you can see in the last picture, I saved it on Home/Documents/Scripts and named it "createShortcut". Save the file somewhere you can access easily. Remember that you don't need to write any extension.

6. Open the terminal. Go to the folder that holds your script.
7. Type:

sh nameOfTheScript

In my case:

sh createShortcut

And that's it. The command will be executed and a simple dialog to make a new launcher on the desktop will be displayed. This is just a super simple example. You can discover your own possibilities!

Thursday, April 11, 2013

Install VMware Workstation 9 on Ubuntu 12.10

submit to reddit
I know some programmers who like to work on Ubuntu. It's good taste, but we have to admit that every now and then we have to use Windows for something. Following this logic, virtual machines are the best option to enjoy the advantages of Linux with the permanent and flexible option of Windows.

Thus, here is a tutorial on how to install VMware Workstation 9 in Ubuntu 12.10. 

Requirements:

  • An Ubuntu 12.10 machine
  • VMware Workstation 9 for linux.  You can get a free trial here.
Steps:

1. After you downloaded Vmware Workstation 9 for Linux, place it in a folder you know. For example: Home/VMware workstation for linux.  That's a folder I created in the Home folder to hold the VMware bundle.


2. Open the Terminal.  Go to the folder holding the VMware Workstation bundle (use the "cd" command). In this case:  Home/VMware workstation for linux.

Note: In the Terminal, in order to access a folder with a name that contains spaces, you have to replace spaces with “\ “.  Check the following image:


3. Type:

sudo chmod +x [Name of the VMware Workstation bundle.]

In my case, I typed:

sudo chmod +x VMware-Workstation-Full-9.0.2-1031769.i386.bundle

4. Type:

sudo ./VMware-Workstation-Full-9.0.2-1031769.i386.bundle

You don't have to press start. An installation dialog will be displayed, like this:


5. From now on, the installation is pretty straight forward. Select "I agree" and press Next.
6. Select if you want the program to check for updates at startup and press Next.
7. Select if you want to send statistics to VMware. I prefer not to.  press Next.


8. In the "Customize the installation" dialog, leave the default user and press Next three times.
9. Press "Install".
10. Wait for a couple of minutes and you already have it!! Remember, in order to power the VMs on, you need registration key.

Tuesday, April 9, 2013

The rise of Bitcoins


submit to reddit
If you have ever been to the TOR network, I’m pretty sure you have heard about bit coins.  Some years ago, when I first found out how to access TOR, I spent a lot of time trying to understand how an “unreal” currency like Bitcoins worked. I was studying economy at that time and I was puzzled about an anonymous currency, free of any government intervention.

Bitcoins consist of an incredible idea by Satoshi Nakamoto, a mysterious person of group of people who thought of an encrypted currency in internet, without the need of Central Bank or a government for regulating the virtual economy. The bitcoins idea is amazing: A virtual currency that needs no central authority to work. Also, bitcoins are anonymous, allowing human rights and terrorist organizations to use them at the same time. Bitcoins are based on cryptography.  You can check this if you want a detailed explanation about it.

In the last days, bitcoins have attracted a lot of attention due the massive use of bitcoins raising its price in the real world to 223 $us in the Mt. Gox market (according to bitcoincharts.com), showing an interesting phenomena related with the savings in bitcoins, speculation and a possible bitcoin bubble ready to explode. 

Here are some articles I read about the bitcoin subject. I think this a very important topic, since more and more people is starting to upload their whole life to internet.

Monday, April 8, 2013

Connecting a C# program with a SQL Server Database (multiline text box)

submit to reddit
Here's a way to connect a program written in C# with a SQL Server Database, all from Visual Studio 2012. This article is focused on the use of a multiline text box. I'll publish another article for using a DataGridView soon. I'm trying to make this as clear as possible. Also, I include some tips in order to get more from this tutorial.

Note: This video was made with a Spanish version of Visual Studio 2012. However, the names of the options and the user friendly interface of Visual Studio make it easy to adapt this tutorial to your language.

Requirements:

  • Visual Studio 2012 (it's what I used).  You can get the express version here.
  • SQL Server 2012.  Get the express version here.  This is not necessary, but I recommend to install SQL Server Management Studio. I'm more comfortable using that tools to manage my databases in SQL Server. To get SQL Server Management Studio along with the other components, download ENU\x86\SQLEXPRADV_x86_ENU.exe or ENU\x64\SQLEXPRADV_x64_ENU.exe, depending of the architecture of your computer.

Steps:

Notes: 

As you can see, there is a video showing the process of connecting the database with the application. Nevertheless, It's always useful to have some notes as a summary.

1. The database

1.1 Open SQL Server Management Studio.
1.2 Create a new database
1.3 Create some tables for the database.
1.4 Fill the database with some dummy data to test.

2. The Visual Studio Project

2.1 Create a new C# project in Visual Studio (Windows Forms)
2.2 Add a new connection
2.3 Add a DataGridView to the Windows Form (This will be used for the next article, now we will focus on the multiline textbox)
2.4 Add a multiline TextBox to the Windows Form

3. The code

3.1 Import the appropriate SQL Server library:
3.2 Create a new connection
3.3 Get the connection string for the database.  For this, open Server Explorer>Expand Data Conection>Right click your database>Properties


In the database properties, copy the content of the Connection String field.


3.4 Designate the connection string to the connection you just created
3.5 Create a new command
3.6 Designate the connection you created to the command
3.7 Give the command the query text
3.8 Open the connection
3.9 Execute the commands you have.
3.10 Print the desired result in the multiline text box.

Attachments

Here is the project I showed in the video. You can check more details there.

Saturday, April 6, 2013

Linux failure in the desktop world


submit to reddit
I'm an enthusiastic Ubuntu user, and I even tried some times to completely switch from Windows to Linux. But as a real world user, I always encountered problems when trying to use Ubuntu for simple tasks such as using a word processor and distribute it among interested people.

I also made some experiments, like using Backtrack as main Operative System. However, I quickly realized that I was just wasting my time, since Backtrack is the Linux distro with less stability of all. I worked for a couple of days in Backtrack, and my desktop crashed after installing some applications from the official repositories for Backtrack.

I think that Linux has several problems, not from the technical point of view, but from the lack of unified marketing efforts among companies and Linux developers.

Here is an interesting article by Miguel de Icaza, a Mexican programmer that started the Gnome and Mono projects. It's somehow disappointing to say it, but Linux has a long way to go in order to compete against Windows and OS X.

Thursday, April 4, 2013

How to make an unattended Sysprep for Windows (with .xml file)

submit to reddit
As I pointed out in another article (you can read it here), Sysprep is an easy way to clone a machine, especially a virtual one. I already wrote on how to make a Sysprep for Windows 8, but now I'm going to show how to make an Unattended Sysprep.

The word "Unattended" indicates that the new installation of a Sysprep machine will be automatized by some script, so settings like the computer name will be already set, and the user will have less things to do when deploying a new machine. Depending on the configuration selected in the .xml file, you can copy a machine, turn it on and just leave it until it configures itself with the settings you gave in the .xml file. Remember that when you don't use an unattended sysprep, you have to make some configurations when you deploy a new machine. To read more about this topic, click here.

This article is focused on the use of virtual machines.

Let's begin.

Requirements:

VMware Workstation installed (get a free trial here).

A Windows 8 Machine (get a free trial here).

Steps:

1. Configure an answer file. The answer file is the .xml file you can use to customize your sysprep. The are a lot of options for this, and they all depend on what you want for the new deployed machine. To configure the answer file automatically, you can use the Windows Assessment and Deployment Kit for Windows 8 (get it here). The only problem with this is that you would have to download about 5 GB just to make your answer file.

Another option is using a template for the answer file. I looked for it in internet, and you always have to make several changes to the available example files. So, I attach an example here. You can directly use this file for the Sysprep, and as far as I tested it, you don't need to change anything for it to work. Of course, you can edit it as you want to custom your deployed machines.

Here is the complete code of the .xml file. Just copy and paste:


2. Once you have the .xml file, place it somewhere you can remember.  In my case, I copied it to C:\Windows\System32\Sysprep.


3. Open the Command Line. Go to C:\Windows\System32\Sysprep.


4. Enter the following command:

sysprep /generalize /oobe /shutdown /unattend:C:\Windows\System32\Sysprep\sysprep.xml

Press Enter. In this case, I'm assuming that the answer file's name is sysprep.xml.

5. Now, just wait until the machine shuts down.


6. Now, you can copy the VM and turn it on.  You'll see that it doesn't ask for any information, and just continues until it reaches the initial screen.



Hope it is useful for everybody!