<?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>Unknown Programmer</title>
	<atom:link href="http://unknownprogrammer.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://unknownprogrammer.com</link>
	<description>The Joe Coder</description>
	<lastBuildDate>Sat, 10 Mar 2012 09:01:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Darker Shade of the PhoneAccentBrush</title>
		<link>http://unknownprogrammer.com/2011/10/darker-shade-of-the-phoneaccentbrush/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=darker-shade-of-the-phoneaccentbrush</link>
		<comments>http://unknownprogrammer.com/2011/10/darker-shade-of-the-phoneaccentbrush/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 10:54:56 +0000</pubDate>
		<dc:creator>unknown</dc:creator>
				<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[application resources]]></category>
		<category><![CDATA[phoneaccentbrush]]></category>
		<category><![CDATA[solidcolorbrush]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://unknownprogrammer.com/?p=50</guid>
		<description><![CDATA[While working with a darker shade of the phoneaccentbrush, I needed to maintain the uniformity of the shade across different PhoneAccentBrushes available. To do this, I used the PhoneAccentBrush SolidColorBrush and added the generated brush to the application resources. Here &#8230; <a href="http://unknownprogrammer.com/2011/10/darker-shade-of-the-phoneaccentbrush/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working with a darker shade of the phoneaccentbrush, I needed to maintain the uniformity of the shade across<br />
different PhoneAccentBrushes available. To do this, I used the PhoneAccentBrush SolidColorBrush and added the generated brush to the application resources. Here is how I did it.</p>
<p>In ShadeHelper.cs,</p>
<pre class="wp-code-highlight prettyprint">public static SolidColorBrush getDarkerShade(SolidColorBrush brush)
        {
            SolidColorBrush darkerShade = new SolidColorBrush();
            byte alpha = 255;
            byte red = (byte)(brush.Color.R - (brush.Color.R*0.4));
            byte blue = (byte)(brush.Color.B - (brush.Color.B * 0.4));
            byte green = (byte)(brush.Color.G - (brush.Color.G * 0.4));
            darkerShade.Color = Color.FromArgb(alpha, red, green, blue);
            return darkerShade;
        }</pre>
<p>In App.xaml.cs,</p>
<pre class="wp-code-highlight prettyprint">Resources.Add(&quot;PhoneDarkAccentBrush&quot;, ShadeHelper.getDarkerShade((Resources[&quot;PhoneAccentBrush&quot;] as SolidColorBrush)));</pre>
<p>Usage:</p>
<pre class="wp-code-highlight prettyprint">&lt;TextBlock x:Name=&quot;darkAccent&quot; Foreground={StaticResource PhoneDarkAccentBrush} Text=&quot;Darker Accent&quot; /&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://unknownprogrammer.com/2011/10/darker-shade-of-the-phoneaccentbrush/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>User defined variable names in ruby</title>
		<link>http://unknownprogrammer.com/2011/10/user-defined-variable-names-in-ruby/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=user-defined-variable-names-in-ruby</link>
		<comments>http://unknownprogrammer.com/2011/10/user-defined-variable-names-in-ruby/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 10:55:56 +0000</pubDate>
		<dc:creator>unknown</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://unknownprogrammer.com/?p=40</guid>
		<description><![CDATA[A few months back, while porting some code from php to ruby, being a newbie that I am, I came across an issue. The php code had a function as such: public string functionName($var1, &#38;$var2, $var3){} Here the caller of &#8230; <a href="http://unknownprogrammer.com/2011/10/user-defined-variable-names-in-ruby/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few months back, while porting some code from php to ruby, being a newbie that I am, I came across an issue.<br />
The php code had a function as such:</p>
<pre class="wp-code-highlight prettyprint">
public string functionName($var1, &amp;$var2, $var3){}
</pre>
<p>Here the caller of the function gets to decide the name of the variable ($var2).<br />
So, the caller can access the result from a variable name of the callers choice.</p>
<pre class="wp-code-highlight prettyprint">
functionName(&quot;variablevalue&quot;, &quot;variableName&quot;, &quot;variableValue&quot;);
echo $variableName;
</pre>
<p>The code was procedural and had nothing to do with classes, methods or objects.</p>
<p>In ruby I had to provide a similar option where the caller can name the variable.<br />
Here is how I had implemented this.</p>
<pre class="wp-code-highlight prettyprint">

attr_accessor :userVar, :varName
</pre>
<p>Adding a couple of properties to the class. attr_accessor defines the get set methods.</p>
<pre class="wp-code-highlight prettyprint">
def method_missing(meth, *x)
		if &quot;#{meth}&quot; == self.varName
	    	class &lt;&lt; self
		    	self
		    end.send :define_method, meth do |args|
		    	 self.userVar
		    end
		    self.send &quot;#{meth}&quot;, x
		else
			puts &quot;#{meth} : Such a method does not exist!&quot;
		end
end
</pre>
<p>This checks to see if the called method exists. Uses define_method .</p>
<pre class="wp-code-highlight prettyprint">

def methodName(var1, userVar=&quot;&quot;, var3)
		// function
		self.userVar = userVar
		self.varName = &quot;#{self.userVar}&quot;
		self.userVar = self.result
		return self.return
end
</pre>
<pre class="wp-code-highlight prettyprint">
 objectName.methodName(var1, &quot;myvariable&quot;, var3)
 puts objectName.myVariable
</pre>
<p>The user input variable name is a new method/property which contains the result.</p>
]]></content:encoded>
			<wfw:commentRss>http://unknownprogrammer.com/2011/10/user-defined-variable-names-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AES Encryption (ECB, PKCS5) in Windows Phone 7</title>
		<link>http://unknownprogrammer.com/2011/10/aes-encryption-in-windows-phone-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aes-encryption-in-windows-phone-7</link>
		<comments>http://unknownprogrammer.com/2011/10/aes-encryption-in-windows-phone-7/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 05:38:49 +0000</pubDate>
		<dc:creator>unknown</dc:creator>
				<category><![CDATA[encryption]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[Awkward Coder]]></category>
		<category><![CDATA[Bouncy Castle]]></category>
		<category><![CDATA[ECB]]></category>
		<category><![CDATA[PKCS5]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://unknownprogrammer.com/?p=19</guid>
		<description><![CDATA[To support compatibility with some old software, I had to encrypt data with PKCS 5 padding and ECB mode with AES encryption. Awkward coder has made this a lot easier by creating a binary for windows phone 7.1 from bouncy &#8230; <a href="http://unknownprogrammer.com/2011/10/aes-encryption-in-windows-phone-7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To support compatibility with some old software, I had to encrypt data with PKCS 5 padding and ECB mode with AES encryption. <a href="http://awkwardcoder.blogspot.com/2011/08/using-bouncy-castle-on-windows-phone-7.html" target="_blank">Awkward coder</a> has made this a lot easier by creating a binary for windows phone 7.1 from bouncy castle. In this post I have an example of how I used the binary. Well, most of the code is from the original post by awkward coder.</p>
<pre class="wp-code-highlight prettyprint">
public static string encrypt(string input, string password)
{
#region encrypt

var byteArray = Encoding.UTF8.GetBytes(input);
var key = Encoding.UTF8.GetBytes(password);
var encryptioncipher = CipherUtilities.GetCipher(&quot;AES/ECB/PKCS5PADDING&quot;);
encryptioncipher.Init(true, new KeyParameter(key));

//string algo = encryptioncipher.AlgorithmName;
int blocksize = encryptioncipher.GetBlockSize();

byte[] bytes = encryptioncipher.ProcessBytes(byteArray);

byte[] final = encryptioncipher.DoFinal();

string resultBytes = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
MemoryStream encryptedstream = new MemoryStream(bytes.Length + final.Length);
encryptedstream.Write(bytes, 0, bytes.Length);
encryptedstream.Write(final, 0, final.Length);
encryptedstream.Flush();

byte[] encryptedData = new byte[encryptedstream.Length];
encryptedstream.Position = 0;
encryptedstream.Read(encryptedData, 0, encryptedData.Length);

//Convert to hex string
string result = HexHelper.GetHextString(encryptedData);
return result;

#endregion

}

public static string decrypt(string encryptedhexstring, string password)
{
#region decrypt

//Covert from hexstring to bytearray
byte[] encryptedData = HexHelper.GetBytes(encryptedhexstring);

var key = Encoding.UTF8.GetBytes(password);
// AES algorthim with ECB cipher &amp;amp; PKCS5 padding...
var cipher = CipherUtilities.GetCipher(&quot;AES/ECB/PKCS5PADDING&quot;);

// Initialise the cipher...
cipher.Init(false, new KeyParameter(key));

// Decrypt the data and write the 'final' byte stream...
var decryptionbytes = cipher.ProcessBytes(encryptedData);
var decryptedfinal = cipher.DoFinal();

// Write the decrypt bytes &amp;amp; final to memory...
var decryptedstream = new MemoryStream(decryptionbytes.Length);
decryptedstream.Write(decryptionbytes, 0, decryptionbytes.Length);
decryptedstream.Write(decryptedfinal, 0, decryptedfinal.Length);
decryptedstream.Flush();

var decryptedData = new byte[decryptedstream.Length];
decryptedstream.Position = 0;
decryptedstream.Read(decryptedData, 0, (int)decryptedstream.Length);

// Convert the decrypted data to a string value...
var resultdecrypted = Encoding.UTF8.GetString(decryptedData, 0, decryptedData.Length);

return resultdecrypted;

#endregion
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://unknownprogrammer.com/2011/10/aes-encryption-in-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

