<?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>geek# &#187; Useful Tricks</title>
	<atom:link href="http://geeksharp.com/category/useful-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://geeksharp.com</link>
	<description>techno-babble for the masses</description>
	<lastBuildDate>Thu, 27 May 2010 14:57:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Windows + Ruby Native Gems (1.9.1)</title>
		<link>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/</link>
		<comments>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:30:02 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Useful Tricks]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/</guid>
		<description><![CDATA[A few weeks back I posted about getting the ruby-debug-ide gem installed in Windows under Ruby 1.8.6.&#160; In that post I outlined how hacking a header file and using the Visual C++ 2008 compiler could be leveraged to get the gem built and installed properly.&#160; Well, after a helpful comment from a reader and watching [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back I posted about getting the <strong>ruby-debug-ide</strong> gem installed in Windows under Ruby 1.8.6.&#160; In that post I outlined how hacking a header file and using the Visual C++ 2008 compiler could be leveraged to get the gem built and installed properly.&#160; Well, after a helpful comment from a reader and watching a few screencasts over on TekPub, I actually found a way to do this with <a href="http://www.rubyinstaller.org" target="_blank">Ruby 1.9.1 from RubyInstaller.org</a>.</p>
<p>As you know, I swapped my Windows development environment for Mac OSX, and so far learning Rails has been a great pleasure thanks to <a href="http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition" target="_blank">Agile Web Development with Rails (Third Edition)</a> from <a href="http://www.pragprog.com/" target="_blank">The Pragmatic Programmers</a>.&#160; When I found this alternate method for installing <strong>ruby-debug-ide</strong> I decided to fire up my Windows 7 VM and give it a go.&#160; Here are the gems I have currently installed on my VM:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydebugide1.9.1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-debug-ide-1.9.1" border="0" alt="ruby-debug-ide-1.9.1" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydebugide1.9.1_thumb.png" width="581" height="435" /></a> </p>
<p>To get this working on my VM, here’s the steps I followed:</p>
<ol>
<li>Install Ruby 1.9.1 from RubyInstaller.org.&#160; When you run the installer, make sure you pay attention to the checkboxes under the install path and check both of them:      <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubyinstallerassociations.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-installer-associations" border="0" alt="ruby-installer-associations" src="http://geeksharp.com/wp-content/uploads/2010/01/rubyinstallerassociations_thumb.png" width="507" height="389" /></a> </li>
<li>Now that you have Ruby installed, you need to get the <a href="http://rubyforge.org/frs/?group_id=167" target="_blank">devkit package from Rubyforge</a>.&#160; You should see an archive in the “Development Kit” section of that page.&#160; The current version as of this writing is 3.4.5r3 (20091110). </li>
<li>Once you have the archive, you’ll need <a href="http://www.7-zip.org/" target="_blank">7-zip</a> to decompress it, so go get it and install it. </li>
<li>When you open the archive in 7-zip, click the <strong>Extract</strong> button and make sure you extract it to wherever you installed Ruby.&#160; In my case this was <strong>C:\Ruby19</strong>.       <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitextraction.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-devkit-extraction" border="0" alt="ruby-devkit-extraction" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitextraction_thumb.png" width="516" height="291" /></a> </li>
<li>The last step is to make the devkit <strong>fstab</strong> file point to the proper Ruby folders.&#160; The <strong>fstab</strong> file is underneath your Ruby install.&#160; Mine was located at <strong>C:\Ruby19\devkit\msys\1.0.11\etc\fstab</strong>.&#160; Just open this file in notepad and change it.       <br /><a href="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitfstab.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ruby-devkit-fstab" border="0" alt="ruby-devkit-fstab" src="http://geeksharp.com/wp-content/uploads/2010/01/rubydevkitfstab_thumb.png" width="481" height="237" /></a> </li>
<li>Now the devkit is installed properly, all you have to do is open up a command prompt (make sure you <strong>Run As Administrator</strong>) and type the following commands (if you want to get the same gems as me):
<pre class="brush: plain;">gem install rails
gem install mongrel
gem install cucumber
gem install rspec
gem install ruby-debug-ide</pre>
</li>
</ol>
<p>That&#8217;s it!&#160; If you run into any weird issues, let me know in the comments.&#160; Enjoy your new Windows-based Ruby on Rails development environment running the latest and greatest Ruby 1.9.1! <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2010/01/18/windows-ruby-native-gems-1-9-1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>MySQL Password Hashing in .NET</title>
		<link>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/</link>
		<comments>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/#comments</comments>
		<pubDate>Fri, 15 May 2009 15:01:08 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Useful Tricks]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SHA1]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/</guid>
		<description><![CDATA[As I was surfing through StackOverflow today, I noticed a question that got me thinking.&#160; This developer had been working with a classic ASP application that used MySQL for it’s backend database.&#160; The project on his plate was to convert this application to ASP.NET with MS-SQL as the database.&#160; The only problem he encountered was [...]]]></description>
			<content:encoded><![CDATA[<p>As I was surfing through <a href="http://stackoverflow.com/questions/868482/simulating-mysqls-password-encryption-using-net-or-ms-sql/" target="_blank">StackOverflow</a> today, I noticed a question that got me thinking.&#160; This developer had been working with a classic ASP application that used MySQL for it’s backend database.&#160; The project on his plate was to convert this application to ASP.NET with MS-SQL as the database.&#160; The only problem he encountered was the fact that passwords were stored in the database using a MySQL-specific hashing algorithm called via the PASSWORD() function.&#160; He needed a way to convert these passwords to .NET.</p>
<p>Given that I have a MySQL database laying around, I decided to poke around in the source code to see exactly how MySQL’s PASSWORD() function really works.&#160; It didn’t take me long to find inside the file “libmysql/password.c” this little gem:</p>
<pre class="brush: objc;">/*
    MySQL 4.1.1 password hashing: SHA conversion (see RFC 2289, 3174) twice
    applied to the password string, and then produced octet sequence is
    converted to hex string.
    The result of this function is used as return value from PASSWORD() and
    is stored in the database.
  SYNOPSIS
    make_scrambled_password()
    buf       OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
    password  IN  NULL-terminated password string
*/

void
make_scrambled_password(char *to, const char *password)
{
  SHA1_CONTEXT sha1_context;
  uint8 hash_stage2[SHA1_HASH_SIZE];

  mysql_sha1_reset(&amp;sha1_context);
  /* stage 1: hash password */
  mysql_sha1_input(&amp;sha1_context, (uint8 *) password, (uint) strlen(password));
  mysql_sha1_result(&amp;sha1_context, (uint8 *) to);
  /* stage 2: hash stage1 output */
  mysql_sha1_reset(&amp;sha1_context);
  mysql_sha1_input(&amp;sha1_context, (uint8 *) to, SHA1_HASH_SIZE);
  /* separate buffer is used to pass 'to' in octet2hex */
  mysql_sha1_result(&amp;sha1_context, hash_stage2);
  /* convert hash_stage2 to hex string */
  *to++= PVERSION41_CHAR;
  octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE);
}</pre>
<p>As you can see, the password algorithm uses a double-SHA1 hash to format the password.&#160; The other little tidbit is that any passwords generated post-4.1 will be pre-pended with an asterisk (*).&#160; Given that I have spent a fair amount of time recently working with cryptography in .NET, it didn’t take long to adapt this code to C#.&#160; The following function produces the same output as the MySQL PASSWORD() function.</p>
<pre class="brush: csharp;">public string GeneralteMySQLHash(string key)
{
    byte[] keyArray = Encoding.UTF8.GetBytes(key);
    SHA1Managed enc = new SHA1Managed();
    byte[] encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
    StringBuilder myBuilder = new StringBuilder(encodedKey.Length);

    foreach (byte b in encodedKey)
        myBuilder.Append(b.ToString(&quot;X&quot;));

    return &quot;*&quot; + myBuilder.ToString();
}</pre>
<p>I hope this helps someone out there. I know it was kinda of fun to put on my super-slueth hat for a while <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Update 5/29/2009:</strong> I found a neat way to do this in T-SQL also.  It&#8217;s a bit ugly, but it works!</p>
<pre class="brush: sql;">SELECT '*' + SUBSTRING(master.dbo.fn_varbintohexstr(HASHBYTES('SHA1',HASHBYTES('SHA1','VALUE-TO-ENCRYPT-GOES-HERE'))),1,42)</pre>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/05/15/mysql-password-hashing-in-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Delicious Toolbar Icon Woes</title>
		<link>http://geeksharp.com/2009/04/17/delicious-toolbar-icon-woes/</link>
		<comments>http://geeksharp.com/2009/04/17/delicious-toolbar-icon-woes/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 18:21:25 +0000</pubDate>
		<dc:creator>Scott Anderson</dc:creator>
				<category><![CDATA[Useful Tricks]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://geeksharp.com/2009/04/17/delicious-toolbar-icon-woes/</guid>
		<description><![CDATA[Recently I’ve begun using the popular bookmarking service <a href="http://www.delicious.com" target="_blank">Delicious</a>.  One of my favorite features of this service is that I can install the associated <a href="http://delicious.com/help/quicktour/firefox" target="_blank">Firefox add-on</a>, and this enables a handy bookmarks toolbar that stays synchronized between my home and work computers.  Recently, however, I’ve noticed a strange incompatibility with the theme I use in Firefox.  For some reason, while using the <a href="https://addons.mozilla.org/en-US/firefox/addon/4129" target="_blank">myFireFox theme</a>, the icons placed in the favorites bar are sometimes improperly sized which makes for a relatively ugly experience.  Read more to see the rest!]]></description>
			<content:encoded><![CDATA[<p>Recently I’ve begun using the popular bookmarking service <a href="http://www.delicious.com" target="_blank">Delicious</a>.  One of my favorite features of this service is that I can install the associated <a href="http://delicious.com/help/quicktour/firefox" target="_blank">Firefox add-on</a>, and this enables a handy bookmarks toolbar that stays synchronized between my home and work computers.  Recently, however, I’ve noticed a strange incompatibility with the theme I use in Firefox.  For some reason, while using the <a href="https://addons.mozilla.org/en-US/firefox/addon/4129" target="_blank">myFireFox theme</a>, the icons placed in the favorites bar are sometimes improperly sized which makes for a relatively ugly experience:</p>
<p><a href="http://geeksharp.com/wp-content/uploads/2009/04/brokendelicons.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Yes I know it looks just like IE8, but I like it that way!" src="http://geeksharp.com/wp-content/uploads/2009/04/brokendelicons-thumb.png" border="0" alt="Yes I know it looks just like IE8, but I like it that way!" width="606" height="443" /></a></p>
<p>Notice the huge icon next to my link for my Doctor’s Office in the photo above?  This was driving me crazy, so I started looking for ways to fix it without having to switch my theme (I know it looks just like IE8, and that’s on purpose!).  After searching for solutions, I really didn’t find any other instances of folks having the same problem, so I set out to devise my own solution.  This solution works best if you have the <a href="https://addons.mozilla.org/en-US/firefox/addon/2108" target="_blank">Stylish add-on</a> installed.</p>
<ol>
<li>Install Stylish</li>
<li>Navigate to <strong>Tools</strong> &gt; <strong>Add-ons</strong>, then find Sylish in the list and click <strong>Options</strong>.</li>
<li>Click the <strong>Write</strong> button and paste the following code:
<pre class="brush: css;">@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
@-moz-document url(chrome://browser/content/browser.xul) {
  #ybToolbar-bookmarksview{
    height:0px !important;
  }
  #ybToolbar .toolbarbutton-icon{
    height:16px !important;
    width:16px!important;
  }
  #ybToolbar-chevron .toolbarbutton-icon{
    height: 5px !important;
    width: 7px !important;
  }
}</pre>
</li>
<li>Save your script and enjoy your fixed delicious toolbar!</li>
</ol>
<p>Good luck, and happy hacking! <img src='http://geeksharp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://geeksharp.com/2009/04/17/delicious-toolbar-icon-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
