Saturday, October 8, 2011

How to Block Websites without using any Software


1.) Open “Run” from the start menu (or press WinKey + r). Just copy paste the following path and hit ENTER.
notepad %windir%\system32\drivers\etc\hosts
Alternately, go to C:\Windows\System32\Drivers\Etc and find the file “hosts”. Open that file in Notepad.
2.) When this hosts file is opened in Notepad, at the end of the file you will see something like “127.0.0.1 localhost”.
3.) Under “127.0.0.1 localhost” just add another website URL that you want to block.
For Example:-
127.0.0.1 localhost
127.0.0.2 www.kalpesh.biz
127.0.0.3 www.consumer-complaints.in
4.) Make sure every time you add another website, the last digit of the address 127.0.0.x should not be the same.

5.) Save the file and exit.
So, here you go. Restart your browser if it is opened and changes will take place immediately.
The good thing is that no message, no pop ups nothing will be displayed when someone tries to open a blocked website. Your browser will just fail to open those websites without any error messages.

Thursday, August 11, 2011

FireFox : Debugging Problem in Silverlight


Solution 1:

Manually attach the visual studio debugger to “plugin-container.exe”


Solution 2:

This involves changing Firefox’s config, and really should only be done to ease silverlight debugging until a proper fix is released.
  1. Type "about:config" into FF's address bar
  2. Accept the warning (if applicable)
  3. Search for the entry "dom.ipc.plugins.enabled.npctrl.dll"
  4. Change its value from "true" to "false" (double-click)
  5. Restart the browser
Thanks MisterGoodcat for this solution  More info

Tuesday, August 9, 2011

RunTime Sum & GroupBy of DataTable using LINQ



            DataTable dt = new DataTable();
            
            dt.Columns.Add("ItemName", typeof(String));
            dt.Columns.Add("SalebyEmployee", typeof(String));
            dt.Columns.Add("ItemRate", typeof(Double));
            dt.Columns.Add("Qty", typeof(Int32));
            dt.Columns.Add("Amount", typeof(Double));

            DataRow oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 5;
            oRow["Amount"] = 50;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 15;
            oRow["Qty"] = 3;
            oRow["Amount"] = 45;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 4;
            oRow["Qty"] = 20;
            oRow["Amount"] = 80;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Chirag";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 20;
            oRow["Amount"] = 200;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Chirag";
            oRow["ItemRate"] = 15;
            oRow["Qty"] = 30;
            oRow["Amount"] = 450;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Kalpesh";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 15;
            oRow["Amount"] = 150;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 1 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 11;
            oRow["Qty"] = 50;
            oRow["Amount"] = 550;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 2 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 20;
            oRow["Amount"] = 200;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 3 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 10;
            oRow["Qty"] = 4;
            oRow["Amount"] = 40;

            oRow = dt.Rows.Add();
            oRow["ItemName"] = "Item No. 4 ";
            oRow["SalebyEmployee"] = "Rohit";
            oRow["ItemRate"] = 100;
            oRow["Qty"] = 50;
            oRow["Amount"] = 5000;


var queryResult = from item in dt.AsEnumerable()
                              group item by new { ItemSale = item.Field<String>("ItemName") + "_" + item.Field<String>("SaleByEmployee") } into grp
                              orderby grp.Key.ItemSale
                              select new
                              {
                                  ItemSaleByEmp = grp.Key.ItemSale,
                                  TotalAmount = grp.Sum(i => i.Field<Double>("Amount"))
                              };

                   DataTable dtNew  = queryResult.ToList().ToDataTable();


        public static DataTable ToDataTable(this IList data)
        {
            PropertyDescriptorCollection props =
                TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();
            for (int i = 0; i < props.Count; i++)
            {
                PropertyDescriptor prop = props[i];
                table.Columns.Add(prop.Name, prop.PropertyType);
            }
            object[] values = new object[props.Count];
            foreach (T item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = props[i].GetValue(item);
                }
                table.Rows.Add(values);
            }
            return table;
        }