Monday, September 20, 2010
Monday, June 28, 2010
New Blog www.weblogs.asp.net/chanderdhall
I haven't been updating my blog lately. However, I am moving to a newer blog now.
Chander Dhall's blog. Please follow me on twitter @csdhall. Also, feel free to visit
www.chanderdhall.com and www.welcometoyoga.com
Chander Dhall's blog. Please follow me on twitter @csdhall. Also, feel free to visit
www.chanderdhall.com and www.welcometoyoga.com
Thursday, August 21, 2008
Password Hacking software program. Nothing to do with real hacking though.
//This question was never asked to me in any of my interviews, however, after many of my friends asked me for a solution, I decided to blog it. I haven't seen any solution online but i happened to have solved it.. Complexity wise, this is really optimized as far as the looping count is concerned. However, there are ways to reduce the space complexity.
THis is a C-style C# code written like that so that it is easy for C, C++ and Java coders to understand. However, if any one wants an equivalent code in any of the above languages, please email me at chander.utd@gmail.com
To help me keep up the good work please click here and check out some cool stuff.Click here
using System;
using System.Collections.Generic;
using System.Text;
namespace Chander
{
///
/// This class runs a password hacking software.
/// Only two things are given.
/// Hack the password.
/// Only 2 things you know that password is having N digit & each
/// digit in the password is in increasing order example 1469 or 468. [1 ]
///
class Program
{
static int count = 0;
const int c = 9;
static void Main(string[] args)
{
int[] arr = new int[c];
for (int i = 0; i < maxvalue =" getMaxDecimalValue(arr);" arr1 =" new" temp =" string.Empty;" i =" 0;" arr1 =" getAllBinaryNumbers(i" cnt =" 0;" a =" 0;"> result = new List();
if (cnt > 1)
{
for (int a = 0; a < temp =" temp" temp =" temp" arrresult =" new" mod =" 0;" bin =" c;" mod =" val" val =" val">= 1);
return arrResult;
}
private static int getMaxDecimalValue(int[] a)
{
int[] b;
b = new int[a.Length];
int sum = 0;
int k = 0;
for (int i = a.Length - 1; i >= 0; i--)
{
b[i] = 1;
sum = sum + pow(2, k);
k++;
}
return sum;
}
private static int pow(int p, int k)
{
int power = 1;
if (k == 0)
{
return 1;
}
for (int i = 0; i < power =" power">
THis is a C-style C# code written like that so that it is easy for C, C++ and Java coders to understand. However, if any one wants an equivalent code in any of the above languages, please email me at chander.utd@gmail.com
To help me keep up the good work please click here and check out some cool stuff.Click here
using System;
using System.Collections.Generic;
using System.Text;
namespace Chander
{
///
/// This class runs a password hacking software.
/// Only two things are given.
/// Hack the password.
/// Only 2 things you know that password is having N digit & each
/// digit in the password is in increasing order example 1469 or 468. [1 ]
///
class Program
{
static int count = 0;
const int c = 9;
static void Main(string[] args)
{
int[] arr = new int[c];
for (int i = 0; i < maxvalue =" getMaxDecimalValue(arr);" arr1 =" new" temp =" string.Empty;" i =" 0;" arr1 =" getAllBinaryNumbers(i" cnt =" 0;" a =" 0;"> result = new List
if (cnt > 1)
{
for (int a = 0; a < temp =" temp" temp =" temp" arrresult =" new" mod =" 0;" bin =" c;" mod =" val" val =" val">= 1);
return arrResult;
}
private static int getMaxDecimalValue(int[] a)
{
int[] b;
b = new int[a.Length];
int sum = 0;
int k = 0;
for (int i = a.Length - 1; i >= 0; i--)
{
b[i] = 1;
sum = sum + pow(2, k);
k++;
}
return sum;
}
private static int pow(int p, int k)
{
int power = 1;
if (k == 0)
{
return 1;
}
for (int i = 0; i < power =" power">
Wednesday, May 28, 2008
Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder1_updatePanel1'. If it is being updated dynamically then it
This is one error that has no concrete solution. I just happened to come across it and decided to blog it after having fixed it.
Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder1_updatePanel1'. If it is being updated dynamically then it must be inside another updatepanel'
The error usually occurs when we add some user controls(child controls) inside another user control(parent control) or in a similar situation using Web Parts. Modifying a property of an Update Panel in the child control usually throws an error. However, this is only if the Update Panel in the child control is not inside the property of the UpdatePanel in the parent control.
In lay man terms we are supposed to treat the Update Panel of the parent control as a PlaceHolderControl for the Child Controls which are inside unique Update Panels already.
Hope that helps.
Please feel free to comment and seek clarifications if required.
Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder1_updatePanel1'. If it is being updated dynamically then it must be inside another updatepanel'
The error usually occurs when we add some user controls(child controls) inside another user control(parent control) or in a similar situation using Web Parts. Modifying a property of an Update Panel in the child control usually throws an error. However, this is only if the Update Panel in the child control is not inside the
In lay man terms we are supposed to treat the Update Panel of the parent control as a PlaceHolderControl for the Child Controls which are inside unique Update Panels already.
Hope that helps.
Please feel free to comment and seek clarifications if required.
Monday, May 26, 2008
Sorting using C# generics
Using anonymous methods and generics can change the nature of coding as a whole and C# does a great job in providing the coveted flexibility to a developer.
Initially, it looks like a whole lot of paradigm shift but later it becomes a habit and more so, an addiction.
Here is an example that shows one of the shortest ways to sort a list of Persons according to any property desired.(Class: Person, List stands for the generic list which is having a type Person now).
Lets us enter some code.
//Class Person
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public int Salary { get; set; }
public Person(string name, int age, int salary)
{
this.Name = name;
this.Age = age;
this.Salary = salary;
}
}
//Initializing a list of Persons
//This may not be static for this example.
//But we might have to make it static for a later example.
static List persons = new List();
public bool isEqual { get; set; }
persons.Add(new Person("chander", 26, 88000));
persons.Add(new Person("jiggi", 26, 80000));
persons.Add(new Person("puneet", 26, 90000));
persons.Add(new Person("chander", 26, 95000));
persons.Add(new Person("jiggi", 26, 10000));
persons.Add(new Person("chander", 26, 85000));
persons.Add(new Person("chander", 26, 1000000));
persons.Add(new Person("jiggi", 26, 34535));
persons.Add(new Person("chander", 26, 86000));
//Sorting according to a property of the class Person.
//It is just a matter of one line code.
persons.Sort(delegate(Person p1, Person p2) { return p1.Name.CompareTo(p2.Name); });
//The anonymous delegate sorts the list 'persons' according to the 'Name' property.
//Replacing 'Name' by other properties could easily make it sortable by that property.
//This could be now printed using a foreach statement
foreach (Person p in persons)
{
Console.Writeline("Name {0}, Salary {1}, Age {2}",p.Name, p.Salary, p.Age);
}
Console.Readkey();
//Comments
//The whole code is just trivia and it's only one line of code that makes it happen. YAY!!!
Initially, it looks like a whole lot of paradigm shift but later it becomes a habit and more so, an addiction.
Here is an example that shows one of the shortest ways to sort a list of Persons according to any property desired.(Class: Person, List
Lets us enter some code.
//Class Person
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public int Salary { get; set; }
public Person(string name, int age, int salary)
{
this.Name = name;
this.Age = age;
this.Salary = salary;
}
}
//Initializing a list of Persons
//This may not be static for this example.
//But we might have to make it static for a later example.
static List
public bool isEqual { get; set; }
persons.Add(new Person("chander", 26, 88000));
persons.Add(new Person("jiggi", 26, 80000));
persons.Add(new Person("puneet", 26, 90000));
persons.Add(new Person("chander", 26, 95000));
persons.Add(new Person("jiggi", 26, 10000));
persons.Add(new Person("chander", 26, 85000));
persons.Add(new Person("chander", 26, 1000000));
persons.Add(new Person("jiggi", 26, 34535));
persons.Add(new Person("chander", 26, 86000));
//Sorting according to a property of the class Person.
//It is just a matter of one line code.
persons.Sort(delegate(Person p1, Person p2) { return p1.Name.CompareTo(p2.Name); });
//The anonymous delegate sorts the list 'persons' according to the 'Name' property.
//Replacing 'Name' by other properties could easily make it sortable by that property.
//This could be now printed using a foreach statement
foreach (Person p in persons)
{
Console.Writeline("Name {0}, Salary {1}, Age {2}",p.Name, p.Salary, p.Age);
}
Console.Readkey();
//Comments
//The whole code is just trivia and it's only one line of code that makes it happen. YAY!!!
Subscribe to:
Posts (Atom)