<?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>Michael E. Chancey Jr.</title>
	<atom:link href="http://michael.chanceyjr.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://michael.chanceyjr.com</link>
	<description></description>
	<lastBuildDate>Thu, 25 Feb 2010 18:38:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WoW UI Screenshot</title>
		<link>http://michael.chanceyjr.com/uncategorized/wow-ui-screenshot/</link>
		<comments>http://michael.chanceyjr.com/uncategorized/wow-ui-screenshot/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 18:38:46 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[World of Warcraft]]></category>
		<category><![CDATA[WOW]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=604</guid>
		<description><![CDATA[



Share


	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p><a href="http://michael.chanceyjr.com/site/wp-content/uploads/2010/02/ScreenShot_022510_133451.jpeg"><img src="http://michael.chanceyjr.com/site/wp-content/uploads/2010/02/ScreenShot_022510_133451-150x93.jpg" alt="" title="WoW UI" width="150" height="93" class="alignnone size-thumbnail wp-image-603" /></a></p>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=WoW%20UI%20Screenshot%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Funcategorized%2Fwow-ui-screenshot%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Funcategorized%2Fwow-ui-screenshot%2F&amp;title=WoW%20UI%20Screenshot&amp;bodytext=" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Funcategorized%2Fwow-ui-screenshot%2F&amp;title=WoW%20UI%20Screenshot" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Funcategorized%2Fwow-ui-screenshot%2F&amp;title=WoW%20UI%20Screenshot&amp;notes=" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/uncategorized/wow-ui-screenshot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Keywords and Description Meta Tags</title>
		<link>http://michael.chanceyjr.com/useful-code/wordpress-keywords-and-description-meta-tags/</link>
		<comments>http://michael.chanceyjr.com/useful-code/wordpress-keywords-and-description-meta-tags/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 15:15:20 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=550</guid>
		<description><![CDATA[The code below allows you to add keywoards and description meta tags to any wordpress theme.  Simple copy the below code and insert it into the header.php of your theme somewhere inside of the &#60;head&#62;&#60;/head&#62; tag.
You could also simply download the plugin I wrote for this as well.  Although I have submitted it [...]]]></description>
			<content:encoded><![CDATA[<p>The code below allows you to add keywoards and description meta tags to any wordpress theme.  Simple copy the below code and insert it into the header.php of your theme somewhere inside of the &lt;head&gt;&lt;/head&gt; tag.</p>
<p>You could also simply download the plugin I wrote for this as well.  Although I have submitted it to Wordpress.org they have not posted it yet so here is a link in the mean time.  Please note the plugin is a little more customizable then the code below.</p>
<p><a href="http://michael.chanceyjr.com/free-stuff/auto-keywords-and-description-generator/">-Auto Keywords and Description Generator-</a></p>
<h3>//Code</h3>
<hr/>
<pre class="brush: php;">
&lt;?php
$keywords = &quot;&quot;;
$description = &quot;&quot;;

if(is_home() || is_front_page())
{
	//LOAD KEYWORDS FROM USER SPECIFIED STRING
	$keywords = &quot;Insert your homepage keywords here&quot;;

	//LOAD DESCRIPTION FROM BLOGINFO
	$description = bloginfo('description');
}
elseif(is_single())
{
	//LOAD POST TITLE AS DESCRIPTION
	$description = $post-&gt;post_title;

	//BUILD LIST OF KEYWORDS FROM TAGS
	$tags = wp_get_post_tags($post-&gt;ID);
	foreach($tags as $tag)
		$keywords = $keywords . $tag-&gt;name . &quot;, &quot;;
}
elseif(is_category())
{
	//LOAD CATEGORY DESCRIPTION
	$keywords = single_cat_title('', false);
	$description = category_description();
}
?&gt;
&lt;meta name=&quot;keywords&quot; content=&quot;&lt;?php echo $keywords ?&gt;&quot; /&gt;
&lt;meta name=&quot;description&quot; content=&quot;&lt;?php echo $description ?&gt;&quot; /&gt;
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Wordpress%20Keywords%20and%20Description%20Meta%20Tags%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fwordpress-keywords-and-description-meta-tags%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fwordpress-keywords-and-description-meta-tags%2F&amp;title=Wordpress%20Keywords%20and%20Description%20Meta%20Tags&amp;bodytext=The%20code%20below%20allows%20you%20to%20add%20keywoards%20and%20description%20meta%20tags%20to%20any%20wordpress%20theme.%20%20Simple%20copy%20the%20below%20code%20and%20insert%20it%20into%20the%20header.php%20of%20your%20theme%20somewhere%20inside%20of%20the%20%26lt%3Bhead%26gt%3B%26lt%3B%2Fhead%26gt%3B%20tag.%0D%0A%0D%0AYou%20could%20also%20simply%20d" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fwordpress-keywords-and-description-meta-tags%2F&amp;title=Wordpress%20Keywords%20and%20Description%20Meta%20Tags" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fwordpress-keywords-and-description-meta-tags%2F&amp;title=Wordpress%20Keywords%20and%20Description%20Meta%20Tags&amp;notes=The%20code%20below%20allows%20you%20to%20add%20keywoards%20and%20description%20meta%20tags%20to%20any%20wordpress%20theme.%20%20Simple%20copy%20the%20below%20code%20and%20insert%20it%20into%20the%20header.php%20of%20your%20theme%20somewhere%20inside%20of%20the%20%26lt%3Bhead%26gt%3B%26lt%3B%2Fhead%26gt%3B%20tag.%0D%0A%0D%0AYou%20could%20also%20simply%20d" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/wordpress-keywords-and-description-meta-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String Truncating Extension</title>
		<link>http://michael.chanceyjr.com/useful-code/string-truncating-extension/</link>
		<comments>http://michael.chanceyjr.com/useful-code/string-truncating-extension/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 10:12:00 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Truncate]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=539</guid>
		<description><![CDATA[This is a simple extension to truncate strings on whole words.  If it can not find a whole word to truncate on then it will fall back to breaking a word up.  You can also pass a string to append to the end of the truncated string.  Other then that there is [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple extension to truncate strings on whole words.  If it can not find a whole word to truncate on then it will fall back to breaking a word up.  You can also pass a string to append to the end of the truncated string.  Other then that there is not a whole lot to say about this one.</p>
<h3>//Code</h3>
<hr/>
<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// TRUNCATES A STRING PREFERRING WHOLE WORD OVER NON WHOLE WORD
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING STRING TO TRUNCATE&lt;/param&gt;
        /// &lt;param name=&quot;len&quot;&gt;LENGTH IN WHICH TO TRUNCATE TO&lt;/param&gt;
        /// &lt;param name=&quot;postTruncate&quot;&gt;ANYTHING TO ADD TO A TRUNCATED STRING SUCH AS ...&lt;/param&gt;
        /// &lt;returns&gt;TRUNCATED STRING WITH POST TRUNCATE ADDED TO IT&lt;/returns&gt;
        public static string Truncate(this string s, int len, string postTruncate)
        {
            //IF THE STRING IS SMALLER THEN THE LENGTH JUST RETURN THE STRING
            if (s == null || s.Length &lt; len)
                return s;
            else
            {
                //INCASE NULL HAS BEEN PASSED IN CHANGE IT TO EMPTY STRING SO IT HAS A COUNT
                if (postTruncate == null)
                    postTruncate = string.Empty;

                //RETURN THE TRUNCATED STRING BACK TO CALLING FUNCTION
                string tmpReturn = string.Concat(Regex.Match(String.Concat(s, &quot; &quot;), string.Format(&quot;^(?&lt;tmpMatch&gt;.{{0,{0}}})\\s&quot;, len)).Groups[&quot;tmpMatch&quot;].Value, postTruncate);

                //IF THE WHOLE WORD TRUNCATE WORKED THEN USE IT OTHERWISE USE NON WHOLE WORD TRUNCATE
                if (tmpReturn != postTruncate)
                    return tmpReturn;
                else
                    return string.Concat(Regex.Match(String.Concat(s, &quot; &quot;), string.Format(&quot;^(?&lt;tmpMatch&gt;.{{0,{0}}})&quot;, len)).Groups[&quot;tmpMatch&quot;].Value, postTruncate);
            }
        }
</pre>
<h3>//Usage</h3>
<hr/>
<pre class="brush: csharp;">
    class Program
    {
        static void Main(string[] args)
        {
            //OUTPUT WILL BE &quot;Hello, World...&quot;
            Console.WriteLine(&quot;Hello, World this is some long text to truncate&quot;.Truncate(15, &quot;...&quot;));
            Console.ReadLine();
        }
    }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=String%20Truncating%20Extension%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-truncating-extension%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-truncating-extension%2F&amp;title=String%20Truncating%20Extension&amp;bodytext=This%20is%20a%20simple%20extension%20to%20truncate%20strings%20on%20whole%20words.%20%20If%20it%20can%20not%20find%20a%20whole%20word%20to%20truncate%20on%20then%20it%20will%20fall%20back%20to%20breaking%20a%20word%20up.%20%20You%20can%20also%20pass%20a%20string%20to%20append%20to%20the%20end%20of%20the%20truncated%20string.%20%20Other%20then%20that%20th" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-truncating-extension%2F&amp;title=String%20Truncating%20Extension" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-truncating-extension%2F&amp;title=String%20Truncating%20Extension&amp;notes=This%20is%20a%20simple%20extension%20to%20truncate%20strings%20on%20whole%20words.%20%20If%20it%20can%20not%20find%20a%20whole%20word%20to%20truncate%20on%20then%20it%20will%20fall%20back%20to%20breaking%20a%20word%20up.%20%20You%20can%20also%20pass%20a%20string%20to%20append%20to%20the%20end%20of%20the%20truncated%20string.%20%20Other%20then%20that%20th" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/string-truncating-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Password Complexity</title>
		<link>http://michael.chanceyjr.com/useful-code/testing-password-complexity/</link>
		<comments>http://michael.chanceyjr.com/useful-code/testing-password-complexity/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 05:15:17 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Password Complexity]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=534</guid>
		<description><![CDATA[Password complexity is a huge deal when a company is applying for its compliance so below is a simple function to test for password complexity based on a rule set passed in.  The following code allows for any of the following rules to be applied to a password.  You can elect to require [...]]]></description>
			<content:encoded><![CDATA[<p>Password complexity is a huge deal when a company is applying for its compliance so below is a simple function to test for password complexity based on a rule set passed in.  The following code allows for any of the following rules to be applied to a password.  You can elect to require any or all of the following 1 upper case character, 1 lower case character, 1 numeric character and 1 special character.</p>
<h3>//Function</h3>
<hr/>
<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// FUNCTION FOR TESTING PASSWORD COMPLEXITY
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING PASSWORD TO TEST&lt;/param&gt;
        /// &lt;param name=&quot;minLength&quot;&gt;MIN LENGTH OF PASSWORD&lt;/param&gt;
        /// &lt;param name=&quot;maxLength&quot;&gt;MAX LENGTH OF PASSWORD&lt;/param&gt;
        /// &lt;param name=&quot;rule&quot;&gt;COMPARISON FLAGS CAN BE ANY COMBINATION OF THE FOLLOWING - UPPER, LOWER, NUMERIC, SPECIAL&lt;/param&gt;
        /// &lt;returns&gt;TRUE OR FALSE IF THE PASSWORD PASSES OR NOT&lt;/returns&gt;
        static bool ValidatePasswordComplexity(string s, int minLength, int maxLength, PasswordRules rule)
        {
            //CONSTANTS FOR COMPARISON GROUPS
            const string UPPER = &quot;(?=.*[A-Z])&quot;;
            const string LOWER = &quot;(?=.*[a-z])&quot;;
            const string NUMERIC = &quot;(?=.*[0-9])&quot;;
            const string SPECIAL = &quot;(?=.*[!@#$%^&amp;*()&lt;&gt;])&quot;;

            //CREATE A NEW VAR TO HOLD THE COMPARE STRING WHILE ITS ASSEMBLED
            StringBuilder tmpCompare = new StringBuilder(&quot;^&quot;);

            //CHECK IF UPPER IS A REQUIREMENT
            if ((rule &amp; PasswordRules.Upper) == PasswordRules.Upper)
                tmpCompare.Append(UPPER);

            //CHECK IF LOWER IS A REQUIREMENT
            if ((rule &amp; PasswordRules.Lower) == PasswordRules.Lower)
                tmpCompare.Append(LOWER);

            //CHECK IF NUMERIC IS A REQUIREMENT
            if ((rule &amp; PasswordRules.Numeric) == PasswordRules.Numeric)
                tmpCompare.Append(NUMERIC);

            //CHECK IF SPECIAL IS A REQUIREMENT
            if ((rule &amp; PasswordRules.Special) == PasswordRules.Special)
                tmpCompare.Append(SPECIAL);

            //APPEND THE LENGTH REQUIREMENTS
            tmpCompare.Append(string.Format(&quot;.{{{0},{1}}}&quot;, minLength, maxLength));

            //RETURN THE RESULT OF THE COMPARISON
            return Regex.Match(s, tmpCompare.ToString()).Success;
        }

        /// &lt;summary&gt;
        /// ERNUMERATIONS FOR PASSWORD COMPLEXITY TESTING
        /// &lt;/summary&gt;
        [Flags]
        public enum PasswordRules
        {
            Upper = 1,
            Lower = 2,
            Numeric = 4,
            Special = 8,
        }
</pre>
<h3>//Usage</h3>
<hr/>
<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// MAIN APPLICATION ENTRY POINT
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;args&quot;&gt;&lt;/param&gt;
        static void Main(string[] args)
        {
            //SOMETHING TO COMPARE
            string pwd = &quot;Password1&quot;;

            //TWO DIFFERENT SAMPLES TO SHOW THE PASSWORD MEETS THE REQUIREMENTS IF YOU ARE NOT LOOKING FOR A SPECIAL CHARACTER
            //BUT FAILS ONCE THE SPECIAL REQUIREMENT IS ADDED TO THE PARAMETER
            Console.WriteLine(&quot;{0}: {1}&quot;, pwd, ValidatePasswordComplexity(pwd, 6, 15, PasswordRules.Upper | PasswordRules.Lower | PasswordRules.Numeric));
            Console.WriteLine(&quot;{0}: {1}&quot;, pwd, ValidatePasswordComplexity(pwd, 6, 15, PasswordRules.Upper | PasswordRules.Lower | PasswordRules.Numeric | PasswordRules.Special));

            //WAIT FOR USER INPUT
            Console.ReadLine();
        }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Testing%20Password%20Complexity%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftesting-password-complexity%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftesting-password-complexity%2F&amp;title=Testing%20Password%20Complexity&amp;bodytext=Password%20complexity%20is%20a%20huge%20deal%20when%20a%20company%20is%20applying%20for%20its%20compliance%20so%20below%20is%20a%20simple%20function%20to%20test%20for%20password%20complexity%20based%20on%20a%20rule%20set%20passed%20in.%20%20The%20following%20code%20allows%20for%20any%20of%20the%20following%20rules%20to%20be%20applied%20to%20a" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftesting-password-complexity%2F&amp;title=Testing%20Password%20Complexity" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftesting-password-complexity%2F&amp;title=Testing%20Password%20Complexity&amp;notes=Password%20complexity%20is%20a%20huge%20deal%20when%20a%20company%20is%20applying%20for%20its%20compliance%20so%20below%20is%20a%20simple%20function%20to%20test%20for%20password%20complexity%20based%20on%20a%20rule%20set%20passed%20in.%20%20The%20following%20code%20allows%20for%20any%20of%20the%20following%20rules%20to%20be%20applied%20to%20a" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/testing-password-complexity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Human Readable Size Formatting Extension</title>
		<link>http://michael.chanceyjr.com/useful-code/human-readable-size-formatting-extension/</link>
		<comments>http://michael.chanceyjr.com/useful-code/human-readable-size-formatting-extension/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:34:17 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Numeric]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=521</guid>
		<description><![CDATA[This is a simple extension to turn unreadable sizes into something that makes more sense to the human eye.  This will convert 1024 into 1KB or 1099511627776 into 1GB.  This is by no means perfect, some additions could be made such as adding ,&#8217;s to separate the digits into proper grouping.  Having [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple extension to turn unreadable sizes into something that makes more sense to the human eye.  This will convert 1024 into 1KB or 1099511627776 into 1GB.  This is by no means perfect, some additions could be made such as adding ,&#8217;s to separate the digits into proper grouping.  Having said that most of the time grouping will be removed because numbers which should be grouped soon fall into the next sizing segment, meaning 1,000B becomes 1KB after only 24 more bytes.</p>
<h3>//Code</h3>
<hr/>
<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// MAIN TO HUMAN READABLE FUNCTION TO CONVERT DOUBLES INTO XB, XKB, XMB, XGB
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;x&quot;&gt;INCOMING NUMBER TO MAKE READABLE&lt;/param&gt;
        /// &lt;returns&gt;HUMAN READABLE SIZE FORMAT SUCH AS 1MB&lt;/returns&gt;
        public static string ToHumanReadable(this double x)
        {
            //CONSTANTS FOR SIZING
            double KB = 1024;
            double MB = 1024 * KB;
            double GB = 1024 * MB;

            if (x &lt; KB)
                return string.Format(&quot;{0}B&quot;, x);
            else if (x &lt; MB)
            {
                return string.Format(&quot;{0:0.##}KB&quot;, x / KB);
            }
            else if (x &lt; GB)
            {
                return string.Format(&quot;{0:0.##}MB&quot;, x / MB);
            }
            else if (x &gt;= GB)
            {
                return string.Format(&quot;{0:0.##}GB&quot;, x / GB);
            }
            else
            {
                //HACK: GET RID OF COMPILER ERROR BECAUSE IT BELEIVES NOT ALL PATHS RETURN A VALUE
                return null;
            }
        }

        /// &lt;summary&gt;
        /// EXTENSION FOR LONG TO MAKE HUMAN READABLE
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;x&quot;&gt;INCOMING NUMBER TO MAKE READABLE&lt;/param&gt;
        /// &lt;returns&gt;HUMAN READABLE SIZE FORMAT SUCH AS 1MB&lt;/returns&gt;
        public static string ToHumanReadable(this long x)
        {
            return ToHumanReadable((double)x);
        }

        /// &lt;summary&gt;
        /// EXTENSION FOR INT TO MAKE HUMAN READABLE
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;x&quot;&gt;INCOMING NUMBER TO MAKE READABLE&lt;/param&gt;
        /// &lt;returns&gt;HUMAN READABLE SIZE FORMAT SUCH AS 1MB&lt;/returns&gt;
        public static string ToHumanReadable(this int x)
        {
            return ToHumanReadable((double)x);
        }

        /// &lt;summary&gt;
        /// EXTENSION FOR SINGLE TO MAKE HUMAN READABLE
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;x&quot;&gt;INCOMING NUMBER TO MAKE READABLE&lt;/param&gt;
        /// &lt;returns&gt;HUMAN READABLE SIZE FORMAT SUCH AS 1MB&lt;/returns&gt;
        public static string ToHumanReadable(this Single x)
        {
            return ToHumanReadable((double)x);
        }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Human%20Readable%20Size%20Formatting%20Extension%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fhuman-readable-size-formatting-extension%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fhuman-readable-size-formatting-extension%2F&amp;title=Human%20Readable%20Size%20Formatting%20Extension&amp;bodytext=This%20is%20a%20simple%20extension%20to%20turn%20unreadable%20sizes%20into%20something%20that%20makes%20more%20sense%20to%20the%20human%20eye.%20%20This%20will%20convert%201024%20into%201KB%20or%201099511627776%20into%201GB.%20%20This%20is%20by%20no%20means%20perfect%2C%20some%20additions%20could%20be%20made%20such%20as%20adding%20%2C%27s%20to%20se" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fhuman-readable-size-formatting-extension%2F&amp;title=Human%20Readable%20Size%20Formatting%20Extension" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fhuman-readable-size-formatting-extension%2F&amp;title=Human%20Readable%20Size%20Formatting%20Extension&amp;notes=This%20is%20a%20simple%20extension%20to%20turn%20unreadable%20sizes%20into%20something%20that%20makes%20more%20sense%20to%20the%20human%20eye.%20%20This%20will%20convert%201024%20into%201KB%20or%201099511627776%20into%201GB.%20%20This%20is%20by%20no%20means%20perfect%2C%20some%20additions%20could%20be%20made%20such%20as%20adding%20%2C%27s%20to%20se" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/human-readable-size-formatting-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interapplication Communication with Named Pipes</title>
		<link>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/</link>
		<comments>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 16:30:00 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[Application Communication]]></category>
		<category><![CDATA[Background Communication]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Named Pipes]]></category>
		<category><![CDATA[Stream]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=506</guid>
		<description><![CDATA[Ever make two separate applications but need them to be able to send information back and forth.  Say an Instant Messenger and a Business app which need direct integration between one another.  Named pipes is a pretty simple solution to achieve this.  .NET 3.5 has made this much simpler by including Named [...]]]></description>
			<content:encoded><![CDATA[<p>Ever make two separate applications but need them to be able to send information back and forth.  Say an Instant Messenger and a Business app which need direct integration between one another.  Named pipes is a pretty simple solution to achieve this.  .NET 3.5 has made this much simpler by including Named Pipes in its release, this used to be real nasty when trying to achieve this in any other language then C++.</p>
<h3>//Application</h3>
<hr/>
<pre class="brush: csharp;">
using System;
using System.IO;
using System.IO.Pipes;

class Program
{
    /// &lt;summary&gt;
    /// MAIN APPLICATION THREAD
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;args&quot;&gt;NOTHING IS ACCEPTED HERE&lt;/param&gt;
    static void Main(string[] args)
    {
        //HOLDS THE SECLECTION A USER MAKES AS TO WHAT THEY WANT TO RUN
        string tmpSelection = string.Empty;

        //ASK THE USER WHAT THEY WANT TO DO
        Console.Write(&quot;Please Enter A Selection 1(Server) or 2(Client): &quot;);
        tmpSelection = Console.ReadLine();

        //CLEAR THE SCREEN AND BEGIN RUNNING THE USERS SELECTION
        Console.Clear();
        if (tmpSelection == &quot;1&quot;)
        {
            //START A PIPE SERVER
            pipeServer();
        }
        else if (tmpSelection == &quot;2&quot;)
        {
            //START A PIPE CLIENT
            pipeClient();
        }
        else
        {
            //LET THE USER KNOW THEY HAVE MADE AN INVALID SELECTION
            Console.WriteLine(&quot;Invalid selection made.  This app will now close.&quot;);
            Console.ReadLine();
        }
    }

    /// &lt;summary&gt;
    /// RUNS A PIPE CLIENT FOR SENDING MESSAGES
    /// &lt;/summary&gt;
    private static void pipeClient()
    {
        //LET THE USER KNOW WHAT IS GOING ON
        Console.WriteLine(&quot;Starting Client!&quot;);

        //LOOP FOREVER FOR TESTING PURPOSES
        while (true)
        {
            //CREATE A CONNECTION TO A NAMED PIPE ON THE LOCAL MACHINE NAMED testPipe
            using (NamedPipeClientStream tmpPipe = new NamedPipeClientStream(&quot;.&quot;, &quot;testPipe&quot;, PipeDirection.Out))
            {
                string tmpSendMessage;

                //GET SOME TEXT TO SEND THROUGH THE PIPE
                Console.Write(&quot;Enter Some Text To Send: &quot;);
                tmpSendMessage = Console.ReadLine();

                //SEND THE MESSAGE THROUGH THE PIPE
                tmpPipe.Connect();
                using (TextWriter tmpWriter = new StreamWriter(tmpPipe))
                {
                    tmpWriter.WriteLine(tmpSendMessage);
                }
            }
        }
    }

    /// &lt;summary&gt;
    /// RUNS A PIPE SERVER FOR ACCEPTING MESSAGES
    /// &lt;/summary&gt;
    private static void pipeServer()
    {
        //LET THE USER KNOW WHAT IS GOING ON
        Console.WriteLine(&quot;Starting Server!&quot;);

        //LOOP FOREVER FOR TESTING PURPOSES
        while (true)
        {
            //CREATE A NAMED PIPE ON THE LOCAL MACHINE NAMED testPipe
            using (NamedPipeServerStream tmpPipe = new NamedPipeServerStream(&quot;testPipe&quot;, PipeDirection.In))
            {
                //READ THE DATA ON THE PIPE
                tmpPipe.WaitForConnection();
                using (TextReader tmpReader = new StreamReader(tmpPipe))
                {
                    Console.WriteLine(tmpReader.ReadLine());
                }
            }
        }
    }
}
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Interapplication%20Communication%20with%20Named%20Pipes%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes&amp;bodytext=Ever%20make%20two%20separate%20applications%20but%20need%20them%20to%20be%20able%20to%20send%20information%20back%20and%20forth.%20%20Say%20an%20Instant%20Messenger%20and%20a%20Business%20app%20which%20need%20direct%20integration%20between%20one%20another.%20%20Named%20pipes%20is%20a%20pretty%20simple%20solution%20to%20achieve%20this." title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes&amp;notes=Ever%20make%20two%20separate%20applications%20but%20need%20them%20to%20be%20able%20to%20send%20information%20back%20and%20forth.%20%20Say%20an%20Instant%20Messenger%20and%20a%20Business%20app%20which%20need%20direct%20integration%20between%20one%20another.%20%20Named%20pipes%20is%20a%20pretty%20simple%20solution%20to%20achieve%20this." title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Projection on Buildings</title>
		<link>http://michael.chanceyjr.com/internet-findings/3d-projection-on-buildings/</link>
		<comments>http://michael.chanceyjr.com/internet-findings/3d-projection-on-buildings/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 21:31:16 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Internet Findings]]></category>
		<category><![CDATA[Article]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=498</guid>
		<description><![CDATA[This is a must watch video. It is 3D animation/video that is projected on buildings by NuFormer Digital Media.

via 3D Projection on Buildings.



Share


	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>This is a must watch video. It is 3D animation/video that is projected on buildings by NuFormer Digital Media.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="288" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=4238052&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="500" height="288" src="http://vimeo.com/moogaloop.swf?clip_id=4238052&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowfullscreen="true"></embed></object></p>
<p>via <a href="http://www.ndesign-studio.com/blog/3d-projection-on-buildings">3D Projection on Buildings</a>.</p>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=3D%20Projection%20on%20Buildings%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Finternet-findings%2F3d-projection-on-buildings%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Finternet-findings%2F3d-projection-on-buildings%2F&amp;title=3D%20Projection%20on%20Buildings&amp;bodytext=This%20is%20a%20must%20watch%20video.%20It%20is%203D%20animation%2Fvideo%20that%20is%20projected%20on%20buildings%20by%20NuFormer%20Digital%20Media.%0D%0A%0D%0A%0D%0A%0D%0Avia%203D%20Projection%20on%20Buildings." title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Finternet-findings%2F3d-projection-on-buildings%2F&amp;title=3D%20Projection%20on%20Buildings" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Finternet-findings%2F3d-projection-on-buildings%2F&amp;title=3D%20Projection%20on%20Buildings&amp;notes=This%20is%20a%20must%20watch%20video.%20It%20is%203D%20animation%2Fvideo%20that%20is%20projected%20on%20buildings%20by%20NuFormer%20Digital%20Media.%0D%0A%0D%0A%0D%0A%0D%0Avia%203D%20Projection%20on%20Buildings." title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/internet-findings/3d-projection-on-buildings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling Code at Runtime</title>
		<link>http://michael.chanceyjr.com/useful-code/compiling-code-at-runtime/</link>
		<comments>http://michael.chanceyjr.com/useful-code/compiling-code-at-runtime/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 17:37:52 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Compiling Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Runtime]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=492</guid>
		<description><![CDATA[This little snippit has only ever been used once by me in an attempt to give the end user the ability to make adjustments to processing scripts.  It turned out to be a little bit of a headache because hoping your end user has the skill and ability to code in C# or any [...]]]></description>
			<content:encoded><![CDATA[<p>This little snippit has only ever been used once by me in an attempt to give the end user the ability to make adjustments to processing scripts.  It turned out to be a little bit of a headache because hoping your end user has the skill and ability to code in C# or any language for that matter is a bit troublesome.  Who knows though you might be able to use this as part of a Visual Studio addin which allows the user to customize the functionality to their likings.  In any event on to some code.</p>
<h3>//Class</h3>
<hr/>
<pre class="brush: csharp;">
    public static class AssemblyBuilder
    {
        /// &lt;summary&gt;
        /// COMPILE CODE INTO A MEMORY DLL
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;Code&quot;&gt;PLAIN TEXT OF THE CODE TO BE EXECUTED&lt;/param&gt;
        /// &lt;returns&gt;MEMORY DLL OF COMPILED CODE&lt;/returns&gt;
        static Assembly BuildAssembly(string Code)
        {
            CSharpCodeProvider tmpProvider = new CSharpCodeProvider();
            CompilerParameters tmpParams = new CompilerParameters() { GenerateExecutable = false, GenerateInMemory = true };

            //ADD ANY ADDITIONAL REFERENCES YOU MAY NEED HERE
            tmpParams.ReferencedAssemblies.Add(&quot;System.dll&quot;);
            tmpParams.ReferencedAssemblies.Add(&quot;System.Windows.Forms.dll&quot;);

            //ATTEMPT TO COMPILE THE CODE INTO A MEMORY DLL
            CompilerResults tmpResults = tmpProvider.CompileAssemblyFromSource(tmpParams, Code);

            //IF IT WORKED THEN RETURN THE COMPILED ASSEMBLY ELSE RETURN NOTHING
            if (!tmpResults.Errors.HasErrors)
                return tmpResults.CompiledAssembly;
            else
                return null;
        }

        /// &lt;summary&gt;
        /// COMPILE AND EXECUTE PLAIN TEXT AS THOUGH IT WERE A LOADED LIBRARY
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;code&quot;&gt;CODE TO COMPILE&lt;/param&gt;
        /// &lt;param name=&quot;namespacename&quot;&gt;NAMESPACE INSIDE THE CODE FROM WHICH TO EXECUTE&lt;/param&gt;
        /// &lt;param name=&quot;classname&quot;&gt;CLASS NAME INSIDE THE NAMESPACE FROM WHICH TO EXECUTE&lt;/param&gt;
        /// &lt;param name=&quot;functionname&quot;&gt;FUNCTION TO EXECUTE INSIDE OF THE CLASS&lt;/param&gt;
        /// &lt;param name=&quot;isstatic&quot;&gt;IS THE METHOD A STATIC METHOD OR AN INSTANCED METHOD&lt;/param&gt;
        /// &lt;param name=&quot;args&quot;&gt;ARRAY OF ARGUMENTS TO BE PASSED INTO THE FUNCTION WE ARE CALLING&lt;/param&gt;
        /// &lt;returns&gt;RETURNS ANY VALUE RETURNED BY THE FUNCTION THAT WAS CALLED&lt;/returns&gt;
        public static object ExecuteCode(string code, string namespacename, string classname, string functionname, bool isstatic, params object[] args)
        {
            Type tmpType = null;
            object tmpInstance = null;
            Assembly tmpAsm = BuildAssembly(code);

            //CHECK TO VERIFY THE BUILDASSEMBLY WORKED
            if (tmpAsm != null)
            {
                //IF THIS IS A STATIC METHOD WE CAN CALL IT DIRECTLY OTHERWISE WE NEED TO CREATE AN INSTANCE OF THE LIBRARY FIRST
                if (isstatic)
                {
                    tmpType = tmpAsm.GetType(namespacename + &quot;.&quot; + classname);
                }
                else
                {
                    tmpInstance = tmpAsm.CreateInstance(namespacename + &quot;.&quot; + classname);
                    tmpType = tmpInstance.GetType();
                }

                //FIND THE METHOD WE WISH TO EXECUTE
                MethodInfo method = tmpType.GetMethod(functionname);

                //RETURN WHATEVER VALUE COMES BACK FROM THE FUNCTION CALL
                return method.Invoke(tmpInstance, args);
            }
            else
            {
                return null;
            }
        }
    }
</pre>
<h3>//Usage</h3>
<hr/>
<pre class="brush: csharp;">
            string plainTextCode = &quot;using System.Windows.Forms;namespace Test{public class Test	{public void Main(){MessageBox.Show(\&quot;Testing!\&quot;, \&quot;Test Title\&quot;);	}}}&quot;;
            AssemblyBuilder.ExecuteCode(plainTextCode, &quot;Test&quot;, &quot;Test&quot;, &quot;Main&quot;, false, new object[]{});
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Compiling%20Code%20at%20Runtime%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompiling-code-at-runtime%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompiling-code-at-runtime%2F&amp;title=Compiling%20Code%20at%20Runtime&amp;bodytext=This%20little%20snippit%20has%20only%20ever%20been%20used%20once%20by%20me%20in%20an%20attempt%20to%20give%20the%20end%20user%20the%20ability%20to%20make%20adjustments%20to%20processing%20scripts.%20%20It%20turned%20out%20to%20be%20a%20little%20bit%20of%20a%20headache%20because%20hoping%20your%20end%20user%20has%20the%20skill%20and%20ability%20to" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompiling-code-at-runtime%2F&amp;title=Compiling%20Code%20at%20Runtime" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompiling-code-at-runtime%2F&amp;title=Compiling%20Code%20at%20Runtime&amp;notes=This%20little%20snippit%20has%20only%20ever%20been%20used%20once%20by%20me%20in%20an%20attempt%20to%20give%20the%20end%20user%20the%20ability%20to%20make%20adjustments%20to%20processing%20scripts.%20%20It%20turned%20out%20to%20be%20a%20little%20bit%20of%20a%20headache%20because%20hoping%20your%20end%20user%20has%20the%20skill%20and%20ability%20to" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/compiling-code-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Execution Timer For Helping With Efficiency</title>
		<link>http://michael.chanceyjr.com/useful-code/execution-timer-for-helping-with-efficiency/</link>
		<comments>http://michael.chanceyjr.com/useful-code/execution-timer-for-helping-with-efficiency/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:00:26 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=481</guid>
		<description><![CDATA[This class is useful when checking times which functions take to execute.  Simply instantiate this class and when you are done timing call the StopTimer function and then you can display how long something too to execute.  I use this class all over the place when I have three different ideas but am [...]]]></description>
			<content:encoded><![CDATA[<p>This class is useful when checking times which functions take to execute.  Simply instantiate this class and when you are done timing call the StopTimer function and then you can display how long something too to execute.  I use this class all over the place when I have three different ideas but am not sure which one will execute faster.</p>
<h3>//Class</h3>
<hr/>
<pre class="brush: csharp;">
    class ExecutionTimer
    {
        //PRIVATE VARIABLES FOR HOLDING THE TIME INFORMATION
        private long startTime;
        private long stopTime;

        //DEFAULT CONSTRUCTOR JUST CALLS THE START TIMER
        public ExecutionTimer()
        {
            StartTimer();
        }

        /// &lt;summary&gt;
        /// MARK THE START TIME FOR CALCULATIONS
        /// &lt;/summary&gt;
        public void StartTimer()
        {
            startTime = DateTime.Now.Ticks;
        }

        /// &lt;summary&gt;
        /// MARK THE STOP TIME FOR CALCULATIONS
        /// &lt;/summary&gt;
        public void StopTimer()
        {
            stopTime = DateTime.Now.Ticks;
        }

        /// &lt;summary&gt;
        /// DEFAULT OVERRIDE OF TOSTRING TO FORMAT THE OUTPUT AS A VALID TIME STRING
        /// &lt;/summary&gt;
        /// &lt;returns&gt;FORMATTED TIME STRING IN FORMAT OF HH:MM:SS.MILISECONDS&lt;/returns&gt;
        public override string ToString()
        {
            return ToString(1);
        }

        /// &lt;summary&gt;
        /// OUTPUT THE STRING USING AN AVERAGE COUNTER INCASE THE USER RAN THE TRACKING MORE THEN ONCE WE NEED TO AVG THE TIME
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;avg&quot;&gt;DIVISOR&lt;/param&gt;
        /// &lt;returns&gt;FORMATTED TIME STRING IN FORMAT OF HH:MM:SS.MILISECONDS AVERAGED OVER X ATTEMPTS&lt;/returns&gt;
        public string ToString(long avg)
        {
            //VERIFY THAT AVG IS A VALID VALUE
            if (avg == 0)
                throw new ArgumentException(&quot;Avg can not be 0&quot;, &quot;avg&quot;);

            //RETURN THE FORMATTED STRING FROM THE NEW DATE
            return string.Format(&quot;{0:HH:mm:ss.ff}&quot;, new DateTime((stopTime - startTime) / avg));
        }
    }
</pre>
<h3>//Usage</h3>
<hr/>
<pre class="brush: csharp;">
    class Program
    {
        static void Main(string[] args)
        {
            ExecutionTimer tmpTimer = new ExecutionTimer();
            System.Threading.Thread.Sleep(5500);
            tmpTimer.StopTimer();
        }
    }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Execution%20Timer%20For%20Helping%20With%20Efficiency%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fexecution-timer-for-helping-with-efficiency%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fexecution-timer-for-helping-with-efficiency%2F&amp;title=Execution%20Timer%20For%20Helping%20With%20Efficiency&amp;bodytext=This%20class%20is%20useful%20when%20checking%20times%20which%20functions%20take%20to%20execute.%20%20Simply%20instantiate%20this%20class%20and%20when%20you%20are%20done%20timing%20call%20the%20StopTimer%20function%20and%20then%20you%20can%20display%20how%20long%20something%20too%20to%20execute.%20%20I%20use%20this%20class%20all%20over%20t" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fexecution-timer-for-helping-with-efficiency%2F&amp;title=Execution%20Timer%20For%20Helping%20With%20Efficiency" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fexecution-timer-for-helping-with-efficiency%2F&amp;title=Execution%20Timer%20For%20Helping%20With%20Efficiency&amp;notes=This%20class%20is%20useful%20when%20checking%20times%20which%20functions%20take%20to%20execute.%20%20Simply%20instantiate%20this%20class%20and%20when%20you%20are%20done%20timing%20call%20the%20StopTimer%20function%20and%20then%20you%20can%20display%20how%20long%20something%20too%20to%20execute.%20%20I%20use%20this%20class%20all%20over%20t" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/execution-timer-for-helping-with-efficiency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String Encryption and Decryption Extension</title>
		<link>http://michael.chanceyjr.com/useful-code/string-encryption-and-decryption-extension/</link>
		<comments>http://michael.chanceyjr.com/useful-code/string-encryption-and-decryption-extension/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 05:26:53 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[AES Encryption]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Decryption]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Extension]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=458</guid>
		<description><![CDATA[This extension is a little longer then usual and it also has a few supporting extensions which are required to make it run; I have included all of which in this post.  I wrote a few extras to just make some of the code a little bit shorter and neater.  The first is [...]]]></description>
			<content:encoded><![CDATA[<p>This extension is a little longer then usual and it also has a few supporting extensions which are required to make it run; I have included all of which in this post.  I wrote a few extras to just make some of the code a little bit shorter and neater.  The first is Reverse which like the name implies reverses an incoming string.  The second is ToByteArray which converts a string to a Byte Array.  The third is ConvertToString which does the exact opposite of ToByteArray by converting a Byte Array back into a string.</p>
<h3>//Code</h3>
<hr/>
<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// ENCRYPTS A STRING USING AES ENCRYPTION AND A PASSWORD
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING STRING TO ENCRYPT&lt;/param&gt;
        /// &lt;param name=&quot;password&quot;&gt;PASSWORD TO USE FOR ENCRYPTION&lt;/param&gt;
        /// &lt;returns&gt;BASE64 ENCODED ENCRYPTED STRING&lt;/returns&gt;
        public static string EncryptString(this string s, string password)
        {
            //CREATE AN AES CRYPTOGRAPHY CLASS
            using (Aes tmpAes = AesCryptoServiceProvider.Create())
            {
                //CREATE A PASSWORD DERIVED BYTES CLASS TO CONVERT A SIMPLE PASSWORD INTO SOMETHING MORE COMPLEX
                PasswordDeriveBytes tmpPasswordBytes = new PasswordDeriveBytes(password.ToByteArray(), password.Reverse().ToByteArray());

                //CREATE A ICRYPTO TRANSFORM PROVIDER USING 256 BITS FOR THE KEY WHICH IS DERIVED FROM THE PASSWORD PASSED IN
                using (ICryptoTransform tmpCrypto = tmpAes.CreateEncryptor(tmpPasswordBytes.GetBytes(256 / 8), tmpPasswordBytes.GetBytes(16)))
                {
                    //CREATE A TEMPORARY MEMORY STREAM TO HOLD THE DATA WHICH IS BEING ENCRYPTED
                    using (MemoryStream tmpMemoryStream = new MemoryStream())
                    {
                        //CREATE THE CRYPTO STREAM WHICH WILL WRITE TO THE UNDERLYING MEMORY STREAM
                        using (CryptoStream tmpStream = new CryptoStream(tmpMemoryStream, tmpCrypto, CryptoStreamMode.Write))
                        {
                            tmpStream.Write(s.ToByteArray(), 0, s.Length);
                            tmpStream.Flush();
                        }

                        //CONVERT THE DATA TO A BASE64 STRING SO WE HAVE ALL VALID CHARACTERS IN THE STRING
                        return Convert.ToBase64String(tmpMemoryStream.ToArray());
                    }
                }
            }
        }

        /// &lt;summary&gt;
        /// DECRYPTS A BASE64 ENCODED STRING USING AES AND PASSWORD
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING BASE64 ENCODED STRING TO DECRYPT&lt;/param&gt;
        /// &lt;param name=&quot;password&quot;&gt;PASSWORD USED DURING THE ENCRYPTION PROCESS TO REVERSE THE SEQUENCE&lt;/param&gt;
        /// &lt;returns&gt;ORIGINAL STRING PRIOR TO ENCRYPTION&lt;/returns&gt;
        public static string DecryptString(this string s, string password)
        {
            //CREATE AN AES CRYPTOGRAPHY CLASS
            using (Aes tmpAes = AesCryptoServiceProvider.Create())
            {
                //CREATE A PASSWORD DERIVED BYTES CLASS TO CONVERT A SIMPLE PASSWORD INTO SOMETHING MORE COMPLEX
                PasswordDeriveBytes tmpPasswordBytes = new PasswordDeriveBytes(password.ToByteArray(), password.Reverse().ToByteArray());

                //CREATE A ICRYPTO TRANSFORM PROVIDER USING 256 BITS FOR THE KEY WHICH IS DERIVED FROM THE PASSWORD PASSED IN
                using (ICryptoTransform tmpCrypto = tmpAes.CreateDecryptor(tmpPasswordBytes.GetBytes(256 / 8), tmpPasswordBytes.GetBytes(16)))
                {
                    //CREATE A MEMORY STREAM FROM THE BASE64 STRING WHICH IS BEING PASSED IN
                    using (MemoryStream tmpMemoryStream = new MemoryStream(Convert.FromBase64String(s)))
                    {
                        //CREATE A NEW STREAM WHICH WILL DECRYPT THE DATA AS WE READ IT
                        using (CryptoStream tmpStream = new CryptoStream(tmpMemoryStream, tmpCrypto, CryptoStreamMode.Read))
                        {
                            int readCount;
                            byte[] tmpBuffer = new byte[1024];
                            StringBuilder tmpReturn = new StringBuilder();

                            //CATCH THE ERROR INCASE THE PASSWORD IS INVALID
                            try
                            {
                                //AS LONG AS THEIR IS DATA ON THE STREAM KEEP READING
                                while ((readCount = tmpStream.Read(tmpBuffer, 0, tmpBuffer.Length)) != 0)
                                {
                                    tmpReturn.Append(tmpBuffer.Take(readCount).ToArray().ConvertToString());
                                }

                                //RETURN THE DECRYPTED STRING VALUE
                                return tmpReturn.ToString();
                            }
                            catch (CryptographicException ex)
                            {
                                return &quot;&quot;;
                            }
                        }
                    }
                }
            }
        }

        #region &quot;Supporting Extensions&quot;
        /// &lt;summary&gt;
        /// CONVERT AN ARRAY OF BYTES INTO THE UTF8 STRING
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;b&quot;&gt;ARRAY OF BYTES COMING IN&lt;/param&gt;
        /// &lt;returns&gt;STRING REPRESENTATION OF THE BYTES PASSED IN&lt;/returns&gt;
        public static string ConvertToString(this byte[] b)
        {
            return System.Text.ASCIIEncoding.UTF8.GetString(b);
        }

        /// &lt;summary&gt;
        /// REVERSES A STRING
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING STRING TO REVERSE&lt;/param&gt;
        /// &lt;returns&gt;REVERSED STRING&lt;/returns&gt;
        public static string Reverse(this string s)
        {
            StringBuilder tmpReturn = new StringBuilder();

            //LOOP THROUGH EACH CHARACTER FROM BACK TO FRONT AND INSERT IT INTO THE BUILDER
            for (int i = s.Length - 1; i &gt;= 0; i--)
                tmpReturn.Append(s[i]);

            //RETURN THE REVERSED STRING TO THE CALLING FUNCTION
            return tmpReturn.ToString();
        }

        /// &lt;summary&gt;
        /// CONVERTS A STRING INTO UTF8 ENCODED BYTE ARRAY
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;INCOMING STRING TO CONVERT&lt;/param&gt;
        /// &lt;returns&gt;BYTE ARRAY OF THE INCOMING STRING&lt;/returns&gt;
        public static byte[] ToByteArray(this string s)
        {
            //CONVERT THE STRING TO A BYTE ARRAY
            return System.Text.ASCIIEncoding.UTF8.GetBytes(s);
        }
        #endregion
</pre>
<h3>//Usage</h3>
<hr/>
<pre class="brush: csharp;">
    class Program
    {
        static void Main(string[] args)
        {
            string tmpEnc = &quot;Hello, World!&quot;.EncryptString(&quot;password&quot;);
            string tmpDec = tmpEnc.DecryptString(&quot;password&quot;);

            Console.WriteLine(&quot;{0}\n{1}&quot;, tmpEnc, tmpDec);
            Console.ReadLine();
        }
    }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=String%20Encryption%20and%20Decryption%20Extension%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-encryption-and-decryption-extension%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-encryption-and-decryption-extension%2F&amp;title=String%20Encryption%20and%20Decryption%20Extension&amp;bodytext=This%20extension%20is%20a%20little%20longer%20then%20usual%20and%20it%20also%20has%20a%20few%20supporting%20extensions%20which%20are%20required%20to%20make%20it%20run%3B%20I%20have%20included%20all%20of%20which%20in%20this%20post.%20%20I%20wrote%20a%20few%20extras%20to%20just%20make%20some%20of%20the%20code%20a%20little%20bit%20shorter%20and%20neater" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-encryption-and-decryption-extension%2F&amp;title=String%20Encryption%20and%20Decryption%20Extension" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fstring-encryption-and-decryption-extension%2F&amp;title=String%20Encryption%20and%20Decryption%20Extension&amp;notes=This%20extension%20is%20a%20little%20longer%20then%20usual%20and%20it%20also%20has%20a%20few%20supporting%20extensions%20which%20are%20required%20to%20make%20it%20run%3B%20I%20have%20included%20all%20of%20which%20in%20this%20post.%20%20I%20wrote%20a%20few%20extras%20to%20just%20make%20some%20of%20the%20code%20a%20little%20bit%20shorter%20and%20neater" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/string-encryption-and-decryption-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
