<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brennydoogles&#039; Programming Blog</title>
	<atom:link href="http://brennydoogles.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://brennydoogles.wordpress.com</link>
	<description>Programming and other such nerdiness</description>
	<lastBuildDate>Sat, 11 Feb 2012 14:25:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='brennydoogles.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brennydoogles&#039; Programming Blog</title>
		<link>http://brennydoogles.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://brennydoogles.wordpress.com/osd.xml" title="Brennydoogles&#039; Programming Blog" />
	<atom:link rel='hub' href='http://brennydoogles.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Interesting Read If You Have the Time</title>
		<link>http://brennydoogles.wordpress.com/2012/01/25/interesting-read-if-you-have-the-time/</link>
		<comments>http://brennydoogles.wordpress.com/2012/01/25/interesting-read-if-you-have-the-time/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 22:15:24 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[The Art of Programming]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Art of Programming]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=314</guid>
		<description><![CDATA[Today I was reading about managing hierarchical data using MySQL when I stumbled upon an excellent and extremely informative article. There&#8217;s nothing I can add to the article that isn&#8217;t better articulated there, so head on over and check it out! Filed under: Programming, The Art of Programming Tagged: Algorithms, Art of Programming, MySQL<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=314&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I was reading about managing hierarchical data using MySQL when I stumbled upon an excellent and extremely informative article. There&#8217;s nothing I can add to the article that isn&#8217;t better articulated there, so <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/">head on over</a> and check it out!</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/the-art-of-programming/'>The Art of Programming</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/algorithms/'>Algorithms</a>, <a href='http://brennydoogles.wordpress.com/tag/art-of-programming/'>Art of Programming</a>, <a href='http://brennydoogles.wordpress.com/tag/mysql/'>MySQL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=314&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2012/01/25/interesting-read-if-you-have-the-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>36.290857 -82.377734</georss:point>
		<geo:lat>36.290857</geo:lat>
		<geo:long>-82.377734</geo:long>
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Not to Beat a Dead Horse: Why You Should Actively Oppose SOPA</title>
		<link>http://brennydoogles.wordpress.com/2012/01/18/not-to-beat-a-dead-horse-why-you-should-actively-oppose-sopa/</link>
		<comments>http://brennydoogles.wordpress.com/2012/01/18/not-to-beat-a-dead-horse-why-you-should-actively-oppose-sopa/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 22:23:52 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Rants]]></category>
		<category><![CDATA[Technology and Law]]></category>
		<category><![CDATA[american innovations]]></category>
		<category><![CDATA[american innovators]]></category>
		<category><![CDATA[domain name server]]></category>
		<category><![CDATA[house judiciary committee]]></category>
		<category><![CDATA[international protections]]></category>
		<category><![CDATA[lamar smith]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=315</guid>
		<description><![CDATA[Unless you have been living in a cave recently you have heard of the bills SOPA (Stop Online Piracy Act) and PIPA (PROTECT IP Act). These bills have been introduced as a way to prevent the distribution of copyrighted materials over the internet by allowing the government increased powers for censoring websites which facilitate the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=315&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_316" class="wp-caption aligncenter" style="width: 310px"><a href="http://brennydoogles.files.wordpress.com/2012/01/fight-sopa.jpg"><img class="wp-image-316 " title="Fight-SOPA" src="http://brennydoogles.files.wordpress.com/2012/01/fight-sopa.jpg?w=300&#038;h=225" alt="Fight SOPA" width="300" height="225" /></a><p class="wp-caption-text">Courtesy of Vaughn Teegarden</p></div>
<p>Unless you have been living in a cave recently you have heard of the bills SOPA (Stop Online Piracy Act) and PIPA (PROTECT IP Act). These bills have been introduced as a way to prevent the distribution of copyrighted materials over the internet by allowing the government increased powers for censoring websites which facilitate the illegal distribution of intellectual property. This would be accomplished mainly by identifying websites which are accused of distributing copyrighted material, and ordering all American DNS&#8217;s (Domain Name Server) to stop referring requests to those websites. According to <a href="http://judiciary.house.gov/news/HR%203261%20Introduced.html">House Judiciary Committee Chairman Lamar Smith (R-Texas),</a></p>
<blockquote><p>
The Stop Online Piracy Act helps stop the flow of revenue to rogue websites and ensures that the profits from American innovations go to American innovators. The bill prevents online thieves from selling counterfeit goods in the U.S., expands international protections for intellectual property, and protects American consumers from dangerous counterfeit products.</p></blockquote>
<p>SOPA and PIPA (which I will refer to collectively as SOPA from now on) are dangerous pieces of legislation, and in my opinion you should actively oppose them. Here&#8217;s why:</p>
<h3>SOPA is Unlikely to Prevent Piracy</h3>
<p>In order to explain why SOPA is unlikely to stop piracy, I want to first give a brief explanation of how DNS (SOPA&#8217;s primary censoring method) works. All computers have what is called an IP address, which is a number representing that computer on the internet. Since every website on the internet is hosted on a computer, every website also has an IP address. This is a very convenient way to direct requests to websites if you&#8217;re a computer, but if you&#8217;re a human you are not likely to be able to remember more than a handful of IP addresses at a time. DNS is the solution to this problem. DNS stores a directory of domain names (such as <a href="http://www.newegg.com/">www.newegg.com</a>) as well as their corresponding IP address (<a href="http://216.52.208.187">216.52.208.187</a>). As you can see, both the IP address and www.newegg.com will load the same page.</p>
<p>This is important because removing a website from DNS does not prevent anyone who is moderately technical from viewing a website. In order to prevent someone with reasonable technical ability from accessing websites, the government would have to start actively monitoring all data which makes it&#8217;s way across the internet in real-time. Not only would this be prohibitively expensive, it would be a massive breach of privacy for everyone on the internet (imagine someone from the government reading some of the more *ahem* exciting emails you have exchanged with your significant other). While this huge invasion of privacy would limit what normal people are willing to share over the internet, the most tech savvy of us would know how to make use of encrypted connections and proxy servers to bypass all restrictions the government tried to place. Every time a company or government has found a way to keep hackers from accessing something, the hackers have found ways to bypass those security measures; a great example of this is <a href="http://en.wikipedia.org/wiki/Gary_McKinnon">Gary McKinnon,</a> the Scottish hacker who penetrated the security measures of multiple US Government agencies looking for evidence that the US covered up contact with Extra Terrestrial Life.</p>
<h3>Those Who Are in a Position to Pass SOPA Don&#8217;t Understand the Internet</h3>
<p>It is well known that the 50+ generation of Americans is largely ignorant to the inner workings of the internet and computers in general. While there are individuals from that generation who were the innovators who designed the internet, there are far more individuals who require a call to the kids to post a photo to Facebook. With that said, the last person you want to make major decisions about an industry is someone who is entirely unfamiliar with that industry.</p>
<p>Most of us remember several years back when Senator Ted Stevens referred to the internet as <a href="http://www.youtube.com/watch?v=f99PcP0aFNE">A Series of Tubes</a>. If you haven&#8217;t listened to his speech recently, take a minute to do so now. I&#8217;ll wait. Throughout all of the stammering in that video, the only recognizable words describe something similar to Netflix, and a series of tubes. Also, it seems like he may have mentioned using the internet for the first time that day. There are no requirements in Congress for knowing what you are talking about before you can vote on a bill. Ted Stevens was given the ability to vote against Net Neutrality not long after that speech. Think about that. Also think about the fact that according to <a href="http://www.senate.gov/reference/resources/pdf/R41647.pdf">www.senate.gov (PDF)</a> the average age of members of the 112th was 62.2 years. </p>
<h3>The Websites You Love Could Be Banned</h3>
<p>It should by now be clear that SOPA has almost no chance of successfully completing it&#8217;s goal, but it does have a great chance of  accomplishing a much more harmful goal: ruining the internet. Many would agree that the strength of the internet is that people of all walks of life can share information about the things they understand, and find information about things they don&#8217;t. Sites like <a href="http://www.wordpress.com">WordPress</a>, <a href="http://www.stackoverflow.com">Stack Overflow</a>, and <a href="http://www.wikipedia.org">Wikipedia</a> provide a great deal of knowledge to people all over the world every day. But sites like these are in danger of being taken down because of a clause in SOPA which <a href="https://www.eff.org/deeplinks/2011/10/disastrous-ip-legislation-back-%E2%80%93-and-it%E2%80%99s-worse-ever">makes domain owners responsible for content posted by their users.</a> In short, if I posted copyrighted material on my blog in a world where SOPA was law, the entire domain wordpress.com could be taken down. As I write this article, wordpress.com is home to roughly 35,247,329 blogs. And they could all be taken down due to the indiscretion of one blogger. The same could be true of Facebook or any number of other sites you use on a daily basis.</p>
<p>SOPA is dangerous, and if it manages to pass the internet will change forever. Not in a good way. Call your local Representatives and tell them to oppose SOPA! </p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/rants/'>Rants</a>, <a href='http://brennydoogles.wordpress.com/category/technology-and-law/'>Technology and Law</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/american-innovations/'>american innovations</a>, <a href='http://brennydoogles.wordpress.com/tag/american-innovators/'>american innovators</a>, <a href='http://brennydoogles.wordpress.com/tag/domain-name-server/'>domain name server</a>, <a href='http://brennydoogles.wordpress.com/tag/house-judiciary-committee/'>house judiciary committee</a>, <a href='http://brennydoogles.wordpress.com/tag/international-protections/'>international protections</a>, <a href='http://brennydoogles.wordpress.com/tag/lamar-smith/'>lamar smith</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/315/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/315/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/315/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=315&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2012/01/18/not-to-beat-a-dead-horse-why-you-should-actively-oppose-sopa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>36.290857 -82.377734</georss:point>
		<geo:lat>36.290857</geo:lat>
		<geo:long>-82.377734</geo:long>
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>

		<media:content url="http://brennydoogles.files.wordpress.com/2012/01/fight-sopa.jpg?w=300" medium="image">
			<media:title type="html">Fight-SOPA</media:title>
		</media:content>
	</item>
		<item>
		<title>Making HTTP POST Requests Part 1 &#8211; PHP</title>
		<link>http://brennydoogles.wordpress.com/2011/12/29/making-http-post-requests-part-1-php/</link>
		<comments>http://brennydoogles.wordpress.com/2011/12/29/making-http-post-requests-part-1-php/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 16:59:34 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[The Art of Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=295</guid>
		<description><![CDATA[Recently at my job I have had several situations in which I needed to pass fairly large amounts of data to a particular page on a website for processing, and in which submitting a form isn&#8217;t a feasible option. Typically in this situation one would attempt to append the data to the url using GET [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=295&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently at my job I have had several situations in which I needed to pass fairly large amounts of data to a particular page on a website for processing, and in which submitting a form isn&#8217;t a feasible option. Typically in this situation one would attempt to append the data to the url using GET parameters, but sometimes your data is too large or too sensitive to pass through the URL. Unfortunately, PHP does not provide an easy way to make post requests natively. Luckily for us, there is <a href="http://php.net/manual/en/book.curl.php">cURL</a>. cURL allows us to communicate across multiple protocols to a variety of different server types. With cURL, we are able to make HTTP POST requests:<br />
<pre class="brush: php;">
function post_request($url, $data) {
	$output = array();
	foreach ($data as $key =&gt; $value) {
		if(is_object($value) || is_array($value)){
			$data[$key] = serialize($value);
		}
	}
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	$result = curl_exec($ch);
	if ($result) {
		$output['status'] = &quot;ok&quot;;
		$output['content'] = $result;
	} else {
		$output['status'] = &quot;failure&quot;;
		$output['error'] = curl_error($ch);
	}
	curl_close($ch);
	return $output;

}
</pre></p>
<p>The above function accepts two parameters, the URL to make the request to, and an associative array containing the keys and values you would like to submit with your POST request. The function returns an associative array containing two values: status, which will either be equal to &#8220;ok&#8221; or &#8220;failure&#8221; depending on the success or failure of the POST request; and either &#8216;content&#8217; or &#8216;error&#8217; depending on success or failure. In the case of a successful POST request, &#8216;content&#8217; will contain the full output from the page you have posted to (In other words, you may need to be prepared for an entire html document). Otherwise, &#8216;error&#8217; will contain the details of the error as returned by cURL.</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/php/'>PHP</a>, <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/the-art-of-programming/'>The Art of Programming</a>, <a href='http://brennydoogles.wordpress.com/category/tutorials/'>Tutorials</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=295&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2011/12/29/making-http-post-requests-part-1-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Subversion to Automatically Publish Your Website</title>
		<link>http://brennydoogles.wordpress.com/2011/10/21/using-subversion-to-automatically-publish-your-website/</link>
		<comments>http://brennydoogles.wordpress.com/2011/10/21/using-subversion-to-automatically-publish-your-website/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 18:46:54 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=277</guid>
		<description><![CDATA[Recently at work my co-workers and I have been working on a fairly large and complex website (which will be top secret until early next year ), and we have encountered one of the pitfalls associated with group web development: Overwriting each other&#8217;s code with FTP. The natural solution was to use Subversion to manage [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=277&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently at work my co-workers and I have been working on a fairly large and complex website (which will be top secret until early next year <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), and we have encountered one of the pitfalls associated with group web development: Overwriting each other&#8217;s code with FTP. The natural solution was to use Subversion to manage our source code. We created our repository, checked out our local copies, and regularly updated and committed our code. While this greatly reduced the frequency and severity of our FTP mishaps, it did not eliminate them entirely. As tension began to mount (exaggerated greatly for literary value), we decided to seek a better solution&#8230; something that would allow for our development server to automatically reflect the contents of our source repository. We eventually settled on the use of a post-commit hook, which for those of you who are new to subversion is simply a script (which can be written in any language your server understands) which is executed every time anyone commits to the repository. Unfortunately for us our Subversion Repository was hosted on a third party server, and we did not have access to the server to write the hook. This meant that we were going to need to create a new repository on a server we could access. We chose to use the Web Server we host our site on, just because it reduces the overall complexity of our setup considerably. The following steps were implemented on an Ubuntu 11.04&#215;64 server, but the steps should be nearly identical (with the exception of possibly the package management) on any modern Linux server.</p>
<h2>Using Subversion to Automatically Publish Your Website</h2>
<h3>Install Subversion and Subversion Apache Support</h3>
<p><pre class="brush: bash;">
sudo apt-get install subversion libapache2-svn
</pre></p>
<h3>Create the SVN Directories</h3>
<p>You can place your SVN Root anywhere you would like on the filesystem, but I chose to place mine in /svn, feel free to edit these commands to reflect your desired location. Also, in my example I change the ownership of the svn directory to the user/group www-data. If you are using a different Linux distribution you may need to check to see which user Apache runs as by default, and adjust the commands accordingly.<br />
<pre class="brush: bash;">
sudo mkdir /svn
sudo chown www-data:www-data /svn
</pre></p>
<h3>Creating Your Repository and Configuring Apache to Serve It</h3>
<p>We need to configure Apache to know the location of our repository (which I realize we haven&#8217;t created yet), so point your favorite text editor (I&#8217;m a Nano guy) at /etc/apache2/mods-available/dav_svn.conf:<br />
<pre class="brush: bash;">
sudo nano /etc/apache2/mods-available/dav_svn.conf
</pre><br />
By default almost everything in the file is commented out. While it is possible to set up your repository to allow anonymous reading (and is in fact the default option), I opted to require authentication for every action on this repository since this source code will most likely end up containing database user credentials. Since an example of setting up anonymous reading is in the configuration file, I will allow you to un-comment it if you would like to use it. Here is an example of the config file I am using:<br />
<pre class="brush: xml;">
&lt;Location /svn/repository&gt;
  # Uncomment this to enable the repository
  DAV svn
  # Set this to the path to your repository
  SVNPath /svn/repository

  # Authorization Data
  AuthType Basic
  AuthName &quot;Subversion Repository&quot;
  AuthUserFile /etc/apache2/dav_svn.passwd
  Require valid-user
&lt;/Location&gt;
</pre></p>
<p>There are a few things to note about the above file. The first is the  tag, which needs to point to the location we plan to create the repository in. Also note that SVNPath should point to the same location. The next section contains data about how to authorize users. I used basic .htaccess style authentication, with an auth file located at /etc/apache2/dav_svn.passwd. The last line before the closing  tag states that only users with a valid username and password are able to access the repository. </p>
<p>Now that we have Apache pointed at the repository, let&#8217;s create it! In order to prevent permissions issues, we need to become the www-data user:<br />
<pre class="brush: bash;">
sudo su www-data
</pre><br />
when asked for a password, enter your own password. Now that we are the correct user, let&#8217;s create the repository at the location we specified above.<br />
<pre class="brush: bash;">
svnadmin create /svn/repository
exit
</pre><br />
Now that the repository exists and Apache is configured to see it, we need to restart Apache to refresh the configuration:<br />
<pre class="brush: bash;">
sudo /etc/init.d/apache2 restart
</pre><br />
After a moment, try to point your browser to http://[yourdomain].com/svn/repository. If everything is configured correctly you should see a password box pop up. Of course, there are no users authenticated for the repository, so at this point you can&#8217;t get in.</p>
<h3>Creating Your SVN User Accounts</h3>
<p>Now that the repository is set up, we need to have authenticated users to commit to and update from the repository. When creating users, the command to create the first user is slightly different from the command to create all other users. For the first user do:<br />
<pre class="brush: bash;">
sudo htpasswd -cm /etc/apache2/dav_svn.passwd username
</pre><br />
and for the rest do:<br />
<pre class="brush: bash;">
sudo htpasswd -m /etc/apache2/dav_svn.passwd username
</pre><br />
After creating a user for yourself, go back to http://[yourdomain].com/svn/repository and enter your username and password. If all goes well, you should see a screen indicating that your repository is at revision 0.</p>
<h3>Setting Up Your Website to Retrieve Data from the Repository</h3>
<p>There are several way to do this next step, and several things to consider before choosing a path. If your website already exists, you may want to set up a new virtual host on your server to hold the new copy until you are satisfied with the performance of the repository, or if you have an up to date local copy you may feel free to simply delete your old directory on the server (as we will be remaking it in a moment). Another thing to consider will be subversion configuration directories inside your website. If your server is configured like mine, it denies access to .svn directories, and an svn checkout command should be an easy way to accomplish our task. Otherwise, you may want to consider using an svn export command instead. Since my server is configured to be safe with .svn directories, I decided to go with the checkout command. Since my website is located at /var/www/mysite, the commands to do a fresh svn checkout is:<br />
<pre class="brush: bash;">
sudo rm -rf /var/www/mysite
cd /var/www
sudo svn checkout file:///svn/repository mysite --username yourusername --password yourpassword
</pre><br />
You should now have a basically empty directory, which has the distinct advantage of being able to be quickly updated to contain the contents of the repository.</p>
<h3>Updating Your Website After SVN Commit</h3>
<p>Now that the repository is set up and our website is pointing to a working copy, we can set up our post-commit hook to update the website every time a commit is made. Due to the somewhat complex nature of Linux permissions, we will be performing three main steps to accomplish this goal: Creating a script to update the working copy in our webroot, giving the Apache user (in my case www-data) the ability to run that script as root without a password, and then creating our hook to call that script as root.<br />
First we create the script (Note: this command will open Nano to a blank file for you to edit and as soon as you save the file it will also make that file executable):<br />
<pre class="brush: bash;">
sudo nano /usr/local/bin/svn-post-commit-update-mysite &amp;&amp; sudo chmod +x /usr/local/bin/svn-post-commit-update-mysite
</pre><br />
And inside place:<br />
<pre class="brush: bash;">
#!/bin/bash
cd /var/www/mysite &amp;&amp; sudo svn update
</pre><br />
This code will simply navigate to the working copy we checked out in the last step, and run svn update. This should update the contents of that folder to reflect the contents of the repository.</p>
<p>Next we will give the Apache user the ability to run this script as root without a password by editing /etc/sudoers<br />
<pre class="brush: bash;">
sudo nano /etc/sudoers
</pre><br />
and adding the following line:<br />
<pre class="brush: bash;">
www-data    ALL=(root) NOPASSWD: /usr/local/bin/svn-post-commit-update-mysite
</pre></p>
<p>Next we will create and edit the post-commit hook for the repository:<br />
<pre class="brush: bash;">
sudo nano /svn/repository/hooks/post-commit &amp;&amp; sudo chmod +x /svn/repository/hooks/post-commit
</pre><br />
And inside place:<br />
<pre class="brush: bash;">
#!/bin/bash
sudo /usr/local/bin/svn-post-commit-update-mysite 1&gt;&amp;2
</pre></p>
<h3>Testing Your Setup</h3>
<p>Now that everything is theoretically set up, all we have left to do is test. The best way to do this would be to do an svn checkout on your local machine, copy the local backup of your website into the folder you performed your checkout into, and then attempt to run a commit on your working copy. If all goes well, you should be able to point your web browser at your Website and see what you just committed.</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/linux/'>Linux</a>, <a href='http://brennydoogles.wordpress.com/category/tutorials/'>Tutorials</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/linux/'>Linux</a>, <a href='http://brennydoogles.wordpress.com/tag/subversion/'>Subversion</a>, <a href='http://brennydoogles.wordpress.com/tag/svn/'>svn</a>, <a href='http://brennydoogles.wordpress.com/tag/tutorials/'>Tutorials</a>, <a href='http://brennydoogles.wordpress.com/tag/ubuntu/'>Ubuntu</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=277&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2011/10/21/using-subversion-to-automatically-publish-your-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>35.598223 -82.538416</georss:point>
		<geo:lat>35.598223</geo:lat>
		<geo:long>-82.538416</geo:long>
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>On a Personal Note: My Long Absence Explained</title>
		<link>http://brennydoogles.wordpress.com/2011/09/07/on-a-personal-note-my-long-absence-explained/</link>
		<comments>http://brennydoogles.wordpress.com/2011/09/07/on-a-personal-note-my-long-absence-explained/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 22:40:02 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Life!]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=265</guid>
		<description><![CDATA[Hey all, I just wanted to take a break from my normal programming to give a personal update. Over the past few months I have not written very many blog posts, but this blog is far from abandoned. I have been extremely busy. In the last few months, I have started a new job for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=265&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all, I just wanted to take a break from my normal programming to give a personal update. Over the past few months I have not written very many blog posts, but this blog is far from abandoned. I have been extremely busy. In the last few months, I have started a new job for a fantastic company in Asheville, NC, as well as a <a href="http://www.yourheartphotography.com">Photography business</a> with my wife. The real distraction, however, has been the birth of our son Aiden!<div id="attachment_266" class="wp-caption alignnone" style="width: 478px"><img src="http://brennydoogles.files.wordpress.com/2011/09/the-dugan-family.jpg?w=468&#038;h=312" alt="The Dugan Family" title="The Dugan Family" width="468" height="312" class="size-full wp-image-266" /><p class="wp-caption-text">My Wife and I with our beautiful baby boy!</p></div></p>
<p>Now that things are calming down a bit, I hope to be able to post more regularly!</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/life/'>Life!</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/life/'>Life!</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=265&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2011/09/07/on-a-personal-note-my-long-absence-explained/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>

		<media:content url="http://brennydoogles.files.wordpress.com/2011/09/the-dugan-family.jpg" medium="image">
			<media:title type="html">The Dugan Family</media:title>
		</media:content>
	</item>
		<item>
		<title>Taking Control of Your PHP Sessions: Using Database Sessions</title>
		<link>http://brennydoogles.wordpress.com/2011/09/06/taking-control-of-your-php-sessions-using-database-sessions/</link>
		<comments>http://brennydoogles.wordpress.com/2011/09/06/taking-control-of-your-php-sessions-using-database-sessions/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 18:05:02 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Art of Programming]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=250</guid>
		<description><![CDATA[Introduction Recently while working on a project for my employer Festiva Hospitality Group, I encountered an interesting issue. I needed to develop a way to add and remove permissions from a User in a system we are building (which will be made open source as a service to the internet community once development is complete), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=250&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>
Recently while working on a project for my employer <a href="www.festiva.travel">Festiva Hospitality Group</a>, I encountered an interesting issue. I needed to develop a way to add and remove permissions from a User in a system we are building (which will be made open source as a service to the internet community once development is complete), but I needed the ability to push out these permission changes even if a user is currently logged in to the system.
</p>
<p>
As far as I know PHP does not provide a way to edit User sessions other than the $_SESSION array, which only applies to the current User&#8217;s session. After some research, I discovered that it is possible to change PHP&#8217;s default session storage method. This can be very useful if you are using a CDN to share server load between multiple servers while still allowing data persistence through the session. Another useful benefit of storing your sessions in the Database is the ability to alter User sessions (for any user) on the fly.
</p>
<p>
There are a few things to note about editing User Sessions on the fly:</p>
<ul>
<li>If you aren&#8217;t careful you can inadvertently edit the wrong session, leading to security issues</li>
<li>The way session data is stored in the database is through a single serialized data field. This means that before editing a session variable you must either parse and change only the value you wish to change, or unserialize the entire session data string, edit the individual values, and then re-serialize the data for insert.</li>
<li>I have never tried the above method, and therefore cannot provide any code to accomplish this task. If this changes, I will edit this post with the relevant code</li>
<li>If you are only storing basic login type data in the session (which would be pulled from the Database), killing a User&#8217;s session and allowing them to log back in is the safest way to ensure that any changes to the session will populate correctly</li>
</ul>
<h3>Setting up the Database</h3>
<p>
The SQL in this tutorial is written to work with MySQL, so if you&#8217;re using something else just bear in mind that your syntax may need to be tweaked, especially in the DDL.
</p>
<h4>Create the Table:</h4>
<p>
<pre class="brush: sql;">
CREATE TABLE SESSION (
id VARCHAR(32) NOT NULL COMMENT 'Stores the Session ID',
access INT(10) UNSIGNED NOT NULL,
data TEXT,
PRIMARY KEY (`id`)
) ENGINE=INNODB
ROW_FORMAT=DEFAULT;
</pre>
</p>
<h4>Create a few PHP classes</h4>
<p>
This first class I built handles the Database connection, and is in two parts: Config.inc.php (for configuring the database variables) and MySQLDatabase.class.php:
</p>
<p>Config.inc.php<br />
<pre class="brush: php;">
&lt;?php
define(&quot;conf_hostname&quot;, &quot;localhost&quot;);
define(&quot;conf_username&quot;, &quot;user&quot;);
define(&quot;conf_password&quot;, &quot;password&quot;);
define(&quot;conf_schema&quot;, &quot;database_to_use&quot;);
?&gt;
</pre><br />
MySQLDatabase.class.php<br />
<pre class="brush: php;">
&lt;?php
include(&quot;Config.inc.php&quot;);
class MySQLDatabase{
	private $db;
	private $hostname;
	private $username;
	private $password;
	private $schema;
	
	function __construct() {
		if(func_num_args() == 0){
			$this-&gt;hostname = conf_hostname;
			$this-&gt;username = conf_username;
			$this-&gt;password = conf_password;
			$this-&gt;schema = conf_schema;
		}
		else{
			$params = func_get_args();
			$this-&gt;hostname = $params[0];
			$this-&gt;username = $params[1];
			$this-&gt;password = $params[2];
			$this-&gt;schema = $params[3];
		}
	}
	
	private function open(){
		$this-&gt;db = mysql_connect($this-&gt;hostname, $this-&gt;username, $this-&gt;password) or die ('Error connecting to mysql');
		mysql_select_db($this-&gt;schema, $this-&gt;db);
	}
	
	public function executeQuery($query){
		$this-&gt;open();
		$results = mysql_query($query, $this-&gt;db) or die (&quot;Error in query: $query. &quot;.mysql_error());
		return $results;
	}
	
	public function close(){
		mysql_close($this-&gt;db);
	}
	
}
?&gt;
</pre></p>
<p>
Next we need to create a class to handle some session related events:
</p>
<p>DatabaseSessionHandler.class.php<br />
<pre class="brush: php;">
&lt;?php
include_once (&quot;MySQLDatabase.class.php&quot;);
/**
 *
 */
class DatabaseSessionHandler {
	private $db;

	public function _open($save_path, $session_name) {
		$this -&gt; db = new MySQLDatabase();
		return true;
	}

	public function _close() {
		$this -&gt; db -&gt; close();
	}

	function _read($id) {

		$id = mysql_real_escape_string($id);

		$query = &quot;SELECT data
				FROM SESSION
				WHERE id = '$id'&quot;;

		if ($result = $this -&gt; db -&gt; executeQuery($query)) {
			if (mysql_num_rows($result)) {
				$record = mysql_fetch_assoc($result);
				return $record['data'];
			}
		}

		return '';
	}

	function _write($id, $data) {
		$access = time();

		$id = mysql_real_escape_string($id);
		$access = mysql_real_escape_string($access);
		$data = mysql_real_escape_string($data);

		$query = &quot;REPLACE
				INTO SESSION
				VALUES ('$id', '$access', '$data')&quot;;

		return $this -&gt; db -&gt; executeQuery($query);
	}

	function _destroy($id) {

		$id = mysql_real_escape_string($id);

		$query = &quot;DELETE
				FROM SESSION
				WHERE id = '$id'&quot;;

		return $this -&gt; db -&gt; executeQuery($query);
	}

	function _clean($max) {
		$old = time() - $max;
		$old = mysql_real_escape_string($old);

		$query = &quot;DELETE
				FROM SESSION
				WHERE access &lt; '$old'&quot;;

		return $this -&gt; db -&gt; executeQuery($query);
	}
	
	public function killUserSession($username){
		$query = &quot;delete from SESSION where data like('%userID|s:%\&quot;&quot;. mysql_real_escape_string($username) .&quot;%\&quot;;first_name|s:%')&quot;;
		$this-&gt;db-&gt;executeQuery($query);
	}

}
?&gt;
</pre></p>
<h3>Replacing PHP&#8217;s Session with our Database Session</h3>
<p>Now all we have left to do is actually utilize our new session handling. This is actually a relatively painless process. In my application the session is started in the header include file for each page. In this case, all I had to do was change:</p>
<p><pre class="brush: php;">
&lt;?php
     session_start();
?&gt;
</pre><br />
to:<br />
<pre class="brush: php;">
&lt;?php
$sess = new DatabaseSessionHandler();
session_set_save_handler(array(&amp;$sess, '_open'),
                         array(&amp;$sess, '_close'),
                         array(&amp;$sess, '_read'),
                         array(&amp;$sess, '_write'),
                         array(&amp;$sess, '_destroy'),
                         array(&amp;$sess, '_clean'));
session_start();
?&gt;
</pre></p>
<p>
From here on out, the session can be handled in code exactly like a PHP session, but now you also have the ability to edit User sessions on the fly!</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/php/'>PHP</a>, <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/tutorials/'>Tutorials</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/art-of-programming/'>Art of Programming</a>, <a href='http://brennydoogles.wordpress.com/tag/php/'>PHP</a>, <a href='http://brennydoogles.wordpress.com/tag/tutorials/'>Tutorials</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/250/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=250&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2011/09/06/taking-control-of-your-php-sessions-using-database-sessions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>35.600782 -82.536241</georss:point>
		<geo:lat>35.600782</geo:lat>
		<geo:long>-82.536241</geo:long>
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Ubuntu: Automatically Disable Touchpad when External Mouse Connected</title>
		<link>http://brennydoogles.wordpress.com/2010/11/23/automatically-disable-touchpad-when-external-mouse-connected/</link>
		<comments>http://brennydoogles.wordpress.com/2010/11/23/automatically-disable-touchpad-when-external-mouse-connected/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 03:30:17 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Touchpad]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=239</guid>
		<description><![CDATA[Introduction: If you&#8217;re like me, you hate using your touchpad when you could be using an external mouse. If you&#8217;re like me you also have a habit of disabling your touchpad when using a mouse, and forgetting to re-enable it until after you unplug your mouse. If you&#8217;re like me, this tutorial is exactly what [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=239&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction:</h3>
<p>If you&#8217;re like me, you hate using your touchpad when you could be using an external mouse. If you&#8217;re like me you also have a habit of disabling your touchpad when using a mouse, and forgetting to re-enable it until after you unplug your mouse. If you&#8217;re like me, this tutorial is exactly what you need.</p>
<h3>What you need to get started:</h3>
<p>You will need to make sure that you have xinput and halevt installed. You almost certainly already have xinput, but the following command will make sure you have what you need:</p>
<p><pre class="brush: bash;">sudo aptitude install xinput halevt</pre></p>
<p>I also recommend that you create a folder for scripts (if you haven&#8217;t already), and add it to your $PATH. I created a &#8220;bin&#8221; folder in my home directory for this. Create the folder with:</p>
<p><pre class="brush: bash;">mkdir ~/bin</pre></p>
<p>and add it to your path by issuing the following commands:</p>
<p><pre class="brush: bash;">
echo &quot;PATH=\$PATH:~/bin&quot; &gt;&gt; ~/.bashrc
echo &quot;export PATH&quot; &gt;&gt; ~/.bashrc
</pre></p>
<h3>Configure the script:</h3>
<p>First we need to create and configure the script which will actually toggle the touchpad:</p>
<p><pre class="brush: bash;">
cd ~/bin
touch toggleTouchpad
gedit toggleTouchpad
</pre></p>
<p>The script should now be open in gedit (feel free to replace gedit with your favorite text editor). Paste the following into the script:</p>
<p><pre class="brush: bash;">
# toggleTouchpad by Brendon Dugan
# Toggles a touchpad on or off depending on it's current state or CLI argument
#
# To configure, run the command 'xinput list' in terminal and identify your touch pad.
# Using the output of the above command, change the touchpadString variable to a substring
# of your touchpad's description that is unique to that device.
#
# To run, simply type 'toggleTouchpad' to toggle your touchpad on or off, or
# 'toggleTouchpad on' to explicitly turn your touchpad on, or
# 'toggleTouchpad off' to explicitly turn it off.
#
# Enjoy!

# A function for logging
safemk () {
if [ ! -d $1 ];
  then mkdir $1;
  chmod +rw $1;
fi
}
logdir=/home/$USER/.toggleTouchpad
touchpadString=&quot;TouchPad&quot;
touchpadID=$(xinput list | grep &quot;$touchpadString&quot; | awk -F &quot; &quot; '{print $6}' | awk -F &quot;=&quot; '{print $2}')
touchpadEnabled=$(xinput list-props $touchpadID | grep &quot;Device Enabled&quot; | awk -F &quot;:&quot; '{print $2}')
sleeptime=1

# Create the logging directory
safemk $logdir
touch $logdir/errorLog.txt

# Check for arguments on the command line
if test $# -eq 1
then
	# Change the argument to lowercase
	arg1=$(echo $1 | tr [:upper:] [:lower:])
	cliArg=1
else
	# There is no argument.
	cliArg=0
fi

if [ $cliArg -eq 1 ]
then
	# If there's an argument, check to see whether it is on, off, or junk
	if [ $arg1 = 'on' ]
	then
		# The argument was 'on', so turn the touchpad on
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 1
		if [ $(xinput list-props $touchpadID | grep &quot;Device Enabled&quot; | awk -F &quot;:&quot; '{print $2}') -eq 0 ]
		then
			echo &quot;Something went wrong\n&quot; &gt;&gt; $logdir/errorLog.txt
		fi
	elif [ $arg1 = 'off' ]
	then
		# Sleep for a short time to fix a bug that re-enabled the touchpad immediately after disabling it
		sleep $sleeptime
		# The argument was 'off', so turn the touchpad off
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 0
		if [ $(xinput list-props $touchpadID | grep &quot;Device Enabled&quot; | awk -F &quot;:&quot; '{print $2}') -eq 1 ]
		then
			echo &quot;Something went wrong, perhaps \$sleeptime needs to be greater than $sleeptime ?\n&quot; &gt;&gt; $logdir/errorLog.txt
		fi
	else
		# The argument was junk, so log the error and go on
		echo &quot;Invalid argument \&quot;&quot;$arg1&quot;\&quot; was supplied\n&quot; &gt;&gt; $logdir/errorLog.txt
	fi
else
	# There was no argument, so just toggle the touchpad to the opposite
	# of the state it has now.
	if [ $touchpadEnabled -eq 1 ]
	then
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 0
	else
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 1
	fi
fi
</pre></p>
<p>Now make the script executable by running:</p>
<p><pre class="brush: bash;">
 chmod +x ~/bin/toggleTouchpad
</pre></p>
<p>Ok, we&#8217;re almost configured. We need to make sure that your touchpad will be affected by the script. Run the following command to get a list of all current input devices:</p>
<p><pre class="brush: bash;">
xinput -list
</pre></p>
<p>It should have an output something like this:</p>
<p><pre class="brush: plain;">
brendon@brendon-lappy-linux:~$ xinput -list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ Logitech Logitech BT Mini-Receiver      	id=15	[slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=12	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Power Button                            	id=8	[slave  keyboard (3)]
    ↳ Sleep Button                            	id=9	[slave  keyboard (3)]
    ↳ Laptop_Integrated_Webcam_2M             	id=10	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=11	[slave  keyboard (3)]
    ↳ Dell WMI hotkeys                        	id=13	[slave  keyboard (3)]
    ↳ Logitech Logitech BT Mini-Receiver      	id=14	[slave  keyboard (3)]
brendon@brendon-lappy-linux:~$
</pre></p>
<p>If your touchpad has the word &#8220;TouchPad&#8221; (case sensitive) in it, the script is ready to go. If it doesn&#8217;t, edit the variable &#8220;touchpadString&#8221; in the script to match your touchpad&#8230; but remember everything is case sensitive. For now, your script is configured. Next step is testing.</p>
<h3>Test the script:</h3>
<p>Make sure your touchpad is working, and then open a new terminal window. We are going to do four tests. Before and after each test, try your touchpad.</p>
<p>Test 1:</p>
<p><pre class="brush: bash;">toggleTouchpad</pre></p>
<p>Did your touchpad stop working? Good!</p>
<p>Test 2:</p>
<p><pre class="brush: bash;">toggleTouchpad</pre></p>
<p>Did your touchpad start working again? Good!</p>
<p>Test 3:</p>
<p><pre class="brush: bash;">toggleTouchpad off</pre></p>
<p>Wait at least one second&#8230;<br />
Did your touchpad stop working? Good!</p>
<p>Test 4:</p>
<p><pre class="brush: bash;">toggleTouchpad on</pre></p>
<p>Wait at least one second&#8230;<br />
Did your touchpad start working again? Good!</p>
<h3>Making the magic happen automatically:</h3>
<p>We&#8217;re almost there! Now we need to set the script to run automatically when your mouse is plugged in. Making sure your mouse is unplugged, run the following command:</p>
<p><pre class="brush: bash;">halevt -i &gt;&gt;~/connectedDevices.txt</pre></p>
<p>While the command is running, plug in your mouse, and then unplug it. Now press Ctrl +c to kill the process. Open ~/connectedDevices.txt, and you should see something that looks like:</p>
<p><pre class="brush: plain;">
New Device: /org/freedesktop/Hal/devices/usb_device_46d_b02_noserial
New Device: /org/freedesktop/Hal/devices/usb_device_46d_b02_noserial_if0
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023_if0
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023_if0_logicaldev_input
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023_if0
New Device: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023_if0_logicaldev_input
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023_if0_logicaldev_input
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023_if0
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023_if0_logicaldev_input
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_b02_noserial_if0
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023_if0
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_c70a_00076142E023
Device removed: /org/freedesktop/Hal/devices/usb_device_46d_b02_noserial
</pre></p>
<p>All of those devices are your mouse. Since each of those events will trigger every time you plug in your mouse, we only need to handle one of them. Pick one that ends in seemingly random numbers, and copy and paste everything after the &#8220;:&#8221; into a text file. We will be using it in a moment. Now, let&#8217;s create our halevt config file:</p>
<p><pre class="brush: bash;">touch ~/.halevt.xml &amp;&amp; gedit ~/.halevt.xml</pre></p>
<p>Paste the following into the file:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;halevt:Configuration version=&quot;0.1&quot; xmlns:halevt=&quot;http://www.environnement.ens.fr/perso/dumas/halevt.html&quot;&gt;
	&lt;halevt:Device match=&quot;hal.info.udi = /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023&quot;&gt;
		&lt;halevt:Insertion exec=&quot;toggleTouchpad off&quot;/&gt;
		&lt;halevt:Removal exec=&quot;toggleTouchpad on&quot;/&gt;
	&lt;/halevt:Device&gt;
&lt;/halevt:Configuration&gt;
</pre></p>
<p>We are almost done! Remember the bit I had you paste into another file?? We are going to use that to identify your device. In the config file, change the line that says:</p>
<p><pre class="brush: xml;">
&lt;halevt:Device match=&quot;hal.info.udi = /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023&quot;&gt;
</pre></p>
<p>to say :</p>
<p><pre class="brush: xml;">
&lt;halevt:Device match=&quot;hal.info.udi = /org/freedesktop/Hal/devices/the_rest_of_what_you_copied_into_the_file&quot;&gt;
</pre></p>
<p>Theoretically, we&#8217;re done!</p>
<h3>Test the Magic:</h3>
<p>From terminal run:</p>
<p><pre class="brush: bash;">
sudo killall halevt
halevt -c ~/.halevt.xml
</pre></p>
<p>Now, connect your mouse. If all is going well, about ~1.5 seconds after you plug in your mouse your touchpad should stop working. Now, disconnect your mouse. Your touchpad should start working again.</p>
<h3>Making it permanent:</h3>
<p>If all went well in the tests, you will want to make this happen automatically forever. Go to &#8220;System-&gt;Preferences-&gt;Startup Applications&#8221;, and add a new startup program. Name it something you will remember, and for the command put &#8220;halevt -c ~/.halevt.xml&#8221;. You&#8217;re done!!</p>
<h3>Special Thanks:</h3>
<p>While writing this script I <a href="http://ubuntuforums.org/showthread.php?t=1628329">received a great deal of help from</a> the user <a href="http://ubuntuforums.org/member.php?u=106064">Arndt</a> at <a href="ubuntuforums.org">Ubuntuforums</a>, so you should go leave him lots of love and thanks.</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/bash/'>Bash</a>, <a href='http://brennydoogles.wordpress.com/category/linux/'>Linux</a>, <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/tutorials/'>Tutorials</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/bash/'>Bash</a>, <a href='http://brennydoogles.wordpress.com/tag/linux/'>Linux</a>, <a href='http://brennydoogles.wordpress.com/tag/touchpad/'>Touchpad</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/239/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=239&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2010/11/23/automatically-disable-touchpad-when-external-mouse-connected/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickly Toggle Your Touchpad in Linux</title>
		<link>http://brennydoogles.wordpress.com/2010/11/16/quickly-toggle-your-touchpad-in-linux/</link>
		<comments>http://brennydoogles.wordpress.com/2010/11/16/quickly-toggle-your-touchpad-in-linux/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 02:45:42 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Touchpad]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=233</guid>
		<description><![CDATA[For me it is often frustrating trying to use my laptop&#8217;s touchpad to do anything that requires even the slightest bit of accuracy, so I use an external mouse whenever possible. Unfortunately, the placement of the touchpad means that I will invariably end up touching it with my palms while I type. Today I finally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=233&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For me it is often frustrating trying to use my laptop&#8217;s touchpad to do anything that requires even the slightest bit of accuracy, so I use an external mouse whenever possible. Unfortunately, the placement of the touchpad means that I will invariably end up touching it with my palms while I type. Today I finally had enough and decided to take matters into my own hands. The following script will allow you to either toggle your touchpad based upon it&#8217;s current setting, or to explicitly turn your touchpad on or off (perhaps as an event to be fired when you plug in or unplug an external mouse). Without further ado:</p>
<p><pre class="brush: bash;">
# toggleTouchpad by Brendon Dugan
# Toggles a touchpad on or off depending on it's current state or CLI argument
#
# To configure, run the command 'xinput list' in terminal and identify your touch pad.
# Using the output of the above command, change the touchpadString variable to a substring
# of your touchpad's description that is unique to that device.
#
# To run, simply type 'toggleTouchpad' to toggle your touchpad on or off, or
# 'toggleTouchpad on' to explicitly turn your touchpad on, or
# 'toggleTouchpad off' to explicitly turn it off.
#
# Enjoy!
touchpadString=&quot;TouchPad&quot;
touchpadID=$(xinput list | grep &quot;$touchpadString&quot; | awk -F &quot; &quot; '{print $6}' | awk -F &quot;=&quot; '{print $2}')
touchpadEnabled=$(xinput list-props $touchpadID | grep &quot;Device Enabled&quot; | awk -F &quot;:&quot; '{print $2}')

# Check for arguments on the command line
if test $# -eq 1
then
	# Change the argument to lowercase
	arg1=$(echo $1 | tr [:upper:] [:lower:])
	cliArg=1
else
	# There is no argument.
	cliArg=0
fi

if [ $cliArg -eq 1 ]
then
	# If there's an argument, check to see whether it is on, off, or junk
	if [ $arg1 = 'on' ]
	then
		# The argument was 'on', so turn the touchpad on
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 1
	elif [ $arg1 = 'off' ]
	then
		# The argument was 'off', so turn the touchpad off
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 0
	else
		# The argument was junk, so do nothing
		sleep 1
	fi
else
	# There was no argument, so just toggle the touchpad to the opposite
	# of the state it has now.
	if [ $touchpadEnabled -eq 1 ]
	then
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 0
	else
		xinput --set-prop $touchpadID &quot;Device Enabled&quot; 1
	fi
fi
</pre></p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/bash/'>Bash</a>, <a href='http://brennydoogles.wordpress.com/category/linux/'>Linux</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/bash/'>Bash</a>, <a href='http://brennydoogles.wordpress.com/tag/linux/'>Linux</a>, <a href='http://brennydoogles.wordpress.com/tag/touchpad/'>Touchpad</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/233/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=233&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2010/11/16/quickly-toggle-your-touchpad-in-linux/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Euler Problem 3</title>
		<link>http://brennydoogles.wordpress.com/2010/03/25/project-euler-problem-3/</link>
		<comments>http://brennydoogles.wordpress.com/2010/03/25/project-euler-problem-3/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 02:21:12 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=197</guid>
		<description><![CDATA[For project Euler problem 3 we work on a few basic principles that we will use for several upcoming problems (yay reusable code!), factorization and determining whether a number is prime. Here is the problem: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=197&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For project Euler problem 3 we work on a few basic principles that we will use for several upcoming problems (yay reusable code!), factorization and determining whether a number is prime. Here is the problem:</p>
<blockquote><p>
The prime factors of 13195 are 5, 7, 13 and 29.</p>
<p>What is the largest prime factor of the number 600851475143 ?
</p></blockquote>
<p>One way one could complete this problem would be to find all factors of the given number, and loop through checking if they are prime, returning only the largest one. To start out, let&#8217;s find all factors of a number.<br />
<pre class="brush: python; collapse: true; light: false; toolbar: true;">
import math
def findAllFactors(number):
    factors = list()
    for i in xrange(1, long(math.sqrt(number))):
        if number%i == 0:
            factors.append(i)  
    return factors
</pre></p>
<p>Here, we are simply looping through the numbers between 1 and the square root of the number, looking for numbers that divide evenly into our original number. Numbers that divide evenly are factors, so we add them to a list which we return afterward. Alternately, we could create a generator to return all factors:</p>
<p><pre class="brush: python; collapse: true; light: false; toolbar: true;">
import math
def findAllFactors(number):
    for i in xrange(1, long(math.sqrt(number))):
        if number%i == 0:
            yield i 
</pre></p>
<p>Next, we loop through each factor, checking to see if it is prime using the following code:</p>
<p><pre class="brush: python; collapse: true; light: false; toolbar: true;">
def isPrime(n):
    n = abs(long(n))
    if n &lt; 2:
        return False
    if n == 2: 
        return True
    if not n &amp; 1: 
        return False
    for x in range(3, long(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True
</pre></p>
<p>If we have a prime factor, let&#8217;s toss it in a list for now:</p>
<p><pre class="brush: python; collapse: true; light: false; toolbar: true;">
if __name__ == &quot;__main__&quot;:
    factors = findAllFactors(600851475143L)
    primeFactors = list()
    for f in factors:
        if isPrime(f):
            primeFactors.append(f)
</pre></p>
<p>or if you are using the generator:</p>
<p><pre class="brush: python; collapse: true; light: false; toolbar: true;">
if __name__ == &quot;__main__&quot;:
    primeFactors = list()
    for f in findAllFactors(600851475143L):
        if isPrime(f):
            primeFactors.append(f)
</pre></p>
<p>Now we simply grab the largest number in the list by sorting it and grabbbing the last item!</p>
<p><pre class="brush: python; collapse: true; light: false; toolbar: true;">
    primeFactors.sort()
    print &quot;The Correct answer is: %d&quot; % (primeFactors[-1])
</pre></p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/programming/project-euler/'>Project Euler</a>, <a href='http://brennydoogles.wordpress.com/category/programming/python/'>Python</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/project-euler/'>Project Euler</a>, <a href='http://brennydoogles.wordpress.com/tag/python/'>Python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=197&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2010/03/25/project-euler-problem-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
		<item>
		<title>Learn to Program with Python pt. 1</title>
		<link>http://brennydoogles.wordpress.com/2010/03/19/learn-to-program-with-python-pt-1/</link>
		<comments>http://brennydoogles.wordpress.com/2010/03/19/learn-to-program-with-python-pt-1/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 16:29:29 +0000</pubDate>
		<dc:creator>Brendon Dugan</dc:creator>
				<category><![CDATA[Learn to Program with Python]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://brennydoogles.wordpress.com/?p=162</guid>
		<description><![CDATA[Programming can be a fun hobby and a well paying career for those who learn to do it well, as well as a great way to keep stimulating your brain to keep you sharp and alert. Learning to program on your own can be difficult for some people however. Many programming tutorials have one of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=162&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Programming can be a fun hobby and a well paying career for those who learn to do it well, as well as a great way to keep stimulating your brain to keep you sharp and alert. Learning to program on your own can be difficult for some people however. Many programming tutorials have one of the following issues:</p>
<ul>
<li>Talking above your head: Many programming tutorials assume a great deal of knowledge beforehand, and are therefore not suitable for brand-new programmers</li>
<li>Being half-heartedly written: Many tutorials start out well, but as the tutorial drags on the author loses interest, and the writing and content suffer dramatically</li>
<li>Generally sucking: That pretty much sums it up</li>
</ul>
<p>I have decided to take my own crack at a programming tutorial, and I will attempt to avoid the previously mentioned pitfalls. There are a few details I would like to cover before we get started. The first is my choice of language. I have chosen to use Python for this tutorial for several reasons, the first and foremost being that I really enjoy programming in Python. I also think Python is great about getting out of your way and letting you program without having to micro-manage details such as Data Types (most of the time) and memory allocation (don&#8217;t worry if you don&#8217;t know what this means). The next detail I would like to cover is the timeline for this tutorial. I plan on writing this tutorial as multiple blog posts over the next several months, with many unrelated posts in between. If it has been a while, feel free to drop me a comment nagging me for the next issue. </p>
<p>Enough introduction, let&#8217;s get started with Programming and Python. To get started, we need to make sure we have Python installed on our system. If you are running Linux, chances are Python is pre-installed. For Windows and Mac users, I recommend <a href="http://www.activestate.com/activepython/">ActivePython</a>. ActivePython will install Python to your system, as well as a very basic Python editor (although any text editor will do). Open up your editor of choice and type the following:<br />
<pre class="brush: python;">
print &quot;Goodbye Cruel World&quot;
</pre><br />
Now save this as emoProgram.py . This is your first program. Kinda lame isn&#8217;t it? Don&#8217;t worry, you&#8217;ll be writing slightly less lame programs in no time. In fact, the only reason I had you do this is so I could teach you to run your program once you have written it. If you are using PythonWin editor (the editor that came with ActivePython) press Ctrl+R and a box will pop up asking you which file you want to run, and it should have emoProgram.py selected. Press OK, and it will run. If you have chosen to use a different editor (or even if you just like the command line), open up a command prompt and navigate to the folder where you saved your script and type:<br />
<code>python emoProgram.py</code><br />
and you will see &#8220;Goodbye Cruel World&#8221; print to your terminal.</p>
<p>In an attempt to make each section as short as possible, I will be stopping here for now and picking up again in a few days with variables, operators, and data types.</p>
<br />Filed under: <a href='http://brennydoogles.wordpress.com/category/tutorials/learn-to-program-with-python/'>Learn to Program with Python</a>, <a href='http://brennydoogles.wordpress.com/category/programming/'>Programming</a>, <a href='http://brennydoogles.wordpress.com/category/programming/python/'>Python</a>, <a href='http://brennydoogles.wordpress.com/category/tutorials/'>Tutorials</a> Tagged: <a href='http://brennydoogles.wordpress.com/tag/learn-to-program-with-python/'>Learn to Program with Python</a>, <a href='http://brennydoogles.wordpress.com/tag/python/'>Python</a>, <a href='http://brennydoogles.wordpress.com/tag/tutorials/'>Tutorials</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brennydoogles.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brennydoogles.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brennydoogles.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brennydoogles.wordpress.com&amp;blog=12263162&amp;post=162&amp;subd=brennydoogles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brennydoogles.wordpress.com/2010/03/19/learn-to-program-with-python-pt-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/262a27937cb6655050fb50e0cb394100?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">brennydoogles</media:title>
		</media:content>
	</item>
	</channel>
</rss>
