Wednesday, February 13, 2013

LightSwitch HTML 5

LightSwitch is a rapid application development (RAD) tool created by Microsoft. In its original version, released in 2010, any applications you created with it ran under the Silverlight runtime. But with the advent of HTML5, Microsoft decided to step LightSwitch up a notch and give it the ability to create HTML5 applications without needing Silverlight. That opens up a lot of doors for developers. LightSwitch is incredibly easy to use, and the resulting applications have a definite Windows 8 look to them. The resulting apps also perform nicely on mobile browsers. The apps you develop can connect to several different types of databases, and from there, you can quickly create screens that are easily navigable. Your users can then browse the data and add new data using simple forms. Under the hood, you can even drop down to the code level and write C# code to enhance the app even more. What follows are screenshots of the development tool itself as well as screens of a running app.

Tuesday, December 14, 2010

New Tab in IE 8.0 not working

Last week I faced a problem that new tab is not working in IE 8.0
The Resolution for this is:

Disabling the Add-ons:

1. click Tools, Manage Add-ons
2. Select Enable or Disable Add-ons option
3. Disable all the add-ons that are under “currently being used by Internet Explorer” option.

To disable the add-on, click each add-on and click disable radio button at the bottom.

4. click OK and restart Internet Explorer when prompted


Hope this should work out.

Tuesday, November 17, 2009

From village to google on wheel chair.... truly inspiring...

'God has always been planning things for me'






Naga Naresh Karutura has just passed out of IIT Madras in Computer Science and has joined Google in Bangalore.

You may ask, what's so special about this 21-year-old when there are hundreds of students passing out from various IITs and joining big companies like Google?

Naresh is special. His parents are illiterate. He has no legs and moves around in his powered wheel chair. (In fact, when I could not locate his lab, he told me over the mobile phone, 'I will come and pick you up'. And in no time, he was there to guide me)

Ever smiling, optimistic and full of spirit; that is Naresh. He says, "God has always been planning things for me. That is why I feel I am lucky."

Read why Naresh feels he is lucky.

Childhood in a village
I spent the first seven years of my life in Teeparru, a small village in Andhra Pradesh, on the banks of the river Godavari. My father Prasad was a lorry driver and my mother Kumari, a house wife. Though they were illiterate, my parents instilled in me and my elder sister (Sirisha) the importance of studying.

Looking back, one thing that surprises me now is the way my father taught me when I was in the 1st and 2nd standards. My father would ask me questions from the text book, and I would answer them. At that time, I didn't know he could not read or write but to make me happy, he helped me in my studies!

Another memory that doesn't go away is the floods in the village and how I was carried on top of a buffalo by my uncle. I also remember plucking fruits from a tree that was full of thorns.

I used to be very naughty, running around and playing all the time with my friends. I used to get a lot of scolding for disturbing the elders who slept in the afternoon. The moment they started scolding, I would run away to the fields!

I also remember finishing my school work fast in class and sleeping on the teacher's lap!

January 11, 1993, the fateful day
On the January 11, 1993 when we had the sankranti holidays, my mother took my sister and me to a nearby village for a family function. From there we were to go with our grandmother to our native place. But my grandmother did not come there. As there were no buses that day, my mother took a lift in my father's friend's lorry. As there were many people in the lorry, he made me sit next to him, close to the door.

It was my fault; I fiddled with the door latch and it opened wide throwing me out. As I fell, my legs got cut by the iron rods protruding from the lorry. Nothing happened to me except scratches on my legs.

The accident had happened just in front of a big private hospital but they refused to treat me saying it was an accident case. Then a police constable who was passing by took us to a government hospital.

First I underwent an operation as my small intestine got twisted. The doctors also bandaged my legs. I was there for a week. When the doctors found that gangrene had developed and it had reached up to my knees, they asked my father to take me to a district hospital. There, the doctors scolded my parents a lot for neglecting the wounds and allowing the gangrene to develop. But what could my ignorant parents do?

In no time, both my legs were amputated up to the hips.

I remember waking up and asking my mother, where are my legs? I also remember that my mother cried when I asked the question. I was in the hospital for three months.

Life without legs
I don't think my life changed dramatically after I lost both my legs. Because all at home were doting on me, I was enjoying all the attention rather than pitying myself. I was happy that I got a lot of fruits and biscuits.

'I never wallowed in self-pity'




The day I reached my village, my house was flooded with curious people; all of them wanted to know how a boy without legs looked. But I was not bothered; I was happy to see so many of them coming to see me, especially my friends!

All my friends saw to it that I was part of all the games they played; they carried me everywhere.

God's hand
I believe in God. I believe in destiny. I feel he plans everything for you. If not for the accident, we would not have moved from the village to Tanuku, a town. There I joined a missionary school, and my father built a house next to the school. Till the tenth standard, I studied in that school.

If I had continued in Teeparu, I may not have studied after the 10th. I may have started working as a farmer or someone like that after my studies. I am sure God had other plans for me.

My sister, my friend
When the school was about to reopen, my parents moved from Teeparu to Tanuku, a town, and admitted both of us in a Missionary school. They decided to put my sister also in the same class though she is two years older. They thought she could take care of me if both of us were in the same class. My sister never complained.

She would be there for everything. Many of my friends used to tell me, you are so lucky to have such a loving sister. There are many who do not care for their siblings.

She carried me in the school for a few years and after a while, my friends took over the task. When I got the tricycle, my sister used to push me around in the school.

My life, I would say, was normal, as everyone treated me like a normal kid. I never wallowed in self-pity. I was a happy boy and competed with others to be on top and the others also looked at me as a competitor.

Inspiration
I was inspired by two people when in school; my Maths teacher Pramod Lal who encouraged me to participate in various local talent tests, and a brilliant boy called Chowdhary, who was my senior.

When I came to know that he had joined Gowtham Junior College to prepare for IIT-JEE, it became my dream too. I was school first in 10th scoring 542/600.

Because I topped in the state exams, Gowtham Junior College waived the fee for me. Pramod Sir's recommendation also helped. The fee was around Rs 50,000 per year, which my parents could never afford.

Moving to a residential school
Living in a residential school was a big change for me because till then my life centred around home and school and I had my parents and sister to take care of all my needs. It was the first time that I was interacting with society. It took one year for me to adjust to the new life.

There, my inspiration was a boy called K K S Bhaskar who was in the top 10 in IIT-JEE exams. He used to come to our school to encourage us. Though my parents didn't know anything about Gowtham Junior School or IIT, they always saw to it that I was encouraged in whatever I wanted to do. If the results were good, they would praise me to the skies and if bad, they would try to see something good in that. They did not want me to feel bad.

They are such wonderful supportive parents.

Life at IIT- Madras
Though my overall rank in the IIT-JEE was not that great (992), I was 4th in the physically handicapped category. So, I joined IIT, Madras to study Computer Science.

Here, my role model was Karthik who was also my senior in school. I looked up to him during my years at IIT- Madras.

He had asked for attached bathrooms for those with special needs before I came here itself. So, when I came here, the room had attached bath. He used to help me and guide me a lot when I was here.

I evolved as a person in these four years, both academically and personally. It has been a great experience studying here. The people I was interacting with were so brilliant that I felt privileged to sit along with them in the class. Just by speaking to my lab mates, I gained a lot.

'There are more good people in society than bad ones'






Words are inadequate to express my gratitude to Prof Pandurangan and all my lab mates; all were simply great. I was sent to Boston along with four others for our internship by Prof Pandurangan. It was a great experience.

Joining Google R&D
I did not want to pursue PhD as I wanted my parents to take rest now.

Morgan Stanley selected me first but I preferred Google because I wanted to work in pure computer science, algorithms and game theory.

I am lucky
Do you know why I say I am lucky?

I get help from total strangers without me asking for it. Once after my second year at IIT, I with some of my friends was travelling in a train for a conference. We met a kind gentleman called Sundar in the train, and he has been taking care of my hostel fees from then on.

I have to mention about Jaipur foot. I had Jaipur foot when I was in 3rd standard. After two years, I stopped using them. As I had almost no stems on my legs, it was very tough to tie them to the body. I found walking with Jaipur foot very, very slow. Sitting also was a problem. I found my tricycle faster because I am one guy who wants to do things faster.

One great thing about the hospital is, they don't think their role ends by just fixing the Jaipur foot; they arrange for livelihood for all. They asked me what help I needed from them. I told them at that time, if I got into an IIT, I needed financial help from them. So, from the day I joined IIT, Madras, my fees were taken care of by them. So, my education at the IIT was never a burden on my parents and they could take care of my sister's Nursing studies.

Surprise awaited me at IIT
After my first year, when I went home, two things happened here at the Institute without my knowledge.

I got a letter from my department that they had arranged a lift and ramps at the department for me. It also said that if I came a bit early and checked whether it met with my requirements, it would be good.

Second surprise was, the Dean, Prof Idichandy and the Students General Secretary, Prasad had located a place that sold powered wheel chairs. The cost was Rs 55,000. What they did was, they did not buy the wheel chair; they gave me the money so that the wheel chair belonged to me and not the institute.

My life changed after that. I felt free and independent.

That's why I say I am lucky. God has planned things for me and takes care of me at every step.

The world is full of good people
I also feel if you are motivated and show some initiative, people around you will always help you. I also feel there are more good people in society than bad ones. I want all those who read this to feel that if Naresh can achieve something in life, you can too.

Tuesday, June 9, 2009

Multithreading

Threading allows a program to execute two or more execution paths in parallel. Threading does not require a multi-processor multi-core processor to run.

Hear the simple program do's that

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MultiThreading
{
class Program
{
static void Main(string[] args)
{
ThreadStart thread = new ThreadStart(NestedThread);
Thread th = new Thread(thread);
th.Start();
for (int i = 0; i <= 100; i++)
{
Console.WriteLine("Main Thread : " + i.ToString());
Thread.Sleep(300);
}
}
protected static void NestedThread()
{
for(int i =0;i<=200;i++)
{
Console.WriteLine("Parallel Thread : " + i.ToString());
Thread.Sleep(200);
}
}
}
}

Friday, December 26, 2008

Password Encryption using SHA256+SALT

Heare I created the C# method for to return the encrypted password where I used SHA256 + SALT

public static string sha256encrypt(string phrase,string UserName)
{
string salt = CreateSalt(UserName);
string saltAndPwd = String.Concat(phrase, salt);
UTF8Encoding encoder = new UTF8Encoding();
SHA256Managed sha256hasher = new SHA256Managed();
byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(saltAndPwd));
string hashedPwd = String.Concat(byteArrayToString(hashedDataBytes), salt);
return hashedPwd;
}

public static string byteArrayToString(byte[] inputArray)
{
StringBuilder output = new StringBuilder("");
for (int i = 0; i < inputArray.Length; i++)
{
output.Append(inputArray[i].ToString("X2"));
}
return output.ToString();
}

Heare I taken Username, converted to a byte array, then XORed the bytes together. I took the xored result as the seed to my random number generator. Then I used the result of the PRG as my salt.

private static string CreateSalt(string UserName)
{
string username = UserName;
byte[] userBytes; string salt;
userBytes = ASCIIEncoding.ASCII.GetBytes(username);
long XORED = 0x00; foreach (int x in userBytes)
XORED = XORED ^ x;
Random rand = new Random(Convert.ToInt32(XORED));
salt = rand.Next().ToString();
salt += rand.Next().ToString();
salt += rand.Next().ToString();
salt += rand.Next().ToString();
return salt;
}

Hope it helps!!!!

Tuesday, May 20, 2008

Definitions

Application - refers to an assembly that has an entry point (§10.1). When an application is run, a new application domain is created. Several different instantiations of an application may exist on the same machine at the same time, and each has its own application domain.

Application domain - an entity that enables application isolation by acting as a container for application state. An application domain acts as a container and boundary for the types defined in the application and the class libraries it uses. Types loaded into one application domain are distinct from the same type loaded into another application domain, and instances of objects are not directly shared between application domains. For instance, each application domain has its own copy of static variables for these types, and a static constructor for a type is run at most once per application domain. Implementations are free to provide implementation-specific policy or mechanisms for the creation and destruction of application domains.

Argument - an expression in the comma-separated list bounded by the parentheses in a method or instance constructor call expression. It is also known as an actual argument.


Assembly - refers to one or more files that are output by the compiler as a result of program compilation. An assembly is a configured set of loadable code modules and other resources that together implement a unit of functionality. An assembly may contain types, the executable code used to implement these types, and references to other assemblies. The physical representation of an assembly is not defined by this specification. Essentially, an assembly is the output of the compiler.


Behavior, undefined - behavior, upon use of a nonportable or erroneous construct or of erroneous data, for which this International Standard imposes no requirements. [Possible handling of undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message)].

Class library - refers to an assembly that can be used by other assemblies. Use of a class library does not cause the creation of a new application domain. Instead, a class library is loaded into the application domain that uses it. For instance, when an application uses a class library, that class library is loaded into the application domain for that application. If an application uses a class library A that itself uses a classlibrary B, then both A and B are loaded into the application domain for the application.

Diagnostic message - a message belonging to an implementation-defined subset of the implementations output messages.

Namespace - a logical organizational system that provides a way of presenting program elements that are exposed to other programs.

Parameter - a variable declared as part of a method, instance constructor, or indexer definition, which acquires a value on entry to that method. It is also known as formal parameter.
Program . refers to one or more source files that are presented to the compiler. Essentially, a program is the input to the compiler.

Unsafe code - code that is permitted to perform such lower-level operations as declaring and operating on pointers, performing conversions between pointers and integral types, and taking the address of variables. Such operations provide functionality such as permitting interfacing with the underlying operating system, accessing a memory-mapped device, or implementing a time-critical algorithm.

Wednesday, May 14, 2008

10 Tips to Improve LINQ to SQL Application Performance

1 – Turn off ObjectTrackingEnabled Property of Data Context If Not Necessary
If you are trying only to retrieve data as read only, and not modifying anything, you don’t need object tracking. So turn it off using it like in the example below:using (NorthwindDataContext context = new NorthwindDataContext())
{
context.ObjectTrackingEnabled = false;
}



This will allow you to turn off the unnecessary identity management of the objects – hence Data Context will not have to store them because it will be sure that there will be no change statements to generate.
2 – Do NOT Dump All Your DB Objects into One Single DataContext
DataContext represents a single unit of work, not all your database. If you have several database objects that are not connected, or they are not used at all (log tables, objects used by batch processes,etc..). These objects just unnecessarily consume space in the memory hence increasing the identity management and object tracking costs in CUD engine of the DataContext.
Instead think of separating your workspace into several DataContexts where each one represents a single unit of work associated with it. You can still configure them to use the same connection via its constructors to not to loose the benefit of connection pooling.
3 – Use CompiledQuery Wherever Needed
When creating and executing your query, there are several steps for generating the appropriate SQL from the expression, just to name some important of them:
Create expression tree
Convert it to SQL
Run the query
Retrieve the data
Convert it to the objects
As you may notice, when you are using the same query over and over, hence first and second steps are just wasting time. This is where this tiny class in System.Data.Linq namespace achieves a lot. With CompiledQuery, you compile your query once and store it somewhere for later usage. This is achieved by static CompiledQuery.Compile method.
Below is a Code Snippet for an example usage:Func> func =
CompiledQuery.Compile>
((NorthwindDataContext context) => context.Categories.
Where(cat => cat.Products.Count > 5));



And now, “func” is my compiled query. It will only be compiled once when it is first run. We can now store it in a static utility class as follows :///
/// Utility class to store compiled queries
///

public static class QueriesUtility
{
///
/// Gets the query that returns categories with more than five products.
///

/// The query containing categories with more than five products.
public static Func>
GetCategoriesWithMoreThanFiveProducts
{
get
{
Func> func =
CompiledQuery.Compile>
((NorthwindDataContext context) => context.Categories.
Where(cat => cat.Products.Count > 5));
return func;
}
}
}



And we can use this compiled query (since it is now a nothing but a strongly typed function for us) very easily as follows:using (NorthwindDataContext context = new NorthwindDataContext())
{
QueriesUtility.GetCategoriesWithMoreThanFiveProducts(context);
}



Storing and using it in this way also reduces the cost of doing a virtual call that’s done each time you access the collection – actually it is decreased to 1 call. If you don’t call the query don’t worry about compilation too, since it will be compiled whenever the query is first executed.
4 – Filter Data Down to What You Need Using DataLoadOptions.AssociateWith
When we retrieve data with Load or LoadWith we are assuming that we want to retrieve all the associated data those are bound with the primary key (and object id). But in most cases we likely need additional filtering to this. Here is where DataLoadOptions.AssociateWith generic method comes very handy. This method takes the criteria to load the data as a parameter and applies it to the query – so you get only the data that you need.
The following code below associates and retrieves the categories only with continuing products:using (NorthwindDataContext context = new NorthwindDataContext())
{
DataLoadOptions options = new DataLoadOptions();
options.AssociateWith(cat=> cat.Products.Where(prod => !prod.Discontinued));
context.LoadOptions = options;
}



5 – Turn Optimistic Concurrency Off Unless You Need It
LINQ to SQL comes with out of the box Optimistic Concurrency support with SQL timestamp columns which are mapped to Binary type. You can turn this feature on and off in both mapping file and attributes for the properties. If your application can afford running on “last update wins” basis, then doing an extra update check is just a waste.
UpdateCheck.Never is used to turn optimistic concurrency off in LINQ to SQL.
Here is an example of turning optimistic concurrency off implemented as attribute level mapping:[Column(Storage=“_Description”, DbType=“NText”,
UpdateCheck=UpdateCheck.Never)]
public string Description
{
get
{
return this._Description;
}
set
{
if ((this._Description != value))
{
this.OnDescriptionChanging(value);
this.SendPropertyChanging();
this._Description = value;
this.SendPropertyChanged(“Description”);
this.OnDescriptionChanged();
}
}
}



6 – Constantly Monitor Queries Generated by the DataContext and Analyze the Data You Retrieve
As your query is generated on the fly, there is this possibility that you may not be aware of additional columns or extra data that is retrieved behind the scenes. Use Data Context’s Log property to be able to see what SQL are being run by the Data Context. An example is as follows:using (NorthwindDataContext context = new NorthwindDataContext())
{
context.Log = Console.Out;
}



Using this snippet while debugging you can see the generated SQL statements in the Output Window in Visual Studio and spot performance leaks by analyzing them. Don’t forget to comment that line out for production systems as it may create a bit of an overhead. (Wouldn’t it be great if this was configurable in the config file?)
To see your DLINQ expressions in a SQL statement manner one can use SQL Query Visualizer which needs to be installed separately from Visual Studio 2008.
7 – Avoid Unnecessary Attaches to Tables in the Context

Since Object Tracking is a great mechanism, nothing comes for free. When you Attach an object to your context, you mean that this object was disconnected for a while and now you now want to get it back in the game. DataContext then marks it as an object that potentially will change - and this is just fine when you really intent to do that.
But there might be some circumstances that aren’t very obvious, and may lead you to attach objects that arent changed. One of such cases is doing an AttachAll for collections and not checking if the object is changed or not. For a better performance, you should check that if you are attaching ONLY the objects in the collection those are changed.
I will provide a sample code for this soon.
8 – Be Careful of Entity Identity Management Overhead
During working with a non-read only context, the objects are still being tracked – so be aware that non intuitive scenarios this can cause while you proceed. Consider the following DLINQ code:using (NorthwindDataContext context = new NorthwindDataContext())
{
var a = from c in context.Categories
select c;
}



Very plain, basic DLINQ isn’t it? That’s true; there doesn’t seem any bad thing in the above code. Now let’s see the code below:using (NorthwindDataContext context = new NorthwindDataContext())
{
var a = from c in context.Categories
select new Category
{
CategoryID = c.CategoryID,
CategoryName = c.CategoryName,
Description = c.Description
};
}



The intuition is to expect that the second query will work slower than the first one, which is WRONG. It is actually much faster than the first one.
The reason for this is in the first query, for each row the objects need to be stored, since there is a possibility that you still can change them. But in the 2nd one, you are throwing that object away and creating a new one, which is more efficient.
9 – Retrieve Only the Number of Records You Need
When you are binding to a data grid, and doing paging – consider the easy to use methods that LINQ to SQL provides. These are mainly Take and Skip methods. The code snippet involves a method which retrieves enough products for a ListView with paging enabled:///
/// Gets the products page by page.
///

/// Index of the starting page.
/// Size of the page.
/// The list of products in the specified page
private IList GetProducts(int startingPageIndex, int pageSize)
{
using (NorthwindDataContext context = new NorthwindDataContext())
{
return context.Products
.Take(pageSize)
.Skip(startingPageIndex * pageSize)
.ToList();
}
}



10 – Don’t Misuse CompiledQuery
I can hear you saying “What? Are you kiddin’ me? How can such a class like this be misused?”
Well, as it applies to all optimization LINQ to SQL is no exception: