Sunday, November 20, 2011

a site for developers...

Hello all,

I've recently launched a sub-domain under thekfactor.info called dev.thekfactor.info (which redirects you to thekfactor.info - i am working on that). In short, this is dev.thekfactor.info:

As engineers you might have gotten the habit of making notes of something you learn/hear, wishing to recollect them later. it would most likely be in a piece of paper and, in most cases it would be lost forever! you may not even remember you learned/heard something new! If this is you, http://dev.thekfactor.info is for you!!

Here you will be able to make a note of whatever you want. you could have a private note, a public note or a protected note (if you are an engineer, you know what i mean already! :) ) for example you could add another user to your group and have them alone view some notes (protected!).. and much more!

Also, there is a section to update users on what's in your mind. (ya, ya, kinda like twitter! )

Try it out friends and let me know your opinions...!!!

Saturday, April 16, 2011

My new website...!

Hi there!

At last I have released my revamped website! I hope to add a lot of interesting and useful stuff out there!! Watch out!!!

Here is the link http://thekfactor.info

Happy coding!

~ Karthik

Thursday, April 7, 2011

Remotely debugging a web application

Check out this article by Abhijit. It outlines how you could test a web application hosted remotely in IIS using msvmon.exe, and the remote debugger tools in visual studio. I promise you, it's a nice read!

http://www.codeproject.com/KB/aspnet/IISRemoteDebugging.aspx

Thursday, March 10, 2011

jQuery Cheat Sheet

Ha! I am blogging after a long time! Check out this link - a jquery cheat sheet! - http://woorkup.com/wp-content/uploads/2011/02/jQuery-1.5-Visual-Cheat-Sheet.pdf

Wednesday, April 7, 2010

A Nice Blog Post I Found - Hidden Features of C#

Hey People,

I was browsing through StackOverflow and found this interesting post. People participating in this particular blog post discuss various hidden/unknown features of C#. Check it out!!!

http://stackoverflow.com/questions/9033/hidden-features-of-c/

Do let me know your comments!!!

Happy coding!

~ Karthik

Tuesday, March 30, 2010

C#: Xml Writer - Applying XML writer settings

Hi People,

I have seen that at times we need to generate XML using code. This is in contrast to web services, where in XML is generated by the compiler. In this post I would like to give some pointers about creating XML files using C# - the "XmlWriter" class. Consider the following piece of code:

XmlWriter xml = XmlWriter.Create(@"c:\file.xml");


This would instantiate a XML writer and you could use various commands like xml.WriteStartElement(...), xml. WriteValue(..), xml.WriteEndElement() to construct the XML file dynamically. But there is a problem w/ this. A file created w/ such an instance of XmlWriter (xml) would like this:

<?xml version="1.0" encoding="utf-8"?><Users><User><Name>user1</Name></User><User><Name>user2</Name></User><User><Name>user3</Name></User></Users>


But, we may expect the XML file to have some line breaks, indentation to make it readable to others (though XML is not meant for that! ;) ). For this we need to apply some XML writer settings using the "XmlWriterSettings" class as shown below:


XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.NewLineOnAttributes = true;
xmlWriterSettings.Indent = true;


Now the XmlWriter would be instantiated as:

XmlWriter xml = XmlWriter.Create(path, xmlWriterSettings);


With this the XML generated would be indented, with line breaks as appropriate! Check out the final output after the addition settings:

<?xml version="1.0" encoding="utf-8"?>
<Users>
<User>
<Name>user1</Name>
</User>
<User>
<Name>user2</Name>
</User>
<User>
<Name>user3</Name>
</User>
</Users>


Check out the code in full:

void Main()
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.NewLineOnAttributes = true;
xmlWriterSettings.Indent = true;

XmlWriter xml = XmlWriter.Create(@"C:\file.xml", xmlWriterSettings);

xml.WriteStartElement("Users");

foreach (string client in new string[] {"user1","user2","user3"})
{
xml.WriteStartElement("User");

xml.WriteStartElement("Name");
xml.WriteValue(client);
xml.WriteEndElement();

xml.WriteEndElement();
}

xml.WriteEndElement();

xml.Close();
}

Saturday, March 20, 2010

S.O.L.I.D C# Code - Writing less code to carry out an activity unlike conventional methods (Comparison)

Hey All!

I am back w/ a C# post at last! Been while since I posted anything related to C#. Its 1'o clock, so I may have to edit this post later. I was reading some posts about S.O.L.I.D C# principles and I thought that I should post something about that. We may be (are) unknowingly using a lot of S.O.L.I.D principles in our day-to-day life probably.

Check out the following example. You would be able to notice clearly that S.O.L.I.D code uses much lesser amount of code to accomplish the same task that conventional code does. Keep in mind that List<T> implements the IEnumerable<T> and IEnumerable interface, but, ArrayList only implements IEnumerable. And, to say the least, both List<T> and ArrayList are extremely useful data structures (I feel!).

public class Content
{
public int a;
public string b;
}

public class EnumQu
{
public ArrayList arrList = null;
public List<Content> list = null;

private static void print(string message)
{
Console.WriteLine("");
Console.WriteLine(message);
Console.WriteLine("");
}

public void loadData()
{
arrList = new ArrayList();
list = new List<Content>();

for (int i = 0; i < 10; i++)
{
Content c = new Content();
c.a = (i + 1);
c.b = "String " + (i + 1);

arrList.Add(c);
list.Add(c);
}
}

public void arrayListTests()
{
// Display the items in ArrayList
// ArrayList implements IEnumerable but not IEnumerable<T>
// so .ForEach cannot be invoked

// S.O.L.I.D code to display (at least partially)
print("Select (S.O.L.I.D):");

var query = (from Content c in arrList select new { c });

foreach (var q in query) { Console.WriteLine(q.c.a + " - " + q.c.b); }

// S.O.L.I.D code to query for a value
print("Select - Single (S.O.L.I.D):");

var query_sel = (from Content c in arrList where c.a == 5 select new { c });

foreach (var q in query_sel) { Console.WriteLine(q.c.a + " - " + q.c.b); }

// Conventional C# code
print("Select:");

foreach (Content c in list)
{
Console.WriteLine(c.a + " - " + c.b);
}

print("Select - Single:");

foreach (Content c in list)
{
if (c.a == 5)
{
Console.WriteLine(c.a + " - " + c.b);
}
}
}

public void listTests()
{
// Display the items in List<T>
// List<T> implements IEnumerable<T> so .ForEach can be invoked

// S.O.L.I.D code
print("Select (S.O.L.I.D):");

list.ForEach(delegate(Content c){ Console.WriteLine(c.a + " - " + c.b); });

// S.O.L.I.D code to query for a value
print("Select - Single (S.O.L.I.D):");

List<Content> cList = list.Where(c => c.a == 5).ToList();

cList.ForEach(delegate(Content c){ Console.WriteLine(c.a + " - " + c.b); });

// Conventional C# code
print("Select:");

foreach (Content c in list)
{
Console.WriteLine(c.a + " - " + c.b);
}

print("Select - Single:");

foreach (Content c in list)
{
if (c.a == 5)
{
Console.WriteLine(c.a + " - " + c.b);
}
}
}

public static void Main(string[] args)
{
EnumQu enumQu = new EnumQu();
enumQu.loadData();
enumQu.arrayListTests();
enumQu.listTests();
}
}

As said before, I may have to add more information in here!! See you soon with another post!!!

Happy coding!

~ Karthik