Wednesday, December 12, 2012

What are Closures in Javascript


Closures in javascript considered as an advanced feature. Closures is little tricky to understand. So understanding closure is an important thing.
Let’s look at a simple example

function start() {
  var text = "Hello World";
  function getText() {
    alert(text);
  }
  getText();
}
start ();

this is a very simple straight forward example. start() defines a local variable “text and a function getText(). And then it calls the getText function which returns the variable “text” which is not local to function getText but which is accessible from the outer scope. This is functional scoping.  
Consider the following example

function start() {
  var text = " Hello World ";
  function getText() {
    alert(text);
  }
  return getText;
}

var myFunc = start();
myFunc();

Basically local variables within a function exist only within the functions execution period.  But since myFunc() outputs an alert, it seems that it still has the access to the variable “text”.  The reason is the variable myFunc() has become a closure.

A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).


Friday, November 30, 2012

URL rewriting

URL rewriting is a software running on web application framework. This software is used to generate more user friendly URL rather than a computer generated URL which are sometimes unreadable. 

Websites with dynamic content are often generated with URLs with computer generated content with query string parameters. URL rewriting can be applied in these situations to generate more readable URL. 

Ex: 
http://www.example.com/Content/Posts.php?Yr=2012&Mon=11&Day=18

this URL can be rewritten as 
http://www.example.com/Content/2012/11/18/article1

Benefits of URL Rewriting

  • More cleaner user friendly URLs
  • Query strings can be used to compromise information about the websites. URL rewriting minimizes this risk
  • Prevent inline linking
Web Frameworks
Almost all the popular web frameworks supports URL rewriting. Following are some of them.
  • Apache HTTP Server
  • IIS
  • Ruby on Rails
  • Java EE
  • Django
  • Codeigniter

Following are some of useful links for URL Rewriting

Thursday, November 29, 2012

Get Windows User ASP.NET


When developing ASP.NET applications, there might be situations where you need to know who is the currently logged in Windows user in to do things like authorization, authentication etc. These might b e useful when you are developing applications for the internal use within an organization. 

Luckily ASP.NET has few options built in to get the currently logged in user. You can use one of the following code snippet to get the current user.

1.

string user = HttpContext.Current.User.Identity.Name;


2. 

string user = Thread.CurrentPrincipal.Identity.Name;

2nd opiton only applies when you have specified in your web applications config file that the authentication mode is windows 

This is pretty straight forward and simple. 



Wednesday, September 12, 2012

Web Designing Guidelines Tips and Tricks

Web designing is a tricky business. It's a big market where lot of people day by day entering in to the profession. To survive the designer has to unique in what he or she designs. 

There are thousands of articles focusing on web designing therefore it is hard to find good set of rules to follow to be a great designer. Following are some of the articles which I find useful for web designing. 





Tuesday, September 4, 2012

User Input Handling in Windows Phone 7

In this tutorial we'll look at how to handle user interaction with Windows Phone. We'll use a Textbox a Button and a TextBlock to do this basic tutorial. This is very similar to the coding you do with Win forms or WPF. Difference is this is Windows Phone. 

1. First open Visual Studio Express 2010 for Windows Phone. Create a new project of the type "Windows Phone Application" . Give any name you like and select a location to be saved. Then the project will be created.

2. From the toolbox on left hand side. Drag and drop a TextBlock and a Textbox and place it in the Design view. Note that TextBlocks acts as the Labels you use in WPF. Remove the text in the Textbox from the properties window and replace the text of the TextBlock as "Enter your name"

3. Also drag and drop a Button and another TextBlock and place it in the Design view. Rename the content of the Button from "Button" to "Display". Remove the text in the TextBlock2. Finally the design view should appear similar to this (figure 1)

4. What we will do in this application is we'll prompt the user to enter his name and press display. Then a message will be displayed on the textBlock added in bottom. 

5. To do the coding for the button click event, double click the Display(button1) button. The event will be created in the code behind and you will be entered to the button1_Click method. 

6. Add the following code in the button1_Click event which will get the input from the textbox and display in the label.


Nothing really to explain. This will simply get the input from the textbox and display it in the textBlock.

7. Debug and run the application in the emulator. Try enter a name and pressing display.


Tuesday, August 7, 2012

Buy and Sell Online Sri Lanka - Ikman.lk




Buy and Sell websites are not new to Sri Lankan web community. Currently there is many local websites in the internet offering these services. automart.lk, kapruka.com  can be named as few of the sites which offer these services. 

But one thing to notice about these sites is that most of these sites are designed for specific category. for example automart.lk is designed to buy and sell vehicles in Sri Lanka. lankapropertyweb, bhoomi are sites designed to purchase land and houses in Sri Lanka. But there was no popular site designed to address all these needs at a one place.

But there is a newcomer to the internet which addresses all these buying and selling needs at a one place. If you've been watching cricket matches in recent through CSN you would've definitely have heard of this site. ikman.lk  is the latest new comer to the Sri Lankan market. 

Ikman.lk offers free classified ads in Sri Lanka. There are other websites such as apekade.com, hitlanka.comandaberaya.com which offers the same service but ikman.lk is unique on it's way. 

With compared to other websites, Ikman.lk offers the best user experience to the end user. It uses AJAX, JQuery for the maximum and it offers only the content expected by the customer no popups or unwanted content. It also categorizes the ads in a very useful way so that the user won't run in to a add he didn't intend to look for. Based on the sellers authorization ikman also posts the telephone number or a email so that buyer can directly contact the seller for there needs.

Ikman is a site to visit to. Experience the ebay in Sri Lanka.

Saturday, June 23, 2012

Kinect SkeletonFrame

SkeletonFrame is a sealed (cannot be inherited) class in Microsoft.Kinect namespace. SkeletonFrame class contains skeleton frame returned by the Kinect API. 

Friday, June 22, 2012

When to use Static Classes in C#

Static classes and static class members are used to create functions which can be accessed without creating an instance of it. Static class members can be used to separate data and behavior that is independent. 


Some of the features of the static classes are, 

  • Only contains static members
  • Cannot be instantiated 
  • They are sealed
Static classes cannot be created using new keyword. Static classes are loaded by the .NET CLR when the program containing the class is loaded. 


Monday, June 18, 2012

Track MouseWheel in XNA

Photo courtesy : ehow.com 
Sometimes in your XNA Application you might need to track the mousewheel event to do some task. Luckily XNA has inbuilt function for this. MouseState class has a property called ScrollWheelValue which returns the current MouseWheel value. 


As the documentation specifies,
ScrollWheelValue : Gets the cumulative mouse scroll wheel value since the game was started.


Unlike Winforms, in XNA ScrollWheelValue reports the total scroll wheel value. To get the wheel movement you must track and compare with the previous ScrollWheelValue. 


MouseState mouseState = Mouse.GetState();

float ScrollWheelChange =mouseState.ScrollWheelValue;

Saturday, March 17, 2012

Kinect for Cricket - A Totally New User Experience

Developed using Microsoft technology stack, Kinect for Cricket promises to give users a totally new user experience unlike any other. Kinect for Cricket will mainly consist of voice commands and hand gestures and body movements. 


Kinect for Cricket is mainly based on state of the art Kinect sensor technology and XNA framework. For voice recognition it will use Microsoft Speech SDK. It will get the support of many other Microsoft technologies to give the maximum benefit of technologies. 


Kinect for Cricket will be developed by a 4 member group as their final year project at SLIIT, Sri Lanka. The product will teach you how to learn basics of Cricketing shots. It will also support you in analyzing cricketing shots. 


Await more details on Kinect for Cricket...

Thursday, March 15, 2012

Kinect for Cricket

Kinect for Cricket is the Kinect based cricket learning and player analyzing tool we will be introducing in the coming few months. It will feature 3D Model Tracking and drawing, Hand gesture commands, voice commands and many amazing features.


Stay tuned for our blog for more information