<?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>The Open Code Project</title>
	<atom:link href="http://opencodeproject.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://opencodeproject.com</link>
	<description>A place for informative articles about programming and technology.</description>
	<lastBuildDate>Fri, 20 Apr 2012 16:43:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JSON Parsing Function for Shell Scripts</title>
		<link>http://opencodeproject.com/2012/04/20/json-parsing-function-for-shell-scripts/</link>
		<comments>http://opencodeproject.com/2012/04/20/json-parsing-function-for-shell-scripts/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 16:43:43 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Parsing]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=281</guid>
		<description><![CDATA[When testing REST-based web services that return JSON you may decide to use a shell script with cURL commands. Some services require a call to authorize a client and a second call to perform some action. In these cases, you &#8230; <a href="http://opencodeproject.com/2012/04/20/json-parsing-function-for-shell-scripts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When testing REST-based web services that return JSON you may decide to use a shell script with cURL commands. Some services require a call to authorize a client and a second call to perform some action. In these cases, you would need to store the returned information in variables to use in subsequent calls. This is only a simple example of why you would want a shell script to parse JSON and return a value, but the usefulness of a JSON parser goes beyond a simple example like this.</p>
<span id="more-281"></span>
<p>It should be noted that the following function works best for JSON objects and hasn&#8217;t been tested with JSON arrays. The tests worked reliably with properly quoted names and values. I cannot promise that this function would work on non-quoted names and values, but there is code to allow non-quoted value types.<p>

<p>
<pre class="prettyprint">
#Gets a single json element value from a json blob.
#For json values (like {"key":{"k2":"val"}}) you need to first get "key"
#then do an additional call with the value as the input to the function and "k2" as the argument
#Example1: cityvar=$(jsonElement "city" "{\"city\":\"Seattle\"}")
#Example2: cityvar=$(jsonElement "city" "{\"city\":{\"name\":\"Seattle\","county":"King"}")
#			countyvar=$(jsonElement "county" "$cityvar")
#			echo $countyvar #outputs "King" (without quotes)
jsonElement(){
	#echo $1
	out=$(echo $2 | awk -F"[,:]" '{for(i=1;i<=NF;i++){if($i~/'$1'\042/){print $(i+1)} } }')
	if [[ $out == \"*\" ]]; #test if the string starts and ends in a quote
	then
		echo "${out:1:${#out}-2}" #removes first and last quotes
	else
		echo $out
	fi
}
</pre>
</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/04/20/json-parsing-function-for-shell-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple c++ string replace function</title>
		<link>http://opencodeproject.com/2012/04/13/a-simple-c-string-replace-function/</link>
		<comments>http://opencodeproject.com/2012/04/13/a-simple-c-string-replace-function/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 05:10:53 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Cplusplus]]></category>
		<category><![CDATA[string replace]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=276</guid>
		<description><![CDATA[I&#8217;ve been privileged by higher-level language string functions, such as PHP&#8217;s easy to use str_replace function, that I&#8217;ve forgotten how performing such simple tasks in lower-level languages like C++ can be such a hassle. Aside from using some library (of &#8230; <a href="http://opencodeproject.com/2012/04/13/a-simple-c-string-replace-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been privileged by higher-level language string functions, such as PHP&#8217;s easy to use str_replace function, that I&#8217;ve forgotten how performing such simple tasks in lower-level languages like C++ can be such a hassle. Aside from using some library (of which I&#8217;m not aware yet), here&#8217;s a simple string replace function which is similar to the PHP version. In this case the function will directly modify the original string, not return an instance of a new string.</p>
<span id="more-276"></span>
<p>
<pre class="prettyprint">
void str_replace(std::string&#038; str, const std::string find, const std::string replace){
	size_t index = 0;
	while (true) {
		 /* Locate the substring to replace. */
		 index = str.find(find, index);
		 if (index == std::string::npos) break;

		 /* Make the replacement. */
		 str.replace(index, find.length(), replace);

		 /* Advance index forward one spot so the next iteration doesn't pick it up as well. */
		 ++index;
	}
}
</pre>
</p>
<h1>Usage:</h1>
<p>
<pre>
std::string str = "Hello Earth!";
str_replace(str,"Earth","World");
//str is "Hello World!" now.
</pre>
</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/04/13/a-simple-c-string-replace-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically Modifying Input Elements on Click</title>
		<link>http://opencodeproject.com/2012/03/28/dynamically-modifying-input-elements-on-click/</link>
		<comments>http://opencodeproject.com/2012/03/28/dynamically-modifying-input-elements-on-click/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 19:45:30 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[text boxes]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=266</guid>
		<description><![CDATA[Sometimes it&#8217;s necessary to modify an input form element when a user clicks on that element. In some cases, the form element can contain information regarding what information is appropriate, or what format is expected. The most common example is &#8230; <a href="http://opencodeproject.com/2012/03/28/dynamically-modifying-input-elements-on-click/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s necessary to modify an input form element when a user clicks on that element. In some cases, the form element can contain information regarding what information is appropriate, or what format is expected. The most common example is showing &#8220;mm/dd/yyyy&#8221; in a text-based date field and automatically removing that information when a user clicks on the field.</p>
<span id="more-266"></span>
<p>This example will show a login form which is pre-populated with some helper information. When the user clicks on it, the information is modified. An additional feature to this code is that the password textbox is dynamically modified from a &#8220;text&#8221; type to a &#8220;password&#8221; type, hiding all of the text that the user enters.</p>

<p>
<pre class="prettyprint">
&lt;form action="#" method="post"&gt;
	&lt;p&gt;Please sign in.&lt;/p&gt;
	&lt;div&gt;&lt;label for="email"&gt;Email&lt;/label&gt;&lt;br /&gt;
	&lt;input type="text" name="email" id="email" value="" /&gt;&lt;/div&gt;
	&lt;div&gt;
		&lt;label for="password"&gt;Password&lt;/label&gt;&lt;br /&gt;
		&lt;input type="password" name="password" id="password" value="" /&gt;
	&lt;/div&gt;
	&lt;div&gt;&lt;input type="submit" name="submit" value="Login" /&gt;&lt;/div&gt;
&lt;/form&gt;

&lt;script type="text/javascript"&gt;
//required: JQuery
//automatically performs the following on page ready
$(document).ready(function(){
	//sets the email text to the following:
	$("#email").val("Email you used to create your account")
		.css({color:"#ccc"}) //changes the color to be hint-like
		.click(function(){
			//changes the text color back to black, 
			//clears the helper text
			$(this).css({color:"#000"}).val("");
		});

	//save the original password box
	var inptPassword = $("#password");

	//replace the password box with a normal text box
	$("#password").replaceWith($('&lt;input type="text" /&gt;').attr({
			name:"password",
			id:"password",
			value:"Password"
		}).css({color:"#ccc"})
		.click(
			function(){
				//replace the textbox-style password box
				//with the original
				$(this).replaceWith(inptPassword);
			}
		).keyup(
			function(){
				var val = $(this).val();
				if($(this).attr("type") == "text"){
					$(this).replaceWith(twdc_inptPassword);
					twdc_inptPassword.focus()
				}
			}
		));
});
&lt;/script&gt;
</pre>
</p>

<p><strong>Note:</strong> Instead of setting a color in Javascript, you should use css classes and the addClass/removeClass methods for when you load and click on a text box.</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/03/28/dynamically-modifying-input-elements-on-click/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Benchmarking with JSBenchtest</title>
		<link>http://opencodeproject.com/2012/03/22/javascript-benchmarking-with-jsbenchtest/</link>
		<comments>http://opencodeproject.com/2012/03/22/javascript-benchmarking-with-jsbenchtest/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 22:35:30 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[jsbenchtest]]></category>
		<category><![CDATA[Speed]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=255</guid>
		<description><![CDATA[Javascript benchmarking couldn&#8217;t be easier. With this webpage you can input any Javascript code and test how fast it is. The webpage will automatically call your code for 1,000,000 iterations and report the total amount of time that it took &#8230; <a href="http://opencodeproject.com/2012/03/22/javascript-benchmarking-with-jsbenchtest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Javascript benchmarking couldn&#8217;t be easier. With this webpage you can input any Javascript code and test how fast it is. The webpage will automatically call your code for 1,000,000 iterations and report the total amount of time that it took to execute. It will even output a variable that you can use for debugging. You can now test an algorithm, make a modification, and test again to see if the modification helped the execution time.</p>
<p><a href="http://opencodeproject.com/jsbenchtest/">Click here to benchmark some code</a>.</p>
<span id="more-255"></span>
<a href="http://opencodeproject.com/wp-content/uploads/2012/03/JSBenchtest.png"><img src="http://opencodeproject.com/wp-content/uploads/2012/03/JSBenchtest-400x235.png" alt="JSBenchtest" title="JSBenchtest" width="400" height="235" class="alignright size-medium wp-image-256" /></a>

<p>When you visit the page it&#8217;ll show you some sample code that you can run. The number of iterations will default to 1,000,000 for all browsers except IE (100,000 for IE). You can change the code to your own algorithm and run the benchmark.</p> 

<p>As soon as you press the button, a cookie will be created to store what you entered. At any time you can come back to the webpage and continue your testing with the code that you entered last.</p>

<p>The page includes jQuery 1.7.1, so you can be confident in using jQuery functions. It also includes setCookie and getCookie functions if you wanted to work with cookies. Instead of using the eval() function, which is considered bad practice in Javascript, the webpage sets your code to a new Function object. This improves the speed considerably at runtime.</p>

<h1>The Code</h1>

<p>
<pre class="prettyprint">
//Pads a number to 2 decimal places
function pad2(number) {
	 return (number < 10 ? '0' : '') + number	   
}

//An output variable that you can use.
var out = "";

//Does the work
function startBenchmark(){
	out = "";
	var SB_iterations;
	var SB_results = document.getElementById("results");
	var SB_code = document.getElementById("code").value;
	setCookie("code",escape(SB_code),365);
		
	//test iterations for incorrect value
	if((SB_iterations = parseInt(document.getElementById("iterations").value,10)) == 'NaN'){
		SB_results.innerHTML = '&lt;span style="color:red;font-weight:bold;"&gt;Error: The iterations must be a whole number such as 100000. Do not use commas or words.&lt;/span&gt;';
		return false;
	}
	//check for blank code
	if(SB_code == ''){
		SB_results.innerHTML = '&lt;span style="color:red;font-weight:bold;"&gt;Error: You must type some code into the text area.&lt;/span&gt;';
		return false;
	}
		
	//too slow
	/*var fn = function() {
		window.eval.call(window,SB_code);
	};*/
	
	//better method
	var fn = new Function(SB_code);

	var SB_start = (new Date).getTime();
	/* Run a test. */
	for(var SB_i=0; SB_i < SB_iterations; SB_i++){
		fn();
	}
	var SB_diff = (new Date).getTime() - SB_start;
		
	var seconds = Math.floor((SB_diff/1000)%60);
	var minutes = Math.floor((SB_diff/(1000*60))%60);
	var ms = SB_diff - (minutes*60*1000) - (seconds*1000);
	SB_results.innerHTML = "&lt;p&gt;Runtime: "+SB_diff+"ms&lt;br /&gt;"+
		pad2(minutes)+":"+pad2(seconds)+":"+pad2(ms)+" (mm:ss:ms)&lt;/p&gt;"+
		(out != ''?'&lt;p&gt;&lt;span class="bold"&gt;Output Variable:&lt;/span&gt; '+out+'&lt;/p&gt;':'');
}
</pre>
</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/03/22/javascript-benchmarking-with-jsbenchtest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Switch vs If &#8211; Which is faster?</title>
		<link>http://opencodeproject.com/2012/03/15/switch-vs-if-which-is-faster/</link>
		<comments>http://opencodeproject.com/2012/03/15/switch-vs-if-which-is-faster/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 21:01:02 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[If]]></category>
		<category><![CDATA[If vs. Switch]]></category>
		<category><![CDATA[If-Then]]></category>
		<category><![CDATA[Speed]]></category>
		<category><![CDATA[Switch]]></category>
		<category><![CDATA[Switch vs. If]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=242</guid>
		<description><![CDATA[In programming there are two different methods that people use to test variables that have a number of different values. One method is to use the If statement and define blocks of code to perform. The other common method is &#8230; <a href="http://opencodeproject.com/2012/03/15/switch-vs-if-which-is-faster/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In programming there are two different methods that people use to test variables that have a number of different values. One method is to use the If statement and define blocks of code to perform. The other common method is to use a switch statement and list all possible values, perhaps including a default value, and perform some process inside the appropriate section of code.</p>
<span id="more-242"></span>
<p>The question that people get stuck on is, besides making the code look prettier, which type of statement is better to use? Some people say If is faster, while others say Switch is. Obviously you should make your code look good, which is why Switch is commonly used, but if Switch causes your website or application to run slow then you wouldn&#8217;t want to use it.</p>

<p>So to answer this question, I&#8217;ve designed some code that tests each version in a very simple manner. The resulting number of milliseconds is written on the webpage after each section is done processing.</p>

<p>
<pre class="prettyprint">
var start = (new Date).getTime();
var b = 0;
var a = 1;
for(var i=0; i<100000000; i++){
	if(a == 1){
		b++;
		a = 0;
	}else if(a == 0){
		a = 1;
	}
}
var diff = (new Date).getTime() - start;
	
document.write(diff+"&lt;br /&gt;");
	
start = (new Date).getTime();
b = 0;
a = 1;
for(var i=0; i<100000000; i++){
	switch(a){
		case 1:
			b++;
			a = 0;
			break;
		case 0: 
			a = 1;
			break;		
	}
}
diff = (new Date).getTime() - start;
	
document.write(diff+"&lt;br /&gt;");
</pre>
</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/03/15/switch-vs-if-which-is-faster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript: Flattening a Multidimensional Array</title>
		<link>http://opencodeproject.com/2012/03/06/javascript-flattening-a-multidimensional-array/</link>
		<comments>http://opencodeproject.com/2012/03/06/javascript-flattening-a-multidimensional-array/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 16:48:21 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[2-dimensional]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[flatten]]></category>
		<category><![CDATA[recurse]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[recusive]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=233</guid>
		<description><![CDATA[A friend had asked me about converting a 2-dimensional array into a flat 1-dimensional array. In array form this would be (written as was provided to me): in = [1,"2",[3,"4"]]; out = [1,"2",3,"4"]; //this is what he wanted out. Keywords &#8230; <a href="http://opencodeproject.com/2012/03/06/javascript-flattening-a-multidimensional-array/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A friend had asked me about converting a 2-dimensional array into a flat 1-dimensional array. In array form this would be (written as was provided to me):</p>
<p>
<pre class="prettyprint">
    in = [1,"2",[3,"4"]];
    out = [1,"2",3,"4"]; //this is what he wanted out.
</pre>
</p>
<span id="more-233"></span>
<h1>Keywords</h1>

<p>Given this task I started to code. However, I had forgotten one glaring issue. His code would fail from the start. He could never use the variable &#8220;in&#8221; because &#8220;in&#8221; is a reserved keyword in Javascript.</p>

<p><a href="http://www.quackit.com/javascript/javascript_reserved_words.cfm">http://www.quackit.com/javascript/javascript_reserved_words.cfm</a></p>

<p>Reserved keywords are those special words that you can&#8217;t use as variables because they have some significant meaning to the Javascript interpreter. In this case &#8220;in&#8221; is used for certain for loops.</p>

<p>Maybe this was a trick question or maybe he just happened to use those variable names. I changed the input variable and tried to figure out the problem.</p>

<h1>Type Checking Variables</h1>
<p>My friend also wanted to make sure that the variable being passed into the function was an array. As I somewhat knew already, this type checking brings all sorts of issues with Javascript. &#8220;typeof&#8221; is a keyword that allows you to check what data type a variable is, but it has some limitations for Arrays and is best used in checking if something is undefined. Arrays will output a typeof &#8220;Object&#8221; instead of &#8220;Array&#8221;.</p>

<p>I found that &#8220;instanceof&#8221; would work, however it has issues if two different objects have the same prototypical attributes. A Javascript object with the class name of &#8220;Object&#8221; is the same as &#8220;Other&#8221; if both objects have the same attributes. Doing a bit more research led me to <a href="http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/">this website</a> which describes a better way to check arrays (and the possibly incorrect ways that systems like JQuery used to use). Doug Crockford suggested Duck Typing in 2003 to address the issue of typing objects and John Resig points out that &#8220;as of 1.3 jQuery no longer uses instanceof or .constructor – for the same reasons that you list here. We were especially hitting problems when dealing with cross-frame pages.&#8221;</p>
<h1>The Code</h1>
<p>Without further adieu, here&#8217;s the code.</p>
<p>
<pre class="prettyprint">
//can't use "in" as a variable!
inArr = ["1",[2,["3"]],4,[5,[6,7,8,[9,[10]]]]];

out = flatten(inArr);
debug(out);

/**
 * Flattens a multidimensional array into a flat 1D array.
 * @param arr -  a multidimensional array
 * @param arrOut - Optional, an initial array
 * @return a flat array
 */
function flatten(arr, arrOut){
	if(typeof arrOut === "undefined") //optional variable
		var arrOut = []; //new Array or [] work the same
	
	//not so easy to simply check if it's an array
	//http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
	if(Object.prototype.toString.call(arr) === '[object Array]'){
		//loop through array values
		for(var i = 0; i < arr.length; i++){
			console.log(i+" - "+arr[i]);
			//check if there's a sub-array
			if(Object.prototype.toString.call(arr[i]) === '[object Array]'){
				//recurse!!
				arrOut = flatten(arr[i],arrOut);
			}else{
				//push the value onto the exising array
				arrOut.push(arr[i]);
			}
		}
	}
	return arrOut; //return the modified array
}

//just a helper function to show the array
function debug(obj){
	out = "";
	for(i in obj){
		out += i+" - "+obj[i]+"\n";
	}
	alert(out);
}
</pre>
</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/03/06/javascript-flattening-a-multidimensional-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raspberry Pi now available!</title>
		<link>http://opencodeproject.com/2012/02/29/raspberry-pi-now-available/</link>
		<comments>http://opencodeproject.com/2012/02/29/raspberry-pi-now-available/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 18:17:21 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[$25 computer]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=220</guid>
		<description><![CDATA[The Raspberry Pi is a computer, it&#8217;s a platform for development, it&#8217;s an educational tool that&#8217;s cheap enough for students and schools, it&#8217;s a media center PC, it&#8217;s a server, and it can be a robot brain. Raspberry Pi became &#8230; <a href="http://opencodeproject.com/2012/02/29/raspberry-pi-now-available/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Raspberry Pi is a computer, it&#8217;s a platform for development, it&#8217;s an educational tool that&#8217;s cheap enough for students and schools, it&#8217;s a media center PC, it&#8217;s a server, and it can <a href="http://www.geek.com/articles/chips/raspberry-pi-announces-the-gertboard-expansion-board-20111215/">be a robot brain</a>.</p>
<span id="more-220"></span>
<div id="attachment_223" class="wp-caption alignright" style="width: 310px"><a href="http://opencodeproject.com/wp-content/uploads/2012/02/Raspberry-Pi-computer.jpg"><img src="http://opencodeproject.com/wp-content/uploads/2012/02/Raspberry-Pi-computer-400x300.jpg" alt="Raspberry Pi" title="Raspberry Pi" width="300" class="size-medium wp-image-223" /></a><p class="wp-caption-text">The Raspberry Pi is a computer system the size of a credit card for $25.</p></div><p>Raspberry Pi became such a sensation that the <a href="http://www.raspberrypi.org/">Raspberry Pi foundation</a> asked website owners to devote some space to the first Linux distribution downloads. The Open Code project has become a mirror to the project and you can find the <a href="http://opencodeproject.com/rasppi/">Debian (and other later distributions) here</a>.</p>

<p>When it was released for public purchases on Wednesday, February 29, 2012 so many people hit the foundation&#8217;s website that they had to implement a static webpage and take down the forums. <a href="http://downloads.element14.com/raspberryPi1.html">Premier Farnell</a> and <a href="http://uk.rs-online.com/web/generalDisplay.html?id=raspberrypi">RS Components</a>, the manufacturers, were set up to take all of the pre-orders. During the morning of the 29th, so many people were interested that all three websites were taken down. At the time of writing they were back up. The Open Code Project mirror, one of hundreds of mirrors all over the world, was hit 76 times, exceeding 60GB of bandwidth usage.</p>

<p>So many people are interested in the Raspberry Pi because it&#8217;s the first sub-$100 computer system that can be used for development and education. Its design and OS is open source as well. <div id="attachment_221" class="wp-caption alignright" style="width: 310px"><a href="http://opencodeproject.com/wp-content/uploads/2012/02/770px-LaptopOLPC_a.jpg"><img src="http://opencodeproject.com/wp-content/uploads/2012/02/770px-LaptopOLPC_a-400x311.jpg" alt="One Laptop Per Child" title="One Laptop Per Child" width="300" class="size-medium wp-image-221" /></a><p class="wp-caption-text">One Laptop Per Child</p></div>Similar public interest was given to the <a href="http://one.laptop.org/">One Laptop Per Child</a>, which was a program designed to give fully functional laptops to children for under $100, however costs ended up above $200 in 2010. Now children can learn with a computer that&#8217;s the size of a credit card that only costs about $35 or less.</p>

<div id="attachment_222" class="wp-caption alignright" style="width: 310px"><a href="http://opencodeproject.com/wp-content/uploads/2012/02/Cotton-Candy.jpg"><img src="http://opencodeproject.com/wp-content/uploads/2012/02/Cotton-Candy-400x349.jpg" alt="FXI Cotton Candy" title="FXI Cotton Candy" width="300" class="size-medium wp-image-222" /></a><p class="wp-caption-text">The FXI Cotton Candy</p></div><p>There are other mini-computer systems out there, such as the <a href="http://www.fxitech.com/products/">FXI Cotton Candy</a>. This system is a computer that runs Ubuntu, the size of a USB thumb drive, for about $200. The price is more expensive than the Raspberry Pi but the processing power is also greater. Raspberry Pi doesn&#8217;t expect their computer to run Crysis, so they&#8217;ve devoted their attention to making a useful educational system for $25 (intended goal price).</p>

]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/02/29/raspberry-pi-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glasir &#8211; an open source PHP/HTML5 media player</title>
		<link>http://opencodeproject.com/2012/02/23/glasir-an-open-source-phphtml5-media-player/</link>
		<comments>http://opencodeproject.com/2012/02/23/glasir-an-open-source-phphtml5-media-player/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 23:19:31 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Media Player]]></category>
		<category><![CDATA[Music Player]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=208</guid>
		<description><![CDATA[Glasir is an open source PHP/HTML5 media player for a personal music collection of unlimited size. For use with Chrome, Firefox, and Android phones. It&#8217;s a project that I developed and open sourced for people to install it on their &#8230; <a href="http://opencodeproject.com/2012/02/23/glasir-an-open-source-phphtml5-media-player/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Glasir is an open source PHP/HTML5 media player for a personal music collection of unlimited size. For use with Chrome, Firefox, and Android phones. It&#8217;s a project that I developed and open sourced for people to install it on their personal web servers and point it at a music folder.</p>
<span id="more-208"></span>
<h1>Glasir</h1>

<p>Glasir is the name of a tree which is &#8220;the most beautiful among gods and men&#8221;, according to Norse mythology, bearing golden leaves located in the realm of Asgard, outside the doors of Valhalla (<a href="http://en.wikipedia.org/wiki/Glasir">source</a>). The folder structure presented in the Glasir music player is supposed to resemble the golden leaves of the Glasir tree.</p>

<h1>Glasir &#8211; The Music Player Website</h1>

<p>The Glasir website was developed as an alternative to systems like <a href="http://www.subsonic.org/pages/index.jsp">Subsonic</a> and <a href="http://grooveshark.com">Grooveshark</a><sub>[<a href="javascript:void(0)" onclick="document.getElementById('note1').style.backgroundColor='#FFFF7E';document.getElementById('note2').style.backgroundColor='';">1</a>]</sub>, which require a paid license to index your local files<sub>[<a href="javascript:void(0)" onclick="document.getElementById('note2').style.backgroundColor='#FFFF7E';document.getElementById('note1').style.backgroundColor='';">2</a>]</sub>.</p>

<p class="small"><span id="note1"><a name="1"></a>[1] Grooveshark offers free music and playlists. Subscribers to Grooveshark Anywhere can get commercial free music for phones and mobile devices for $9 per month (at the time of writing).</span>
<br /><span id="note2"><a name="2"></a>[2] Subsonic is a free music server which requires a single payment/donation for a premium license. Mentioning it here is not a complaint, but a sign of respect to a wonderful cross-OS music system.</span></p>

<p>Glasir is open source and completely free, although the development and updates are more limited than a paid system. Its intended purpose is to scan your media folder for mp3 and ogg files, such as music, then it will index those files using their ID3 properties and display the information to you. You can then create a playlist and play your songs in order or shuffle them.</p>

<h1>Screenshots</h1>

<div>User not logged in.<br /><a href="http://ajbogh.github.com/Glasir/images/screenshot0.png"><img src="http://ajbogh.github.com/Glasir/images/screenshot0_sm.png" border=0 /></a></div>
<div>User logged in. Playlist shown.<br /><a href="http://ajbogh.github.com/Glasir/images/screenshot1.png"><img src="http://ajbogh.github.com/Glasir/images/screenshot1_sm.png" border=0 /></a></div>

<h1>Compatibility</h1>

<p>Glasir is developed for Google Chrome (or Linux Chromium) and Firefox. While it may work in other browsers, it&#8217;s not specifically targeting them at this point in the development process. It also seems to work with Firefox mobile and Opera Mobile, to a limited extent.</p>

<h1>Future of Glasir</h1>

<p>Future development of Glasir will include various features depending on the availability within the HTML5 specification. The github notes about functionality include these possibilities:</p>

<pre>
--Volume Buttons--
	Up and down independant of the system volume (mute not necessary)

--Export playlist to zip--
   Playlists are great but, what about taking a copy with you?

--Cover Art--
	If the folder has cover art, then try to use that.
	Check the album name, artist, and song against a website like Amazon to find the cover art.

--Custom playlists/Searches--
	- Songs listened to most
	- Songs listened to least
	- Artist
	- Album
	- Year
	- Song name

#### Low priority ####

--Visualizations--
	Firefox includes a method to obtain visualization information from the audio tags. Include the functionality
	only for Firefox users. Add more visualizations as other browsers adopt the functionality.

--Beats per Minute--
	Process the audio in the database to determine the BPM for each song. This requires background processing.
	Load the BPM into the database to allow custom playlists, like "Fast Songs", "Slow Songs", etc.

--Song Preview--
	If the player is paused and the user hovers over a song in the playlist then play a short sample (10 seconds?)
</pre>

<p>You can find more information and the source files <a href="http://ajbogh.github.com/Glasir/">here</a> if you&#8217;re interested in testing it out. The project is open for new developers too, so if you like the idea and think you can add something to the project, then please join.</p>

<p><a href="http://ajbogh.github.com/Glasir/">http://ajbogh.github.com/Glasir/</a></p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/02/23/glasir-an-open-source-phphtml5-media-player/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving a Failing Hard Drive with GNU/Linux</title>
		<link>http://opencodeproject.com/2012/02/19/saving-a-failing-hard-drive-with-gnulinux/</link>
		<comments>http://opencodeproject.com/2012/02/19/saving-a-failing-hard-drive-with-gnulinux/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 08:18:54 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[chkdsk]]></category>
		<category><![CDATA[Clonezilla]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[ddrescue]]></category>
		<category><![CDATA[failing]]></category>
		<category><![CDATA[hard drive]]></category>
		<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Office]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=201</guid>
		<description><![CDATA[I came to find out that my mother&#8217;s computer&#8217;s hard drive was failing. Programs took a long time to open and the computer would suddenly reboot for no reason. I discovered that the hard drive had bad sectors, which means &#8230; <a href="http://opencodeproject.com/2012/02/19/saving-a-failing-hard-drive-with-gnulinux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I came to find out that my mother&#8217;s computer&#8217;s hard drive was failing. Programs took a long time to open and the computer would suddenly reboot for no reason. I discovered that the hard drive had bad sectors, which means potentially lost data if it decided to quit before I could save the data onto a different drive. Various GNU/Linux-based systems saved the day.</p>
<span id="more-201"></span>
<p>I determined that the problem must have been a failing hard drive, although there was very little to go by, so I purchased a new one and began the copy process. I started with <a href="http://clonezilla.org/">Clonezilla</a>, which is a very good drive duplication utility, but it kept failing. At first I thought this was because of the bad sectors, but it may have been because the USB drive that I had connected would turn off after a while (perhaps it wasn&#8217;t getting enough power from the one USB port). I decided to try something different.</p>

<p>Within Linux there&#8217;s a program called &#8216;<a href="http://en.wikipedia.org/wiki/Dd_(Unix)">dd</a>&#8216;. This program can take a bit-for-bit backup of a drive and copy it to another. Since each bit on the drive is duplicated, it will also copy partition maps and boot sectors. Surprisingly, it also copies potentially bad data from within a bad sector, but this is easily fixed afterward. The problem again with dd is that if the external backup drive keeps disconnecting from the computer then I would always have to restart it. This is where a program called <a href="http://www.gnu.org/software/ddrescue/ddrescue.html">ddrescue</a> saves the day</p>

<p>ddrescue takes the power of dd and gives it a memory. In the simplest configuration you would tell it what drive to copy from, what drive to copy data to, and where a log file can be found. If anything happens during the copy process, such as if a drive suddenly fails or stops responding, then ddrescue can continue where it left off because of the log file.</p>

<p>I was able to use the following command:</p>
<pre>
ddrescue -B -v /dev/sda /dev/sdb /mnt/log/ddrescue_logfile_AAAA-MM-JJ.log
</pre>
<p>The &#8220;-B&#8221; option will display units of 1024 instead of 1000 for the number of bits copied. The &#8220;-v&#8221; option is for verbose mode. &#8220;/dev/sda&#8221; is the source drive that has the errors. &#8220;/dev/sdb&#8221; is the new destination drive, it can be a larger size with Windows Vista or later computers. The &#8220;mnt/log&#8221; location is a mounted folder that is not located on either drive. This can be a flash drive or, in my case, a network share. The log file is named &#8220;ddrescue_logfile_2012-02-19.log&#8221;. As long as this same command is used whenever the copy process is interrupted, the process will automatically continue where it left off, as if nothing ever happened.</p>

<p>Once ddrescue was complete (a long time later), I put the new drive in the computer and booted into Windows. Windows booted up and I was able to log in. I told it to do a chkdsk by opening the command prompt and typing &#8220;chkdsk C: -F -R -B&#8221; and rebooted. Windows found several bad files and fixed them during the reboot. Using Windows&#8217; disk management tool I was able to extend the volume to fill the new, larger drive.</p>

<p>Later on I found out that Microsoft Office was unable to run due to the bad sectors being where an important Office file was located. I was able to use the Programs and Features Control Panel application to repair the Office install. I didn&#8217;t even need the Office disk (which you never get with new computers). Now everything works again. I do have to say that <a href="http://www.libreoffice.org/">LibreOffice</a> was used to supplement MS Office until I could find out the problem with MS Office and figure out a solution.</p>

<p>With this I have to thank the GNU/Linux developers, the creators of Clonezilla, dd, and ddrescue, <a href="http://www.ubuntu.com/">Ubuntu</a> for their live CDs, and the LibreOffice developers.</p>]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/02/19/saving-a-failing-hard-drive-with-gnulinux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Set Up an Ubuntu Active Directory Client</title>
		<link>http://opencodeproject.com/2012/02/13/how-to-set-up-an-ubuntu-active-directory-client/</link>
		<comments>http://opencodeproject.com/2012/02/13/how-to-set-up-an-ubuntu-active-directory-client/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 23:19:49 +0000</pubDate>
		<dc:creator>Allan Bogh</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Likewise]]></category>

		<guid isPermaLink="false">http://opencodeproject.com/?p=186</guid>
		<description><![CDATA[Here I will explain a solution that worked for me to configure an Ubuntu workstation to authenticate with an Active Directory domain. The workstation was able to browse domain resources (ie, filesystem) without having to log in and it pulled &#8230; <a href="http://opencodeproject.com/2012/02/13/how-to-set-up-an-ubuntu-active-directory-client/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here I will explain a solution that worked for me to configure an Ubuntu workstation to authenticate with an Active Directory domain. The workstation was able to browse domain resources (ie, filesystem) without having to log in and it pulled the AD group information from the domain controller. A process was used to map certain groups to Linux (Ubuntu) groups, however extensive verification of the results could not be performed.</p>
<span id="more-186"></span>
<p>
If you&#8217;re using a VMWare client then you must set a static MAC address, don&#8217;t allow your VM software to automatically update the MAC address.</p>
<h1>Setup your network</h1><p>
First, set your IP to static IP and configure DNS to point to your domain controllers or any other DNS server you may have. This will allow you to call Windows computers by their short names. You must also fill in the Search Domains with your domain name.</p>
<img width="425" height="515" alt="Network Settings" src="/wp-content/uploads/2012/02/Screenshot-Editing-Auto-eth0.png" /><p>
Notice that I used &#8220;mydomain.<strong>local</strong>&#8220;. This causes a stupid issue with mDNS that will need to be adjusted. If you use something like &#8220;mydomain.com&#8221; then you shouldn&#8217;t need to do the next step.</p>
<h1>Modify nsswitch.conf (fix the .local mDNS issue)</h1>
<p>
Open the file <strong>/etc/nsswitch.conf</strong> by starting your terminal (Applications &gt;&gt; Accessories &gt;&gt; Terminal) and type in:</p>
<pre class="prettyprint">
sudo gedit /etc/nsswitch.conf</pre>
<p>
Modify the line that reads:</p>
<pre class="prettyprint">
hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4</pre>
<p>
Change it to:</p>
<pre class="prettyprint">
hosts:          files dns mdns4_minimal mdns4</pre>
<p>
This should allow a program called <a href="http://www.likewise.com/products/likewise_open/">Likewise-open</a> to authenticate with Active Directory and create a computer account.</p>
<h1>Install Likewise-open</h1>
<p>
Now, in the terminal, type in</p>
<pre class="prettyprint">
sudo apt-get install likewise-open5 likewise-open5-gui</pre>
<p>
You can also use Synaptic and search for &#8220;likewise&#8221;. You&#8217;ll notice a likewise-open and also likewise-open5. They both seem to work. I have installed likewise-open5 and likewise-open5-gui.</p><p>
<h1><strong>Join the domain</strong></h1></p><p>
Once those are installed you can configure Likewise-open by going to System &gt;&gt; Administration &gt;&gt; Active Directory membership. Likewise-open will ask you for a username and password. This user must have privileges to join a computer to the domain.</p><p>
<img width="414" height="551" alt="Likewise-open GUI configuration" src="/wp-content/uploads/2012/02/Screenshot-Ubuntu-32bit-Running-VirtualBox-OSE.png" /></p><p>
You can also use the command line to join the computer to the domain:</p>
<pre class="prettyprint">
sudo domainjoin-cli join mydomain.local Administrator</pre>
<p>
You will then be asked to restart the computer. When the computer restarts you can use the Other User login option.</p>
<img width="500" height="374" src="/wp-content/uploads/2012/02/4065116840_93b8fb959b.jpg" alt="Other User login" /><p>
Type in &#8220;<strong>mydomain\username</strong>&#8221; where &#8220;mydomain&#8221; is the short name for your domain and &#8220;username&#8221; is some domain user account. If all of the steps above worked out well then you should be authenticated and logged into Ubuntu. You might get an Authentication Failure notice, which is usually due to one of the network settings from above being messed up or the username being typed in wrong.</p><p>
When you&#8217;ve verified that the account can log in you can log out and return to your normal Ubuntu account. A few more optional steps can be used to complete the process.</p><p>
<h1><strong>Sudoers</strong></h1></p><p>
Edit your sudoers file by opening up a terminal window and typing </p>
<pre class="prettyprint">
sudo visudo</pre>
<p>
A vi-style program will show and allow you to edit the sudoers configuration. Under the %admin line you should add the following:</p>
<pre class="prettyprint">
%MYDOMAIN\\Domain^Admins ALL=(ALL) ALL</pre>
<p>
Make MYDOMAIN whatever your short domain name is (don&#8217;t make it MYDOMAIN.LOCAL).</p>
<h1>Add users to the login screen</h1>

<p>Most domains won&#8217;t want this but you might like it for a Kiosk or a sample computer. When using domain logins you will have to type &#8220;mydomain\username&#8221; using the Other User login option. This can be too many steps for some people so it may be necessary to add a single-click option for their username. The end result will look like the following image.</p>
<img width="500" height="362" src="/wp-content/uploads/2012/02/Screenshot-Ubuntu-32bit-Running-VirtualBox-OSE-1.png" alt="Ubuntu login" />
<p>
Log in as your domain user and open up the terminal. Type &#8220;id&#8221; in the terminal window to view your UID and GID information. It will look something like:</p>
<pre class="prettyprint">
DOMAIN\username@ubuntu-client:~$ id
uid=1234567889(username) ....</pre>

<p>We only really care about the uid at this point. Write it down and log out of this user and back into the normal Ubuntu user account.</p><p>
You will need to edit your <strong>/etc/passwd</strong> file. Open a terminal window and type the following command:</p>
<pre class="prettyprint">
sudo gedit /etc/passwd</pre>

<p>Make a new line at the bottom and duplicate the following information with the numbers that you wrote down: </p>
<pre class="prettyprint">
DOMAIN\username:x:1234567889:0:John Doe,,,:/home/DOMAIN/username:/bin/bash</pre>

<p>The group id (0) is admin to help make this person a local admin, but you should be able to use the uid in it&#8217;s place if you don&#8217;t want to use the admin group. It should look like this in that case:</p>
<pre class="prettyprint">
DOMAIN\username:x:1234567889:1234567889:John Doe,,,:/home/DOMAIN/username:/bin/bash</pre>

<p>Now you can log out of the local Ubuntu user&#8217;s account and see the updated login screen. The domain user or kiosk user can click on the big button and type in the password for the account.</p>
]]></content:encoded>
			<wfw:commentRss>http://opencodeproject.com/2012/02/13/how-to-set-up-an-ubuntu-active-directory-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

