<?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>AaronStaves.com &#187; Python</title>
	<atom:link href="http://aaronstaves.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaronstaves.com</link>
	<description>Not quite extinct!</description>
	<lastBuildDate>Wed, 13 May 2009 18:49:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Welcome to Planningville &#8211; Population++</title>
		<link>http://aaronstaves.com/2008/02/10/welcome-to-planningville-population/</link>
		<comments>http://aaronstaves.com/2008/02/10/welcome-to-planningville-population/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 08:29:32 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plan]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[wireframe]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://aaronstaves.com/2008/02/10/welcome-to-planningville-population/</guid>
		<description><![CDATA[Inspired by a recent comment on my last blog, I've taken David up on the webpage wireframe and prototype tutorials he found.  Both of the articles seem to be geared towards actual graphic designers or user interface designers that have very little or limited knowledge of javascript; and almost no knowledge of the server [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by a recent <a href="http://aaronstaves.com/2008/02/06/all-hail-the-user/#comment-19" title="comment on previous blog" target="_blank">comment</a> on my last blog, I've taken <a href="http://www.hackyourlife.org/" title="David's Blog" target="_blank">David</a> up on the webpage wireframe and prototype tutorials he found.  Both of the articles seem to be geared towards actual graphic designers or user interface designers that have very little or limited knowledge of javascript; and almost no knowledge of the server side of their applications.  But nonetheless, there was some really good info in there.</p>
<p>From what I gather, a wireframe is just that a wire-frame.  It should purely consist of a layout, with the possibility of some actual production CSS in the page.  The articles suggested that there are two main ways to do this:</p>
<ol>
<li>Create a page for each "flow" of your application.</li>
<li>Create one page with a "stacked flow" of your application.</li>
</ol>
<p>Basically, a flow is the various screens/interfaces that the end-user will be presented with.  They give a nice "login" example (one which I actually made one of my own as well) with a "stacked flow" wireframe.  You can see my example of that <a href="http://aaronstaves.com/wp-content/uploads/2008/02/login_wireframes.html" title="Login Wireframes" target="_blank">here</a>. Comments are welcome, but keep in mind:</p>
<ol>
<li>I'm not a graphic designer</li>
<li>This is my first crack at this</li>
<li>It's 2am... and I'm making wireframes...</li>
</ol>
<p><span id="more-14"></span><br />
<img src="http://aaronstaves.com/wp-content/uploads/2008/02/wireframepn8.jpg" alt="Wireframe Maddness!" /></p>
<p>Needless to say, that's kind of how I feel at the moment.  The actual prototype, which I plan on using <a href="http://developer.yahoo.com/yui/" title="Yahoo User Interface Library" target="_blank">YUI</a> for will probably come out tomorrow or sometime next week.</p>
<p>The reason I actually went through and <em>made</em> a wireframe, is because I'm attempting to get some sort of side project going for myself (yet again...) so I can play around with some new things.  These things being YUI; as mentioned above, Python; which I've been somewhat getting into and web frameworks - namely <a href="http://pylonshq.com/" title="Pylons Homepage" target="_blank">Pylons</a>.  So tonight at least I got some wireframes done for the login, the next step will be to learn some YUI and get some fake data going for the prototype.</p>
<p>Lastly, I (possibly re)learned some interesting things today regarding CSS.  As you can see in the source for my wireframes, I'm actually using display: table.  Insane!  I've never actually used that, ever.  I initially had a pretty descent layout, but when looking at it on my Nokia N800, it looked completely borked!  So the only way was to make div's within my login box actually span set percentage widths.</p>
<p>Now you're probably saying, whoa! Just set a width on that puppy and your good to go.  Wrong!  Since I wanted somewhat "tabular" data, consisting of two rows, and two colums.  Each row being 100% the width of the box and each column being 50% of the row, there was no way to do that using pure css and <strong><em>not</em></strong> using tables.  This is for two reasons:</p>
<ol>
<li>Div elements are initially set as display: block.  This means there is a line break before and after the element.  So there's no way to have two "columns" side by side.</li>
<li>Inline elements (or elements set to display:inline!) do line up side by side; however!, they will only take on as much width as they need, and don't respond to width: styles.  They may use the width attribute in some browsers, but not what I was testing it in (FireFox 2).</li>
</ol>
<p>So I  came across an article talking about using display: table.  And really, it couldn't be simpler.  Parent element needs to be set as <strong>display: table</strong>.  The children of that needs to be set as <strong>display: table-row</strong>.  And the children of the rows need to be set to <strong>display: table-cell</strong>.  The only downside, is there is absolutely no support for colspan or rowspan in css or the markup.  Even if they did work, it looks like the CSS for those will be depricated in CSS 3 and replaced by some other multi-row/column attribute.</p>
<p>So all in all, a night of learning pylons, which I'm <em>reall</em>y<em> </em>starting to like.  And hopefully I'll keep cranking out these wireframes/prototypes and get good enough at them so I can actually use them in my daily work.  And although I'm posting more now... I hope I don't make a habit of posting at 2:30am : (.  Next time I'll hopefully have some stuff on prototypes to discuss.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronstaves.com/2008/02/10/welcome-to-planningville-population/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nokia n800 python posting!</title>
		<link>http://aaronstaves.com/2008/01/05/nokia-n800-python-posting/</link>
		<comments>http://aaronstaves.com/2008/01/05/nokia-n800-python-posting/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 06:17:10 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://aaronstaves.com/2008/01/05/nokia-n800-python-posting/</guid>
		<description><![CDATA[So recently I'e made the purchase of a Nokia n800. A few of my friends recommended it and I can safely say that (so far) it's a great purchase. Video chat, ssh, vnc, email, etc. Most people seem to have trouble classifying the device; fot me its's basically a laptop replacement when I don't feel [...]]]></description>
			<content:encoded><![CDATA[<p>So recently I'e made the purchase of a <a href="http://www.nseries.com/products/n800/">Nokia n800</a>. A few of my friends recommended it and I can safely say that (so far) it's a great purchase. Video chat, ssh, vnc, email, etc. Most people seem to have trouble classifying the device; fot me its's basically a laptop replacement when I don't feel like lugging around my laptop.</p>
<p>All in all this post is just me wanting to try out  <a href="http://maemo-wordpy.garage.maemo.org">maemo-wordpy</a>. And yup! This is posted from my new internet tablet!</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronstaves.com/2008/01/05/nokia-n800-python-posting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Problem 10 &#8211; More prime numbers</title>
		<link>http://aaronstaves.com/2008/01/02/problem-10-more-prime-numbers/</link>
		<comments>http://aaronstaves.com/2008/01/02/problem-10-more-prime-numbers/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 04:54:56 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[ProjectEuler]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://aaronstaves.com/2008/01/02/problem-10-more-prime-numbers/</guid>
		<description><![CDATA[So a big part of all this Project Euler nonsense includes prime numbers.  Problem 10, begs the ever-so-common question Find the sum of all the primes below one million.  Obviously, the first attempt would be to just straight out calculate it using my previous program in Problem 3.  Adapting that program to [...]]]></description>
			<content:encoded><![CDATA[<p>So a big part of all this <a href="http://aaronstaves.com/2008/01/01/code-test/" title="Project Euler">Project Euler</a> nonsense includes prime numbers.  Problem 10, begs the ever-so-common question <em>Find the sum of all the primes below one million.</em>  Obviously, the first attempt would be to just straight out calculate it using my previous program in Problem 3.  Adapting that program to one million integers resulted in about 768 seconds (read: over 10 minutes) of time.  Obviously this breaks the 1 minute rule the program needed to be tweaked.</p>
<p>Trying other various methods I still came up short with the result being about 176 seconds at best.  To optimize my program I was mainly looking for some information on how prime numbers might be related to bits/bytes to see if I could perhaps try some bitwise operations to speed things up.  In doing so, I came across an article suggesting that having an array of bits (essentially a long char) with each char representing a number in an array from 0 to x; x being the limit.  Once this array was created, simply just iterate from 0 to the square root of your limit, and mark all multiples of any primes found on your way.  Makes sense - and this <em>greatly</em> cuts down on all the harsh prime calculating going on in the background.<br />
<span id="more-9"></span><br />
As I'm still learning python, I figured I'd try the next best thing and just make an array of boolean variables.  This way I can just check to see if they're true/false.  After adapting my program to do this -  having a representative array as opposed to an array of actual values, the finished product was able to find the answer in 2 to 3 seconds.  Awesome.</p>
<p>Code is posted below.  Sooner or later I'm hoping these problems will force me into creating more of an OO type program.  But for the time being I'm being pretty lame and writing everything procedurally.  As always, comments/criticism is welcome!</p>
<h1>Problem 10</h1>
<p><em>Calculate the sum of all the primes below one million.</em></p>
<pre class="code">
#!/usr/bin/python#function to find if a number is prime

def is_prime(n):

#check found prime numbers first

  global primes

  for prime in primes:

    if(n%prime == 0):

      return False

  return True

#function to mark prime numbers

def mark_primes(n):

  global numbers

  x = 2

  while(x*n &lt; 1000000):

    if(numbers[x*n]):

      numbers[x*n] = False

    x += 1

#initialize vars

total   = 0

numbers = []

primes  = []

#initially set everything to true

for x in xrange(0, 1000000):

  numbers.append(True)

#we know 0 and 1 are false

numbers[0] = False

numbers[1] = False

#start with multiples of primes from 2 to 1000 (sqrt 1,000,000)

for x in xrange(2, 1000):

#if prime, add to prime pool and mark it and it's multiples

  if(is_prime(x)):

    primes.append(x)

    mark_primes(x)

#calculate the final sum

for x in xrange(0, len(numbers)):

  if(numbers[x]):

    total += x

print "Total: ", total</pre>
]]></content:encoded>
			<wfw:commentRss>http://aaronstaves.com/2008/01/02/problem-10-more-prime-numbers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Project Euler</title>
		<link>http://aaronstaves.com/2008/01/01/code-test/</link>
		<comments>http://aaronstaves.com/2008/01/01/code-test/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 00:33:04 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[ProjectEuler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python project euler]]></category>

		<guid isPermaLink="false">http://aaronstaves.com/2008/01/01/code-test/</guid>
		<description><![CDATA[So as many already probably know Euler was a famous European mathematician and physicist.  Recently at work a lot of talk has been going around about Project Euler; basically a website which poses mathematical problems that need to be solved by writing program. So a few of us at work have decided to take [...]]]></description>
			<content:encoded><![CDATA[<p>So as many already probably know Euler was a famous European mathematician and physicist.  Recently at work a lot of talk has been going around about <a href="http://projecteuler.net" title="Project Euler" target="_blank">Project Euler</a>; basically a website which poses mathematical problems that need to be solved by writing program. So a few of us at work have decided to take the plunge and learn a completely new language while attempting to answer some of these questions.</p>
<p>So I guess I should start with saying I'll be using/learning <a href="http://python.org" title="Python" target="_blank">Python</a> for all of my problems.  Not a terribly hard choice as I'm already pretty familiar with Perl and PHP which seem to be somewhat similar to Python.  Anyways, if anyone else wants to get in on the fun.  Feel free to do so and post links to your own blogs/solutions or simply just put them here!  I plan on using these solutions as an excuse to actually get posting more on here.  So, we'll see how that goes.  I may also have to make some sort of hiding script so solutions aren't completely revealed to those that want to accomplish everything on their own.  Without further adieu - the first 3 problems and my solutions.<span id="more-8"></span></p>
<h1>Problem 1</h1>
<p><em>Add all the natural numbers below 1000 that are multiples of 3 or 5.</em></p>
<p>A simple brute force script - nothing really too elegant.</p>
<pre class="code">#!/usr/bin/python
total = 0;
for n in range(1, 1000):
  if n%3 == 0 or n%5 == 0:
    total += n

print total</pre>
<h1>Problem 2</h1>
<p><em>Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed one million.</em></p>
<p>Another brute force script - nothing fancy.</p>
<pre class="code">#!/usr/bin/python
f1    = 0
f2    = 1
total = 0;

while (f1+f2) &lt; 1000000:
  tmp = f1 + f2
  if tmp%2 == 0:
    total += tmp
  f1 = f2
  f2 = tmp

print total</pre>
<h1>Problem 3</h1>
<p><em>Find the largest prime factor of 317584931803.</em></p>
<p>This problem was the first one that actually posed some thought.  Given the example "<em>The prime factors of 13195 are 5, 7, 13 and 29.</em>", as well as doing some research; prime factors are just prime numbers that all multiply into the initial number given.  Rather than explaining, I'll just let the code speak for itself.</p>
<pre class="code">#!/usr/bin/python
limit = 317584931803

#function to find if a number is prime
def is_prime(n) :
  test  = 2
  while (test &lt;= n/2):
    if(n%test == 0):
      return False
    else:
      test += 1
  return True

primes  = []  #holds prime factors
num = 2       #starting point

#loop through all possibilities until we hit the limit
while (num &lt;= limit):

  #assume it's not a multiple of any prime numbers
  is_multiple = False
  add = 1

  #check already known primes
  for prime in primes:
    #check to see if it's a multiple of a prime number
    if(num%prime == 0):
      is_multiple = True

  #if it's not a multiple and it devides into our current limit
  if(not is_multiple and limit%num == 0):

    #actually check to see if it's prime
    if(is_prime(num)):

      #it is! don't increment our current number yet
      #until it's not a factor of our limit
      add = 0

      #add to our array, and re-calculate the new limit
      primes.append(num)
      limit = limit/num

  #incriment to the next number
  num += add

#print our results
print primes</pre>
<p>So, all in all these seem like some pretty alright challenges.  I've already got my roomate doing them (Java) and I wouldn't be surprised if a few other friends (on or off the blogroll) would get interested as well.  I'd also be very interested to hear from some of the veteran pyCoders on things they would've done different, or some key aspects of the language that I'm missing.  I quickly found out already that the following code results in an overflow - hence why i'm using the while loop as opposed to a for x in y loop.  As always, comments, criticism and randomness is welcome!</p>
<pre class="code">for x in range(2, 317584931803):
  #creates array with 317584931803 variables! yikes!</pre>
<p>Any better ways to loop through that without having to do a while loop?</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronstaves.com/2008/01/01/code-test/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dinoriffic</title>
		<link>http://aaronstaves.com/2007/12/11/dinoriffic/</link>
		<comments>http://aaronstaves.com/2007/12/11/dinoriffic/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 04:20:28 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[webfaction]]></category>

		<guid isPermaLink="false">http://aaronstaves.com/?p=5</guid>
		<description><![CDATA[So I decided on a theme.  Feel free to leave comments on it!  I'm pretty pleased with how it turned out.
Today I also ended up setting up my webfaction account with a few friends of mine.  We mainly decided to move there because of dreamhost's policy against long running processes.  Don't [...]]]></description>
			<content:encoded><![CDATA[<p>So I decided on a theme.  Feel free to leave comments on it!  I'm pretty pleased with how it turned out.</p>
<p>Today I also ended up setting up my <a href="http://webfaction.com">webfaction</a> account with a few friends of mine.  We mainly decided to move there because of <a href="http://dreamhost.com">dreamhost's</a> policy against long running processes.  Don't get me wrong! Dreamhost is a <em>dream</em> hosting company with super cheap plans with tons of storage and bandwidth.  But myself and some of my friends have taken quite an interest in learning <a href="http://python.org">python</a> as of late.  It seems a lot of their web frameworks (mainly pylons and django) involve running some sort of python WSGI "middleware" to communicate between webservers and the actual web applications.  At any rate, this was a nightmare to try and get running properly dreamhost.  Webfaction seems to be more than python friendly, so we'll see how it goes!</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronstaves.com/2007/12/11/dinoriffic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
