Posted by archworx on June 10, 2007
I have been developing Custom ASP.NET Server Controls for a while now and I think it is worthwhile to write a series of blog posts about how to develop them. So here we go with the first introductory blog. First, let us think why developing .NET components is important. Well, first of all Microsoft has developed a decent set of components and controls for the .NET framework, but surely these preexisting components don’t fit every scenario that you might need when you are developing your application, so this is why creating new components (or extending existing ones) is needed. More importantly it is the concept of reusability that particularly makes developing such components useful. Identifying certain recurring scenarios and common functionalities and developing a certain component that can be reused by yourself and others without having to re-write the same code again is very valuable. A friend of mine has recently told me that “A good developer only writes code once”. This proverb, albeit an oversimplification, captures the essence of reusability. Great, so what implications does this have on you as a developer? Well, being able to capture repetitive scenarios into reusable code is very important. So next time you write code try to think if you have written this code before (or if you are going to write it again in the future) and if so then you can try to encapsulate it into a component that can be reused (even if this means creating a simple code snippet). This doesn’t only apply to code that you write, but if you are smart enough you can identify recurring patterns inside applications that your organization is developing and hence suggest how reusable components can be used within the company to improve the development process. So, with this introduction over we will turn to talking about Custom Controls in .NET and how they differ from User Controls. But alas, this will have to wait till the next blog.
Posted in .NET 2.0, AFathalla, Programming, Reusable Components | Leave a Comment »
Posted by archworx on June 4, 2007
I was developing a Control Library for .NET 2.0 and wanted to generate neat looking documentation from XML tags that I had written in code. So I googled around for a bit until I found that you can use a tool called SandCastle to generate HTML documentation that could be transformed into CHM and HxS formats. Here are the steps you have to do:
1- Inside VS2005 right click your project in the Solution Explorer and choose ”Properties”.
2- Click “Build” tab, under “Ouput” make sure that you check the “XML documentation file” checkbox. Once you do so, you can fill in a textbox that specifies the path of where the XML file (that contains the tags you put in code) will be generated.
3- Download and Install HTML Help Workshop .
3- Download and Install SandCastle March 2007 CTP .
4- Download and Install SandCastle Help File Builder (A really cool project on CodePlex that provides a UI that utilizes Sandcastle to generate Help Files)
5- Use SandCastle Help file Builder to generate your documentation .
Voila, you’ve got a cool professional documentation for your .NET project
Posted in .NET 2.0, AFathalla, Documentation, VS 2005 | 5 Comments »
Posted by archworx on May 17, 2007
Here’s an easy one:
Given a string that contains only parenthesis like “(” “[” “)” “]”
We call a string balanced if every opening parenthesis has its corresponding closing parenthesis (and vice versa) , but they have to be in closed in correct order i.e. if you open a nested parenthesis inside another the nested one should be closed before the outer one is closed.
So an example of a balanced string would be “([[(())]])”
Examples of unbalanced strings would be “]([()])[” and “[[[((]))]]”
Can you write a function that takes a string (or characher array) as a parameter and returns true if it is balanced and false if it is not.
Waiting for your answers
Posted in AFathalla, Interview Question | 5 Comments »
Posted by archworx on May 9, 2007
There has been a post drought on our blog lately, I decided to write a post to elaborate more about the NP-Complete Problems Post I had posted earlier. The subject is not small so I think it will take a series of post.Let’s first begin by defining a set of problems that are called NP. The set of NP problems is the set of decision problems (i.e. have an answer of either YES or NO) that can be verified by an algorithm that runs in polynomial time (Remember polynomial time is n^k where k is a constant). But what does that mean, it means that if we are given an instance of this problem and a solution of the problem we can verify whether or not this solution is a correct one using an algorithm that runs in polynomial time. But does this mean that this problem itself can be solved in polynomial time, not necessarily. There currently does not exist a polynomial time algorithm for the Traveling Salesman Problem (TSP), but given an instance of TSP and a solution we can easily verify whether this solution is correct or not using an algorithm that runs in polynomial time. But wait, we said that NP problems are decision problems and TSP is an optimization problem. That is not an issue, as any problem can be transformed to a decision problem. In the TSP example we can slightly change the problem statement to be “Is there a path that passes by all cities once and only once having a cost no more than x (where x is a positive integer). Now it is easy to create an algorithm that checks that the solution is correct by verifying that all cities were visited and that the cost is less than the one given in the problem statement, it is easy to prove such an algorithm runs in polynomial time. Now that we have defined the set NP lets present a formal definition of the set of NP-Complete problems; a problem Z belongs to this set if:
1- Z E NP (where E is the set notation for ‘is an element of’)
2- Every problem in the set NP can be polynomialy reduced to Z.
But what does polynomialy reduced mean. Well,this will just have to wait for next time.
N.B. I don’t trust my powers of explanation 100% so be sure to post a comment about anything you want elaborated 🙂
Posted in AFathalla, Algorithms | Leave a Comment »
Posted by archworx on March 15, 2007
So, you must have heard this term before. I had heard it before and was really looking forward to know it. Yesterday I learnt it in my algorithms class. Basically, computer scientists have considered algorithms that execute in polynomial time (n^k) (where n is the size of the problem k is a constant and ^ denotes power) better than those solved in exponential time (k^n) (where k is a constant and n is the size of the problem ^ denotes power). This is a bit intuitive because exponential time algorithms have a tremendous growth rate (as the problem size increases, the time needed to solve it increases exponentially). After this quick introduction lets turn back to NP-complete problems. Strictly, NP-complete problems are defined as a class of problems/algorithms which if one can be solved in polynomial time then all others can be solved in polynomial time, and since people have been unable to prove for more than thirty years that even one of these problems can be solved in polynomial time, it is unlikely (to our current knowledge) that they can be solved in polynomial time. In other words (from my understanding) if a problem is NP-complete then we cannot (to our current knowledge) solve it using an efficient algorithm (one that takes polynomial time). This is because the problem grows very rapidly with increase in input, and is practically unsolvable for large values of n. An example of an NP-complete problem is the well known traveling salesman problem . For more on the issue of NP-completeness read the wikipedia article.
Posted in AFathalla, Algorithms | 2 Comments »
Posted by archworx on February 25, 2007
Due to the popularity of our Interviewing Question posts, we’ve decided to add yet another question. This time its easy and straight forward. You have a singly linked list of integers that are ordered ascendingly (for example -2,1,4,6,7). Can you devise an algorithm by which you insert a node into the linked list while maintaining its order. For example if you want to add a node containing the integer ‘5’ the linked list in the previous example will become (-2,1,4,5,6,7). Can you write the algorithm in C++ ?
Posted in AFathalla, Interview Question | 14 Comments »
Posted by archworx on February 19, 2007
Think of this, you have a building which is 100 floors high and you have 3 eggs. You can throw an egg from any floor and it might or might not break, but there is a certain floor (a threshold floor) afterwhich eggs are guranteed to break for all floors above this certain floor. If We want to know exactly which floor is the threshold floor, what is the minimum number of egg throws do we have do make?
Remember: You have only 3 eggs, so if you break all the 3 eggs without finding the threshold floor then you have failed. Also remember that we want the minimum number of throws.
Posted in AFathalla, Interview Question | 28 Comments »
Posted by archworx on February 7, 2007
Yesterday I attended a session on Language Integrated Query (LINQ) at MDC. Simply said it is a new technology introduced with C# 3.0 and VB 9.0 which will be shipped in the next version (Orcas) of Visual Studio. Basically, LINQ allows you to perform queries on objects, databases and XML files from within .NET languages allowing you, for example, to query your database without writing a single line of SQL code. LINQ helps you create an object mapping of your database; converting your database tables into classes which you can query from within the language. This way you can reap the advantages of Intellisense and Type Checking which were never present when you wrote SQL strings from inside the code. Below are screenshots containing the code I wrote to perform a query on the Northwind database that retrieves the customerID of customers who live in London and the results obtained from the query. It is important to mention that prior to performing this query , I used a visual designer (included with LINQ) to drag the database tables on screen, allowing LINQ to convert them into the corresponding objects.
N.B. I am using the May CTP of LINQ.
Posted in AFathalla, LINQ | 2 Comments »
Posted by archworx on January 22, 2007
Last Saturday I attended the first Java Developers Conference (JDC) to be held in Egypt. The event was organized by the Egyptian Java Users Group (EGJUG) and was held at Intercontinental City Stars Cairo. Consisting of 7 sessions, the conference covered topics ranging from SOA and Webservices to IDEs and productivity. I thought the conference was successful overall, it was well organized (albeit a bit late on the agenda), had good food 🙂 and hosted knowledgable speakers. The sessions I liked most were the ones about “Bullet Proofing your Webservices” and “New Features in Java 6” which were lectured by Chuk Mun Lee (Sun Singapore Senior Developer Consultant). The first talked about best practices in the use of webservices in Java and how the ease of creation of webservices has evolved in J2EE 5 and JavaSE 6. The second talked about new syntactic features and APIs shipped with JavaSE 6, the most important introduction (in my opinion) being the introduction of Webservices in Java SE for the first time. I also liked the Netbeans session given by Roman Strobl (Netbeans Technical Evangelist), although I must say that the new databinding features that will be shipped with Netbeans 6 were present in .NET 2.0 for ages now, overall I think Netbeans has an edge on other Java IDEs by being the best (again in my opinion) in providing Visual Editors for Java Developers. Anyways, that was it. Microsoft’s Middle East Developers Conference (MDC) is coming to Egypt this Feburary, we’ll just have to see what Microsoft can come up with to counter Java’s new features 🙂
Posted in AFathalla, Java | 3 Comments »
Posted by archworx on October 18, 2006
Encrypting sections in your Web.config file that contain sensitive information (such as Connection Strings) is a security precaution that any decent ASP.NET developer should take care of, and in .NET 2.0 it couldn’t be any easier. You can encrypt any section of your Web.config file from the command line using the aspnet_regiis command or programatically from within your code. To do it from the command line you can open your Visual Studio Command Prompt and type
aspnet_regiis -pe "NAME OF YOUR WEB.CONFIG SECTION" -app "/YOUR WEBSITE NAME ON IIS"
Voila….the configuration section you typed in the command now is now encrypted, here are screenshots of a ConnectionStrings Section in a web.config file after it has been encrypted.
If you prefer to encrypt a Web.config section programatically, you can do it through the following code:
Configuration config = Configuration.GetWebConfig
ConfigurationSection section = config.Sections["connectionStrings"];
You can use this technique if you don’t have full access to the Web Server.
References : http://www.developerfusion.co.uk/show/5263/
Posted in .NET 2.0, AFathalla, VS 2005 | 2 Comments »