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:

http://1470.net/api/ping
http://api.feedster.com/ping
http://api.moreover.com/ping
http://api.moreover.com/RPC2
http://api.my.yahoo.com/RPC2
http://api.my.yahoo.com/rss/ping
http://bblog.com/ping.php
http://bitacoras.net/ping
http://blog.goo.ne.jp/XMLRPC
http://blogdb.jp/xmlrpc
http://blogmatcher.com/u.php
http://blogsearch.google.com/ping/RPC2
http://bulkfeeds.net/rpc
http://coreblog.org/ping/
http://mod-pubsub.org/kn_apps/blogchatt
http://ping.amagle.com/
http://ping.bitacoras.com
http://ping.blo.gs/
http://ping.bloggers.jp/rpc/
http://ping.blogmura.jp/rpc/
http://ping.cocolog-nifty.com/xmlrpc
http://ping.exblog.jp/xmlrpc
http://ping.feedburner.com
http://ping.myblog.jp
http://ping.rootblog.com/rpc.php
http://ping.syndic8.com/xmlrpc.php
http://ping.weblogalot.com/rpc.php
http://ping.weblogs.se/
http://pingoat.com/goat/RPC2
http://rcs.datashed.net/RPC2/
http://rpc.blogbuzzmachine.com/RPC2
http://rpc.blogrolling.com/pinger/
http://rpc.icerocket.com:10080/
http://rpc.newsgator.com/
http://rpc.pingomatic.com
http://rpc.pingomatic.com/
http://rpc.technorati.com/rpc/ping
http://rpc.weblogs.com/RPC2
http://topicexchange.com/RPC2
http://trackback.bakeinu.jp/bakeping.php
http://www.a2b.cc/setloc/bp.a2b
http://www.bitacoles.net/ping.php
http://www.blogdigger.com/RPC2
http://www.blogoole.com/ping/
http://www.blogoon.net/ping/
http://www.blogpeople.net/servlet/weblogUpdates
http://www.blogroots.com/tb_populi.blog?id=1
http://www.blogshares.com/rpc.php
http://www.blogsnow.com/ping
http://www.blogstreet.com/xrbin/xmlrpc.cgi
http://www.lasermemory.com/lsrpc/
http://www.mod-pubsub.org/kn_apps/blogchatter/ping.php
http://www.mod-pubsub.org/ping.php
http://www.newsisfree.com/RPCCloud
http://www.newsisfree.com/xmlrpctest.php
http://www.popdex.com/addsite.php
http://www.snipsnap.org/RPC2
http://www.weblogues.com/RPC/
http://xmlrpc.blogg.de
http://xmlrpc.blogg.de/
http://xping.pubsub.com/ping/
Technorati Tags: ,,

::boost for C# - Umbrella

Nice project: http://umbrella.codeplex.com/. 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()))
        .Distinct().OrderBy(i=>i)
        .ToDictionary(i => i);
double total = 0.0;
var stopWatch = new Stopwatch();
//Console.WriteLine("Starting KVP");
stopWatch.Reset();
stopWatch.Start();
foreach (KeyValuePair<double, double> kvp in randomDictionaryOfDoubles)
{
    total += (kvp.Value);
}
stopWatch.Stop();
Console.WriteLine("KVP took:    {0} Total = {1}", stopWatch.Elapsed, total);
//Console.WriteLine("Starting Values");
total = 0.0;
stopWatch.Reset();
stopWatch.Start();
// To get the values alone, use the Values property.
Dictionary<double, double>.ValueCollection valueColl = randomDictionaryOfDoubles.Values;
foreach (double d in valueColl)
{
    total += d;
}
stopWatch.Stop();
Console.WriteLine("Values took: {0} Total = {1}", stopWatch.Elapsed, total);
//Console.WriteLine("Starting keys");
total = 0.0;
stopWatch.Reset();
stopWatch.Start();
// To get the keys alone, use the Keys property.
Dictionary<double, double>.KeyCollection keyColl = randomDictionaryOfDoubles.Keys;
foreach (double d in keyColl)
{
    total += d;
}
stopWatch.Stop();
Console.WriteLine("Keys took:   {0} Total = {1}", stopWatch.Elapsed, total);
Console.ReadLine();

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: http://dotnetperls.com/dictionary-lookup

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;
    Console.WriteLine(
        "Rand() was called {0} times. Same number was observed in {1} % cases",
        numElements, probabilityGetSameNumber);
}

Results:

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

http://www.evernote.com/about/home.php

http://www.sendmehome.com/

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!
Console.WriteLine(item.DoublePrice);
}
}
}



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).