<?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>A Conflagration of Randomness &#187; Programming</title>
	<atom:link href="http://blog.robertkania.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robertkania.com</link>
	<description>A blog about technology, college, and life.</description>
	<lastBuildDate>Fri, 23 Apr 2010 04:16:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javabat Changes to CodingBat to Include Python</title>
		<link>http://blog.robertkania.com/2010/03/16/javabat-changes-to-codingbat-to-include-python/</link>
		<comments>http://blog.robertkania.com/2010/03/16/javabat-changes-to-codingbat-to-include-python/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 04:28:20 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=644</guid>
		<description><![CDATA[Recently Javabat changed its name to Codingbat since it added the ability to code in Python.  However, the exercises are the same as in Java, just to be submitted in Python format.  I feel this addition will help people realize and learn about Python, as I have found it to be a very [...]]]></description>
			<content:encoded><![CDATA[<p>Recently Javabat changed its name to Codingbat since it added the ability to code in Python.  However, the exercises are the same as in Java, just to be submitted in Python format.  I feel this addition will help people realize and learn about Python, as I have found it to be a very useful language.  Below is a screenshot of the new Javabat homepage.</p>
<p><a rel="lytebox" href="http://blog.robertkania.com/wp-content/uploads/2010/03/codingbat.jpg"><img class="size-large wp-image-646 alignnone" title="codingbat" src="http://blog.robertkania.com/wp-content/uploads/2010/03/codingbat-1024x640.jpg" alt="" width="614" height="384" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2010/03/16/javabat-changes-to-codingbat-to-include-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javabat Solutions</title>
		<link>http://blog.robertkania.com/2010/03/07/javabat-solutions/</link>
		<comments>http://blog.robertkania.com/2010/03/07/javabat-solutions/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 17:41:01 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=615</guid>
		<description><![CDATA[Warmup-1
Sleep In:
Monkey Trouble: 
Warmup-2
String Times:
Front Times: 
String-1
Hello Name:
Make ABBA: 
Make Tags: 
Make Out Word: 
Extra End:
First Two: 
First Half: 
Without End: 
Combo String: 
]]></description>
			<content:encoded><![CDATA[<h2><strong>Warmup-1</strong></h2>
<p>Sleep In: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1761917254'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1761917254' style='display:none;'>
<pre>public boolean sleepIn(boolean weekday, boolean vacation) {
  if(!weekday || vacation){
  return true;
  }
  return false;
}</pre>
</div>
<p>Monkey Trouble: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID864991833'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID864991833' style='display:none;'>
<pre>public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
  return (aSmile == bSmile);
}</pre>
</div>
<h2><strong>Warmup-2</strong></h2>
<p>String Times: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID189167854'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID189167854' style='display:none;'>
<pre>public String stringTimes(String str, int n) {
  String newString = "";
  for(int i = 1; i &lt;= n; i++){
  newString += str;
  }
  return newString;
}
</pre>
</div>
<p>Front Times: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1145947143'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1145947143' style='display:none;'>
<pre>public String frontTimes(String str, int n) {
  String newString = "";
  int gui = 3;
  for(int i = 1; i &lt;= n; i++){
  if(str.length() &lt; 3){
  gui = str.length();
  }
  newString += str.substring(0,gui);
  }
  return newString;
}
</pre>
</div>
<h2><strong>String-1</strong></h2>
<p>Hello Name: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1523039645'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1523039645' style='display:none;'>
<pre>public String helloName(String name) {
  return "Hello " + name + "!";
}
</pre>
</div>
<p>Make ABBA: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1893565647'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1893565647' style='display:none;'>
<pre>public String makeAbba(String a, String b) {
return a+b+b+a;
}</pre>
</div>
<p>Make Tags: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID493007394'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID493007394' style='display:none;'>
<pre>public String makeTags(String tag, String word) {
 return "&lt;" + tag + "&gt;" + word + "&lt;/" + tag + "&gt;";
}</pre>
</div>
<p>Make Out Word: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID498728333'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID498728333' style='display:none;'>
<pre>public String makeOutWord(String out, String word) {
 return out.substring(0,2)+word+out.substring(2,4);
}</pre>
</div>
<p>Extra End: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1568702635'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1568702635' style='display:none;'>
<pre>public String extraEnd(String str) {
 return str.substring(str.length()-2)+str.substring(str.length()-2)+str.substring(str.length()-2);
}</pre>
</div>
<p>First Two: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID131763418'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID131763418' style='display:none;'>
<pre>public String firstTwo(String str) {
 if(str.length() &lt; 2) {
 if(str.length() == 0){
 return "";
 }
 return str;
 }else{
 return str.substring(0,2);
 }
}
</pre>
</div>
<p>First Half: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1625518684'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1625518684' style='display:none;'>
<pre>public String firstHalf(String str) {
 return str.substring(0, str.length()/2);
}</pre>
</div>
<p>Without End: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID900431608'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID900431608' style='display:none;'>
<pre>public String withoutEnd(String str) {
 return str.substring(1, str.length()-1);
}</pre>
</div>
<p>Combo String: <a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1411480646'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p>
<div id='SID1411480646' style='display:none;'>
<pre>public String comboString(String a, String b) {
 if(a.length() &lt; b.length()){
 return a + b + a;
 }
 if(a.length() &gt; b.length()){
 return b + a + b;
 }
 return "";
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2010/03/07/javabat-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hack this Site Programming Problem 2 Solution</title>
		<link>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/</link>
		<comments>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:00:16 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=602</guid>
		<description><![CDATA[A few years ago I joined the site, Hack This Site in order to practice coding and see how much I knew.  Although the name is suggestive of illegal material, this site is in no way promoting hacking.  It simply is a site to practice programming and learning better techniques.  One of the challenges, Programming [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="lytebox" href="http://blog.robertkania.com/wp-content/uploads/2010/01/hts-program2.gif"><img class="alignright size-medium wp-image-603" title="hts-program2" src="http://blog.robertkania.com/wp-content/uploads/2010/01/hts-program2-300x243.gif" alt="" width="300" height="243" /></a>A few years ago I joined the site, <a href="http://www.hackthissite.org">Hack This Site</a> in order to practice coding and see how much I knew.  Although the name is suggestive of illegal material, this site is in no way promoting hacking.  It simply is a site to practice programming and learning better techniques.  One of the challenges, Programming Problem 2 involves writing a program to take an image filled with black and white pixels, find the distance between the white pixels, which are ascii characters.  Convert these ascii characters then into Morse code, which then is translated into numbers and letters.  I spent some time initially looking for a language that could read an image in pixel by pixel and the one I settled on was Python.  This was the second program I had written in Python.</p>
<p>The exact instructions for the program were</p>
<blockquote><p>The pixels in the above image are numbered 0..99 for the first row,  100..199 for the second row etc.                  White pixels represent ascii codes.                  The ascii code for a particular white pixel is equal to  the offset from the last white pixel.                  For example, the first white pixel at location 65 would  represent ascii code 65 (&#8216;A&#8217;),                   the next at location 131 would represent ascii code  (131 &#8211; 65) = 66 (&#8216;B&#8217;) and so on.</p>
<p>The text contained in the image is the answer encoded  in Morse, where &#8220;a test&#8221; would be encoded as &#8220;.- / &#8211; . &#8230; -&#8221;</p>
<p>You have 15 seconds time to send the solution.</p></blockquote>
<p>Now of course it says you have 15 seconds which is true and I did do it in 15 seconds, but since this site uses Javascript to count, you can simply disabe javascript to have unlimited time by using the Firefox plugin <a href="https://addons.mozilla.org/en-US/firefox/addon/722">NoScript</a>.</p>
<p>For example, the image I used was:</p>
<p><a href="http://blog.robertkania.com/wp-content/uploads/2010/01/PNG.png"><img class="size-full wp-image-605 alignnone" title="PNG" src="http://blog.robertkania.com/wp-content/uploads/2010/01/PNG.png" alt="" width="100" height="30" /></a></p>
<p>which gave the following numbers:</p>
<blockquote><p>45 46 46 32 45 46 46 32 45 46 46 46 46 32 45 45 45 32 46 45 32 45 46 45 32 46 46 46 32 46 46 46 46 32 46 45 45 45 45 32 46 45 32</p></blockquote>
<p>which was translated in the following ascii characters</p>
<blockquote><p>-..  -..  -&#8230;.  &#8212;  .-  -.-  &#8230;  &#8230;.  .&#8212;-  .-</p></blockquote>
<p>which produced the following output using Morse code to translate:</p>
<blockquote><p>dd6oaksh1a</p></blockquote>
<p>The code that I used to program this was:</p>
<pre>import Image
def multipleReplace(text, morse_code):
    for key in morse_code:
        text = text.replace(key, morse_code[key])
    return text
morse_code = {' .- ':'a',' -... ':'b',' -.-. ':'c',' -.. ':'d',' . ':'e',
            ' ..-. ':'f',' --. ':'g',' .... ':'h',' .. ':'i',' .--- ':'j',
            ' -.- ':'k',' .-.. ':'l',' -- ':'m',' -. ':'n',' --- ':'o',
            ' .--. ':'p',' --.- ':'q',' .-. ':'r',' ... ':'s',' _ ':'t',
            ' ..- ':'u',' ...- ':'v',' .-- ':'w',' -..- ':'x',' -.-- ':'y',
            ' --.. ':'z',' ----- ':'0',' .---- ':'1',' ..--- ':'2',
            ' ...-- ':'3',' ....- ':'4',' ..... ':'5',' -.... ':'6',
            ' --... ':'7',' ---.. ':'8',' ----. ':'9'}
im = Image.open("C:\PNG.png")
size = im.size
width = size[0]
height = size[1]
L = list()
last = 0
#The loop transforms the image into a list
#If the pixel is white, return 0, otherwise return 1
for i in range (0,height):
    K = list()
    for j in range (0,width):
        checker = (int)(im.getpixel((j,i)))
        if(checker == 1):
            K.append(1)
        else:
            K.append(0)
    L.append(K)
ascii = list()
count = 0
for i in range (0,height):
    for j in range (0,width):
        if(L[i][j] == 1): #determines if the pixel is on
            char = chr(count-last) #converts the distance
            #between the pixels to ascii
            if(char == " "):
                char = "  "
            ascii.append(char)
            last = count
        count+=1
morseCode = " "
for i in range (0,len(ascii)-1):
    morseCode += ascii[i]
morseCode += " "
print multipleReplace(morseCode, morse_code) #replaces the morse code
#with letters and numbers
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2010/02/09/hack-this-site-programming-problem-2-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Code to Include Content in Layout</title>
		<link>http://blog.robertkania.com/2009/12/13/php-code-to-include-content-in-layout/</link>
		<comments>http://blog.robertkania.com/2009/12/13/php-code-to-include-content-in-layout/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 00:14:18 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=402</guid>
		<description><![CDATA[When I didn&#8217;t know PHP I spent a lot of time trying to find the coveted script that would allow me to include content in a page by including a page so that I could change the layout and it would remain the same for all pages, only the content would change.  I of [...]]]></description>
			<content:encoded><![CDATA[<p>When I didn&#8217;t know PHP I spent a lot of time trying to find the coveted script that would allow me to include content in a page by including a page so that I could change the layout and it would remain the same for all pages, only the content would change.  I of course didn&#8217;t want to use an iframe because these scroll and look hideous.  The solution I found, but did not understand for several months later.  When a bit later I lost this code I realized it was time for me to learn PHP.  The code I wished to know was the code that allows you to include pages with content like http://example.com/index.php?page=home.php.  The layout would be in the file index.php but the content for the homepage would be at home.php.  The code to do this would be:</p>
<blockquote><p>&lt;?php if($_GET['page'] == null) { include &#8220;default.php&#8221;; } else { include $_GET['page']; } ?&gt;</p></blockquote>
<p>The explaination of this is:</p>
<p>$_GET['page']<br />
is the PHP way to get a parameter from a url.  In PHP all the page parameters are stored after the ? in the url.  For example in this page index.php?page=anything.php the only variable is page and in this case page is equal to &#8220;anything.php&#8221;.  The $_GET['page'] gets the value of page.  If you wish to add more variables to the url you simply add an &amp; in between the variables.  For example &#8220;index.php?page=anything.php&amp;loggedin=false&#8221; Thus $_GET['loggedin'] would result in false.   Next time you do a go0ogle search check the url and you can see these variables.</p>
<p>include &#8220;default.php&#8221;<br />
The first include will be shown if the page variable is null.  In this case it will show the default page you assign it.</p>
<p>include $_GET['page']<br />
This will show the page of whatever follows the page variable in the url.</p>
<p>For an example of this visit my homepage <a href="http://rkania.com/index.php?view=home">http://rkania.com/index.php?view=home</a>.  My site has customized code and mod rewrite so it won&#8217;t work exactly the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2009/12/13/php-code-to-include-content-in-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Have you ever?</title>
		<link>http://blog.robertkania.com/2009/12/09/have-you-ever/</link>
		<comments>http://blog.robertkania.com/2009/12/09/have-you-ever/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 05:58:21 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web/Internet]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://blog.robertkania.com/?p=387</guid>
		<description><![CDATA[Have you ever used Facebook? You have, have you?  Well then I built a great application for you.  The Have You Ever Facebook application. I built this Facebook application last year in a night, but never blogged about it.   It was down for a few months while I upgraded my webhost, [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_389" class="wp-caption alignright" style="width: 268px"><a href="http://apps.facebook.com/have_you_ever/"><img class="size-full wp-image-389 " title="usage" src="http://blog.robertkania.com/wp-content/uploads/2009/12/usage.png" alt="usage" width="258" height="128" /></a><p class="wp-caption-text">The user statistics of my app.</p></div>
<p>Have you ever used Facebook? You have, have you?  Well then I built a great application for you.  The <a href="http://apps.facebook.com/have_you_ever/" target="_blank">Have You Ever Facebook application</a>. I built this Facebook application last year in a night, but never blogged about it.   It was down for a few months while I upgraded my webhost, but now it is back up and slightly improved. I currently have over 3000 current users and approximately 250 monthly active users which has increased from about 150 before I upgraded it last week.  This application allows you to ask your friends a question and have them respond yes or no to the question.  I am trying to improve this application so that it can do more things, but I will to sort out the source code.  In order to create this application I had to use the Facebook Develper&#8217;s PHP api. I learned a lot from this project.  I got the idea to create this application from the game we had to play at college orientation.  We stood in a circle with some sort of marker where we stood.  Then someone in the center calls out something that they have done or are wearing etc and everyone who has also has to move to a new spot.</p>
<p>To visit my application go to: <a href="http://apps.facebook.com/have_you_ever/" target="_blank">http://apps.facebook.com/have_you_ever/</a></p>
<div id="attachment_388" class="wp-caption alignnone" style="width: 546px"><a href="http://apps.facebook.com/have_you_ever/"><img class="size-full wp-image-388  " title="haveyouever" src="http://blog.robertkania.com/wp-content/uploads/2009/12/haveyouever.png" alt="haveyouever" width="536" height="328" /></a><p class="wp-caption-text">My Application</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2009/12/09/have-you-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun in Computer Science&#8230;.</title>
		<link>http://blog.robertkania.com/2009/04/13/fun-in-computer-science/</link>
		<comments>http://blog.robertkania.com/2009/04/13/fun-in-computer-science/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 23:17:45 +0000</pubDate>
		<dc:creator>Robert Kania</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.rkania.com/?p=140</guid>
		<description><![CDATA[I&#8217;m taking a Problem Solving in Computer Science class this semester and one of the problems was:
How could a (normal, human) baby (accidently!) fall out of a twenty-story building onto the ground and live? 
One of our solutions?  Drop the baby onto wet cement &#62;_&#62; What?!  It will survive (at least for a short time).  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m taking a Problem Solving in Computer Science class this semester and one of the problems was:</p>
<blockquote><p><em>How could a (normal, human) baby (accidently!) fall out of a twenty-story building onto the ground and live? </em></p></blockquote>
<p>One of our solutions?  Drop the baby onto wet cement &gt;_&gt; What?!  It will survive (at least for a short time).  Fine what other suggestions do you have?</p>
<blockquote><p><em><br />
</em></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.robertkania.com/2009/04/13/fun-in-computer-science/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
