Saturday, August 16, 2008

Easy log parsing with FileHelper

FileHelper is .NET library that provides a very easy and fast parsing methods for delimited or fixed length logs. You can import/export data in file, strings or steams. According to site:

The idea is very simple

You can strong type your flat file (fixed or delimited) simply describing a class that maps to each record and later read/write your file as an strong typed .NET array

Sunday, August 03, 2008

I want a better...

Ahh.. everybody is coming up with new idea and printing money. How about a site that have wish list of frustrated customers. Who knows you may get a new idea from the wish list. 'I-want-a-better' internet connection !!!

Every block - next level of public data processing

This site aggregates tons of public data source by geo location. You can search by various categories. For example, you can view all crime news local to your area in particular city. Currently site is supporting only few cities. According to site:

"EveryBlock is a new experiment in journalism, offering a Web "newspaper" for every city block in Charlotte, Chicago, New York, Philadelphia and San Francisco — with more cities to come. Enter any address, neighborhood or ZIP code in those cities, and the site shows you recent public records, news articles and other Web content that’s geographically relevant to you. To our knowledge, it’s the most granular approach to local news ever attempted."

Monday, July 28, 2008

Better searching with Cuil (hopefully)

Cuil was created by a former Google employee and has entirely different approach for indexing. Till now, this search engine has indexed 120 billion pages, 3 times of Google. Only the time will tell, how it goes, but its result formatting is much better than of Google. It gives results in magazine style formatting. One more thing I like - Home page with black background. I don't know whether it was intentional, but global warming fighter community will surely admire it.

Sunday, July 27, 2008

Reference Cards

Visit this site to get collection of really cool reference cards:
http://refcards.com/

I found reference of this site having SQL server cheat sheet.

Thursday, June 05, 2008

Web Development Helper

Another master piece from Nikhil Kothari, similar to firebug but also having http trace and script console utility.
Download link: http://www.codeplex.com/webdevhelper/Release/ProjectReleases.aspx?ReleaseId=11062

Monday, May 26, 2008

.NET Regex Balanced Grouping

Last time when I tried to understand balanced grouping from MSDN, it hurt my brain badly. Thanks to this guy, though he is not .NET coder, he explained balanced grouping very nicely. A must read for Regex lovers.

Friday, May 23, 2008

Google plays foul

Google hands over user information


Personally, I feel, if you don't like someone, you should not criticize him in filthy language. Being in democracy doesn't mean you strike someone below the belt, specially when someone is top public figure. In 110 crore population, all may not happy with Sonia's government. People should express their view in ethical way.

Whats wrong with Google. I am agree that boy should have not used foul language, but who gives rights to Google to hand over the information. This was not any terrorist activity. If Google thinks, user is using foul language, he should have simple blocked the user. Activity done by Google, simply indicates that they have nothing to do with providing a free social networking platform to public, its all about BUSINESS, its all about getting POWER, its all about MONEY. I read somewhere IBM helped Nazis in holocaust by providing data of Jews population. Google has not done that bad right!!! Well done Google!!.

Friday, February 08, 2008

You have seen Y2K, worse to come!!!

Y2038 Bug!!

According to computer scientists, Unix and Linux system will be massively affected. But of course, still having plenty of time. Surprisingly Perl 10 is Y2038 safe but thats not the reason why I love this language.

Read this:

It is explained that Unix and similar operating systems do not calculate time based on the Gregorian calendar. Instead, they are known to simply count time in seconds from their arbitrary "birthday", that is, GMT 00:00:00, Thursday, January 1, 1970. The accepted practice among software programmers is to use a 32-bit variable for this number (32-bit signed time_t). The largest possible value for the end integer in this calculation is 2**31-1 = 2,147,483,647. So, 2,147,483,647 seconds after Unix's birthday falls on Tuesday, January 19, 2038. And one second later, theoretically Unix systems will revert to their birth date (like an odometer switching back from 999999 to 000000).

See original Post.

Thursday, January 17, 2008

Definitions related with SQL Server

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

Examples: SELECT, UPDATE, INSERT, DELETE

DDL

DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.

Examples: CREATE, ALTER, DROP statements

DCL

DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

Examples: GRANT, REVOKE statements

TCL

TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.

Monday, January 07, 2008

Fun with WWW::Mechanize

WWW::Mechanize is really a very handy module if you want to automate web page related tasks. Following PERL script downloads the Perl Cook Book pages in a directory. You can put this Perl script in a scheduler and all pages will be collected in few days.

use strict;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
my $ouputDir = 'E:\work\documents\PerlCookBook';
my @urls = (
'http://www.perl.com/cookbook/perlckbk2/solution.csp?day=1',
'http://www.perl.com/cookbook/perlckbk2/solution.csp?day=2',
'http://www.perl.com/cookbook/perlckbk2/solution.csp?day=3',
'http://www.perl.com/cookbook/perlckbk2/solution.csp?day=4',
'http://www.perl.com/cookbook/perlckbk2/solution.csp?day=5'
);

foreach my $url (@urls) {
GetPage($url);
}

sub GetPage {
my $url = $_[0];
$mech->get($url);
if ( $mech->success() ) {
my $content = $mech->content();
if ( $content =~ /\<h2 class="head1"\>(.*)?\<\/h2>/ ) {
my $title = $1;

#$title =~ s/\s+//g;
my $filePath = $ouputDir . "\\PCB_" . $title . ".html";
if ( !-e $filePath ) {
open( WR, ">$filePath" ) or die "Can't create file $filePath\n";
print WR $content;
close WR;
print "File was created successfully\n";
}
else {
print "File already exists\n.";
}
}
}
else {
print "Reqeust was not successful\n";
}
}

Friday, January 04, 2008

Recompilation in SQL Server 2005

Before executing SQL statement, SQL server checks for the validity and correctness of the query and generates the execution plan if it's not all already available. No need to say compilation is very CPU intensive process. Before executing the already compiled SQL statement, SQL server perform several other checks and if any of these checks fails, SQL server perform again compilation of SQL statement. Such compilations are known as recompilations. Following are some reasons for recompilation:

  1. Schema change
  2. Statistics change
  3. Deferred compile
  4. SET option change
  5. Temporary table change
  6. Stored procedure created with RECOMPILE query hint or OPTION(RECOMPILE)

In SQL Server 2000, if you need to recompile a portion of stored procedure, you need to compile the whole stored procedure, however in SQL Server 2005, you can perform recompilation at statement level. Less recompilation means less CPU consumption and less contention.

For more information, see Identifying Recompilation

Wednesday, January 02, 2008

Considerations while designing own types

Though Value Types are created on stack and in some situation gives better performance as compare to Reference Types, we should not tempt with choosing Value Type for every situation. General misconception is that if we are not having complex functionality, we should choose Value Type. We should not forget that size of instance also does matter in copy operation. In functions, Value Types are passed by copying the instance as a parameter. Similarly if function is returning Value Type, that is also copied in caller function's memory space. We can make our type as Value Type in following situations:

  1. Type has no members that modify any of the type's instance field. In other words, type is immutable.
  2. Type should not lie in inheritance chain. That means, it should inherit from any other type and also any other type should derived from it.
  3. Instances of the type are small in size (16-20 bytes or less)
  4. Instances of the type are large (greater than 20 bytes) and are not passed as argument or return value in functions.

Most promising technologies in 2008

Welcome 2008. I see following technologies which can take a big leap in 2008:

  1. Microsoft Silverlight framework – facilitates you to run a desktop like application in Internet Explorer.
  2. Ultra Mobile PC (UMPC)- Size of a your hardback book, weight less than a Kg, no hard drive, only flash memory of approx 4 Gb. Visit Asus EEE
  3. ADSL2+: Broadband speed up to 24 Mbps (Of course not in India J)
  4. IPTV: Progress in this field was hampered in past. But now with the increase in broadband speed, this technology is ready to take off.

Monday, December 31, 2007

Bye Bye 2007

2007 was really a vibrant year for me. New Company, new projects, new peoples, new challenges, achievements, awards, anxiety and excitement were some few colors of 2007, but above all, becoming a father will make 2007 is the most memorable year of my life. I am very thankful to my family and friends who gave their support in every up and down phase of my life. I don't believe in resolutions but keeping the tradition, I want to make this resolution and I will my try my best to follow this resolution throughout the year – I will start my sketching again. I am an artist by instinct. I left sketching few years back when I went college for engineering. I know this can't be excuse but really that time I just wanted to concentrate on my career. This unusual blog post is note to me and it will keep reminding me of my New Year resolution.

Sunday, December 30, 2007

RedGate SQL Data Generator

RedGate launched a new tool for generating SQL server for dummy/test data.

Features:
- Full SQL Server 2000 and 2005 support
- All data types supported except CLR types
- Pre & Post Scripts execution
- Command-line access version
- Import data from CSV or SQL tables
- Customizable generator settings that allow configuring the amount of nulls, unique values, minimum and maximum values, etc..
- Diverse range of inbuilt generators

Please visit here for more detail.

By the way, I have already created few PERL scripts to achieve same type functionality to some extent.

Thursday, December 20, 2007

Yet another good article on Cluster and Non cluster index

Take the example of a phone book. The actual data - that is, the name, address and phone number records - is ordered by the name. If you want to look up Joe Bloggs's phone number, you open the book somewhere near the middle, maybe see the names there start with "M", but "Bloggs" is before "M", so you go a bit earlier in the book. You keep narrowing it down until you find the entry labelled Bloggs, and that's it - all the data for that record is right there. That's a bit like a clustered index.

On the other hand, a book might have a table of contents, sorted alphabetically. If you want to find out about llamas, you search the contents for llamas, which probably then gives you a page number, at which point you go to the page, and there's the data about llamas. The difference here is that you've had to do an extra bit of indirection - following the page number pointer - in order to get to the data. You can probably now see that while you can have as many tables of contents, ordered in any way you like, one set of data can only be physically arranged in one way. This means you can have many non-clustered indexes, but only one clustered index on a table.

Full Article

Wednesday, December 19, 2007

Perl 5.10 is out

Perl is no longer teenager. Its Perl's 20th Bithday and its coming in its brand new suite.
Checkout new features of 5.10 in this document.

Of course you have to wait for 5.10 and chances are you never get it but till then Perl 5 is rocking.

Tuesday, December 18, 2007

String - Reference or Value Type

In my interviews, I observed that 90% candidates don't have clear understanding of Reference or Value Types in .NET. I am not going to explain these two things here but want to clear one interesting point here.

Though String in .NET is Reference type object but it works as Value type.
Following code snippet will print "test"

static void Main(string[] args)

{

string str = "test";

ChangeString(str);

Console.WriteLine(str);

Console.ReadLine();

}

static void ChangeString(string str)

{

str += " Changed";

}





Following some line will better explain the things:
although strings are reference types, they work rather more like value types. When one string is set to the value of another, eg
string s1 = "hello";
string s2 = s1;

Then s2 does at this point reference the same string object as s1. However, when the value of s1 is changed, for instance with

s1 = "goodbye";

what happens is that a new string object is created for s1 to point to. Hence, following this piece of code, s1 equals "goodbye", whereas s2 still equals "hello".

The reason for this behaviour is that string objects are 'immutable'. That is, the properties of these objects can't themselves change. So in order to change what a string variable references, a new string object must be created.


Restrictions on TempDB

I found it on internet. Thought you guys like to know:

  • Adding filegroups.
  • Backing up or restoring the database.
  • Changing collation. The default collation is the server collation.
  • Changing the database owner. tempdb is owned by dbo.
  • Creating a database snapshot.
  • Dropping the database.
  • Dropping the guest user from the database.
  • Participating in database mirroring.
  • Removing the primary filegroup, primary data file, or log file.
  • Renaming the database or primary filegroup.
  • Running DBCC CHECKALLOC.
  • Running DBCC CHECKCATALOG.
  • Setting the database to OFFLINE.
  • Setting the database or primary filegroup to READ_ONLY.

Monday, December 17, 2007

SQL Helper - New functionalities (2)

In my last posts, I talked about SQL helper developed by me. Following are two new functionalities added recently to application:

  1. Create database documentation in word or html format
  2. Do Uppercase SQL keywords option in Stored procedures and functions.

Tuesday, November 27, 2007

Part 1: Using XML in SQL Server 2005

Suppose you want to generate following output from stored procedure :

1 <Companies>

2 <Company id="1" name="Company A">

3 <Address>

4 <Street>101 A St.Street>

5 <City>HaysCity>

6 <State>KansasState>

7 <Zip>67601Zip>

8 Address>

9 <Contacts>

10 <Contact id="1" name="Bob Black">

11 <ContactInfo email="bb@companyA.com" phone="(123) 456-7890" />

12 <Login uid="bb" pwd="bb7" />

13 Contact>

14 <Contact id="2" name="Bob Brown">

15 <ContactInfo email="bbn@companyA.com" phone="(123) 456-7891" />

16 <Login uid="bn" pwd="bn1" />

17 Contact>

18 <Contact id="3" name="Bob White">

19 <ContactInfo email="bw@companyA.com" phone="(123) 456-7892" />

20 <Login uid="bw" pwd="bw2" />

21 Contact>

22 Contacts>

23 Company>

24 Companies>



Following is the code snippet to achieve above output from SQL query

select

Company.Cmp_id "@id",

Company.[Name] "@name",

Company.Address "Address/Street",

Company.City "Address/City",

Company.State "Address/State",

Company.Zip "Address/Zip",

(

select

Contact.Cnt_id "@id",

Contact.[Name] "@name",

Contact.Email "ContactInfo/@email",

Contact.Phone "ContactInfo/@phone",

Contact.UserName "Login/@uid",

Contact.Password "Login/@pwd"

from

Contact

where

Contact.Cmp_id = @CompanyId

order by

Contact.[Name]

for xml path ('Contact'), root('Contacts'), type

)

from

Company

where

Company.Cmp_id = @CompanyId

for xml path ('Company'), root('Companies'), type

Monday, November 12, 2007

Showing enum as dropdown or listbox

Following function returns ListItemCollection for given enum type. This ListItemCollection can be bound to dropdown or listbox:

public static System.Web.UI.WebControls.ListItemCollection GetListItemsFromEnum(Type typeOfEnum)
{
System.Web.UI.WebControls.ListItemCollection lstColl
= new System.Web.UI.WebControls.ListItemCollection();
foreach (string name in Enum.GetNames(typeOfEnum))
{
System.Web.UI.WebControls.ListItem li
= new System.Web.UI.WebControls.ListItem();
li.Text = name;
li.Value = ((int)Enum.Parse(typeOfEnum, name)).ToString();
lstColl.Add(li);
}
return lstColl;
}