Monthly Archives: June 2012

compare two null values in sql

If you compare two values and either of them can be null or one of them null equal (=) operator does not work. Equal operator is not null sensitive. To compare the two you have to changed null to valid string value and then apply = operator.

declare @v1 varchar(20)
declare @v2 varchar(20)

if (isnull(@v1,'0') = isnull(@v2,'0'))
select 'Match Found'
else
select 'Match not found'

The above code demonstrates the correct way of comparing null values.

if (@v1 = @v2)
select 'Match Found'
else
select 'Match not found'

the above code will always return false if either end is null or both ends are null. Therefore this is wrong syntax.

If you are comparing more than oen value between two tables, you can use SQL Intersect as well

RegEx Gready vs Lazy

Lets say we have this string

John said, "What are you doing"

We want to get only the style sheet and not the rest of the contents. How about if we use this?

Regular Expression: style=".+"

This will match John said, "What are you doing"

What about if we use
Regular expression : style=".*"

This will again match from start of style=" ........ to the end of quote in the same line.... "

This is called Greedy Algorithm

Regular Expression Greedy

It returns the whole line until the last character is reached.

Regular Expression Lazy

Lazy search means it does not want to go that far. It will return the first match of pattern. Example is below

Regular Expression: style=".+?"

This will return style="color: red;". Notice ? after +. This basically says do Lazy search or not greedy to return the first match.

Summary

John said, "What are you doing"

style=".*", when matches style="color: red;", it does not stop there. It continues to find more matches or rather a bigger match. It goes till the very hand of the line, then it back tracks. When it find the last " then it stops.

style=".*?", when matches style="color: red;", stops there and does not search anymore. This returns the shortest string.

In nutshell, Lazy return the smallest string, greedy returns the largest string.

SVN Server for Mac OSX

If you have worked with SVN Repositories on Windows and you are migrating to a Macintosh, you might be wondering if there is any free SVN Server available for mac such as Visual SVN?

The answer is, Yes. There is one that ships right in the box with Mac OSX. It is included both in Snow Leopard and Lion. The trick is though it does not have any GUI. You have to use command line to create and manage your repository. That may not be the best thing in the world. But apart from that is is very powerful. You can check out things from a local system, remote server, HTTPS server and works very smooth. I have had many troubles with SVN Servers on Windows but not on Mac.

A quicker tutorial on how to use SVN on mac can be found here

I will try to guide you brief how to setup your repository.

1. Type “Terminal” in spot light (that is search in top right corner). You will see Terminal in the result. Click on it to start Terminal.

2. Where you want to create the repository? It is best to create a separate folder for your repository. Lets create one now

mkdir MyFiles
cd MyFiles

Note that we create a f older first then we moved into that folder.

3. Next create repository

svnadmin create .

This says, create SVN Repository in the current folder. Dot is for current folder. We could have combined the first two steps into one by issuing this command without creating any directory

svnadmin create MyFiles

This would create MyFiles Repository and will store it in MyFiles folder.

4. The next step would be to import files

svn import destination-folder file:///full-path-to-the-repository -m "Initial Import"

The first argument to svn import is

  1. Destination Folder
  2. Full path to your repository folder

The last argument is just a comment. It is best to put meaningful comments.

This is all your need to setup a repository on MacOSX.

The next step would be, you want to use this repository. So you have check out. Use the following command to check out your files into any folder you want

svn checkout file:///full-path-to-the-repository destination-folder
svn checkout . ../workinCopy (example)

Note that I used the . (dot) to indicate checkout everything in the current folder. The second is path to the folder where the files will be copied.

The next thing is, you want to work in the working copy. Basically you will need SVN client where you can see your work, what have you changed, what needs to be reverted, see difference between working copy and repository etc. There are a couple of good SVN Clients for although they are not free

  • CornerStone
  • Version

Macbook Pro 2012 vs 2011 Benchmark

Just how fast Macbook pro 2012 is vs Macbook Pro 2011? Or Is Macbook Air 2012 faster than macbook pro 2011, check the benchmark below obtained from geekbench.

Macbook Pro/Air 2012 vs 2011 vs 2010 – All 13″ models

.

MacBook Pro (13-inch Mid 2012)
Intel Core i7-3520M 2.9 GHz (2 cores)
7,841
 
MacBook Pro (13-inch Late 2011)
Intel Core i7-2640M 2.8 GHz (2 cores)
6,973
 
MacBook Air (13-inch Mid 2012)
Intel Core i7-3667U 2.0 GHz (2 cores)
6,785
 
MacBook Pro (13-inch Early 2011)
Intel Core i7-2620M 2.7 GHz (2 cores)
6,776
 
MacBook Pro (13-inch Mid 2012)
Intel Core i5-3210M 2.5 GHz (2 cores)
6,690
 
MacBook Air (13-inch Mid 2012)
Intel Core i5-3427U 1.8 GHz (2 cores)
6,108
 
MacBook Pro (13-inch Late 2011)
Intel Core i5-2435M 2.4 GHz (2 cores)
6,049
 
MacBook Pro (13-inch Early 2011)
Intel Core i5-2415M 2.3 GHz (2 cores)
5,883
 
MacBook Air (13-inch Mid 2011)
Intel Core i7-2677M 1.8 GHz (2 cores)
5,626
 
MacBook Air (13-inch Mid 2011)
Intel Core i5-2557M 1.7 GHz (2 cores)
5,266
 
MacBook Pro (13-inch Early 2010)
Intel Core 2 Duo P8800 2.66 GHz (2 cores)
3,653
 
MacBook Pro (13-inch Early 2010)
Intel Core 2 Duo P8600 2.4 GHz (2 cores)
3,329
 
MacBook Air (13-inch Late 2010)
Intel Core 2 Duo L9600 2.13 GHz (2 cores)
3,007
 
MacBook Air (13-inch Late 2010)
Intel Core 2 Duo L9400 1.86 GHz (2 cores)
2,693
 

Complete Benchmark of All Macbook Pros 2012 vs 2011 vs 2010

15-inch Mid 2012
Intel Core i7-3820QM 2.7 GHz (4 cores)
12,303
 
15-inch Retina Display
Intel Core i7-3720QM 2.6 GHz (4 cores)
11,844
 
15-inch Mid 2012
Intel Core i7-3720QM 2.6 GHz (4 cores)
11,800
 
15-inch Retina Display
Intel Core i7-3615QM 2.3 GHz (4 cores)
10,810
 
17-inch Late 2011
Intel Core i7-2860QM 2.5 GHz (4 cores)
10,760
 
15-inch Late 2011
Intel Core i7-2860QM 2.5 GHz (4 cores)
10,642
 
17-inch Late 2011
Intel Core i7-2760QM 2.4 GHz (4 cores)
10,420
 
15-inch Late 2011
Intel Core i7-2760QM 2.4 GHz (4 cores)
10,360
 
15-inch Early 2011
Intel Core i7-2820QM 2.3 GHz (4 cores)
10,191
 
17-inch Early 2011
Intel Core i7-2820QM 2.3 GHz (4 cores)
10,124
 
17-inch Early 2011
Intel Core i7-2720QM 2.2 GHz (4 cores)
9,868
 
15-inch Early 2011
Intel Core i7-2720QM 2.2 GHz (4 cores)
9,834
 
15-inch Late 2011
Intel Core i7-2675QM 2.2 GHz (4 cores)
9,315
 
15-inch Early 2011
Intel Core i7-2635QM 2.0 GHz (4 cores)
8,712
 
13-inch Late 2011
Intel Core i7-2640M 2.8 GHz (2 cores)
6,964
 
13-inch Early 2011
Intel Core i7-2620M 2.7 GHz (2 cores)
6,782
 
13-inch Late 2011
Intel Core i5-2435M 2.4 GHz (2 cores)
6,047
 
13-inch Early 2011
Intel Core i5-2415M 2.3 GHz (2 cores)
5,881
 
15-inch Early 2010
Intel Core i7-640M 2.8 GHz (2 cores)
5,852
 
17-inch Early 2010
Intel Core i7-640M 2.8 GHz (2 cores)
5,785
 
17-inch Early 2010
Intel Core i7-620M 2.6 GHz (2 cores)
5,543
 
15-inch Early 2010
Intel Core i7-620M 2.6 GHz (2 cores)
5,540
 
15-inch Early 2010
Intel Core i5-540M 2.5 GHz (2 cores)
4,973
 
17-inch Early 2010
Intel Core i5-540M 2.5 GHz (2 cores)
4,955
 
15-inch Early 2010
Intel Core i5-520M 2.4 GHz (2 cores)
4,860
 
13-inch Early 2010
Intel Core 2 Duo P8800 2.66 GHz (2 cores)
3,652
 
13-inch Early 2010
Intel Core 2 Duo P8600 2.4 GHz (2 cores)
3,328
 

Macbook Pro 2011 vs 2012

The specs of macbook pro 2011 13″ laptop are not easily available on apple.com site. If you want to look at it, here is the apple.com link

Here I will do a breif comparison, should you upgrade and what has changed and what has not.

Macbook Pro 2011 vs 2012 13In Model
No Comparison Macbook Pro 2011 Macbook Pro 2012 Verdict
1 Resolution 1280 x 900 Max 1280 x 900 Max Same
2 Screen Size 13" 13" Same
3 Camera 720p 720p Same
4 Processor Sandy Bridge i5 Ivy Bridge i5 2012 Wins
5 Graphics Card HD 3000 integrated HD 4000 integrated 2012 Wins
6 Memory 4GB 1333 MHz 4GB 1600 MHz 2012 Wins
7 Hard Disk 320 GB 500 GB 2012 Wins
8 CD Drive super drive none 2012 looses
9 Wired Ethernet RJ45 none 2012 looses
10 Thunderbolt 1 2 2012 Wins
11 USB 3 none 2 2012 Wins
12 HDMI Output through thunderbolt sperate HDMI provided 2012 Wins
13 Weight 4.46 lb 4.46 lb Same
14 Battery Life 7 hours 7 hours same

From the specs about it basically means, 2012 macbook pro 13″ wins clearly over 2011 macbook pro 13″ primarily because of faster processor, better integrated graphics card, faster ram, support for USB3 and HDMI output.

If you have a 2011 macbook pro or even 2010, I would say you do not need to upgrade because at least you can brag about the CD drive and wired ethernet that you have have. Plus although the new macbook pro is going to be faster, the speed of the older macbook pro is fast enough for every day and even advance task. Since the design of the 2012 macbook pro has not changed, they basically will look the same.

If you have a 2010 macbook pro, you might want to consider the 2012 macbook pro because it has a better FaceTime camera. The 2011 camera is really bad. Apart from that, you really do not need to upgrade.

If you haven’t not owned a macbook pro, you should buy the new macbook pro 2012. This is significant upgrade for someone new to buy the macbook pro 2012 and I am sure you will be thrilled with it.

I all of the above version, I would recommend to upgrade your RAM to 8GB or 16GB. They will signficanly make your macbook pro faster esp if you are used to running multiple software together. For example you run photoshop, Windows VM or other big programs. If you want to RUN Virtaul Windows like Parallel Desktop, I would recommend to go 16GB (not 8GB) as they really need more memory.

Macbook pro 2011 esp that his memory problem. 4GB of memory is definitely not enough for heavy laptop user and you will basically see the thinking ball all the time.

If you have any benchmarks of the old one vs the new one, please send it me along images so I can post it.
Thank you

This was a brief comparison of Macbook pro 2011 vs 2012 feature wise and had provided brief buying/upgrade guide. Hope it is helpful.

Islamic World on Syria

It has been more more than an year since the Syrian Revolution started in Jan 2011. It was part of a wider Arab Spring movement that started first in Tunisa then Egypt, Beharain, Libya, had ripples in Saudi Arabia and Jordon and now Syria. The Syrian people want Bashar-Al-Assan removed and topple his govement. But he is not letting it go. It is really simple, people dont want him and he is just not willing to let go. As a result there is heniours war going on Syria just to protect one man that is Bashar-Al-Assad.

What I want to discuss here is the reaction of Islamic World to Syrian conflict. It has been pathetic and probably the worse by any standards. No Muslim leader has come forward to offer any kind of help to Syrian people. Remember they are all around int he neighbor. Turkey, Iraq, Jordon and Lebenon are Syria neighbor. others are not far away. But they are simply silent as if nothing is happening. It has been an year now and one can think who long will these people be silent. The answer is for ever.

If there is any hope anyone can do anything, that is United States. In Libya it was United States and Europe who intervened and get rid of Qadafi who still have some follower around. Just because he was Muslim, he will have some eternal followers and praiser. The fact that he was not longer wanted by his people is never counted int account.

I think we Muslim need to understand how deep of a trouble we are in today. Before blaming American next time, we should realized how good of a people we are. What have we dont to save even our own people let alone others.

This is beyond description. We will never realized how bad people we ourselves are but we will constantly blame united states for what ever they are doing. It is time to think about our leaders and our future. Wake up please!

If Else Short form

In most language a short form of if else is available. It is a space saver as well as helps maintain clean code. The form is

if (condition=true) then return 1 else return 0. It can be written in different languages as follows

[c#]
Bool Paid;
Paid = IsTheBillPaid(id) ? 1 : 0;
[/c#]

The actual condition here after the equal sign. The fist statement can be a function or logical test. The function must return a logical true or false value in order to work here. If the value is true the value after question mark (?) mark is returned. Otherwise the value after colon (:).

[c#]
string result;
if (number1 > number2>
result = “greater”;
else
result=”smaller”;
[/s#]

In short hand form, it becomes

[c#]
string result;
result = number1 > number2 ? “greater” : “smaller”;
[/c#]

As you can see the code with shorthand form is much cleaner and clear. This was brief demonstration of “if else short form”.

DateTime with Null values

In C#, if you declare a DateTime type variable, it can only accept a valid date, time value. If they are invalid dates, it will not accept it. But what about if a date is simply null? Well it it wont take a null date either. So where is the solution?

I had similar situation where I had to format my datetime field which was actually stored in a string. I needed to output in proper date form in Excel Cell. When I would output it as string, it was not formatted properly and could not be formatted in Excel without clicking inside every cell. When I outputted as DateTime, it would throw exception on null dates. So I spend a couple of hours to find the solution. I was working on this logic

DateTime.TryParse(MyStringDate,out Date1) ? Date1 : null

but this did not work because null values can not be assigned to DateTime field.

First I noticed that there are nullable Datetime Field.

Nullable Datetime Type

This is declared as

DateTime? mynullabledate;

Note that it is declare same as DateTime except that it has a question mark at the end. For more information please see nullabe types in C#. DateTime? (nullable) can basically store a valid datetime or a null value. Being nullable, it can also be check for true or false value as well.

The problem here I faced was you can not use TryParse with nullable DateTime field.

Use Shorthand If Else

Then I came across stackoverflow where Jon Skeet helped answer my problem by using the following syntax

DateTime.TryParse(MyStringDate,out Date1) ? Date1 : (DateTime?) null

This is the same syntax as I was working before but could not make it work now is workable. If string is correcly parsed as valid date, we return Date1 field or if it failed then we return null value but we must typecast it as nullable datetime in order for it to be accepted.

This solution worked in my problem where I just need to change the formatting of the output. The orginal string need not be changed.