Sunday, 25 May 2014

Simple Math Problem

Problem Statement:

IN a shop, the cost of 4 shirts, 4 pairs of trousers and 2 hats is TK 560. The cost of 9 shirts, 9 pairs of trousers and 6 hats is tk 1290. what is the total cost of 1 shirt, 1 pair of trousers and 1 hat?

Answer: 

Statement1: 4 shirts, 4 pairs of trousers and 2 hats is TK 560.
                    let, 4s + 4p + 2h = 560.....(1)

statement2: 9s + 9p+6h = 1290 .....(2)

                  statement (1) divided by 2 and get
                   2s+2P+1h = 280....(3)                   statement (2) divided by 3 and get
                   3s+3p+2h = 430.....(4)
                   statement (4) divided by statement (3)
                   1s+1P+1h = 150.....(ANS)
                   

Wednesday, 21 May 2014

MVC JQuery AutoComplete plugin in action

In my MVC project I used JQuery auto complete plugin which had id and value. Now I'm going to show you how I had done all this.

In controller I have a method implemented like this:

public JsonResult AutocompleteSuggestions(string term)
        {
            var suggestions = unitOfWork.EmployeesRepository.Get().
                             Where(w => w.IdentificationNumber.Contains(term)).
                              Select(s => new {  value = s.EmpID, label = s.IdentificationNumber }).ToList();

               return Json(suggestions, JsonRequestBehavior.AllowGet);
        }

From View I have a textbox which I'm using for auto-complete: HTML part like this:

<input id="SearchTerm" name="searchTerm" type="text" />
<input type="hidden" id="SelectedEmpID" name="SelectedEmpID"/>

binding the textbox (id: SearchTerm) binding with JQuery like this:

<script type="text/javascript">
        $(function () {
            $("#SearchTerm").autocomplete({
                source: "/AREA_NAME/CONTROLLER_NAME/mETHOD_NAME",  
                minLength: 1,
                select: function (event, ui) {
                    $('input[name="searchTerm"]').val(ui.item.label);  // SETTING LABEL
                    $('input[name="SelectedEmpID"]').val(ui.item.value); // SETTING ID IN CURRESPONDING HIDDEN FIELD
                    return false;
                }
            });
        });

You are done!! whenever you type something in textbox it will fetch data from specified URL with that search term.
When you select item label will set in the textbox and value will be set  in the hidden field.


so, you can use the ID from that hidden field!!!

if you have any problem let me know by mail.


Monday, 19 May 2014

ASP MVC Cookie not working properly

I was working on cookie to change my website theme. My intention was to save theme name in cookie variable. It can be done by JQuery too but I was trying with .NET.

What was my problem scenario:

After setting the cookie variable I returned a View() but it didn't change the theme :( if reload the page againg then theme changed as expected. that means cookie was actually setting correctly.

my Server side code was like this -

     public ActionResult ChangeTheme(string themename = "") //hope you know how to call this ChangeTheme method.
        {
            HttpCookie cookie = new HttpCookie("Theme");
            cookie.Values["ThemeName"] = themename;
            cookie.Expires = DateTime.Now.AddDays(365);
            Response.Cookies.Add(cookie);
            return View("Index"); // this line will be changed
        }

Solution:

Index view was returning but theme was not changing first time. I changed that line -

            return RedirectToAction("Index", "Home");

Now everything is fine. theme is changing after reloading the page.

Sunday, 18 May 2014

Math related to combination

At a party, everyone shook hands with everybody else. There are 66 handshakes. How many people were there in the party?

According to the rule of combination we know nCr = n! / (n-r)! r! 

so, n(n-1)(n-2)! / (n-2)! 2! = 66 [study combination online if don't know how it works]
=> n(n-1) = 66 x 2 = 132
=> n² - n - 132 = 0
=> n² - 12n + 11n - 132 = 0 [there are thumb rule how to middle term break any big integer]
=> (n-12)(n+11)  = 0
=> n = 12, -11
n cannot be negative so ans is 12.

ASP MVC : difference between HTML.Partial and HTML.RenderPartial?

Interesting point.
I found there are little difference. But there are difference in writing.

@Html.Partial("Viewname"); // returns like a string
@{ Html.RenderPartial("Viewname"); } // returns like a method

while I'm note this learning I don't if there are more difference further.

Friday, 16 May 2014

Red squiggly (error sign) under ViewBag in MVC project

I found this error wavy sign under Viewbag. We know ViewBag object solve in runtime so this sign is not major issue in compile time but I feel bad to see any red sign under my code.

How to remove:
After googling I found a solution that adding following line to Application_Start method at global.asax page solve that issue:

ViewEngines.Engines.Add(new RazorViewEngine()); // just add this line.

Tuesday, 6 May 2014

Eclipse IntelliSense Slow???

Hi,

I am recently working on android platform. As I am a .Net developer, the first thing I didn't like in eclipse IDE is that it's intellisense is too much slow... but don't worry! You just need to tune your IDE to speed it up :)

Windows > Preference > Java > Editor > Content Assist. Now reduce the Auto Activation Delay. Apply.
Hope that's work... ;)

Monday, 5 May 2014

JQuery "contains"-method incompatible in google chrome

Scenario:

I found this problem when I was testing my MVC application in google chrome. It was working fine on Mozilla but chrome show the error that jquery "contains" is not a valid function. :(

Solution:

Ok fine. If  "contains" is not a valid function please use "indexOf" which has cross browser compatibility.

Format:

var path = somePath;

if(path.contains("xyz"))
{
   alert("hello"); // works fine in mozilla
}

now, with indexOf it should be

if(path.indexOf("xyz") > -1)
{
   alert("hello"); // cross browser compatible
}

Sunday, 4 May 2014

font-awesome.css not found



Scenario:
I faced this problem when I deployed my MVC 4 application to IIS. I had used font-awesome.css which was all fine while development perion but after deployed I always see this firebug error that font-awesome.css not found.

Why this problem?

Actually iis change the url request like something ../fonts/fontawesome-webfont.eot%3F which is not actually valid path so this 404 not found occur.

What to do?

There could be several way I found over google like configure IIS or changing to web.config. I always prefer write and solve rather than configuring wizard. Enough talking,

Just add/merge the following line to web.config and your problem going to be solved!!

<system.webServer>
    <staticContent>
      <remove fileExtension=".woff" /> <!-- In case IIS already has this mime type -->
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    </staticContent>    
  </system.webServer>

feeling confused which web.config as you've two web.config file inside your project; one at the top directory and another inside views sub-directory. Well, when someone don't specify which one then assume it's the top one :)

Unable to find the requested .NET Framework Data Provider. It may not be installed.



I faced this problem and it took me a lot of time to solve. This problem may occur for many cases - not for any particular case.

My scenario:

I deployed my application to IIS, which was an mvc 4 application and oracle 11g was in backend, and I found that error. Spent a lot of time, found many solution over google but ultimately I found the solution was easy...



Go to the deployed application pool> advanced settings > then enable 32 bit application  to TRUE.
that's it... enjoy...