Wednesday, March 31, 2010

Tools I can’t imagine my dev life without #1: Ninite.com

Hi,

Last day of March and I want to start today this new series of posts where I’ll try to share with you some of the gems already there, but I suppose the majority of developers in the world don’t really know about.

So one of these gems is site Ninite.com.

Every time when I need to install a fresh version of Windows somewhere (and as a programmer I do this more than I would like to) and there is an internet connection I use Ninite installer to install all the software that is needed. It does have almost everything there, and the list is growing.

Once you’ve chosen the programs you’d like to install, it will generate an installer for you, and you should save it on your machine and download it. Now after you’ve downloaded it, run it and you will see something like these (it depends on the programs you’ve chosen).

After that, you’ll just need to wait while all of your programs will finish to install, and that’s all!

Awesome!!! Isn’t it?

Ideas, concerns, suggestions, tips & tricks – I’m waiting for all these. Take care.

Friday, March 26, 2010

jQuery - SlideShare

I love and use JQuery, it should be used in each and every single web application. Don't use raw javascript use JQuery instead.

Here is the presentation of Rey Bango jQuery Team Member. It should gave you a little overview on what is JQuery and how to use it.

Have questions, ideas? Post a comment and I will try to answer you.

Friday, March 19, 2010

.NET 4.0 : String.IsNullOrWhiteSpace Method

Hello one more time guys,

So I think the most of you are familiar with string.IsNullOrEmpty method which is very useful when you’re checking your string on actually having the data for different reasons:

  • Sometimes we need to parse the string
  • Add something to the string
  • Use some of the string members
  • AND try to see if the data from the database/xml/file is valid.

But now another problem is around: often the data in database has some whitespaces because there are constraints on some varchar columns NOT NULL. To works these around when something is not available, someone could insert a whitespace, and this would solve the problem, for the moment.

Actually it’s not a lot of fun to do something like

if (!string.IsNullOrEmpty(" ") && " ".Trim() != string.Empty) 

{
            

}

What’s why .NET framework 4.0 has the string.IsNullOrWhiteSpace method.

To compare there 2 methods I did the following program:

using System;
using System.Collections.Generic;

namespace Intro.StringIsNullOrWhiteSpace
{
    class Program
    {
        /// 
        /// The main entry point for the application.
        /// 
        static void Main(string[] args)
        {
            // let's say we have a Dictionary of int - string
            // the string representation of a number. Example: 1 - one
            Dictionary integerDictionary = new Dictionary();
            integerDictionary.Add(1, "one");
            integerDictionary.Add(2, "two");
            integerDictionary.Add(300, "three hundreds");
            integerDictionary.Add(4, "four");
            integerDictionary.Add(67, "sixty seven");

            // let's assume that we don't know anything about the data in the dictionary
            // we also could have something like
            integerDictionary.Add(5000, null);
            integerDictionary.Add(50001, string.Empty);
            integerDictionary.Add(56565, " ");
            integerDictionary.Add(23, " \r\n ");

            // now let's check it with string.IsNullOrEmpty
            Console.WriteLine("string.IsNullOrEmpty");
            Console.WriteLine("===================================");
            foreach (var keyValuePair in integerDictionary)
            {
                if (string.IsNullOrEmpty(keyValuePair.Value))
                {
                    Console.WriteLine(keyValuePair.Value + " - True");
                }
                else
                {
                    Console.WriteLine(keyValuePair.Value + " - False");
                }
            }
            Console.ReadKey();
            Console.WriteLine(Environment.NewLine);

            // let's check it now with the new one : string.IsNullOrWhiteSpace
            Console.WriteLine("string.IsNullOrWhiteSpace");
            Console.WriteLine("===================================");
            foreach (var keyValuePair in integerDictionary)
            {
                if (string.IsNullOrWhiteSpace(keyValuePair.Value))
                {
                    Console.WriteLine(keyValuePair.Value + " - True");
                }
                else
                {
                    Console.WriteLine(keyValuePair.Value + " - False");
                }
            }
            Console.ReadKey();
        }
    }
}

Here is the output of the program:

Have a nice day and  use it in .NET 4.0 !

Friday, February 26, 2010

.NET 4.0 : Complex Numbers

 

    Hello today I’m going to start to describe and apply the new classes which were added into .NET 4.0 Framework.

 

When I was 16, it always was a problem there. Sex was in the air, a lot of different opportunities had the habit to rise without any prevention at all, and I was loving challenges. BUT, it also was the period when the most useless and useful information was taken in and out from the classes. Physics, mathematics, chemistry and others were at the same time boring and challenging.

One of the basic subjects in math was : Quadratic equations, and also introduction of complex numbers, which was pretty strange… imaginary and real parts formed the complex number. But these numbers has a lot applications in physics, astronomy and geometry.

Question how did we solved these kind of equations in the past?
We did a structure or a class and tried different things with it, like multiplication and division, and others as well. But sometimes we didn’t really figured out very well the logic.

Now, guess what, in .NET 4.0 we already got a Complex structure, which in fact represents the complex number.

So here is a very simple application of it:

using System;
using System.Numerics;

namespace Intro.ComplexNumbers
{
    class Program
    {

        static void Main(string[] args)
        {
            // do it always, we'll stop the loop by pressing Ctrl + C.
            while (true)
            {
                string errorMsg = string.Empty;

                Console.WriteLine("To solve the quadratic equations using the Quadratic Formula,");

                int a = ReadCoeficientValueFromConsole("a", "Please enter ax^2: ", ref errorMsg);

                if (!string.IsNullOrEmpty(errorMsg))
                {
                    ShowErrorMessage(errorMsg);
                    break;    
                }

                int b = ReadCoeficientValueFromConsole("b", "Please enter bx: ", ref errorMsg);

                if (!string.IsNullOrEmpty(errorMsg))
                {
                    ShowErrorMessage(errorMsg);
                    break;
                }

                int c = ReadCoeficientValueFromConsole("c", "Please enter c: ", ref errorMsg);

                if (!string.IsNullOrEmpty(errorMsg))
                {
                    ShowErrorMessage(errorMsg);
                    break;
                }

                // we're assuming that the discriminant is negative
                // for more information visit http://en.wikipedia.org/wiki/Quadratic_Formula#Quadratic_formula
                Complex root1 = new Complex(-b / 2 * a, Math.Sqrt(4 * a * c - b * b) / 2 * a);
                Complex root2 = new Complex(-b / 2 * a, (-1) * Math.Sqrt(4 * a * c - b * b) / 2 * a);

                Console.WriteLine("Roots are: ");
                Console.WriteLine("Root1 (positive): {0}", root1);
                Console.WriteLine("Root2 (negative): {0}", root2);
            }
        }

        /// 
        /// Shows error message in console.
        /// 
        /// Error message.
        private static void ShowErrorMessage(string errorMsg)
        {
            Console.WriteLine(errorMsg);
            Console.ReadKey();
        }

        /// 
        /// Reads a string from console and tries to convert it into an Int32, and assign it 
        /// to a coefficient.
        /// 
        /// Coefficient name.
        /// String which will be shown to ask the coefficient introduction.
        /// The coefficient Int32 value.
        private static int ReadCoeficientValueFromConsole(string coefficientName, string requieringString, ref string errorMsg)
        {
            int coeficient = 0;

            Console.WriteLine(requieringString);

            string aValue = Console.ReadLine();
            if (!string.IsNullOrEmpty(aValue))
            {
                try
                {
                    coeficient = Convert.ToInt32(aValue);
                }
                catch (FormatException)
                {
                    errorMsg = "Your '" + coefficientName + "' coeficient is not a numeric value.";
                }
                catch (Exception)
                {
                    errorMsg = "There was an exception raised because of coeficient '" + coefficientName + "'";
                }
            }

            return coeficient;
        }
    }
}

Here are some screenshots:

Figure 1. Coefficient error

Figure 2. Good coefficients solving 3x2 + 9x +7 = 0

Download source from here

NOTE: I’ve done this project using Visual Studio 2010 RC.

Wednesday, February 24, 2010

What’s going to blow our mind in 2010 ?

Hi guys, now a little time passed, half of the year while I'm semi-actively posting here.

We took a step back and tried to write about things which could matters. And which isn’t really discussed by anyone else.

I really tried to make it better, although I hope that this year I’m gonna obtain my goal of writing at least once per week.

So what is going to blow our mind ?

 

I will be writing about:

  • Udevi community
  • F# 2.0
  • Visual Studio 2010
  • ASP.NET MVC 2.0
  • .NET 4.0
  • JQuery
  • Open source projects in which I’ll be participating
  • Tips and tricks

Hope you will like it !