<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sumit Gupta &#187; Code Snippets</title>
	<atom:link href="http://www.sumitgupta.net/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sumitgupta.net</link>
	<description>bookmarking my life</description>
	<lastBuildDate>Wed, 08 Feb 2012 11:23:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hello World</title>
		<link>http://www.sumitgupta.net/hello-world/</link>
		<comments>http://www.sumitgupta.net/hello-world/#comments</comments>
		<pubDate>Mon, 05 May 2008 10:18:01 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=85</guid>
		<description><![CDATA[As a computer software programmer, one must have learned and use these two words &#8220;Hello World&#8221;. It is unsaid theory to write a hello world program to start learning a programming language. You can read the &#8220;greatness&#8221; of hello world at http://en.wikipedia.org/wiki/Hello_world_program. Or get a Hello world program for your programming language from this collection [...]]]></description>
			<content:encoded><![CDATA[<p>As a computer software programmer, one must have learned and use these two words &#8220;Hello World&#8221;. It is unsaid theory to write a hello world program to start learning a programming language. You can read the &#8220;greatness&#8221; of hello world at <a href="http://en.wikipedia.org/wiki/Hello_world_program">http://en.wikipedia.org/wiki/Hello_world_program</a>.</p>
<p>Or get a Hello world program for your programming language from this <a target="_blank" href="http://www.roesler-ac.de/wolfram/hello.htm" title="Hello World Collection">collection of Hello world</a></p>
<p><a href="http://www.roesler-ac.de/wolfram/hello.htm">http://www.roesler-ac.de/wolfram/hello.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LightBox Vs VideoBox Vs Custom Code</title>
		<link>http://www.sumitgupta.net/lightbox-vs-videobox-vs-custom-code/</link>
		<comments>http://www.sumitgupta.net/lightbox-vs-videobox-vs-custom-code/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 02:49:27 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Fullscreen video and Image display]]></category>
		<category><![CDATA[Lightbox]]></category>
		<category><![CDATA[vidbox]]></category>
		<category><![CDATA[videobox]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=78</guid>
		<description><![CDATA[Recently I was given a task to make LightBox and VideoBox work on same page, where we have Images and Video to show. However, Videobox is inspired by Lightbox as per developer, they are not compatible with each other. The reason I found is that they share few variable and hence they are breaking each other&#8217;s code. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was given a task to make <a title="LightBox" href="http://www.huddletogether.com/projects/lightbox2/" target="_blank">LightBox</a> and <a title="Video Box" href="http://videobox-lb.sourceforge.net/" target="_blank">VideoBox</a> work on same page, where we have Images and Video to show. However, Videobox is inspired by Lightbox as per developer, they are not compatible with each other. The reason I found is that they share few variable and hence they are breaking each other&#8217;s code. Now since we need functionality to be done, I have give to find a quick alternative solution..When my company said quick solution they mean a solution in next 1 hr.</p>
<p>Let us check what we can do..Lightbox, read image tag with a tag and show image based on those, and this is what Videobox do, it read for &#8220;rel=vidbox&#8221; in anchor tag, and then it detect the type of video source to display the item in bigger div. What I do is I modify it to recognize images as well, i.e. if we put rel=&#8221;vidbox&#8221; in anchor tag for your images, (something we do in lightbox) my modified VideoBox code will read and check for extension jpg, jpeg, gif,png and if found i write &#8220;custom code&#8221; in variable this.other to show img tag instead of SWFObject or other.</p>
<p>Now VideoBox is no more a video only box, and it can handle Images for me as well <img src='http://www.sumitgupta.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><a title="Download for Modified video Box" href="http://www.sumitgupta.net/download/videobox.zip">Download modified VideoBox Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/lightbox-vs-videobox-vs-custom-code/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Creating SQL Table from another table</title>
		<link>http://www.sumitgupta.net/creating-sql-table-from-another-table/</link>
		<comments>http://www.sumitgupta.net/creating-sql-table-from-another-table/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 10:12:11 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=68</guid>
		<description><![CDATA[Often we need to take quick backup of database with data before we can make changes in table. for this I create the image of table within same database, as it is the fastest method. It is one of the reason why one need to create image a table.. or copy one table from another. [...]]]></description>
			<content:encoded><![CDATA[<p>Often we need to take quick backup of database with data before we can make changes in table. for this I create the image of table within same database, as it is the fastest method. It is one of the reason why one need to create image a table.. or copy one table from another.</p>
<p>It can be achieved in all RDBMS</p>
<p>Here is SQL for MS SQL</p>
<p><strong><em>select * into newTable from OldTable</em></strong></p>
<p>However, their is another command (it works for me on mysql)</p>
<p><strong><em>create table newtable as (select * from oldtable)</em></strong></p>
<p>Best of luck with backup and server transfers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/creating-sql-table-from-another-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting/Resetting Auto increment value in MSSQL 2005</title>
		<link>http://www.sumitgupta.net/settingresetting-auto-increment-value-in-mssql-2005/</link>
		<comments>http://www.sumitgupta.net/settingresetting-auto-increment-value-in-mssql-2005/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 14:33:36 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=64</guid>
		<description><![CDATA[Once you create a table and what to reset autoincrement value of a table to your desire number, you need to set some system table values, which are not available for direct editing. To perform this you need to do following: SELECT OBJECT_ID,OBJECT_NAME(OBJECT_ID) AS TABLENAME, NAME AS COLUMNNAME, SEED_VALUE, INCREMENT_VALUE, LAST_VALUE, IS_NOT_FOR_REPLICATION FROM SYS.IDENTITY_COLUMNS ORDER [...]]]></description>
			<content:encoded><![CDATA[<p>Once you create a table and what to reset autoincrement value of a table to your desire number, you need to set some system table values, which are not available for direct editing. To perform this you need to do following:</p>
<p><em>SELECT OBJECT_ID,OBJECT_NAME(OBJECT_ID) AS TABLENAME, NAME AS COLUMNNAME, SEED_VALUE, INCREMENT_VALUE, LAST_VALUE, IS_NOT_FOR_REPLICATION FROM SYS.IDENTITY_COLUMNS ORDER BY 2</em></p>
<p>This statement simply show all table in your select table with auto increment value. Once this gives you good information, you can run following command to change value</p>
<p><em>DBCC CHECKIDENT(&#8216;mytable&#8217;,RESEED,[new numeric value]) </em></p>
<p>If this runs perfect give something like this:</p>
<p><em>Checking identity information: current identity value &#8217;14&#8242;, current column value &#8217;30&#8242;.DBCC execution completed. If DBCC printed error messages, contact your system administrator.</em></p>
<p>Otherwise it give an error. (In above message 14 and 30 will be replaced with your values.</p>
<p>MSDN Link for more details : <a href="http://msdn2.microsoft.com/en-us/library/ms176057.aspx">http://msdn2.microsoft.com/en-us/library/ms176057.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/settingresetting-auto-increment-value-in-mssql-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating distance</title>
		<link>http://www.sumitgupta.net/calculating-distance/</link>
		<comments>http://www.sumitgupta.net/calculating-distance/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 16:05:37 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=60</guid>
		<description><![CDATA[With increasing use of Map service such as google, yahoo and MSN one often need to calculate distance between two location. This can be done many ways I suppose. However, to calculate the short distance we can perform calculation based on longitude and latitude values of those two location.  However, it is simply a math [...]]]></description>
			<content:encoded><![CDATA[<p>With increasing use of Map service such as google, yahoo and MSN one often need to calculate distance between two location. This can be done many ways I suppose. However, to calculate the short distance we can perform calculation based on longitude and latitude values of those two location.</p>
<p>  However, it is simply a math formula you need to learn but you should now the coordinates of location as well. Here is one beautiful article and Javascript method do to that</p>
<p><a href="http://www.movable-type.co.uk/scripts/latlong.html">http://www.movable-type.co.uk/scripts/latlong.html</a></p>
<p>This script explain all its working and from where it is drived. Such a nice place to learn something new <img src='http://www.sumitgupta.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/calculating-distance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to remove all child movieClip through AS 2.0 Code</title>
		<link>http://www.sumitgupta.net/how-to-remove-all-child-movieclip-through-as-20-code/</link>
		<comments>http://www.sumitgupta.net/how-to-remove-all-child-movieclip-through-as-20-code/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 07:55:32 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=49</guid>
		<description><![CDATA[To remove all child from a given movie clip simple loop through its all object and remove the type of object you want. Following code does the same for related_mc.sp_related name movie clip: for (obj in related_mc.sp_related){ // root.mc1[obj] instanceof MovieClip same as typeof(_root.mc1[obj])==&#8221;movieclip&#8221;        if (typeof(related_mc.sp_related[obj])==&#8221;movieclip&#8221;){          related_mc.sp_related[obj].removeMovieClip();   [...]]]></description>
			<content:encoded><![CDATA[<p>To remove all child from a given movie clip simple loop through its all object and remove the type of object you want. Following code does the same for related_mc.sp_related name movie clip:</p>
<p>for (obj in related_mc.sp_related){<br />
// root.mc1[obj] instanceof MovieClip same as typeof(_root.mc1[obj])==&#8221;movieclip&#8221;<br />
        if (typeof(related_mc.sp_related[obj])==&#8221;movieclip&#8221;){<br />
          related_mc.sp_related[obj].removeMovieClip();<br />
        }<br />
}</p>
<p>this loop through all child of related_mc.sp_related and remove the instance if its of the type &#8220;movieclip&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/how-to-remove-all-child-movieclip-through-as-20-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing Text Document in .NET 2.0</title>
		<link>http://www.sumitgupta.net/printing-text-document-in-net-20/</link>
		<comments>http://www.sumitgupta.net/printing-text-document-in-net-20/#comments</comments>
		<pubDate>Tue, 10 Jul 2007 05:44:29 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET/VB]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/?p=43</guid>
		<description><![CDATA[Some time reporting tools are too heavy to use with a small application. Something similar happens with me, I need to print a Single page text information for this I cannot use any Heavy reporting software although this information is fetched from XML/Database. So I opt to use in built .NET feature and having following [...]]]></description>
			<content:encoded><![CDATA[<p>Some time reporting tools are too heavy to use with a small application. Something similar happens with me, I need to print a Single page text information for this I cannot use any Heavy reporting software although this information is fetched from XML/Database. So I opt to use in built .NET feature and having following for you to use now.</p>
<p>  First Add a <strong>PrintDialog </strong>box on your Windows Application that gives printing capability.</p>
<p>Now Include a Object with its events in your code</p>
<p><em><code>Private WithEvents doctoprint As New Printing.PrintDocument</code></em></p>
<p>Once we have these basic Set up now, we can simply copy paste given two function on page to Print document define in FILE_PATH constant</p>
<pre>Private Sub PrintDocument()
PrintText.AllowSomePages = False
PrintText.AllowSelection = False
 PrintText.ShowHelp = False
 PrintText.Document = doctoprint

 Dim result As DialogResult = PrintText.ShowDialog

 If result = Windows.Forms.DialogResult.OK Then
 Try
 streamToPrint = New StreamReader(FILE_PATH)
 doctoprint.DocumentName = "Title to Show on 'Now printing dialog'"
 doctoprint.Print()
 streamToPrint.Close()
 Catch ex As Exception
 MsgBox("Unable to print")
 End Try
 End If
 End Sub

 Private Sub doctoprint_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles doctoprint.PrintPage

'change this line tochange default font for printing.
 Dim printFont As New System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Regular)

 Dim linesPerPage As Single = 0
 Dim yPos As Single = 0
 Dim count As Integer = 0
 Dim leftMargin As Single = e.MarginBounds.Left
 Dim topMargin As Single = e.MarginBounds.Top
 Dim line As String = Nothing

 ' Calculate the number of lines per page.
 linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)

 ' Print each line of the file.
 While count &lt; linesPerPage
 line = streamToPrint.ReadLine()
 If line Is Nothing Then
 Exit While
 End If
 yPos = topMargin + count * printFont.GetHeight(e.Graphics)
 e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
 count += 1
 End While

 ' If more lines exist, print another page.
 If Not (line Is Nothing) Then
 e.HasMorePages = True
 Else
 e.HasMorePages = False
 End If
 End Sub</pre>
<p>Now, simply call your <strong><em>PrintDocument()</em></strong> function to start printing of <strong><em>FILE_PATH</em></strong> using your Print Button or menu option.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/printing-text-document-in-net-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filling Text Boxes for Testing</title>
		<link>http://www.sumitgupta.net/filling-text-boxes-for-testing/</link>
		<comments>http://www.sumitgupta.net/filling-text-boxes-for-testing/#comments</comments>
		<pubDate>Tue, 26 Dec 2006 05:55:11 +0000</pubDate>
		<dc:creator>Sumit Gupta</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.sumitgupta.net/blog/2006/12/26/filling-text-boxes-for-testing/</guid>
		<description><![CDATA[It is often required to fillin the form on webpage so you can test the form submission action. For this I often need to put different value so I can recognize the values are coming good. Like I need to create PDF on the fly, In that I need to fill the form on web [...]]]></description>
			<content:encoded><![CDATA[<p>It is often required to fillin the form on webpage so you can test the form submission action. For this I often need to put different value so I can recognize the values are coming good. Like I need to create PDF on the fly, In that I need to fill the form on web page than generate the PDF as per data in web form, this consist of 30 field, so To place each field data correctly I need to fill the form again and again. Though data validation is not required and not there. But still to check if need data to be transfer.</p>
<p>Ã‚  So, I add this small JS code to do that for me, within body tag</p>
<p><em><strong>for (i = 0; i < document.forms[0].elements.length; i++) </strong></em></p>
<p><em><strong>{ </strong></em></p>
<p><em><strong>   if (document.Form1.elements[i].type == &#8220;text&#8221;) </strong></em></p>
<p><em><strong>{ </strong></em></p>
<p><em><strong>document.Form1.elements[i].value = document.Form1.elements[i].name; </strong></em></p>
<p><em><strong>} </strong></em></p>
<p><em><strong>}</strong></em></p>
<p>That solve my problem&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumitgupta.net/filling-text-boxes-for-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

