среда, 7 декабря 2011 г.

Orchard is slow. I know Why

Orchard becomes very slow because of ... Advanced Menu. Yea. I profiled it and had values of page response with menu - 1.8 min without menu - 0.003 min Just try to remove it.

суббота, 5 февраля 2011 г.

small validation helper for MVC3 unobtrusive validation

// The problem: MVC 3 unobtrusive validation attach validation handlers only 
// when global validation script loaded. It use parse() method to find items to
// attach validation to. If some page content is loading after parse called, 
// then it is not parsed, as a result no validation work with it.
// Possible solution: call $.validator.unobtrusive.parse(selector) each time when add new content
// that claims validation.
// It's just a helper to call it automatically like this example:
//  $('#panel').html(newContent).initValidation();
// instead of 
//  $('#panel').html(newContent);
//  $.validator.unobtrusive.parse('#panel');
$.fn.initValidation = function () {
 return this.each(function (i,e) {
  $.validator.unobtrusive.parse(e);
 });
};

вторник, 30 ноября 2010 г.

таймлайнер

Справа вверху можно видеть кнопку "записаться". Это - виджет таймлайнера.
Я его поместил здесь для тестов.

не стесняйтесь нажимайте кликайте. Если найдете ошибку, я буду вам очень благодарен, если напишите о ней здесь.


There is button (white with red text) at the right top coner. It's timeliner widget. I'm testing it here. You can click and play also. If you find error, let me know, i will thank you.

понедельник, 23 августа 2010 г.

MongoDB. How to filter embedded array items of document.

Let we have collection

> db.A.find(); 

{ "_id" : ObjectId("4c70b753d87f000000006850"), "Name" : "Doc1", 
"Items" : [ 
        {                "x" : 1,                "y" : 1        }, 
        {                "x" : 1,                "y" : 2        }, 
        {                "x" : 3,                "y" : 3        }] } 
{ "_id" : ObjectId("4c70b888d87f000000006851"), "Name" : "Doc2", 
"Items" : [ 
        {                "x" : 3,                "y" : 1        }, 
        {                "x" : 2,                "y" : 1        }, 
        {                "x" : 1,                "y" : 3        }] } 

Let say we want to get items where A.Items.x>1.

we use server-stored function for this purposes.

var x = function() {
    var docs = db.A.find();                 // condition 1 to find. get cursor
    var d = null, i = null, ret = [];
    while (docs.hasNext())                    // get items one by one
    {
        d = docs.next().Items;                 // access embedded array here
        if (d == null) continue;
        for (var i = 0; i < d.length; i++)    // step one by one
            if (d[i].x > 1)                    // condition 2 . filter by content here
                ret.push(d[i]);                // push to output if need.
    }
    return ret;
};

And have the following output

> x()
[
        {
                "x" : 3,
                "y" : 3
        },
        {
                "x" : 3,
                "y" : 1
        },
        {
                "x" : 2,
                "y" : 1
        }
]

пятница, 20 августа 2010 г.

MongoDB. C#. How to serialize custom object.

How to serialize custom object using BSONWriter.
It's need to take into account MongoIgnore attributes that can be set on properties.

So common Json.Net or DataContractJsonSerializer is unusable here.

I'm finding answer now...

In the driver of samus it's impossible now. v0.90.0.1

mongoDB. C#. How to insert item into embedded array

Let I have classes

class X 
{ 
   Y[] Items; 
   string user; 
} 

class Y 
{ 
   string A; 
   string B; 
}

I want to add new instance of Y into collection X.Items

Other words, I want to run the following query (mongo shell syntax):

db.X.update( { user:'tim' }, { $push : { Items : { A:'a', B:'b' } } ) ;

Question: How to run it fom c# driver ?
Answer:

Document f = new Document();
f["A"] = "a";
f["B"] = "b";
Document z = new Document("Items",f);
Document x = new Document("$push", z);
Document finder = new Document("user","tim");

_mdb.GetCollection<X>().Update(x, finder, true);

понедельник, 19 апреля 2010 г.

Win 2008 Server experience

After 2 years of stable working, I have changed win2003Server to Win2008 server. And it crashed after 2 months.

So here just a small tips for reinstalling OS and environment.

1. How to disable beep
# net stop beep
# sc config beep start= disabled

2. Disabling annoying eventTracker on restart and etc. (tool that asking to enter reason "why we are going to reboot")
# gpedit.msc
Computer Configuration > Administrative Templates > System and in the right hand pane, “Display Shutdown Event Tracker” setting.



Repair some items
1. sfc /scannow /offbootdir=c:\ /offwindir=c:\windows