Tuesday, March 24, 2009

Malyalam Dictionary Orkut Application

I have created my first orkut application. An english - Malayalam Dictionary. Same as one in my home page.
http://www.orkut.co.in/Main#AppInfo.aspx?appId=160907011366

Wednesday, March 11, 2009

Free ASP.NET MVC Book

ASP.NET MVC Book written by Scott gu,Scott Hanselman, Rob Conery, and Phil Haack

http://www.amazon.com/gp/product/0470384611?ie=UTF8&tag=scoblo04-20&linkCode=xm2&camp=1789&creativeASIN=0470384611

First chaptter of this book is available as a Free Download. 185 pages of walk-through that takes us into creating a complete MVC application (Called Nerddinner) from scratch. Check the application live at http://www.nerddinner.com/. Source code available at codeplex http://nerddinner.codeplex.com/

Download the e-book and source code from scott gu's blog.
http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx

Also check scott hanselman's blog about it.
http://www.hanselman.com/blog/FreeASPNETMVCEBookNerdDinnercomWalkthrough.aspx

Tuesday, March 3, 2009

SQL Server- Get Rows AS XML, Traverse XML in TSQL

I have a table 'Tags' , see below


To get the rows as XMl

SELECT * FROM Tags for xml auto

The result will be

I want to get the tags separated by coma for the given music id, i wrote a function that
will traverse the XML and return the tags as a single row separated by coma

CREATE FUNCTION [dbo].GetMusicTags
(
@MusicID INT
)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Xdoc XML
DECLARE @Count INT
DECLARE @i INT
DECLARE @Tag VARCHAR(MAX)
DECLARE @Temp VARCHAR(MAX)
--
SET @i=1
SET @Tag=''
SET @Temp=''
--
SET @Xdoc=''+(SELECT * FROM Tags WHERE MusicID=@MusicID for xml auto)+''
SET @Count = @Xdoc.query('
{ count(/doc/Tags) }
').value('e[1]','VARCHAR(MAX)')

WHILE @i <= @Count
BEGIN
SELECT @Temp= e.x.value('@Tag[1]', 'VARCHAR(MAX)') FROM
@Xdoc.nodes('/doc/Tags[position()=sql:variable("@i")]') e(x)
SET @Tag=@Tag+@Temp
IF @i<>@Count
SET @Tag=@Tag+','
SET @i = @i + 1
END
RETURN @Tag
END
GO

Result will be


Download Sql Script

Wednesday, February 18, 2009

Get start and end date of current week in C#



DayOfWeek day = DateTime.Now.DayOfWeek;
int days = day - DayOfWeek.Monday;
DateTime start = DateTime.Now.AddDays(-days);
DateTime end = start.AddDays(6);
Code from
http://www.codekeep.net/snippets/0d955fdd-ff9e-4403-90cb-15dac8391034.aspx

Monday, February 16, 2009

SQL SERVER: Function To Search Coma or Delimiter separated value in a column

We sometimes stores Coma or other delimiter separated values in a column, to search a particular value in that column, the following function will be helpful.



--30-jan-2009 Priyan R
CREATE FUNCTION [dbo].[IsExistInString]
(
@Data VARCHAR(MAX),
@Delim VARCHAR(100),
@ValueToFind VARCHAR(MAX)
)
RETURNS BIT
AS
BEGIN
DECLARE @pos1 INT
DECLARE @pos2 INT
DECLARE @tbl_Split_Data TABLE
(
Data VARCHAR(MAX)
)
SET @pos1=1
IF(CHARINDEX(@Delim,@Data,1)=0)
BEGIN
INSERT INTO @tbl_Split_Data VALUES(@Data)
END
ELSE
BEGIN
WHILE (@pos1<>0)
BEGIN
SET @pos2=CHARINDEX(@Delim,@Data,@pos1)
IF(@pos2=0)
BEGIN
INSERT INTO @tbl_Split_Data VALUES(SUBSTRING (@Data,@pos1,LEN(@Data)))
END
ELSE
BEGIN
INSERT INTO @tbl_Split_Data VALUES(SUBSTRING (@Data,@Pos1,@Pos2-@Pos1))
END
IF(@pos2<>0) SET @pos2=@pos2+LEN(@Delim)
SET @pos1=@pos2
END
END
SELECT @POS1=COUNT(*) FROM @tbl_Split_Data WHERE Data=@ValueToFind
IF(@POS1<>0)
BEGIN
RETURN 1
END
RETURN 0
END

go
--eg
SELECT dbo.IsExistInString('one|$|two|$|three','|$|','one')

C# :Seconds TO String

This functions return a string like 1 hours ago, a day ago etc.

//Returns seconds to 1 hour ago, 10 sec ago etc.
public static string SecondsToString(double seconds)
{

string time = "";
if (seconds >= 3600)
{
time =Convert.ToInt32((seconds / 3600)).ToString();
if (seconds > 24)
{
time = Convert.ToInt32((seconds / 24)).ToString();
time += " days ago";
}
else
time += " hrs ago";
}
else if (seconds >= 60)
{
time = Convert.ToInt32((seconds / 60)).ToString();
time += " minutes ago";
}
else
{
time = Convert.ToInt32(seconds).ToString();
time += " sec ago";
}
return time;
}

Wednesday, February 4, 2009

Programmers And Mathematics

I have been coding in various languages for more than 6 years. Till now i havent used much mathematics for programming. From my experience i feel that one can be a very good programmer without a deep knowledge in maths. But i think proficieny in mathematics will be an added advantage for Programmer. With maths we can write many interesting & funny programs easily without any difficulty.

There is good blog post about it by Steve Yegge.

http://steve-yegge.blogspot.com/2006/03/math-for-programmers.html