<?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>Server Side Guy &#187; Uncategorized</title>
	<atom:link href="http://serversideguy.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://serversideguy.com</link>
	<description>Just another Barsness Solutions weblog</description>
	<lastBuildDate>Tue, 31 Jan 2012 14:57:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ext Js 4: Merging store data</title>
		<link>http://serversideguy.com/2012/01/31/ext-js-4-merging-store-data/</link>
		<comments>http://serversideguy.com/2012/01/31/ext-js-4-merging-store-data/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 14:57:06 +0000</pubDate>
		<dc:creator>Andy Stramer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=680</guid>
		<description><![CDATA[In a project I&#8217;ve been working on I needed to get a bunch of different stores of data and then have a separate store that would contain all of them combined. This was to save on ajax calls. I couldn&#8217;t find anything as far as native methods that would merge stores but I did come [...]]]></description>
			<content:encoded><![CDATA[<p>In a project I&#8217;ve been working on I needed to get a bunch of different stores of data and then have a separate store that would contain all of them combined. This was to save on ajax calls. I couldn&#8217;t find anything as far as native methods that would merge stores but I did come up with a solution.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> emptyArr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> aggregatedStore <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">ArrayStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		data<span style="color: #339933;">:</span> emptyArr<span style="color: #339933;">,</span>	
		fields<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field1'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field2'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> singularStore <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		autoload<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		proxy<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax'</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/getDataPlease'</span><span style="color: #339933;">,</span>
			reader<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
				type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
				root<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fieldRoot'</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		fields<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field1'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field2'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So what I want to do here is push the contents of singularStore into aggregatedStore. What I ended up doing is adding a listener on singularStore load to accomplish this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> emptyArr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> aggregatedStore <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">ArrayStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		data<span style="color: #339933;">:</span> emptyArr<span style="color: #339933;">,</span>	
		fields<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field1'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field2'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> singularStore <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		autoload<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		proxy<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax'</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/getDataPlease'</span><span style="color: #339933;">,</span>
			reader<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
				type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
				root<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fieldRoot'</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		fields<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field1'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'field2'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                listeners<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">'load'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>store<span style="color: #339933;">,</span> records<span style="color: #339933;">,</span> successful<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				aggregatedStore.<span style="color: #660066;">loadData</span><span style="color: #009900;">&#40;</span>records<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now I can use singularStore to get just the data from that url. I can then add that load listener to any other store and use aggregatedStore to show the combined data.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/31/ext-js-4-merging-store-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I use traits in PHP 5.4</title>
		<link>http://serversideguy.com/2012/01/31/how-do-i-use-traits-in-php-5-4/</link>
		<comments>http://serversideguy.com/2012/01/31/how-do-i-use-traits-in-php-5-4/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 14:12:37 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=670</guid>
		<description><![CDATA[The biggest change in PHP 5.4 is the addition of traits to the object-oriented programmability. Traits prevent code duplication by allowing multiple classes to include a collection of methods implemented as a trait. This means multiple classes can include the same method implementations without duplicating code. Traits improve on interfaces because they include not only [...]]]></description>
			<content:encoded><![CDATA[<p>The biggest change in PHP 5.4 is the addition of traits to the object-oriented programmability.  <a href="http://en.wikipedia.org/wiki/Trait_(computer_programming)" target="_blank">Traits</a> prevent code duplication by allowing multiple classes to include a collection of methods implemented as a trait.  This means multiple classes can include the same method implementations without duplicating code.</p>
<p>Traits improve on interfaces because they include not only the function definition, but also the implementation.  Traits can also use other traits, meaning that one trait could be a collection of others.  So, if you had traits Roll and Bounce, you could have trait Movements that used both Roll and Bounce.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">trait HelloWorld <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello '</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'World!'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #009900;">&#123;</span>
    use HelloWorld<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHelloWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayhello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayWorld</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayHelloWorld</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// outputs &quot;Hello World!&quot;</span></pre></div></div>

<p>In implementing traits, the keywords trait and insteadof were added to PHP.  Usage of trait is outlined above.  The PHP keyword insteadof is used for conflict resolution.  Here&#8217;s an example of how to use insteadof:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">trait A <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> smallTalk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bigTalk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'A'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
trait B <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> smallTalk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bigTalk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Talker <span style="color: #009900;">&#123;</span>
    use A<span style="color: #339933;">,</span> B <span style="color: #009900;">&#123;</span>
        B<span style="color: #339933;">::</span><span style="color: #004000;">smallTalk</span> insteadof A<span style="color: #339933;">;</span>
        A<span style="color: #339933;">::</span><span style="color: #004000;">bigTalk</span> insteadof B<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Aliased_Talker <span style="color: #009900;">&#123;</span>
    use A<span style="color: #339933;">,</span> B <span style="color: #009900;">&#123;</span>
        B<span style="color: #339933;">::</span><span style="color: #004000;">smallTalk</span> insteadof A<span style="color: #339933;">;</span>
        A<span style="color: #339933;">::</span><span style="color: #004000;">bigTalk</span> insteadof B<span style="color: #339933;">;</span>
        B<span style="color: #339933;">::</span><span style="color: #004000;">bigTalk</span> <span style="color: #b1b100;">as</span> talk<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/31/how-do-i-use-traits-in-php-5-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Fix Text Links in the iPhone-Slide Plugin</title>
		<link>http://serversideguy.com/2012/01/30/text-links-dont-work-in-the-iphone-slide-plugin-solution/</link>
		<comments>http://serversideguy.com/2012/01/30/text-links-dont-work-in-the-iphone-slide-plugin-solution/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 22:26:02 +0000</pubDate>
		<dc:creator>Sarah Relander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=668</guid>
		<description><![CDATA[On a previous post I told you all about this amazing plugin I found that would create a slider that takes advantage of the iPad&#8217;s touch and drag functionality. However, if you didn&#8217;t use it just for images and had the slides contain text, you may have noticed that the links within the slides would [...]]]></description>
			<content:encoded><![CDATA[<p>On a <a href="/2012/01/08/how-can-i-make-a-div-slider-that-is-ipad-friendly/">previous post</a> I told you all about this amazing plugin I found that would create a slider that takes advantage of the iPad&#8217;s touch and drag functionality. </p>
<p>However, if you didn&#8217;t use it just for images and had the slides contain text, you may have noticed that the links within the slides would not work. This plugin appears as it was mainly created to swipe through images, and not necessarily for content with text links.</p>
<p>I went into the plugin (jquery.iphone-slide.js) and changed a few things so it would do my bidding:</p>
<p>OLD CODE:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">helpers.<span style="color: #660066;">goto_url</span><span style="color: #009900;">&#40;</span>thislink<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>NEW CODE:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> thislink <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>thislink<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> thislink <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>thislink<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   window.<span style="color: #660066;">location</span><span style="color: #009900;">&#40;</span>thislink<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//similar behavior as clicking on a link</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Turns out the __mouseup function was preventing the default action and the &#8220;helpers.goto_url&#8221; function only opened image links.  But now it&#8217;s set up to do everything, Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/30/text-links-dont-work-in-the-iphone-slide-plugin-solution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple CSS gradient</title>
		<link>http://serversideguy.com/2012/01/23/simple-css-gradient/</link>
		<comments>http://serversideguy.com/2012/01/23/simple-css-gradient/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 15:08:35 +0000</pubDate>
		<dc:creator>Andy Stramer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=663</guid>
		<description><![CDATA[CSS has continued to simplify common design operations and CSS3 doesn&#8217;t show any signs of that trend changing. Gradients, which have been around for awhile now have commonly replaced the old way of creating custom images for a couple quick css lines of code. .orange-gradient &#123; background: #f78d1d; /* initial background for default */ background: [...]]]></description>
			<content:encoded><![CDATA[<p>CSS has continued to simplify common design operations and CSS3 doesn&#8217;t show any signs of that trend changing. Gradients, which have been around for awhile now have commonly replaced the old way of creating custom images for a couple quick css lines of code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.orange-gradient</span>
<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f78d1d</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* initial background for default */</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> from<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#faa51a</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> to<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#f47a20</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Webkit Chrome/Safari etc.. */</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#faa51a</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#f47a20</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*mozilla*/</span>
filter<span style="color: #00AA00;">:</span>  progid<span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.gradient<span style="color: #00AA00;">&#40;</span>startColorstr<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'#faa51a'</span><span style="color: #00AA00;">,</span> endColorstr<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'#f47a20'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p> This would make a great orange gradient for a background. Another great trick is to reverse the gradient on hover</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.orange-gradient</span><span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> from<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#f47a20</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> to<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#faa51a</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#f47a20</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#faa51a</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
filter<span style="color: #00AA00;">:</span>  progid<span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.gradient<span style="color: #00AA00;">&#40;</span>startColorstr<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'#f47a20'</span><span style="color: #00AA00;">,</span> endColorstr<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'#faa51a'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Add this class to a button or link, add some padding and you have a quick and great-looking button.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/23/simple-css-gradient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a simple jQuery slide-down login form</title>
		<link>http://serversideguy.com/2012/01/06/creating-a-simple-jquery-slide-down-login-form/</link>
		<comments>http://serversideguy.com/2012/01/06/creating-a-simple-jquery-slide-down-login-form/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 21:14:36 +0000</pubDate>
		<dc:creator>Andy Stramer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=649</guid>
		<description><![CDATA[jQuery can really add some great touches to a website and one that is easy to do is a slide-down form. &#60;div id =&#34;login_container&#34;&#62; &#60;a href=&#34;#&#34; onClick=&#34;openForm()&#34;&#62;Login&#60;/a&#62; &#60;div id=&#34;login_form&#34;&#62; &#60;form action=&#34;&#34; method=&#34;post&#34; name=&#34;form1&#34;&#62; Username: &#60;input type=&#34;text&#34; name=&#34;username&#34; /&#62;&#60;br /&#62; Password: &#60;input type=&#34;password&#34; name=&#34;pword&#34; /&#62;&#60;br /&#62; &#60;input type=&#34;submit&#34; /&#62;&#60;br /&#62; &#60;/form&#62; &#60;/div&#62; Obviously we want to [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery can really add some great touches to a website and one that is easy to do is a slide-down form.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id =&quot;login_container&quot;&gt; 
&lt;a href=&quot;#&quot; onClick=&quot;openForm()&quot;&gt;Login&lt;/a&gt;
&lt;div id=&quot;login_form&quot;&gt;
&lt;form action=&quot;&quot; method=&quot;post&quot; name=&quot;form1&quot;&gt;
Username: &lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;&lt;br /&gt;
Password: &lt;input type=&quot;password&quot; name=&quot;pword&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot;  /&gt;&lt;br /&gt;
&lt;/form&gt;
&lt;/div&gt;</pre></div></div>

<p>Obviously we want to initially hide the form and display it on the &#8220;Login&#8221; link:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#login_container</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#login_form</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>There is a very important part lying in that CSS and that is the container needs to be absolutely positioned. Otherwise it will push all other block elements down when the form flies open.</p>
<p>Finally, we need the jQuery to make it all happen</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> openForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#login_form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:hidden&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#login_form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#login_form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now you have a great UI component that gives a user access to the login form at anytime but doesn&#8217;t clog up the design.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/06/creating-a-simple-jquery-slide-down-login-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I Add Data to a Spark DataGrid in Flex Mobile?</title>
		<link>http://serversideguy.com/2012/01/01/how-do-i-add-data-to-a-spark-datagrid-in-flex-mobile/</link>
		<comments>http://serversideguy.com/2012/01/01/how-do-i-add-data-to-a-spark-datagrid-in-flex-mobile/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 05:51:28 +0000</pubDate>
		<dc:creator>Sarah Relander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=644</guid>
		<description><![CDATA[When coding for mobile developments in flex (Flash Builder), I had a hard time populating the dataGrid element because it doesn&#8217;t use arrayCollections like lists do.  The data source is actually bounded to the IList data type.  An example of setting it up is listed below. &#60;s:Application &#60;fx:Script&#62; import mx.collections.IList; [Bindable] public var dataGrid:IList = [...]]]></description>
			<content:encoded><![CDATA[<p>When coding for mobile developments in flex (Flash Builder), I had a hard time populating the dataGrid element because it doesn&#8217;t use arrayCollections like lists do.  The data source is actually bounded to the IList data type.  An example of setting it up is listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;s:Application
    &lt;fx:Script&gt;
        import mx.collections.IList;
        [Bindable] public var dataGrid:IList = new ArrayList([
            {firstName: &quot;John&quot;, lastName: &quot;Doe&quot;, phone: &quot;1231231234&quot;, email: &quot;test@test.com&quot;},
	    // ... whichever variable names in the DataGrid
        ]);
    &lt;/fx:Script&gt;
    &lt;s:DataGrid id=&quot;dataGrid&quot; dataProvider=&quot;{dataGrid}&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
        &lt;s:columns&gt;
            &lt;s:ArrayList&gt;
		&lt;s:GridColumn dataField=&quot;firstName&quot;/&gt;
		&lt;s:GridColumn dataField=&quot;lastName&quot;/&gt;
		&lt;s:GridColumn dataField=&quot;phone&quot;/&gt;
		&lt;s:GridColumn dataField=&quot;email&quot;/&gt;
            &lt;/s:ArrayList&gt;
        &lt;/s:columns&gt;
    &lt;/s:DataGrid&gt;
&lt;/s:Application&gt;</pre></div></div>

<p>This DataGrid example has a column per property( GridColumn) and dataField attribute is used to select the dataProvider object property to display in that column.  The dataProvider is  a list of the object properties that are defined in the dataGrid (firstname, lastname,phone, email) and their values for that row.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2012/01/01/how-do-i-add-data-to-a-spark-datagrid-in-flex-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 17</title>
		<link>http://serversideguy.com/2011/12/27/project-euler-problem-17/</link>
		<comments>http://serversideguy.com/2011/12/27/project-euler-problem-17/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 04:17:40 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=639</guid>
		<description><![CDATA[I&#8217;ve been having some fun doing the first few problems of Project Euler and figured I&#8217;d share my solution to problem 17 here. The Problem If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having some fun doing the first few problems of <a href="http://projecteuler.net/">Project Euler</a> and figured I&#8217;d share my solution to <a href="http://projecteuler.net/problem=17">problem 17</a> here.  </p>
<p><b>The Problem</b><br />
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.</p>
<p>If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?</p>
<p>NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of &#8220;and&#8221; when writing out numbers is in compliance with British usage.</p>
<p><b>The Solution</b><br />
The reason I love this solution is I found a PHP library that writes out these numbers for you.  It comes from PECL 1.0 and is part of PHP 5.3 via that <a href="http://php.net/manual/en/class.numberformatter.php" target="_blank">NumberFormatter</a> class.  This class did most of the work for me.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberFormatter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #339933;">,</span> NumberFormatter<span style="color: #339933;">::</span><span style="color: #004000;">SPELLOUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> format<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">100</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">100</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$res</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'and'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>My first submission was incorrect and I quickly figured out it was because the NumberFormatter class was missing the &#8220;and&#8221; after the hundreds.  I simply added that at the end since we&#8217;re only looking for a count and came up with the correct result.</p>
<p>Installing the NumberFormatter class in Debian squeeze was pretty easy.  I simply had to install the <a href="http://www.php.net/manual/en/intl.setup.php" target="_blank">PHP5 international compatibility</a> package:  sudo apt-get instal php5-intl</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2011/12/27/project-euler-problem-17/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I perform integer division in PHP</title>
		<link>http://serversideguy.com/2011/12/27/how-do-i-perform-integer-division-in-php/</link>
		<comments>http://serversideguy.com/2011/12/27/how-do-i-perform-integer-division-in-php/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 02:34:48 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=633</guid>
		<description><![CDATA[PHP&#8217;s division operator returns a floating point result from the division operator unless both operands are integers and they are evenly divisible (the result is an integer). I was recently working on Project Euler Problem 13 and needed to do integer division, something I haven&#8217;t come across in PHP before. Integer division in PHP is [...]]]></description>
			<content:encoded><![CDATA[<p>PHP&#8217;s division operator returns a floating point result from the division operator unless both operands are integers and they are evenly divisible (the result is an integer).  I was recently working on Project Euler Problem 13 and needed to do integer division, something I haven&#8217;t come across in PHP before.  </p>
<p>Integer division in PHP is pretty straight forward.  Casting the result as an integer will yield an integer.  That is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;">// float(3.5714285714286) </span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// int(3)</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// float(4)</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2011/12/27/how-do-i-perform-integer-division-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 10</title>
		<link>http://serversideguy.com/2011/12/23/project-euler-problem-10/</link>
		<comments>http://serversideguy.com/2011/12/23/project-euler-problem-10/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 18:12:42 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=628</guid>
		<description><![CDATA[I&#8217;ve been having some fun doing the first few problems of Project Euler and figured I&#8217;d share my solution to problem 10 here. The Problem The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. The Solution My [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having some fun doing the first few problems of <a href="http://projecteuler.net/">Project Euler</a> and figured I&#8217;d share my solution to <a href="http://projecteuler.net/problem=10">problem 10</a> here.  </p>
<p><b>The Problem</b><br />
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.<br />
Find the sum of all the primes below two million.</p>
<p><b>The Solution</b><br />
My solution is fairly simple, testing primality for all the numbers below 2,000,000.  If prime, adding them to a running total.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/**
 * Calculate the sum of all the primes below two million. 
 **/</span>
<span style="color: #339900;">#include </span>
<span style="color: #339900;">#include </span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> isPrime<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span> num<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">*</span><span style="color:#800080;">1.0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">%</span>i<span style="color: #000080;">==</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">long</span> upperlimit <span style="color: #000080;">=</span> <span style="color: #0000dd;">2000000</span>, sum <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> upperlimit<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>isPrime<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			sum <span style="color: #000040;">+</span><span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Prime found: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> i <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;The sum of primes below &quot;</span> <span style="color: #000080;">&lt;&lt;</span> upperlimit <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; is &quot;</span> <span style="color: #000080;">&lt;&lt;</span> sum <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The interesting part of this problem for me was I updated my primality test to include the fact that if a number n has a factor greater than sqrt(n) it must also have one less than sqrt(n), so we only have to test up to sqrt(n) in our primality test:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> isPrime<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span> num<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">*</span><span style="color:#800080;">1.0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">%</span>i<span style="color: #000080;">==</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2011/12/23/project-euler-problem-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 9</title>
		<link>http://serversideguy.com/2011/12/22/project-euler-problem-9/</link>
		<comments>http://serversideguy.com/2011/12/22/project-euler-problem-9/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 21:37:04 +0000</pubDate>
		<dc:creator>Tim Barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=616</guid>
		<description><![CDATA[I&#8217;ve been having some fun doing the first few problems of Project Euler and figured I&#8217;d share my solution to problem 9 here. The Problem A Pythagorean triplet is a set of three natural numbers, a b c, for which,a^2 + b^2 = c^2 There exists exactly one Pythagorean triplet for which a + b [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having some fun doing the first few problems of <a href="http://projecteuler.net/">Project Euler</a> and figured I&#8217;d share my solution to <a href="http://projecteuler.net/problem=9">problem 9</a> here.  </p>
<p><b>The Problem</b><br />
A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,a^2 + b^2 = c^2<br />
There exists exactly one Pythagorean triplet for which a + b + c = 1000.  Find the product abc.</p>
<p><b>The Solution</b><br />
This is pretty basic and inefficient, but I decided to loop through a and b, calculating c from the difference.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include </span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
        <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> a <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> a <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">1000</span><span style="color: #008080;">;</span> a<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> b <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> b <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">1000</span><span style="color: #008080;">;</span> b<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;a: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> a <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; b: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> b <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; c: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a <span style="color: #000040;">-</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; a^2 + b^2: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #008000;">&#40;</span>a <span style="color: #000040;">*</span> a <span style="color: #000040;">+</span> b <span style="color: #000040;">*</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; c^2: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a <span style="color: #000040;">-</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a <span style="color: #000040;">-</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
                        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>a <span style="color: #000040;">*</span> a <span style="color: #000040;">+</span> b <span style="color: #000040;">*</span> b <span style="color: #000080;">==</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a <span style="color: #000040;">-</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a <span style="color: #000040;">-</span> b<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                                <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                        <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>There you have it, the program stops at a^2 + b^2 = c^2 where c = (1000 &#8211; a &#8211; b).  I then took a*b*c to get the answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2011/12/22/project-euler-problem-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

