Thursday, August 26, 2010

16 years of survival in extreme conditions - in 43 sentences

Below is my (partial) translation of a short story written by Varlam Tihonovich Shalamov who was prisoner of Gulag camps from 1937 till 1953.
It’s called “What I have seen and understood in jail”.
16 years of survival in extreme conditions in 43 sentences…

What I have seen and understood in jail:
1. Extreme fragility of human culture, civilization. Man turns into beast after three weeks of hard work, coldness, hunger and beating.
2. The main way of spirit defilement is coldness – people enjailed in camps of Asia hold for longer – it was warmer there.
3. I understood that friendship and fellowship never starts in difficult, really difficult conditions – when your life is a stake. Friendship may start in conditions that are difficult but feasible.
4. I understood that emotion that man keeps for last is the emotion of hate. It’s enough flesh on a hunger man to keep only his hate. A hunger man is indifferent to the else.

7. I understood that humans raised the humankind because human is more strong and tenacious than any animal – horse can’t sustain hard work in conditions of Far North, human – does.
8. The only group of people that were behaving a bit like humans were religious, mostly sectarian and camisters.
9. Former militaries and politicians are broken first.
10. I’ve seen what a sound argument an ordinary slap can be.
11. Mob differentiates leaders by their ardor and strength of beating.
12. Beating is an irresistible argument.

16. I understood that you may live only by hate.
17. I understood that you may live by apathy.
18. In extreme conditions – man not motivated by his hopes (there is no hopes), not by his will but rather by animal instinct, instinct of survival similar to one that exist in tree, animal or a stone.

23. I’ve seen that women more fair and selfless than man. There was not a single case when man followed his wife to the North, but the opposite was common.

31. You should differentiate people not as ‘good’ and ‘bad’, but as coward and brave. 95% are coward and ready to do any villainy in case of even minor danger.
32. I’m convinced that every single hour you’ve spent in camp adds to your defilement.

36. I learned to plan one day ahead only
37. I understood that thieves are not humans.


Sunday, May 09, 2010

Some photos from Think Next 2010

Some photos from Think Next 2010:

Portable sonar device, enable to show people locations through walls:

Big touch-screen device:

Technorati Tags:

Wednesday, March 10, 2010

Solution for "Impossible to log SQL 2008 performance counters under Windows 2008 64 bit?"

Alex Pinsker: Impossible to log SQL 2008 performance counters under Windows 2008 64 bit?

Here is solution, found by our DBA:
1. Open regedit.exe
2. Find the key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSSQLSERVER\Performance"
3. Find the value named "Performance counters disabled"
4. Ensure, that its value is NOT "4" or "1". If it is - enforce it to "0"
5. Notice file name in value of "PerfIniFile" key and copy it to clipboard
6. Close the regedit
7. Open cmd and go to Binn folder of Sql Server installation. Usually in "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn"
8. Run the following commands:
8.1 unlodctr mssqlserver
8.2 lodctr [clipboard filename from (5.) above]
8.2.1 lodctr [clipboard filename from (.5) above]
(this only needs for sure, that counters are installed - there will be a message notifying on that)
8.3 lodctr /T:mssqlserver
9. Restart the server
10. Use perfmon to ensure, that counters for Sql Server reappeared

Monday, March 01, 2010

blog ping list

Long blog ping list - compiled from few sources:
Technorati Tags: ,,

::boost for C# - Umbrella

Nice project: Provides many components similar to the ::boost basics (like bind()...) - for C#.

Technorati Tags: ,,

Wednesday, February 24, 2010

C# - the fastest way to iterate over dictionary

Having a big dictionary, say 1M of <double,double> samples – what is the fastest way to iterate over it?
Comparing 3 options (iterate over KeyValuePair in the dictionary, iterate over Values collection and iterate over Keys collection) – below is code and timing comparison results.
// Of course if you iterating over Keys collection and accessing the value by key – it would be the slowest case.

// Create sample dictionary
var random = new Random();
var randomDictionaryOfDoubles =
    Enumerable.Repeat(0, 1000000).Select(
        i => Convert.ToDouble(random.Next()))
        .ToDictionary(i => i);
double total = 0.0;
var stopWatch = new Stopwatch();
//Console.WriteLine("Starting KVP");
foreach (KeyValuePair<double, double> kvp in randomDictionaryOfDoubles)
    total += (kvp.Value);
Console.WriteLine("KVP took:    {0} Total = {1}", stopWatch.Elapsed, total);
//Console.WriteLine("Starting Values");
total = 0.0;
// To get the values alone, use the Values property.
Dictionary<double, double>.ValueCollection valueColl = randomDictionaryOfDoubles.Values;
foreach (double d in valueColl)
    total += d;
Console.WriteLine("Values took: {0} Total = {1}", stopWatch.Elapsed, total);
//Console.WriteLine("Starting keys");
total = 0.0;
// To get the keys alone, use the Keys property.
Dictionary<double, double>.KeyCollection keyColl = randomDictionaryOfDoubles.Keys;
foreach (double d in keyColl)
    total += d;
Console.WriteLine("Keys took:   {0} Total = {1}", stopWatch.Elapsed, total);

Here are results:

Method Time spent in iteration
Over key-value pairs 00:00:00.1854684
Over Values collection 00:00:00.1221380
Over Keys collection 00:00:00.0955291

Related article:

Technorati Теги: ,,

Tuesday, February 23, 2010

Copy code as HTML from VS 2008 into Live Writer

The best option for me is this:

Technorati Теги: ,

Probability to observe the same number calling Random.Rand()

It’s not an efficient query. Just a game…
for (int j = 1; j < 8; j++)
    int numElements = (int)Math.Pow(10, j);
    var numersList = Enumerable.Repeat(0, numElements).Select(
        i => Convert.ToDouble(random.Next()))
        .Distinct().OrderBy(i => i);
    double probabilityGetSameNumber = 1 - (double) numersList.Count()/numElements;
        "Rand() was called {0} times. Same number was observed in {1} % cases",
        numElements, probabilityGetSameNumber);


Num of Rand() calls Same number observed in % of cases Cases count
10 0 0
100 0 0
1000 0 0
10000 0 0
100000 0.00002999999999997 3
1000000 0.00024100000000004 241
10000000 0.00234760000000001 23476


Technorati Теги: ,,,

Random clicks

Wednesday, February 17, 2010

Impossible to log SQL 2008 performance counters under Windows 2008 64 bit?

Here is some strange problem I’ve experienced (right now it seems to me as a bug in Windows 2008 64 bit):

I have an environment with Windows 2008 64 bit and SQL Enterprise 64 bit.

To begin with - it's possible to see SQL-related performance counters values only in perfmon opened from SysWow64 (i.e. 32 bit) - they are not present in 64-bit perfmon.

Now, if I open perfmon (32 bit) and add any SQL counters (e.g. SQL Latches) to the "Performance Monitor" section I can see that those values are updated "live" in perfmon graphs.

Yet, if I create a new Data Collector Set for the same values under Data Collector Sets -> User Defined - the values for SQL counters are not being stored in the created log file. If I add some other counters (e.g. Processor) they ARE saved.

Seems that this is some sort of bug/problem related to 64 bit…

There are some clues on this problem in two following articles:

but both do not help (for the first one – there is no such service anymore in Windows 2008…

Many, many pretties... piled high beyond the sky

Yes, it could be a lot more small rectangles in it, I know ;o)
(But you can't look too far - when you look too far - it looks back).
Strong Server
Technorati Tags: ,

Thursday, January 21, 2010

LINQ extension method to Capitalize string

LINQ extension method to Capitalize first letter of each word in a sentence:

public static string Capitalize(this string s)
    return s.ToCharArray().Aggregate(String.Empty,
      (currentWord, nextWord) =>
        currentWord.Length == 0 && nextWord != ' ' ? nextWord.ToString().ToUpper() : (
          currentWord.EndsWith(" ") ? currentWord + nextWord.ToString().ToUpper() :
            currentWord + nextWord.ToString()

Thursday, January 14, 2010

Return collection of anonymous type from method in LINQ

Technorati Tags:
Let’s say you have some method that execute a LINQ query over collection and constructs a collection of (new) anonymous type as result. Here is how you can return it and use it below the scope of the method:
public class Program
public static IEnumerable<T> GetExampleCollection<T>(T type)
// generate some random collection simulating source data
var random = new Random();
var collection =
Enumerable.Repeat(0, 100).Select(
i => new { ClientId = random.Next(), OrderId = random.Next(), Price = random.NextDouble() });

// run some linq query over it
var queryOverCollection = from item in collection
where item.ClientId % 2 == 0
select new { DoublePrice = item.Price * 2.0 };
IQueryable v = (from item in collection
where item.ClientId % 2 == 0
select new { DoublePrice = item.Price * 2.0 }).AsQueryable();

return queryOverCollection as IEnumerable<T>;

static void Main(string[] args)
// bring collection of anonymous type items from a method!
var v = GetExampleCollection(new { DoublePrice = new double() });
foreach (var item in v)
// ... and use it!

Note, that anonymous type is resolved on the assemble level, so you can’t reference it in another assembly.

Wednesday, January 13, 2010

SQL connection string application name

Add “Application Name=My Application Name” to connection string to differentiate your connections (e.g. in SQL Profiler).
(it’s a self reminder post).