Tuesday, July 08, 2008
Windows User List
string defaultDomain =
System.Environment.GetEnvironmentVariable("USERDOMAIN");
string queryString = string.Format( "select * from Win32_UserAccount where Domain = '{0}' ",defaultDomain);
SelectQuery query = new SelectQuery(queryString);
ManagementObjectSearcher searcher =
ManagementObjectSearcher(query);
ArrayList ExistingWindowsUsers = new ArrayList();
foreach (ManagementObject envVar in searcher.Get())
ExistingWindowsUsers.Add(envVar["Name"]);
Monday, June 30, 2008
F# : My First Post
I recently started looking into F# and I must say that it is highly useful when applying to Mathematical problems. I had this Euler Problem to solve which wanted me to get the value of 2^1000.
Now if i try the same in C#,I would end of up having a overflow or truncated value as C# doesn't contain any data type that can hold such a big number. However, F# supports a datatype BigInt which can hold such large values and one line of code is all that you need to write a function to calculate it.
let rec Power (x:bigint) (y:bigint) = if y=of_int 1 then x else x* Power x (y-(1|> of_int))
The above code exemplifies why F# provides more flexibility and ease when solving mathematical problems.
Wednesday, June 18, 2008
Scrollbar issue with .Net
The behavior of scrollbars in container controls like Panel in .Net does raise the question of whether it’s a bug.
Scroll down the scrollbar to the bottom and attempt to bring it to top most position using code.
panel1.VerticalScroll.Value = 0;
This would definetly make the contends of the control to be scrolled up, how ever, if you notice the scrollbar associated with the control is still in that topmost position.
The only available workaround is to assign the VerticalScroll.Value twice.
panel1.VerticalScroll.Value = 0;
panel1.VerticalScroll.Value = 0;
Its quite shocking that this bug, which was seen in .Net 2005, hasn’t been fixed in .Net 2008.
Friday, June 13, 2008
Making Anonymous Types Read-Write
Tried creating anonymous types and changing its value ?? Its strange, but Anonymous types in C# are readonly.
var v = new { FName = "aaa" , LName = "bbb" };
v.FName = "aaaa";
Above lines of code would yield following error
"Property or indexer 'AnonymousType#1.FName' cannot be assigned to -- it is read only"
But ofcourse, there is a workaround, you can use reflection to change the value of the Anonymous Method.
Type t = v.GetType();
FieldInfo fi = t.GetField( "
fi.SetValue(v, "1234");
Its true that the power of reflection cannot be ignored no matter what new features are added to .Net framework.
Saturday, June 07, 2008
Wide Band Delhi using Confidence interval
In my earlier post I talked about Wide Band Delphi. WBD stands of its own when the requirements are clear and there are no possible hindrances. But, how often do you make software in ideal conditions? As Murphy’s Law states, if something can go wrong, it will go wrong.So it’s better to make a range estimate when compared to a point estimate. These are highly useful in cases where the requirements would become gradually clear and not initially.
Here, just like WBD, estimators whose have expertise in the particular field assemble. But unlike earlier, here they provide 3 estimates for each task.
a) Best Case
b) Worst Case
c) Most likely
But we are not done yet. The next step is to assign probability to each of these cases. Let’s say we assign
a) P(Best Case) = 0.2
b) P(Most Likely) = 0.6
c) P(Worst Case) = 0.2
Next step would obviously be calculate the estimated value and of course the Standard deviation as we are mentioning the range.
Expected Value = μ = Sum ( x ) * P ( x)
Standard Deviation = σ = Worst Case * P (Worst Case ) – Best Case * P( Best Case)
You would do this for each of the estimators and take their average to find the cumulative Expected Value and Standard Deviation. We now proceed to calculate (μ-3 σ) and (μ+3 σ) values, which would in-effect, give us a better estimate than the usual WBD method.
We could also calculate (μ-6 σ) and (μ+6 σ) values or (μ-1 σ) and (μ+1 σ) values depending on whether want 68% CI or 95 CI or 99% CI. Now doesn’t this sounds more analytical than the default Wide Band Delphi method ??