Feb 19, 2010

Quick reference for regular expressions

Syntax:
Regex regex = new Regex(@"
^                   # anchor at the start
(?=.*\d)        # must contain at least one numeric character
(?=.*[a-z])    # must contain one lowercase character
(?=.*[A-Z])  # must contain one uppercase character
.{8,10}         # From 8 to 10 characters in length
\s                  # allows a space
$                  # anchor at the end",
RegexOptions.IgnorePatternWhitespace);

Code example:

   1:    public static string emailPattern = 
   2:            @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; 
   3:    public static bool IsEmail(string email)
   4:    {
   5:       if (email != null) return Regex.IsMatch(email, emailPattern);
   6:       else return false;
   7:    }


Reference:

URL
Field Expression Format Samples
Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names. You can modify this list.
Name ^[a-zA-Z''-'\s]{1,40}$ John Doe

O'Dell
Validates the format, type, and length of the supplied input field. The input must consist of 3 numeric characters followed by a dash, then 2 numeric characters followed by a dash, and then 4 numeric characters.
Social Security Number ^\d{3}-\d{2}-\d{4}$ 111-11-1111
Validates a U.S. phone number. It must consist of 3 numeric characters, optionally enclosed in parentheses, followed by a set of 3 numeric characters and then a set of 4 numeric characters.
Phone Number
^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$
(425) 555-0123

425-555-0123

425 555 0123

1-425-555-0123
Validates an e-mail address.
E-mail ^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$ me@example.com
Validates a URL
^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$ http://www.msn.com Validates a URL
Validates a U.S. ZIP Code. The code must consist of 5 or 9 numeric characters.
ZIP Code ^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$ 12345
Validates a strong password. It must be between 8 and 10 characters, contain at least one digit and one alphabetic character, and must not contain special characters.
Password (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$
Validates that the field contains an integer greater than zero.
Non- negative integer ^\d+$ 0

986
Validates a positive currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point. For example, 3.00 is valid but 3.1 is not.
Currency (non- negative) ^\d+(\.\d\d)?$ 1.00
Validates for a positive or negative currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point.
Currency (positive or negative) ^(-)?\d+(\.\d\d)?$ 1.20

Feb 18, 2010

Obsolete types and members in .Net framework 4

Microsoft did it again! They changed many type and member definitions in framework 4. Same thing had happened when framework 3.5 published. For example in 3.5 version mail class was transferred to System.Net from System.Web and Page.RegisterStartupScript was changed to ClientScriptManager.RegisterStartupScript etc.

And now the most interesting change is about System.Data.OracleClient. It is not actually a change, they will not support OracleClient class in next versions. It seems they give the responsibility to Oracle to create new .net classes to work with new frameworks.
(In framework 4) The types in System.Data.OracleClient are deprecated. The types are supported in version 4 of the .NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.

To see full list click here.

What's new in the .Net framework 4

Visual Studio 2010 RC1 has been published on Microsoft's site. There are new features in new version of .net (Framework 4).
Asp.Net version 4 features are below. [Refer to msdn page for all features.]
  • Core services, including a new API that lets you extend caching, support for compression for session-state data, and a new application preload manager (autostart feature).
  • Web Forms, including more integrated support for ASP.NET routing, enhanced support for Web standards, updated browser support, new features for data controls, and new features for view state management.
  • Web Forms controls, including a new Chart control.
  • MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.
  • Dynamic Data, including support for existing Web applications, support for many-to-many relationships and inheritance, new field templates and attributes, and enhanced data filtering.
  • Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft Ajax Library.
  • Visual Web Developer, including improved IntelliSense for JScript, new auto-complete snippets for HTML and ASP.NET markup, and enhanced CSS compatibility.
  • Deployment, including new tools for automating typical deployment tasks.
  • Multi-targeting, including better filtering for features that are not available in the target version of the .NET Framework.

Feb 11, 2010

Web Farm (Load Balancing)

Web farm term is used for load balancing. It means running a web application (or a website) on multiple servers to distribute workload. If there are too much traffic on a server then distributing load among servers is a good way. It is scalable. Once you created an environment you can add more servers easily. But there are some criteria that must be taken into consideration:
First make it clear whether there is high traffic load on your server or not. Using cache or any other technologies may solve problem. Don't jump into load balancing solution until defining real problem. Problems may come from database. The database server may have wrong configuration or insufficient hardware. Network configuration also have a place in problem space.
If you decide to make web farm then you should use a load balancer. There are very smart balancers that have features like firewall, cache, filtering, client authentication, tcp buffering, http compression, DDoS protection and so on. 
Be careful when you update your website. To keep all servers synchronized all of them must be updated. Deploying new versions must be tracked.
As you see there are too much servers. We had one before load balance. After that we have at least 3- load balancer, 2 web servers.

I want to mention an important point about web farm in terms of Asp.net. A couple of years ago a company that have a load balancing solution came to us. We decided to try it. I don't know what they did on our servers. But i know they weren't successful. Because they didn't know how to manage ASP.NET sessions. This is another task that we need to complete. 

A state server must be created to keep sessions. I won't write detailed steps. You should know about tags that is used to set some parameters in web.config file. You may want to keep sessions on Sql Server than you must set sessionstate mode to SQLServer. You can read ASP.NET State Management Overview article.

<sessionstate cookieless="false" mode="SQLServer" sqlconnectionstring="data source=SERVERNAME; user id=sa; password=sa" stateconnectionstring="tcpip=127.0.0.1:42424" timeout="20">

Feb 4, 2010

Cloud Computing

There are many discussions on the internet about cloud computing. Cloud is internet. But computing is a fuzzy word with cloud.
The best definition that i've seen is on wiki page. Please read it to get detailed explanation.
What i understand from Cloud Computing is "software as a service" concept.

The problems with software set up are:
  • installing an application,
  • downloading updates,
  • buying server to host application,
  • providing office spaces for server,
  • paying to set up server (physical set up-hardware, network-, software set up)
  • worrying about security,
  • buying expensive licences,
  • hiring experts with high costs.
These problems are general. But the question is which applications should we use as a service. Many applications need to be installed on the local of the corporation becasue they worry about their security especially about data security. What cloud computing offer is an alternative solution to use technology. It is a model and growing concept. We must take it into consideration.

If corporations use this model wisely then they will reduce costs. All of the problems that i mentioned above consume resources. Why do we buy Microsoft Office? Do we use all features? In the future we will use office as a service. Google started a big challenge with many services. Google Docs is a very sophisticated service. I use especially "service" keyword. Because we don't install anything. We don't keep any application files. We only use it.

I hope we will see many alternative services soon. Mail applications and office packages are only examples. We can connect those services together and reach them from everywhere.

Feb 1, 2010

Oracle architecture

If you want to be an expert in an area you must understand working principals and architecture of that system. Many people use Google to find solutions. But this doesn't give you a profession. Our subject is Oracle now. If you have a problem with your database server you must identify it and find best solution. Since every database system has its own environment with full of parameters your solution must fit that environment. If you set up your system with wrong parameters you will get wrong results. So you must learn architecture of Oracle. I copied some useful items about this topic from Oracle documents. Also you can read a detailed article here.
System Global Area
• The SGA consists of several memory structures:
– Shared Pool
– Database Buffer Cache
– Redo Log Buffer
– Other structures (for example, lock and latch management, statistical data)
• There are two additional memory structures that can be configured within the SGA:
– Large Pool
– Java Pool
• SGA is dynamic
• Sized by the SGA_MAX_SIZE parameter
• Allocated and tracked in granules by SGA components
– Contiguous virtual memory allocation
– Granule size based on total estimated SGA_MAX_SIZE

Shared Pool
• Used to store:
– Most recently executed SQL statements
– Most recently used data definitions
• It consists of two key performance-related memory structures:
– Library Cache
– Data Dictionary Cache
• Sized by the parameter SHARED_POOL_SIZE
ALTER SYSTEM SET SHARED_POOL_SIZE = 64M;

Library Cache
• Stores information about the most recently used
SQL and PL/SQL statements
• Enables the sharing of commonly used statements
• Is managed by a least recently used (LRU) algorithm
• Consists of two structures:
– Shared SQL area
– Shared PL/SQL area
• Size determined by the Shared Pool sizing

Data Dictionary Cache
• A collection of the most recently used definitions in the database
• Includes information about database files, tables, indexes, columns, users, privileges, and other database objects
• During the parse phase, the server process looks at the data dictionary for information to resolve object names and validate access
• Caching data dictionary information into memory improves response time on queries and DML
• Size determined by the Shared Pool sizing

Database Buffer Cache
• Stores copies of data blocks that have been retrieved from the datafiles
• Enables great performance gains when you obtain and update data
• Managed through an LRU algorithm
• DB_BLOCK_SIZE determines primary block size

Redo Log Buffer
• Records all changes made to the database data blocks
• Primary purpose is recovery
• Changes recorded within are called redo entries
• Redo entries contain information to reconstruct or redo changes
• Size defined by LOG_BUFFER

Program Global Area
• Memory reserved for each user process connecting to an Oracle database
• Allocated when a process is created
• Deallocated when the process is terminated
• Used by only one process

Jan 28, 2010

Open source software

Last week i filled a survey about open source software (OSS). The questions were about advantages/disadvantages of OSS.  I realize that in spite of its advantages we don't prefer OSS. There are many software like operating systems, office packages, vpn, e-mail client etc. You can see a list of OSS here.

Usage of OSS is increasing but there are some concerns. Licensing and long term support may be problems. Too much developers may decrease quality of code. Too much development need to be tested very well. Installation costs may be high. Also there is no guarantee for updates.

Some advantages of open source software:
• High quality: By its very nature, open-source software has nothing hidden. This means that bugs or security holes can be observed, found, and fixed by all. Through peer review and use, the resulting product is more secure, tested, and stable than many closed-source products.

• Fast innovation: With a large community of developers and third-party add-ons, new features and capabilities can be added to open-source software in shorter cycle times, without waiting for a calendar-driven “release train” schedule. Freely available access to source and binary code not only allows developers and customers to try it out, but also enables users to provide feedback during development. This provides a much tighter feedback loop than closed-source software, improving overall quality and functionality.

• Transparency and extensibility: Open-source software enables everyone to see what is being built and what features will be included, as soon as possible, so enterprise users can plan well in advance of the actual release. Developers and customers do not need to wait for a vendor to publish a roadmap or hold a product launch to know what is being developed. Companies can make better, faster, and more informed decisions relating to their software infrastructure.

• Pay at the point of value: Open-source project code is freely available for any use, and if a company is proficient with its use they are generally free to do so in any way, from evaluation to production. Only when open-source customers see value —in support, integration, or additional functionality or expertise—do they need to spend money. Unlike proprietary software, where customers must purchase a license or deploy a restrictive “trial-only” version for evaluation purposes, opensource software allows evaluation, proof of concept development, and more.
There are no restrictions on when open-source software can be used.

I copied advantages list from internet which i don't remember website name. So i can't give a source.
If you want to read open source articles i recommend to follow Open Source Technology blog.

Jan 27, 2010

Change Excel color palette

I am using Office 2003 at work. I don't like fill colors in Excel. In Office 2007 there are nice, smooth colors. Today i learned that i can change color palette in Excel.

You can use Tools / Options / Color tab to modify colors. Also you can import color palette from an excel file. On Rae's Blog there are some instructions to do that. Also you can download a nice color palette to import your workbook. Click here to download palette file. Then you get nice colors for Excel 2003.