Posts

Showing posts from February, 2012

Interview questions

1) What are constraints? These are used to constraint(limit) the data that can go into SQL tables There are generally six types of constraints in SQL: NOT NULL Constraint - Check Constraint - Default Constarint - Primary Key Constraint - Unique Key Constraint - Foreign Key Constraint - 2) What are ACID properties? ACID stands for Atomicity, Consistency, Isolation and Durability. Database professionals when evaluating the database, looks at these features of database. Atomicity: Each transaction is said to be atomic. If one part of the transaction fails, entire transaction should fail. Its all or none rule. Consistency: Only valid data should be written into database. If a transaction is executed that violates the Database consistency rules then entire transaction should be rolled back. Database should not leave your transaction in half finished state. Isolation: Database should isolate two concurrent transactions until they are finished. Durability: Any transac

Lync and Exchange UM integration

For this I found a very useful post and here is the link to follow: http://blog.schertz.name/2010/11/lync-and-exchange-um-integration/ and ofcourse the microsoft link is also very useful: http://technet.microsoft.com/en-us/library/bb803622(office.12).aspx

Is not recognized as a valid cmdlet!!!

When we install Lync Server and try to import, export or use some other cmdlets, make sure you use Lync server management shell. If you use windows powersell then we will get the errors as mentioned in the title.. Silly but i did it few times this way :)

Installing Lync Server 2010

For installing Lync server topology, i want to brief down some points which will be useful in installing : 1) In wave 13(OCS 2007 R2) we can install AD and OCS on the same machine but Lync server 2010 doesnt allow it. We need to install AD on a separate machine first by using dcpromo. 2) Then next task will be installing AD components of Lync server on AD machine. 3) If you are opting for enterprise edition, install SQL Server on a separate machine. Else just skip this step. 4) Now on another machine from the Lync server deployment wizard install First standard or Enterprise edition. 5) On the same machine install topology builder. From -> All Programs, open topology builder and build a topology. After that publish the topology. For EE, we need to point to SQL server for CMS. And important point here is every organisation irrespective of number of SE and EE pools, a forest can contain only one Central management Store. So if you are planning for a child domain and in

How Voicemail will be reached to a OCS/Lync User??

I did so many settings in the Exchange and Lync to configure the voicemail. Ofcourse i successfully did it but i just followed some documents. After reading this link i felt myself relaxed by understanding the basic concept.. http://www.ocspedia.com/Misc/How_OCS_Selects_UM_Server.aspx

WCF

BareMessage=Unrecognized configuration section system.servicemodel. Edit system.servicemodel to system.serviceModel to solve this issue. This error can also cause if machine.config file doesn't have the system.serviceModel section.

WCF

An error occurred when verifying security for the message If you are running Client and Service on one machine successfully and when you are running service on one machine and client one machine there is a possibility of receiveing the above message. For this we need to have the following stuff in the code: proxy.ClientCredentials.Windows.ClientCredential.UserName = "user"; proxy.ClientCredentials.Windows.ClientCredential.Password = "password"; proxy.ClientCredentials.Windows.ClientCredential.Domain = "domain";

WCF Error

Unable to connect to the remote server Even after giving the correct service IP and port in the config file, if you face the above error then the probable problem may be that when the service is published as "localhost". Try to change it to the IP of the machine name and try. Note:The time on the machines where client and service are running should be in sync

Sorting - Bubble Sort

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AsscendingOrder { class Program { static void Main(string[] args) { int[] a = { 2,1,2,1,2,13,19,31,6}; for (int j = a.Length - 1; j > 0; j--) { for (int i = 0; i < j; i++) { if (a[i] > a[i + 1]) { int temp = a[i]; a[i] = a[i + 1]; a[i + 1] = temp; } } } for (int i = 0; i < a.Length; i++ ) Console.WriteLine(a[i]); Console.ReadLine(); } } }

Hex to Decimal

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HexToDec { class Program { static void Main(string[] args) { string hex = Console.ReadLine(); int Total = 0; //TBD: Need to check for other characters are entered for (int i = 0; i <= hex.Length - 1; i++) { switch (Convert.ToChar(hex[i].ToString().ToUpper())) { case 'A': Total = Total + 10*((Int32)Math.Pow(16,hex.Length-1-i)); break; case 'B': Total = Total + 11 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'C': Total = Total + 12 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'D': Total = Total + 13 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'E': Total = Total + 14 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'F': Total = Total + 15 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; default: Total = Total + Convert.ToInt32(hex[i].ToString()) * ((Int

Second max element in a array

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SecMax { class Program { static void Main(string[] args) { int[] arr = { 10000, 2000, 300, 200, 1, 50, 56, 72 }; //assumption: no 2 numbers will be equal. That part is not covered if (arr[0] < arr[1]) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; } for (int i = 2; i <= arr.Length - 1; i++) { if (arr[i] >= arr[0]) { arr[0] = arr[i]; } else if (arr[i] >= arr[1]) { arr[1] = arr[i]; } } Console.WriteLine(arr[0]); Console.WriteLine(arr[1]); Console.ReadLine(); } } }

Binary Search Tree Operations

#include "iostream" #include "cstdlib" using namespace std; class BinarySearchTree { private: struct tree_node { int data; tree_node* left; tree_node* right; }; tree_node* root; public: BinarySearchTree() { root = NULL; } void Print_PreOrder(); void Print_PostOrder(); void Print_InOrder(); void inorder(tree_node*); void preorder(tree_node*); void postorder(tree_node*); void insert(int); }; void BinarySearchTree::insert(int d) { tree_node* current = new tree_node; current->data = d; current->left = NULL; current->right = NULL; tree_node* parent; parent = root; tree_node* temp; if(root == NULL) { root = current; } else { while(parent) { temp = parent; if(current->data > parent->data ) { parent = parent->right; } else { parent = parent->left; } } if(current->data > temp->data) { temp->right = current; } else { temp->left = current; } } } void Bina

C# - Reference Example

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace reference { class Program { static void Main(string[] args) { int i = 5; Method(ref i); Console.WriteLine(i.ToString()); Console.ReadLine(); } static void Method(ref int j) { j = j + 7; } } }

string reverse

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stringreverse { class Program { static void Main(string[] args) { string first; int j=0; Console.WriteLine("Enter the first string"); first = Console.ReadLine(); char[] firstArr = first.ToCharArray(); char[] secondArr = first.ToCharArray(); for (int i = first.Length - 1; i >= 0; i--) { secondArr[j] = firstArr[i]; j++; } Console.WriteLine(secondArr); Console.ReadLine(); } } }

reverse word C++

#include "iostream" #include "string" using namespace std; int main() { string first; //with spaces this will not work cout<<"Enter the first word"; cin>>first; const char * cs = first.c_str (); while(*cs) { cs++; } cs--; while(*cs) { cout<<(*cs); cs--; } cin>>first; }

Base Class and Derived Class

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BaseDerived { class Program { static void Main(string[] args) { BaseClass bc = new BaseClass(); bc.fn(); BaseClass bcd = new DerivedClass(); bcd.fn(); DerivedClass d = new DerivedClass(); d.fn(); Console.ReadLine(); } } class BaseClass { public virtual void fn() { Console.WriteLine("Base"); } } class DerivedClass: BaseClass { public override void fn() { Console.WriteLine("Derived"); } } }

Constructor, Destructor and Virtual Destructor

Comment either base or derived objects in the main function and see the variation in the output. For virtual destructor concept remove the virtual keyword for base class destructor and see the output. #include "iostream" using namespace std; class BaseClass { public: BaseClass() { cout<<"Base Class constructor"< } virtual ~ BaseClass() { cout<<"Base Class Destructor"< } }; class DerivedClass :public BaseClass { public: DerivedClass() { cout<<"Derived Class Constructor"< } ~ DerivedClass() { cout<<"Derived Class Destructor"< } }; int main() { char ch; BaseClass *bc = new BaseClass() ; DerivedClass *dc = new DerivedClass(); BaseClass *bcd = new DerivedClass(); delete bc; delete dc; delete bcd; cin>>ch; }

Factorial using Recursion C#

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Factorial { class Program { static void Main(string[] args) { Console.WriteLine(factorial(4)); Console.ReadLine(); } static int factorial(int n) { if (n > 1) { return factorial(n - 1) * n; } else { return 1; } } } }

Least Common Ancestor

#include "iostream" using namespace std; class LcaClass { struct Node { int data; Node* left; Node* right; }; Node* root; public: LcaClass() { root = NULL; } void insert(int data); int lca(int first, int second); }; void LcaClass::insert(int data) { Node* current = new Node; current->data = data; current->left = NULL; current->right = NULL; Node* parent = root; Node* temp = NULL; if(parent == NULL) { root = current; parent = root; } else { while(parent) { temp = parent; if(data > parent->data) { parent = parent->right; } else { parent = parent->left; } } if(temp->data > data) { temp->left = current; } else { temp->right = current; } } } int LcaClass::lca(int firstvalue,int secondvalue) { if(root == NULL) { cout<<"root value is NULL"< return 0; } while(root) { if(root->data > firstvalue && root->data > secondvalue) { root = root->left; } else if(root->data <= firstvalue && root->

Reversing words in a string- Method 1

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ReverseString { class Program { static void Main(string[] args) { string test = "Hi How are you"; int len = test.Length; int i = 0; int j = 0; int k = 0; int l = 0; bool spaceOccurred = false; char[] charArray = test.ToCharArray(); char[] finalArray = test.ToCharArray(); char[] reverseArray = test.ToArray(); for (i = len-1; i >= 0; i-- ) { finalArray[j] = charArray[i]; j++; } string finalString = new string(finalArray); Console.WriteLine(finalString); for (i = 0; i < len; i++) { if (finalArray[i] == ' ') { if (!spaceOccurred) { for (k = i-1; k >= 0; k--) { if (finalArray[k] != ' ') { reverseArray[l] = finalArray[k]; l++; } else { break; } } reverseArray[l] = ' '; l++; spaceOccurred = true; } else { reverseArray[l] = ' '; l++; } } else { spaceOccurred = false; } } for (i =

Reversing Words - Method 2

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ReverseString { class Program { static void Main(string[] args) { string test = "Hi How are you "; int len = 0; char[] charArray = test.ToCharArray(); char[] finalArray = test.ToCharArray(); int i = 0; int j = 0; int k = 0; bool spaceOccurred = false; foreach (char ch in charArray) { i++; } len = i; for (i = len-1; i >= 0; i--) { if (charArray[i] == ' ' || i == 0) { if (!spaceOccurred || i == 0) { if (i == 0) { i = -1; } for (k = i+1; k != len && charArray[k] != ' '; k++) { finalArray[j] = charArray[k]; j++; } if (i != -1) { finalArray[j] = ' '; j++; } spaceOccurred = true; } else { finalArray[j] = ' '; j++; } } else { spaceOccurred = false; } } Console.WriteLine(finalArray); Console.ReadLine(); } } }

Error: Identifier not found

Below example throws a error saying "Identifier not found" even when both the functions are defined above main because "even" is not visible from "odd" method. Therefore it is a good practice to declare all the methods above the main and define the methods below the main. For the code to work uncomment the commented lines and move the 'odd' and 'even' methods below the main(). #include using namespace std; //void odd (int a); //void even (int a); void odd (int a) { if ((a%2)!=0) cout << "Number is odd.\n"; else even (a); } void even (int a) { if ((a%2)==0) cout << "Number is even.\n"; else odd (a); } int main () { int i; do { cout << "Type a number (0 to exit): "; cin >> i; odd (i); } while (i!=0); return 0;

First repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FirstNonRepeatingCharacter { class Program { static void Main(string[] args) { bool[] arr = new bool[256]; bool repeated = false; Console.WriteLine("Enter the string" ); string str = Console.ReadLine(); if (str.Equals("")) { Console.WriteLine("String is null"); Console.ReadLine(); return; } foreach (char ch in str) { if (!arr[(int)ch] == true) { arr[(int)ch] = true; } else { Console.WriteLine("First non repeated character: " + ch); repeated = true; break; } } if (repeated == false) Console.WriteLine("No repeated characters"); Console.ReadLine(); } } }

First repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace FirstRepeatedCharacter1 { class Program { static void Main(string[] args) { Console.WriteLine("Enter the string"); string str = Console.ReadLine(); if (str == "") { Console.WriteLine("string is empty"); Console.ReadLine(); return; } bool repeated = false; Hashtable strhash = new Hashtable(); foreach (char ch in str) { if (strhash.ContainsValue(ch)) { Console.WriteLine("First non repeated character: " + ch); repeated = true; break; } else { strhash.Add((int)ch, ch); } } if (repeated == false) { Console.WriteLine("No repeated characters"); } Console.ReadLine(); } } }

Two strings are given, remove all occurrences or the characters in the second string from the first string

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace RemoveRepeatedCharacters { class Program { static void Main(string[] args) { Console.WriteLine("Enter the orirginal string"); string str = Console.ReadLine(); Console.WriteLine("Enter the characters to be removed string"); string rem = Console.ReadLine(); Hashtable remhash = new Hashtable(); foreach (char ch in rem) { if (!remhash.ContainsValue(ch)) { remhash.Add((int)ch, ch); } } string final = ""; foreach (char ch in str) { if (!remhash.ContainsValue(ch)) { final = final + ch; } } Console.WriteLine(final); Console.ReadLine(); } } }

Maximum times repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace MaxRepeatedCharacters { class Program { static void Main(string[] args) { int max = 0; Console.WriteLine("Enter the string"); string str = Console.ReadLine(); char maxRepeatedCharacter = str[0]; if (str == "") { Console.WriteLine("String is empty"); Console.ReadLine(); return; } Hashtable hash = new Hashtable(); foreach(char ch in str) { if (hash.ContainsKey(ch)) { hash[ch] = (int)hash[ch] + 1; if ((int)hash[ch] > max) { maxRepeatedCharacter = ch; max = (int)hash[ch]; } } else { hash.Add(ch, 1); } } Console.WriteLine("Max repeated character is: " + Convert.ToString(maxRepeatedCharacter)); Console.ReadLine(); } } }

Expression Validator using Stack

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ExpressionValidator { class Program { static void Main(string[] args) { Console.WriteLine("Enter the string"); string input = Console.ReadLine(); if (IsInputValid(input)) { Console.WriteLine("Expression is valid"); } else { Console.WriteLine("Expression is not valid"); } Console.ReadLine(); } static bool IsInputValid(string input) { Stack s = new Stack (); foreach (char ch in input) { if (ch == '(' || ch == '{') { s.Push(ch); } else { if (ch == ')' || ch == '}') { char poppedItem = s.Pop(); if ((ch == ')' && poppedItem == '(') || (ch == '}' && poppedItem == '{')) { continue; } else { return false; } } } } if (s.Count != 0) return false; return true; } } }

ReverseLinkedList

#include using namespace std; class LinkedList { private: struct Node { int data; Node *next; }; Node *root; public: LinkedList() { root = NULL; } void insert(int); void Print(); void Reverse(); }; void LinkedList::insert(int d) { Node* current = new Node; current->data = d; current->next = NULL; Node* parent; parent = root; Node* temp; if(root == NULL) { root = current; } else { while(parent) { temp = parent; parent = parent->next; } temp->next = current; } } void LinkedList::Print() { Node* temp; temp = root; while(temp) { cout< data< temp = temp->next; } } void LinkedList::Reverse() { Node* temp; Node* previous; bool first = true; while(root) { temp = root->next; if(first) { first = false; root->next = NULL; } else { root->next = previous; } previous = root; root = temp; } root = previous; } int main() { LinkedList ll ; int choice, value; do { cout<<"Insert the elements"< cin>>value; ll.insert(value); cout<<"

How to retrieve the private key of a certificate?

private string PrivateKey(X509Certificate2 certificate) { string pk; if (certificate.PrivateKey != null) { RSACryptoServiceProvider rsaProvider = certificate.PrivateKey as RSACryptoServiceProvider; pk = rsaProvider.CspKeyContainerInfo.UniqueKeyContainerName; } return pk; }

Network Security: LAN manager authentication level

In windows server 2008, if we go to Network Security: LAN manager authentication level(gpedit.msc -> Computer Configuration -> WindowsSettings -> SecuritySettings LocalPolicies -> securityoptions ) and right click on it, we cannot change the value of the authentication level. It is greyed out. To change this we need to go to following registry entry.. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\LmCompatibilityLevel and set the value. LmCompatibilityLevel should be 0 for Send LM & NTLM responses 1 for Send LM & NLTM - use NTLMv2 session security if negotiated 2 for Send NTLM response only 3 for Send NTLMv2 response only 4 for Send NTLMv2 response only\refuse LM 5 for Send NTLMv2 response only\refuse LM & NTLM

Exchange Server

How to configure a HTTP endpoint for Exchange Web Services in Exchange Server? In Exchange Server 2007, what we need to do it is just uncheck Require SSL in IIS. For 2010 Exchange even after doing the above step doesnt solve the issue.. This article addresses and solves the issue clearly.. http://blogs.msdn.com/dvespa/archive/2009/12/22/how-to-configure-a-http-endpoint-for-exchange-web-services-in-exchange-2010.aspx

Windbg / ntsd Debugging commands

.load sos.dll -> Loads sos.dll which can analyze managed code !threads – shows the current threads running at the point when dump is taken !threadpool – shows the thread pool threads, queued items and timers ~*e!clrstack -> Shows the stack trace of threads !dumpheap –stat -> shows the heap memory contents !gcroot - shows all the references to managed memory in heap. If the above command does not show try the below command it gives correctly: For iterating thru gcroot .foreach (obj {!dumpheap -short -mt 0x000123ab}) {!gcroot obj} 0x000123ab – Address of the object we need to look for any references

Thread and Process

Both Threads and Processes are used for parallelisation. A thread is an independent execution path and a process contain minimum one thread. Operating system runs all our applications as processes and OS itself is a Process. Now each application(Process) can have any number of threads. Differerence between Thread and Process: Threads can share the heap memory among them. Whereas Processes are completely isolated. Then what is inter-process communication? It is the communication between threads may be of single process or different processes. And therefore it is also called inter-thread communication. Funny terminology to confuse me :@

ASP.NET page life cycle

Page Request: When the page is requested by a user, ASP.NET engine determines whether page needs to be parsed or it can directly send the page which is in control or view state. Start: At this stage, Request and Response objects are set. And in this state itself whether the request is Postback or not is set. Initialisation: : Controls on the page will be available. Matser page with the theme will be loaded if applicable. Load: If the current request is a post back, control properties are loaded from the load state or view state. Postbackeventhandling: If the request is a postback, then the relevant control event handlers will be called. And after that IsValidate is called for validating the the control values based on the request. Render: Now just before rendering the content on the page, content is loaded into view state. During this stage Render for each control is called by the page. Unload: After the page is completely rendered and sent to client, Response and Request obj