<?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>Jeremy Massel&#039;s Blog &#187; Tips</title>
	<atom:link href="http://masseltech.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://masseltech.com</link>
	<description>Because sometimes I have good ideas too</description>
	<lastBuildDate>Wed, 11 Aug 2010 17:16:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Select DataSet and number of total rows with one stored procedure</title>
		<link>http://masseltech.com/2010/08/select-dataset-and-number-of-total-rows-with-one-stored-procedure/</link>
		<comments>http://masseltech.com/2010/08/select-dataset-and-number-of-total-rows-with-one-stored-procedure/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 17:16:18 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[iPhone programming]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=213</guid>
		<description><![CDATA[when you want to write a search using .net and MSSQL, it&#8217;s a pain. This is because you&#8217;re forced to select every row in the table and then only display a small subset of it. This works okay for tables that have a few hundred rows, as query caching can make this faster. But what [...]]]></description>
			<content:encoded><![CDATA[<p>when you want to write a search using .net and MSSQL, it&#8217;s a pain. This is because you&#8217;re forced to select every row in the table and then only display a small subset of it. This works okay for tables that have a few hundred rows, as query caching can make this faster. But what happens when you&#8217;re searching a table with half a million rows? </p>
<p>Unless you&#8217;re a complete masochist, you&#8217;re doing to want to split this into a more manageable data set, otherwise you&#8217;re gonna eat all the memory on your server. But this means that you can no longer use the DataSet.Tables[0].Rows.Count property to figure out how many rows you have. You can write a second stored procedure that&#8217;ll count the rows. But who wants to clog up their database with tons of stored procedures for no reason? Let&#8217;s consolidate it into one.</p>
<p>So what does this look like?</p>
<p>First: the stored procedure.</p>
<p>We&#8217;ll use output parameters to pass the row count back to our code</p>
<p><code><br />
create procedure [dbo].[Search]<br />
@searchText varchar(512), @recordsToReturn INT, @pageNumber INT, @numberofrows INT OUTPUT<br />
AS</p>
<p>-- get the page we want to view<br />
select * from<br />
(<br />
     select *,  ROW_NUMBER() OVER (ORDER BY creation_timestamp DESC) AS row from [table] where [table].columnName like '%' + @searchText + '%'<br />
)<br />
AS results WHERE row between (@pageNumber - 1) * @recordsToReturn + 1 and @pageNumber*@recordsToReturn;</p>
<p>-- get the total number of rows, not just the subset we want<br />
set @numberofrows = (select count(*)  from [table] where [table].columnName like '%' + @searchText + '%')</p>
<p>END</p>
<p></code></p>
<p>Now the C# (this&#8217;ll work in VB too, but feel free to convert it yourself)</p>
<p><code><br />
      SqlConnection conn = new SqlConnection();<br />
      conn.ConnectionString = ".....your connection string here.....";<br />
      conn.Open();</p>
<p>      DataSet returnData = new DataSet();</p>
<p>      SqlDataAdapter da = new SqlDataAdapter( "SearchMessages", conn);<br />
      da.SelectCommand.CommandType = CommandType.StoredProcedure;</p>
<p>      da.SelectCommand.Parameters.Add("@searchText", SqlDbType.VarChar).Value = "bob";<br />
      da.SelectCommand.Parameters.Add("@recordsToReturn", SqlDbType.Int).Value = 10;<br />
      da.SelectCommand.Parameters.Add("@pageNumber", SqlDbType.Int).Value = 1;</p>
<p>      //number of rows<br />
      SqlParameter outputParameter = new SqlParameter("@numberofrows", SqlDbType.Int, 2);<br />
      outputParameter.Direction = ParameterDirection.Output;  </p>
<p>      da.SelectCommand.Parameters.Add(outputParameter);</p>
<p>      da.Fill(returnData, "theData");</p>
<p>      int numberOfRowsInDataSet = (int)outputParameter.Value;</p>
<p>      da.Dispose();<br />
      conn.Close();<br />
</code></p>
<p>Best of luck! As always, leave a message in the comments if you have questions</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/08/select-dataset-and-number-of-total-rows-with-one-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Duplicate Function</title>
		<link>http://masseltech.com/2010/07/mysql-duplicate-function/</link>
		<comments>http://masseltech.com/2010/07/mysql-duplicate-function/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:13:13 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[mySql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=208</guid>
		<description><![CDATA[Sometimes you want the ability to duplicate (clone) entities in mySQL. But duplicating their children can be a huge pain! Here&#8217;s how: /* parent table */ insert into [parent table] select 0, [field1, field2, field3] from [tablename] where [parent table primary key] = [parent table object ID] /* child table */ insert into [child table] [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want the ability to duplicate (clone) entities in mySQL. But duplicating their children can be a huge pain! Here&#8217;s how:</p>
<p><code></p>
<p>/* parent table */<br />
insert into [parent table]<br />
select 0, [field1, field2, field3] from [tablename] where [parent table primary key] = [parent table object ID]</p>
<p>/* child table */<br />
insert into [child table]<br />
select 0, [field1, field2, field3], (select max([parent table primary key]) from [parent table]) from [child table] where [parent table primary key] = [parent table object ID]</p>
<p></code></p>
<p><strong>important note! </strong> make sure that you don&#8217;t select the primary key of the table. instead, select 0, and the auto_increment function will automatically figure out the correct primary key</p>
<p>As always, if you have questions, post em in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/07/mysql-duplicate-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress Multi Page Posts</title>
		<link>http://masseltech.com/2010/06/wordpress-multi-page-posts/</link>
		<comments>http://masseltech.com/2010/06/wordpress-multi-page-posts/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 16:57:51 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=195</guid>
		<description><![CDATA[Use &#60;!--nextpage--&#62; to allow muti-page posts in WordPress]]></description>
			<content:encoded><![CDATA[<p>So, multi paged posts in WordPress. That would be a handy feature, right? </p>
<p>Well it turns out it&#8217;s been around since at least 2007. Just found out about it today though. &#8220;How do I use it?&#8221; you ask?</p>
<p>Simply put </p>
<p><code><br />
&lt;!--nextpage--&gt;<br />
</code></p>
<p>into your post. This tag acts as a page break. Done!</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/06/wordpress-multi-page-posts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Batch Delete Performance SQL Server</title>
		<link>http://masseltech.com/2010/06/batch-delete-performance-sql-server/</link>
		<comments>http://masseltech.com/2010/06/batch-delete-performance-sql-server/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 17:38:32 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=187</guid>
		<description><![CDATA[Deleting old records from a table with > 3 000 00 rows. What&#8217;s the best way to do this? It seems the fastest way to do this is simply to: delete from [table] where creation_timestamp < dateadd (mm, -6, getdate()) (deleting anything older than 6 months) It took 3 hours (10916 seconds to be exact) [...]]]></description>
			<content:encoded><![CDATA[<p>Deleting old records from a table with > 3 000 00 rows. What&#8217;s the best way to do this? </p>
<p>It seems the fastest way to do this is simply to:<br />
<code><br />
delete from [table] where creation_timestamp < dateadd (mm, -6, getdate())<br />
</code><br />
(deleting anything older than 6 months)</p>
<p>It took 3 hours (10916 seconds to be exact) to delete 1.6 million (1,619,433) records this way. (148.35 / second).</p>
<p>We needed to do a second batch the next day, but wanted to split it into batches to try to get better performance.</p>
<p>Running: </p>
<p><code><br />
delete from [table] where pk_id in(<br />
select pk_id from (<br />
SELECT ROW_NUMBER() OVER (ORDER BY creation_timestamp desc) AS RowNumber, pk_id<br />
FROM [table]<br />
where creation_timestamp < '2009-12-16 13:52:08.673') _objectsToDelete<br />
WHERE RowNumber between 1 and 100000)<br />
</code></p>
<p>takes 12 minutes. (732 seconds) (136.61 / second).</p>
<p>Strangely, using the TOP command with a subquery takes the longest:</p>
<p><code><br />
delete from [table] where pk_id in (select TOP 100000 pk_id from [table] where creation_timestamp < '2009-12-16 13:52:08.673')<br />
</code></p>
<p>15 minutes (904 seconds) (110.61 / second)</p>
<p>Have a better way? Let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/06/batch-delete-performance-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode Fix Recent Projects Empty</title>
		<link>http://masseltech.com/2010/04/xcode-fix-recent-projects-empty/</link>
		<comments>http://masseltech.com/2010/04/xcode-fix-recent-projects-empty/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 23:30:57 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[iPhone programming]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=177</guid>
		<description><![CDATA[Terminal Command: defaults write com.apple.Xcode NSRecentDocumentsLimit -int 10 Relaunch Xcode. Done.]]></description>
			<content:encoded><![CDATA[<p>Terminal Command:<br />
<code>defaults write com.apple.Xcode NSRecentDocumentsLimit -int 10</code></p>
<p>Relaunch Xcode. Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/04/xcode-fix-recent-projects-empty/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Favourite Terminal Command</title>
		<link>http://masseltech.com/2010/03/new-favourite-terminal-command/</link>
		<comments>http://masseltech.com/2010/03/new-favourite-terminal-command/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 23:43:30 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=171</guid>
		<description><![CDATA[Best command ever: sudo !! Tells the terminal to run the last command again, but to throw sudo in front of it. obligatory XKCD link: http://xkcd.com/149/]]></description>
			<content:encoded><![CDATA[<p>Best command ever: </p>
<p><code> sudo !! </code></p>
<p></p>
<p>Tells the terminal to run the last command again, but to throw sudo in front of it. </p>
<p>
obligatory XKCD link:<br />
<a href="http://xkcd.com/149/"><img alt="Sandwich" src="http://imgs.xkcd.com/comics/sandwich.png" title="Make me a sandwich" class="alignleft" width="360" height="299" /></a></p>
<p>http://xkcd.com/149/</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/03/new-favourite-terminal-command/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run JavaScript function every n seconds</title>
		<link>http://masseltech.com/2010/01/run-javascript-function-every-n-seconds/</link>
		<comments>http://masseltech.com/2010/01/run-javascript-function-every-n-seconds/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:15:55 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=132</guid>
		<description><![CDATA[//tell javascript to run a function in 1 second setTimeout ("myFunction()", 1000 ); function myFunction(){ //do stuff //once the function is finished, queue this function up to run again in 1 second setTimeout ( "myFunction()", 1000 ); }]]></description>
			<content:encoded><![CDATA[<p><code><br />
//tell javascript to run a function in 1 second<br />
setTimeout ("myFunction()", 1000 );</p>
<p>function myFunction(){<br />
        //do stuff</p>
<p>        //once the function is finished, queue this function up to run again in 1 second<br />
	setTimeout ( "myFunction()", 1000 );<br />
}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2010/01/run-javascript-function-every-n-seconds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get latitude and longitude of an address using google maps</title>
		<link>http://masseltech.com/2009/09/get-latitude-and-longitude-of-an-address-using-google-mapst/</link>
		<comments>http://masseltech.com/2009/09/get-latitude-and-longitude-of-an-address-using-google-mapst/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 04:33:51 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=98</guid>
		<description><![CDATA[Google doesn&#8217;t make it easy to show you the latitude and longitude of an address you search in google maps, but there&#8217;s an easy way to get the info. go to google maps, type the address, and click search once you&#8217;ve found it, go to your address bar and clear what&#8217;s in it paste: javascript:void(prompt('',gApplication.getMap().getCenter())); [...]]]></description>
			<content:encoded><![CDATA[<p>Google doesn&#8217;t make it easy to show you the latitude and longitude of an address you search in google maps, but there&#8217;s an easy way to get the info.</p>
<ol>
<li>go to google maps, type the address, and click search</li>
<li>once you&#8217;ve found it, go to your address bar and clear what&#8217;s in it</li>
<li>paste: <code>javascript:void(prompt('',gApplication.getMap().getCenter()));</code> into the address bar</li>
<li>use the coordinates for whatever you wish!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2009/09/get-latitude-and-longitude-of-an-address-using-google-mapst/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualHostX and mod_rewrite</title>
		<link>http://masseltech.com/2009/08/virtualhostx-and-mod_rewrite/</link>
		<comments>http://masseltech.com/2009/08/virtualhostx-and-mod_rewrite/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:41:58 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=91</guid>
		<description><![CDATA[To enable mod_rewrite manually, see: OS X server tips but if you are using VirtualHostX it changes your default config file. Add the following code to the Directives box: Options FollowSymLinks AllowOverride All AuthConfig Order deny,allow Deny from all if you&#8217;re using the new version of VirtualHostX, make sure that you select Directory from the [...]]]></description>
			<content:encoded><![CDATA[<p>To enable mod_rewrite manually, see: <a href="http://masseltech.com/2009/03/os-x-server-tips/">OS X server tips</a> but if you are using <a href="http://clickontyler.com/virtualhostx/">VirtualHostX</a> it changes your default config file. Add the following code to the Directives box:<br />
<code><br />
<Directory /><br />
    Options FollowSymLinks<br />
    AllowOverride All AuthConfig<br />
    Order deny,allow<br />
    Deny from all<br />
</Directory><br />
</code></p>
<p>if you&#8217;re using the new version of VirtualHostX, make sure that you select Directory from the dropdown, then use:<br />
<code><br />
<Directory /><br />
    Options FollowSymLinks<br />
    AllowOverride All AuthConfig<br />
</Directory><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2009/08/virtualhostx-and-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding Web Fonts: A cautionary tale</title>
		<link>http://masseltech.com/2009/07/embedding-web-fonts-a-cautionary-tale/</link>
		<comments>http://masseltech.com/2009/07/embedding-web-fonts-a-cautionary-tale/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 21:14:46 +0000</pubDate>
		<dc:creator>jeremy.massel</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://masseltech.com/?p=74</guid>
		<description><![CDATA[So for work, the designer says &#8220;Hey, can we use this font in the webpage&#8221; and like an idiot, I say &#8220;sure, why not?&#8221;. Well, FF and Safari don&#8217;t support .otf files (for whatever reason) So I download FontForge, open it in X11 (on my mac) and convert it to .ttf, which works great. Then [...]]]></description>
			<content:encoded><![CDATA[<p>So for work, the designer says &#8220;Hey, can we use this font in the webpage&#8221; and like an idiot, I say &#8220;sure, why not?&#8221;. Well, FF and Safari don&#8217;t support .otf files (for whatever reason) So I download FontForge, open it in X11 (on my mac) and convert it to .ttf, which works great.</p>
<p>Then I messed around in IE, trying to make it work, even downloading this tool:</p>
<p><a href="http://masseltech.com/wp-content/uploads/2009/07/Picture-31.png"><img class="alignnone size-thumbnail wp-image-76" title="Microsoft WEFT" src="http://masseltech.com/wp-content/uploads/2009/07/Picture-31-150x150.png" alt="Microsoft WEFT" width="150" height="150" /></a></p>
<p>Worst thing EVER. Don&#8217;t do this. Don&#8217;t get this. Don&#8217;t even look at this. You will feel violated if you use it.</p>
<p>So&#8230;how to embed an OTF font in a website (make sure you have a license to do so kids):</p>
<ol>
<li>Convert OTF file to .ttf (use fontForge)</li>
<li>Embed with @font-face</li>
<li>When adding the font to a style, in IE you <strong><em><span style="text-decoration: underline;">CAN NOT</span><span style="font-style: normal; font-weight: normal;"> call it by the name you gave it with the @font-face declaration. You have to call it by it&#8217;s name. So if the font&#8217;s name is myfontLTSTDBOLDITALICROMAN you have to do: body{ font-family: myfontLTSTDBOLDITALICROMAN; } Sucky? Very. Works? yes.</span></em></strong></li>
</ol>
<p>Have a nice day</p>
]]></content:encoded>
			<wfw:commentRss>http://masseltech.com/2009/07/embedding-web-fonts-a-cautionary-tale/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
