<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Daily Build &#187; tutorial</title>
	<atom:link href="http://blog.bstpierre.org/tag/tutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bstpierre.org</link>
	<description>Software Development, version 3.0</description>
	<lastBuildDate>Wed, 26 May 2010 16:08:50 +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>Use SSH to Forward Multiple Protocols to Multiple Machines</title>
		<link>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines</link>
		<comments>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines#comments</comments>
		<pubDate>Fri, 04 Dec 2009 16:03:33 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=239</guid>
		<description><![CDATA[Let's say you have a half-dozen machines at work you want to log into. Instead of setting up a remote forwarding connection from each of those machines, you can have the connection from your main machine perform multiple forwardings instead of just one. This even works if some of the machines don't support ssh.


Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><em>(This is part five in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Let&#8217;s say you have a half-dozen machines at work you want to log into. Instead of setting up a <a href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">remote forwarding connection</a> from each of those machines, you can have the connection from your main machine perform multiple forwardings instead of just one. This even works if some of the machines don&#8217;t support ssh.</p>
<p>It shouldn&#8217;t surprise you at this point that you can do this with your config file. On your work machine, you might have something like:</p>
<pre>Host tunnel
  HostName cloud.example.com
  User mycloudusername
  IdentityFile ~/.ssh/id_dsa
  Port 22
  RSAAuthentication yes
  PubkeyAuthentication yes
  ExitOnForwardFailure yes
  # tunnel ssh to myworkmachine
  RemoteForward 4022 localhost:22
  # tunnel remote desktop to mywindowsbox via myworkmachine
  RemoteForward 5389 192.168.4.10:3389
  # tunnel http to mywindowsbox via myworkmachine
  RemoteForward 5080 192.168.4.10:80
  # tunnel remote desktop to otherwindowsbox via myworkmachine
  RemoteForward 6389 192.168.4.11:3389
  # tunnel ssh to workserver via myworkmachine
  RemoteForward 7022 192.168.4.2:22</pre>
<p>You can add a bunch of forwardings as shown above. Each entry will open the given port on cloud and forward it to the specified port on the specified machine. Now when you run &#8220;ssh tunnel&#8221; on your work machine, it will connect to cloud and set up the five port forwardings specified in your config file.</p>
<p>Then when logged in to cloud.example.com, you can do, for example, &#8220;ssh -p 7022 myserverlogin@localhost&#8221; to log into the machine called workserver.</p>
<p>If you mirror the remote forwardings in your home config file as local forwardings, then when you &#8220;ssh work&#8221; from home you can remote desktop to a windows machine from your home pc by doing &#8220;rdesktop -u myworkwinuser localhost:5389&#8243; and it will use the tunnel. (The connection will go from your home pc to cloud, to myworkmachine, to mywindowsbox.) The windows machine does not need to know anything about ssh.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open an SSH Tunnel in Four Seconds or Less</title>
		<link>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less</link>
		<comments>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less#comments</comments>
		<pubDate>Thu, 03 Dec 2009 15:28:47 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=233</guid>
		<description><![CDATA[As I mentioned in a previous post on ssh configuration, your config file can specify a variety settings for each server. In fact, the Hosts you use don't even have to exist! Consider the following snippet in your ~/.ssh/config.


Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><em>(This is part four in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>As I mentioned in a previous post on <a href="http://blog.bstpierre.org/configure-ssh-username">ssh configuration</a>, your config file can specify a variety settings for each server.</p>
<p>In fact, the Hosts you use don&#8217;t even have to exist! (The HostName is the important part.) Consider the following snippet in your ~/.ssh/config.</p>
<pre>#
Host work
  HostName localhost
  User myworklogin
  IdentityFile ~/.ssh/id_dsa
  Port 4022
  RSAAuthentication yes
  PubkeyAuthentication yes
  LocalForward 4022 localhost:4022</pre>
<p>I&#8217;m going to assume remote forwarding is set up and the connection is open from work to cloud as described in <a href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">this post on remote forwarding</a>; and you&#8217;ve got local forwarding set up from home to cloud as described in this post on <a href="http://blog.bstpierre.org/local-ssh-forwarding">local port forwarding</a>.</p>
<p>Now you can do &#8220;ssh work&#8221; from your home pc, and it will automatically log you into your work pc with the right credentials using the tunnel on cloud.example.com. And the scp example above simplifies to &#8220;scp work:/tmp/foo.txt ~/foo.txt&#8221; &#8212; you don&#8217;t have to remember the forwarded port numbers.</p>
<p>Typing &#8220;ssh work&#8221; is nine keystrokes (eight letters plus enter). If you can type 40 wpm, that&#8217;s 200 keystrokes per minute, or 3.33 keystrokes per second, which means you can open the tunnel in four seconds!</p>
<p>If you add &#8220;alias ssw=&#8217;ssh work&#8217;&#8221; to your ~/.bashrc, you&#8217;re down to four keystrokes.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Local SSH Forwarding to Reduce the Number of Manual Hops</title>
		<link>http://blog.bstpierre.org/local-ssh-forwarding</link>
		<comments>http://blog.bstpierre.org/local-ssh-forwarding#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:12:19 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=219</guid>
		<description><![CDATA[Local port forwarding is the same as remote port forwarding but works in the opposite direction. An example is the clearest way to explain...


Related posts:<ol><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><em>(This is part three in a <a href="../category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Local port forwarding is the same as <a title="How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels" href="http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels">remote port forwarding</a> but works in the opposite direction. An example is the clearest way to explain.</p>
<p>Assuming you&#8217;ve done the steps in the previous posts, then at home you can run &#8220;ssh -L 4022:localhost:4022 me@cloud.example.com&#8221;. This listens on TCP port 4022 on your home machine. Any connections there will be forwarded through the ssh connection to port 4022 on cloud&#8230; which, as we recall, gets forwarded to port 22 (ssh) at work. If you leave this connection open, you can run &#8220;ssh -p 4022 localhost&#8221; on your home machine and it will connect to work in just one hop. This means that you can use scp to copy files from home to work or vice versa. For example, &#8220;scp -P 4022 localhost:/tmp/foo.txt ~/foo.txt&#8221; will copy a file from work to home. (<em>Note: scp needs capital &#8220;-P&#8221; to give the port. I got it wrong the first time.</em>)</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/local-ssh-forwarding/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</title>
		<link>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels</link>
		<comments>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:35:17 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=215</guid>
		<description><![CDATA[Ssh tunneling can be a bit mind bending at first, but it's simple when you get used to it.


Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><em>(This is part two in a <a href="http://blog.bstpierre.org/category/tools/ssh">series of posts on ssh</a>.)</em></p>
<p>Ssh tunneling can be a bit mind bending at first, but it&#8217;s simple when you get used to it. Assume that you&#8217;re trying to ssh between two sites that do not allow incoming ssh. Maybe your IT at work is unenlightened and doesn&#8217;t have an ssh gateway. And your ISP has braindead configuration rules that don&#8217;t allow incoming ssh or they make it difficult.</p>
<p>What you need to get around this is a server &#8220;in the cloud&#8221; that permits ssh logins. This could be a hosting server that you pay for, or even a friend with an enlightened ISP who will give you a login account.</p>
<p>On your work PC, use ssh to login to the &#8220;cloud&#8221; server. Using the &#8220;-R&#8221; argument, you tell ssh to listen on a TCP port on the cloud server. Any connection coming in to this server will be forwarded back through the ssh connection to the TCP port you specify. For example, on mymachine.work.com, &#8220;ssh -R 4022:localhost:22 me@cloud.example.com&#8221; tells ssh to listen on cloud&#8217;s port 4022. Incoming connections to that port on cloud will be forwarded to port 22 (ssh) on mymachine.</p>
<p>By default, ssh will only listen to port 4022 on cloud&#8217;s localhost interface. So to log in to work, you will first need to log into cloud, and then use &#8220;ssh -p 4022 myworklogin@localhost&#8221; to log into work.</p>
<p>We&#8217;ll work around this limitation in the next post in this series.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Tell SSH Who You Are</title>
		<link>http://blog.bstpierre.org/configure-ssh-username</link>
		<comments>http://blog.bstpierre.org/configure-ssh-username#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:11:10 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[ssh]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=222</guid>
		<description><![CDATA[Do you log in to several servers with different usernames via ssh? Save typing by telling ssh which username to use on each server.


Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Ssh has amazing capabilities that you probably aren&#8217;t using on a daily basis.</p>
<p>The capability that you probably aren&#8217;t using, and the easiest to use, is customizing your config file (in ~/.ssh/config) for the various servers you log into.</p>
<p>For example, I frequently log into about ten different servers using at least four different usernames. By default, if I type &#8220;ssh server&#8221; the client will use my login name on the client machine to try to log into the server &#8212; which is usually wrong. Instead you can <a href="http://superuser.com/questions/64996/how-to-make-ssh-log-in-as-the-right-user">tell your ssh client which username to use on each server</a>. (Thanks to <a href="http://wblinks.com/">Rich Adams</a> for the tip.)</p>
<p>You can customize a variety of settings &#8212; not just the username. For example, I specify a different identity file for a couple of servers.</p>
<p>This saves a bunch of typing and occasional confusion. (By avoiding login errrors as I try to log into a server using the wrong username and can&#8217;t figure out why my password isn&#8217;t working&#8230;)</p>
<p><em>(This is the first post in <a href="../category/tools/ssh">series of posts about how to get the most out of ssh</a>. Make sure you don&#8217;t miss the rest of the series: <a href="http://feeds2.feedburner.com/TheDailyBuild">subscribe to my feed</a> or <a href="http://twitter.com/bstpierre">follow me on twitter</a>.)</em></p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-remote-port-forwarding-tunnels' rel='bookmark' title='Permanent Link: How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels'>How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels</a> <small>Ssh tunneling can be a bit...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/configure-ssh-username/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Python&#8217;s ctypes to Call Into C Libraries</title>
		<link>http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls</link>
		<comments>http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls#comments</comments>
		<pubDate>Wed, 05 Aug 2009 10:35:55 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=185</guid>
		<description><![CDATA[The ctypes module makes loading and calling into a dynamic library incredibly easy.


Related posts:<ol><li><a href='http://blog.bstpierre.org/pid-file-race' rel='bookmark' title='Permanent Link: An Interesting pid File Race'>An Interesting pid File Race</a> <small> ISC&#8217;s dhcpd uses this code...</small></li><li><a href='http://blog.bstpierre.org/3-easy-ways-to-stick-to-a-coding-standard' rel='bookmark' title='Permanent Link: 3 Easy Ways to Stick to a Coding Standard'>3 Easy Ways to Stick to a Coding Standard</a> <small> When you&#8217;re writing python, you...</small></li><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>The ctypes module makes loading and calling into a dynamic library incredibly easy:</p>
<pre>&gt;&gt;&gt; from ctypes import CDLL
&gt;&gt;&gt; libc = CDLL('libc.so.6')
&gt;&gt;&gt; print libc.strlen('abcde')
5</pre>
<p>As with everything else in python, it gets even better when you scratch the surface. In the example above, CDLL returns an object that represents the dynamic library. You can access the functions in that library by attribute access (&#8220;libc.strlen&#8221;) or item access (&#8220;libc['strlen']&#8220;). Both access mechanisms return a callable object.</p>
<p>This callable object has an &#8220;errcheck&#8221; attribute that can be assigned a callable. We can use this for error-checking our calls into the library. Let&#8217;s write a simple version of the &#8220;kill&#8221; command that uses the kill(2) system call.</p>
<pre>import sys
from ctypes import *

# Load the library.
libc = CDLL('libc.so.6')

# Our error checking function. This will receive the
# return value of the library function, the function that
# was called, and the arguments passed to the function as a
# tuple.
def kill_errcheck(retval, func, funcargs):
    '''Check for error -- retval == -1.'''
    if retval &lt; 0:
        raise Exception('kill%s failed' % (funcargs, ))
    return True

# Get the kill function from the standard library.
kill = libc.kill

# Set the error checker for kill().
kill.errcheck = kill_errcheck

# Pass the command line argument as a pid to kill, with
# SIGSEGV (11).
pid = int(sys.argv[1])
kill(pid, 11)</pre>
<p>Save this as kill.py. Then, in your shell, try something like this:</p>
<pre># Notice that the 3401 is the pid of the process
# we're putting into the background. Yours will
# be different.
bash$ sleep 120&amp;
[1] 3401
bash$ python kill.py 3401
[1]+ Segmentation Fault         sleep 120
bash$ python kill.py 3401
Traceback (most recent call last):
  File "kill.py", line 17, in
    kill(pid, 11)
  File "kill.py", line 10, in kill_errcheck
    raise Exception('kill%s failed' % (funcargs, ))
Exception: kill(3401, 11) failed</pre>
<p>At line 4 of the output we run sleep in the background. At line 5 we learn the pid of this process. At line 6 we run our kill program, giving it the pid we just spawned, and we see the notification from bash that the process was killed (with signal 11, segmentation fault). At line 8 we run our kill program again on pid 3401, but it doesn&#8217;t exist, the kill system call returns -1, and our error checker raises an exception when it detects the system call failure.</p>
<p>But wait, there&#8217;s more&#8230; I&#8217;m working on a follow up post that combines ctypes.Structure with calls into a linux system call.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/pid-file-race' rel='bookmark' title='Permanent Link: An Interesting pid File Race'>An Interesting pid File Race</a> <small> ISC&#8217;s dhcpd uses this code...</small></li><li><a href='http://blog.bstpierre.org/3-easy-ways-to-stick-to-a-coding-standard' rel='bookmark' title='Permanent Link: 3 Easy Ways to Stick to a Coding Standard'>3 Easy Ways to Stick to a Coding Standard</a> <small> When you&#8217;re writing python, you...</small></li><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Exception Handling: Cleanup and Reraise</title>
		<link>http://blog.bstpierre.org/python-exception-handling-cleanup-and-reraise</link>
		<comments>http://blog.bstpierre.org/python-exception-handling-cleanup-and-reraise#comments</comments>
		<pubDate>Thu, 16 Jul 2009 03:35:49 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/python-exception-handling-cleanup-and-reraise</guid>
		<description><![CDATA[I&#8217;ve had this code around for a while and had an opportunity to drag it out the other day and dust it off. The problem: Every now and again there&#8217;s a situation where you don&#8217;t really want to catch an exception, but you do want to perform some cleanup and let the exception propagate up [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/data-vs-code' rel='bookmark' title='Permanent Link: Data vs Code'>Data vs Code</a> <small> I&#8217;ll take an array over...</small></li><li><a href='http://blog.bstpierre.org/configure-ssh-username' rel='bookmark' title='Permanent Link: How to Tell SSH Who You Are'>How to Tell SSH Who You Are</a> <small>Do you log in to several...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had <a href="http://gist.github.com/148135">this code</a> around for a while and had an opportunity to drag it out the other day and dust it off. The problem: Every now and again there&#8217;s a situation where you don&#8217;t really want to catch an exception, but you do want to perform some cleanup and let the exception propagate up the stack. Sometimes there&#8217;s an extra wrinkle in that the cleanup code may itself throw an exception (that I&#8217;m simply going to assume we can ignore).</p>
<p><script src="http://gist.github.com/148135.js"></script></p>
<p>You can run the file to see the behavior. Simply provide an integer 1-5 as a command line argument and you&#8217;ll run the selected scenario and see the output. The goal in this case is for cleanup to occur and an exception to be reported as having occurred at line 10.</p>
<p>The code in reraiser1 is wrong because this behaves as if a brand new exception were thrown at line 27. That may not seem so bad, but this code is pretty simple. If this happens and the stack trace is deep, it will be almost impossible to diagnose what went wrong.</p>
<p>The code in reraiser2 shows what happens when a second exception occurs in the except block. A bare raise statement here might be an attempt to re-raise the original exception, but python&#8217;s rules about re-raising specify that the most recent exception in the scope is what is reraised. In this case, that&#8217;s the exception thrown from the cleanup function. Again, this makes troubleshooting difficult.</p>
<p>In reraiser3 I worked around the problem in reraiser2 by moving the cleanup function&#8217;s exception into a separate scope by defining a local cleanup function and calling it from within the except block. This prevents the cleanup function&#8217;s exception from polluting the scope with an irrelevant exception and we can re-raise the original exception. This results in a stack trace rooted at line 10.</p>
<p>Reraiser4 takes a different approach. Instead of moving the cleanup function&#8217;s exception into a separate scope, it captures the traceback information from the original exception and then passes it back to the raise statement so that the reported traceback is accurate.</p>
<p>The cleanest way to handle this is to use a finally block as shown in reraiser5. This situation is what &#8220;finally&#8221; is meant for: it does not trap the exception, it just gives you a chance to clean up before control moves back up the stack to the caller. The presence of finally clues readers in to the fact that you aren&#8217;t messing with the exception, and that the point of the block is to perform cleanup.</p>
<p>Kindly drop me a note if I&#8217;ve got something wrong above, or if I&#8217;m missing a technique (or a common anti-pattern!). Thanks.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/data-vs-code' rel='bookmark' title='Permanent Link: Data vs Code'>Data vs Code</a> <small> I&#8217;ll take an array over...</small></li><li><a href='http://blog.bstpierre.org/configure-ssh-username' rel='bookmark' title='Permanent Link: How to Tell SSH Who You Are'>How to Tell SSH Who You Are</a> <small>Do you log in to several...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/python-exception-handling-cleanup-and-reraise/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Five Days to a Django Web App: Day Four, Deployment</title>
		<link>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-four-deployment</link>
		<comments>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-four-deployment#comments</comments>
		<pubDate>Mon, 02 Mar 2009 16:48:20 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=169</guid>
		<description><![CDATA[Thanks for your patience, and for coming back for a discussion of deploying our Django web app.
In case you missed any of the previous posts in this series, here they are:

Day One, Get Ready (Concept and prep)
Day Two, Mockups (Creating a design)
Day Three, Coding (Coding tests, views, templates, and models)

Pre-Deployment
First, we need to make a [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Thanks for your patience, and for coming back for a discussion of deploying our Django web app.</p>
<p>In case you missed any of the previous posts in this series, here they are:</p>
<ol>
<li><a href="/five-days-to-a-django-web-app-day-one-get-ready">Day One, Get Ready</a> (Concept and prep)</li>
<li><a href="/five-days-to-a-django-web-app-day-two-mockups">Day Two, Mockups</a> (Creating a design)</li>
<li><a href="/five-days-to-a-django-web-app-day-three-coding">Day Three, Coding</a> (Coding tests, views, templates, and models)</li>
</ol>
<h2>Pre-Deployment</h2>
<p>First, we need to make a couple of decisions:</p>
<ul>
<li>How are we going to push updates to the live site: FTP, git, svn?</li>
<li>How are we going to handle backups?</li>
</ul>
<h3>Version Control as Distribution System</h3>
<p>In my case, I&#8217;m using svn+ssh to push updates. Notice that this does not require special setup on your server &#8212; you do not need to install the svn stuff that DreamHost or your host may provide. Just do svn init to create a repository on the server (<em>outside</em> the DocumentRoot!). Then point your development pc to svn+ssh://USERNAME@host.example.com/home/USERNAME/svn/PROJECT. (Git works similarly, no support from your host required except the binaries.)</p>
<p>In the directory on the host where you&#8217;re going to store your project files, point to the same URL. (You could use the file:///&#8230;/ url, but I prefer to avoid accessing the repo directly. Superstition?)</p>
<p>Now, whenever you make a change on your development system, just &quot;svn ci&quot; and then on the host &#8220;svn up&#8221; and restart your fcgi to pick up the new code. Presto! The live site is updated with your change.</p>
<h3>Backups</h3>
<p>You must have a backup strategy: Your app will have users. Your host&#8217;s disk will burp. Your users will hate you when the disk burps and you don&#8217;t have a good backup.</p>
<p>There are probably 374 different ways of backing up your Django app. The two major things you need to capture are the database and your code. If you are storing objects (e.g. uploaded files) outside the database, you&#8217;ll need to back these up too. The option I&#8217;m using is <a href="http://code.google.com/p/django-backup/">django-backup</a>.</p>
<p>Pull the code from subversion into your project. Rename the directory to &quot;django_backup&quot;. Add django_backup to your INSTALLED_APPS. Verify it works by running <code>./manage.py backup -c</code>. Sanity check the backup by doing <code>zless backups/*.gz</code>. We&#8217;ll set up a cron job on the host to run this regularly when we deploy.</p>
<h2>Deploy</h2>
<p>I&#8217;ve previously written about <a href="/deploying-django-apps-on-dreamhost">deploying Django apps on DreamHost</a>, so I&#8217;m not going to duplicate that here. Keep in mind that you want to use the version control strategy outlined above. Read that article, deploy your app and come back here when you&#8217;re done.</p>
<h2>Post-Deployment</h2>
<h3>Backup</h3>
<p>Let&#8217;s add that cron job we previously mentioned. On the host, run <code>crontab -e</code>. If you&#8217;re on DreamHost and this if the first time you&#8217;ve used cron, it will prompt you for an email address to send output to. Then it will dump you into an editor. (Side note: &quot;joe&quot; is the default. If you want something different, like vim, be sure that EDITOR=/usr/bin/vim is set in your environment.)</p>
<p>Set up a job something similar to the following:</p>
<pre><code>
MAILTO="YOU@EXAMPLE.com"

# m h  dom mon dow   command
4 2 * * * (cd /home/PATH/TO/PROJECT; ./manage.py backup -c --email=YOU@EXAMPLE.com)
</code></pre>
<p>This will run a backup every day at 02:04 (AM). You will get two emails: one with the output from the job, and one with the compressed backup file. (When you get to the point where your database backups are too big for email, you&#8217;ll need to find another strategy.)</p>
<p>Now we&#8217;ve got another problem to solve: we&#8217;re going to accumulate a bunch of backups on the disk. Let&#8217;s get rid of the old backups. This is pretty safe, since we&#8217;re receiving backup files via email. Add a cron job like this:</p>
<pre><code>
14 2 * * * (cd /home/PATH/TO/PROJECT;
    touch --date=`date --iso --date='10 days ago'` .backup.oldest;
    find ./backups/ -mindepth 1 \! -newer .backup.oldest -execdir rm '{}' +)
</code></pre>
<p>(Formatted here for readability &mdash; you need to put that all on one line.)</p>
<p>This will remove backup files older than 10 days. You could do this more concisely with a tool like tmpwatch or tmpreaper, but neither is installed on my host and this incantation should work on pretty much any flavor and installation of linux.</p>
<p>At this point we&#8217;re deployed and the majority of the work is done. Tomorrow we&#8217;ll take a look at some maintenance issues.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/local-ssh-forwarding' rel='bookmark' title='Permanent Link: Use Local SSH Forwarding to Reduce the Number of Manual Hops'>Use Local SSH Forwarding to Reduce the Number of Manual Hops</a> <small>Local port forwarding is the same...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-four-deployment/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five Days to a Django Web App: Day Three, Coding</title>
		<link>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-three-coding</link>
		<comments>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-three-coding#comments</comments>
		<pubDate>Wed, 11 Feb 2009 15:14:41 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=141</guid>
		<description><![CDATA[Thanks for coming back for Day Three!
[Note: Sorry this post is a day late. It was all ready to go late yesterday, but some of the code included below triggered a bug either in WordPress or ScribeFire and the whole post got mangled. I managed to resurrect it today from drafts, and I think it's [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/3-easy-ways-to-stick-to-a-coding-standard' rel='bookmark' title='Permanent Link: 3 Easy Ways to Stick to a Coding Standard'>3 Easy Ways to Stick to a Coding Standard</a> <small> When you&#8217;re writing python, you...</small></li><li><a href='http://blog.bstpierre.org/configure-ssh-username' rel='bookmark' title='Permanent Link: How to Tell SSH Who You Are'>How to Tell SSH Who You Are</a> <small>Do you log in to several...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Thanks for coming back for Day Three!</p>
<p>[Note: Sorry this post is a day late. It was all ready to go late yesterday, but some of the code included below triggered a bug either in WordPress or ScribeFire and the whole post got mangled. I managed to resurrect it today from drafts, and I think it's coherent, but if you find some problem with it please drop me a note.]</p>
<h2>Progress So Far</h2>
<p>Yesterday we <a href="../five-days-to-a-django-web-app-day-two-mockups">built some mockups</a>, just HTML and CSS — nothing active. Hopefully you’ve had a chance to run your mockups past a couple of people for feedback and ideas.</p>
<p>Armed with these mockups, we’re ready to get started coding. Today’s post is the longest in the series. Take it in chunks if you need to. (I didn’t write it all at once either.)</p>
<h2>Foundation</h2>
<h3>MySQL</h3>
<p>First, go to your web host’s control panel and create two MySQL databases for this project. I created &#8220;resumandb&#8221; and &#8220;test_resumandb&#8221;. This latter database is needed for running the built-in test system.</p>
<p>You’ll get an error/warning if the test database exists when you first run tests. However, the control panel needs to set user privileges and it seems like the only way it knows how to do this is by creating the database.</p>
<p>Set up the same databases on your local system:</p>
<pre><code>
bash$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1969
Server version: 5.0.32-Debian_7etch8-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&gt; CREATE DATABASE resumandb;
Query OK, 1 row affected (0.00 sec)

mysql&gt; GRANT ALL ON resumandb.* TO 'resuman'@'localhost' identified
    by 'reallY_baD_9passworD!';
Query OK, 0 rows affected (0.11 sec)

mysql&gt; GRANT ALL ON test_resumandb.* TO 'resuman'@'localhost' identified
    by 'reallY_baD_9passworD!';
Query OK, 0 rows affected (0.0 sec)

</code></pre>
<p>Notice that you don&#8217;t need to create the test database. As mentioned above, this will happen when you run tests.</p>
<h3>Project Skeleton</h3>
<p>What follows is a bunch of steps: do-this, do-that. At the end of this section you should have a runnable (but empty) project that is ready to start hanging functionality onto.</p>
<p>Then generate a skeleton for your project: <code>django-admin.py  startproject YOURPROJECT</code>.</p>
<p>Then dive right in to settings.py and change a few things:</p>
<ul>
<li>Set the admin email to your email address.</li>
<li>Set the MySQL database according to your web host&#8217;s settings.</li>
<li>Timezone.</li>
<li>MEDIA_ROOT, MEDIA_URL and variants — see note below.</li>
<li>TEMPLATE_DIRS — see note below.</li>
</ul>
<p>To make it easier to use the same settings file to test both locally and on your host, I add the following to my settings.py to set MEDIA_ROOT and TEMPLATE_DIRS:</p>
<pre><code>
import os

def full_path_to(path):
    '''This makes this settings file relocatable.'''
    return os.path.join(os.getcwd(), path)

MEDIA_ROOT = full_path_to('static/')
TEMPLATE_DIRS = (
    full_path_to('templates')
)
</code></pre>
<p>Then you just have to make sure to cd to the directory where your settings.py lives whenever the app runs (more on this when we deploy to the host). I find this easier than monkeying with PYTHONPATH.</p>
<p>Similarly, the following will change your URLs based on whether you&#8217;re running locally or on the host. (Just make sure you test for a directory that only exists locally! My paths are a little different on the host.)</p>
<pre><code>
MEDIA_URL = 'http://media.resuman.com/resuman/static/'
if os.path.exists('/home/brian/projects/resuman'):
    MEDIA_URL = 'http://localhost/apache2-default/resuman-static/'

ADMIN_MEDIA_PREFIX = 'http://media.example.com/admin_media/'
if os.path.exists('/home/brian/projects/resuman'):
    ADMIN_MEDIA_PREFIX = 'http://localhost/apache2-default/resuman-admin/'
</code></pre>
<p>Now it&#8217;s time to generate the app: <code>./manage.py startapp YOURAPP</code>. Notice that the app name should be different from the project name (otherwise it gets too confusing later on).</p>
<p>Edit your YOURPROJECT/urls.py to include a reference to YOURAPP:</p>
<pre><code>
    (r'^funnel/$', include('resuman.jobfunnel.urls')),
</code></pre>
<p>Also uncomment the admin lines so you can use the built-in admin app.</p>
<p>Now it&#8217;s time to generate the app: <code>./manage.py startapp YOURAPP</code>.</p>
<p>Now edit YOURAPP/urls.py &#8212; paste in the needed bits from the existing urls.py, but drop the admin lines and the include().</p>
<p>In your settings file, add the admin and admindoc apps and &#8220;YOURPROJECT.YOURAPP&#8221; to INSTALLED_APPS.</p>
<p>Under the YOURPROJECT directory, create a templates directory and a static directory. Copy your HTML files from the mockup to the templates directory. Copy the CSS file to the static directory.</p>
<p>My system is configured by default to serve from /var/www/apache2-default/, and we specified above to fetch static files from http://localhost/resuman-static/, so we need to do the following to make this possible (substituting your paths, of course):</p>
<pre><code>
bash$ ln -s /home/brian/projects/resuman/static /var/www/apache2-default/resuman-static
bash$ ln -s /home/brian/projects/django/git/django/contrib/admin/media/ \
    /var/www/apache2-default/resuman-admin
</code></pre>
<p>Restart apache.</p>
<p>Change directory to YOURPROJECT and <code>./manage.py syncdb; ./manage.py runserver</code>.</p>
<p>Browse to <a href="http://127.0.0.1:8000/admin/">http://127.0.0.1:8000/admin/</a>. Log in, and you should see the admin app in all its glory. If the stylesheet didn&#8217;t load (ie. it looks really ugly), View Source on the page. At the top, find the URL to that ends something like &#8230;/resuman-admin/css/base.css. Copy-paste this into the address bar. It probably doesn&#8217;t load. Verify that it is the right URL — if not then change your settings.py to have the right URL base. If the URL is right, then you need to fix your symlink, server config, or permissions (I often get bit by having the wrong permissions).</p>
<h3>Adding Some Meat</h3>
<p>This wouldn&#8217;t be a bad time to push a snapshot into your version control system (e.g. <code>git init; git add .; git commit -m'YOURPROJECT skeleton done'</code>).</p>
<p>Now we&#8217;re finally ready to write the first view for this app. Edit YOURAPP/urls.py. Lay out the URL map that you want to use for your app. We&#8217;re on a tight five day schedule, so don&#8217;t go nuts! There&#8217;s only time to get a couple of pages done. Don&#8217;t worry, you can add more later. Here&#8217;s what mine looks like:</p>
<pre><code>
from django.conf.urls.defaults import *

urlpatterns = patterns(
    '',
    (r'^$', 'resuman.jobfunnel.views.dashboard'),
    (r'^add/$', 'resuman.jobfunnel.views.add_job'),
    (r'^edit/$', 'resuman.jobfunnel.views.edit_job'),
)
</code></pre>
<p>Remember that my toplevel urls.py includes this based on the <code>^funnel/$</code> pattern, so each of the patterns above will have …funnel/ as a prefix in the URL.</p>
<p>Now let’s write our first couple of tests. Edit YOURAPP/tests.py and add something similar to the code below. You’ll have to change URLs and logins. The class ViewTestCase is defined in viewtestcase.py, a convenience TestCase subclass I wrote for testing Django views. Copy that file into YOURAPPNAME directory.</p>
<pre><code>
from viewtestcase import ViewTestCase
class DashboardViewTestBase(ViewTestCase):
    # Override in subclass to use post/head/etc. Must match a
    # method defined in django.test.TestCase.
    TESTMETHOD = 'get'

    # Override.
    TESTURL = '/funnel/'
    TESTARGS = {}
    TEMPLATE = 'dashboard.html'

class DashboardViewLoginTest(DashboardViewTestBase):
    # We're expecting an error, so set TEMPLATE to None to avoid getting a bogus test failure.
    TEMPLATE = None

    def test_login_required(self):
        """
        Tests that a login is required to view the page.
        """
        self.expect_login_redirect()
        return

class DashboardViewTest(DashboardViewTestBase):
    # This uses TEMPLATE from the parent class.

    # Set username and password and the base class will automagically login the test client.
    USERNAME = 'brian'
    TESTLOGIN = (USERNAME, 'a')

    def test_logged_in_ok(self):
        pass
</code></pre>
<p>Now run the test: <code>./manage.py test</code>. You should see exactly two failures. If a bunch of stuff fails (like built-in django tests), fix whatever is wrong before continuing.</p>
<pre><code>
bash$ ./manage.py test
Creating test database...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table jobfunnel_job
Installing index for admin.LogEntry model
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for jobfunnel.Job model
Installing json fixture 'initial_data' from '/home/brian/projects/resuman/../resuman/jobfunnel/fixtures'.
Installed 1 object(s) from 1 fixture(s)
..........EE......
======================================================================
ERROR: test_login_required (resuman.jobfunnel.tests.DashboardViewLoginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/brian/projects/resuman/../resuman/jobfunnel/viewtestcase.py", line 98, in setUp
    self.fetch_view(self.TESTMETHOD, self.TESTURL, self.TESTARGS)
  File "/home/brian/projects/resuman/../resuman/jobfunnel/viewtestcase.py", line 79, in fetch_view
    self.response = function(testurl, testargs, **extra)
  File "/usr/lib/python2.5/site-packages/django/test/client.py", line 277, in get
    return self.request(**r)
  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 77, in get_response
    request.path_info)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 183, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 183, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 124, in resolve
    return self.callback, args, kwargs
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 136, in _get_callback
    raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
ViewDoesNotExist: Tried dashboard in module resuman.jobfunnel.views. Error was: 'module' object has no attribute 'dashboard'

======================================================================
ERROR: test_logged_in_ok (resuman.jobfunnel.tests.DashboardViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/brian/projects/resuman/../resuman/jobfunnel/viewtestcase.py", line 98, in setUp
    self.fetch_view(self.TESTMETHOD, self.TESTURL, self.TESTARGS)
  File "/home/brian/projects/resuman/../resuman/jobfunnel/viewtestcase.py", line 79, in fetch_view
    self.response = function(testurl, testargs, **extra)
  File "/usr/lib/python2.5/site-packages/django/test/client.py", line 277, in get
    return self.request(**r)
  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 77, in get_response
    request.path_info)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 183, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 183, in resolve
    sub_match = pattern.resolve(new_path)
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 124, in resolve
    return self.callback, args, kwargs
  File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 136, in _get_callback
    raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
ViewDoesNotExist: Tried dashboard in module resuman.jobfunnel.views. Error was: 'module' object has no attribute 'dashboard'

----------------------------------------------------------------------
Ran 18 tests in 4.364s

FAILED (errors=2)
Destroying test database...
</code></pre>
<p>Let’s write the view so the test will pass. Edit views.py:</p>
<pre><code>
@login_required
def dashboard(request):
    return render_to_response('dashboard.html',
                              {'title': 'Dashboard'},
                              context_instance=RequestContext(request))
</code></pre>
<p>This view uses a template called dashboard.html. Let’s make that template. Go back to the mockup for the dashboard. Copy everything into templates/base.html, then rip out the content so all you have left is the generic skeleton of a page in your app. Something like this (notice that this is using the title variable passed into the context by the view):</p>
<pre><code>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;!--
# Resuman: keep track of job applications, cover letters, and resumes
#
# Copyright (c) 2009, Blakita Software LLC
# All rights reserved.
--&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
&lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;

  &lt;title&gt;
    {{ title }}
  &lt;/title&gt;

  &lt;style type="text/css"&gt;
    @import "{{ MEDIA_URL }}base.css";
  &lt;/style&gt;

  {% block scripts %}
  {% endblock scripts %}

&lt;/head&gt;

&lt;body&gt;

&lt;div id="container"&gt;

&lt;div id="menu"&gt;
TBD
&lt;/div&gt; &lt;!-- end div=menu --&gt;

&lt;div id="header"&gt;
&lt;h1&gt;{{ title }}&lt;/h1&gt;
&lt;/div&gt; &lt;!-- end div=header --&gt;

&lt;div id="content"&gt;

{% block content %}
{% endblock content %}

&lt;/div&gt; &lt;!-- end div=content --&gt;

&lt;div id="footer"&gt;
&lt;div class="nav"&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="/blog/about"&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="/privacy.html"&gt;Privacy&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;div class="copyright"&gt;Copyright © 2009, Blakita Software LLC&lt;/div&gt;
&lt;/div&gt; &lt;!-- end div=footer --&gt;

&lt;/div&gt; &lt;!-- end div=container --&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Now take the content you ripped out and put it into dashboard.html:</p>
<pre><code>
{% extends "base.html" %}

{% block content %}
&lt;ul id="funnel"&gt;
  &lt;li class="phase first"&gt;
    &lt;div class="phase"&gt;Applied&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;AAA&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li class="phase"&gt;
    &lt;div class="phase"&gt;Confirmed&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;BBB&lt;/li&gt;
        &lt;li class="company"&gt;CCC&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li class="phase"&gt;
    &lt;div class="phase"&gt;Screen&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;Fubar&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li class="phase"&gt;
    &lt;div class="phase"&gt;Interview&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;Rabuf&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li class="phase"&gt;
    &lt;div class="phase"&gt;Offer&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;Oof Rab&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li class="phase last"&gt;
    &lt;div class="phase"&gt;Start!&lt;/div&gt;
    &lt;div class="companies"&gt;
    &lt;ul class="companies"&gt;
        &lt;li class="company"&gt;Rab Oof&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

{% endblock content %}
</code></pre>
<p>Obviously this still just has dummy static data. We&#8217;ll get some active data in there very soon, but now we&#8217;re ready to rerun the test. It should pass this time. If not, fix the problem. When you get all tests passing, celebrate!</p>
<p>For real data, we need to write the model(s) used by this app. Let&#8217;s add another test:</p>
<pre><code>
class DashboardViewTest(DashboardViewTestBase):
    USERNAME = 'brian'
    TESTLOGIN = (USERNAME, 'a')

    def test_company_list(self):
        self.expect_div_content('content', 'Foobar Corp')
        return
</code></pre>
<p>Edit models.py to add the model:</p>
<pre><code>
from django.contrib.auth.models import User
from django.db import models

class Job(models.Model):
    applicant = models.ForeignKey(User)
    company = models.CharField(max_length=80)
</code></pre>
<p>The test depends on having a job in the database. Let&#8217;s set up a test fixture. Edit YOURAPPNAME/fixtures/initial_data.json:</p>
<pre><code>
[{"pk": 1, "model": "auth.user", "fields":
    {"username": "brian", "first_name": "", "last_name": "",
     "is_active": 1, "is_superuser": 0, "is_staff": 0,
     "last_login": "2009-02-06 13:50:02", "groups": [], "user_permissions": [],
     "password": "sha1$0fcc8$c4cf5184f5c005f90165e782fb090e7d75b72986",
     "email": "brian@example.com", "date_joined": "2009-02-06 13:44:04"}},
 {"pk": 2, "model": "auth.user", "fields":
    {"username": "alan", "first_name": "", "last_name": "",
     "is_active": 1, "is_superuser": 0, "is_staff": 0,
     "last_login": "2009-02-06 13:50:02", "groups": [], "user_permissions": [],
     "password": "sha1$0fcc8$c4cf5184f5c005f90165e782fb090e7d75b72986",
     "email": "alan@example.org", "date_joined": "2009-02-06 13:44:04"}},
 {"pk": 1, "model": "jobfunnel.job", "fields":
    {"position_url": "http://example.com/career/", "title": "Foobar Eng",
     "company_url": "http://example.com/", "company": "Foobar Corp", "applicant": 1,
     "phase": "Apply", "date": "2009-02-11", "position": "Engineer",
     "notes": "Applied via website"}}
]
</code></pre>
<p>This will populate the database with a couple of users, both with password &#8220;a&#8221;, and a job before each test runs.</p>
<p>Run this test, expecting exactly one failure — the content div does not contain the expected string. Let&#8217;s grab the list of jobs in the view and pass it into the template:</p>
<pre><code>
@login_required
def dashboard(request):
    jobs = models.Job.objects.all()
    return render_to_response('dashboard.html',
                              {'title': 'Dashboard',
                               'jobs': jobs,
                               },
                              context_instance=RequestContext(request))
</code></pre>
<p>I won&#8217;t paste all of the code here again, but we need to edit the template to use the jobs list:</p>
<pre><code>
    &lt;ul class="companies"&gt;
      {% for job in jobs %}
        &lt;li class="company"&gt;{{ job.company }}&lt;/li&gt;
      {% empty %}
        &lt;li class="company"&gt;No jobs in this phase.&lt;/li&gt;
      {% endfor %}
    &lt;/ul&gt;
</code></pre>
<p>Now rerun the test and expect it to pass. Hooray!</p>
<p>One last refinement before we quit for today: users shouldn&#8217;t be able to see each others applications. The way this is coded, all jobs are going to show up on everybody&#8217;s dashboards. Not good. Here&#8217;s another test that checks that the application for Foobar Corp only shows up on Brian&#8217;s dashboard, not on Alan&#8217;s.</p>
<pre><code>
class PrivateDashboardViewTest(DashboardViewTestBase):
    USERNAME = 'alan'
    TESTLOGIN = (USERNAME, 'a')

    def test_private_applications(self):
        assert('Foobar' not in self.get_div_content('content'))
        return
</code></pre>
<p>Run the test, watch it fail, and then change one line in the view:</p>
<pre><code>
    jobs = models.Job.objects.filter(applicant=request.user)
</code></pre>
<p>Now the all the tests should pass.</p>
<p>Push a copy of your code into your version control tool. Take a break, you deserve it.</p>
<p>For &#8220;homework&#8221;, put together your other views in the same way as this one. We’ll look at deployment tomorrow.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/3-easy-ways-to-stick-to-a-coding-standard' rel='bookmark' title='Permanent Link: 3 Easy Ways to Stick to a Coding Standard'>3 Easy Ways to Stick to a Coding Standard</a> <small> When you&#8217;re writing python, you...</small></li><li><a href='http://blog.bstpierre.org/configure-ssh-username' rel='bookmark' title='Permanent Link: How to Tell SSH Who You Are'>How to Tell SSH Who You Are</a> <small>Do you log in to several...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-three-coding/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five Days to a Django Web App: Day Two, Mockups</title>
		<link>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-two-mockups</link>
		<comments>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-two-mockups#comments</comments>
		<pubDate>Tue, 10 Feb 2009 14:40:54 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=139</guid>
		<description><![CDATA[Welcome back.
Ready for Day Two? Did you get your &#8220;hello world&#8221; app running on your host?
Where We Stand
Yesterday we nailed down our concept, bought a domain name and hosting, set up our toolkit, and deployed a practice app on the host.
Here&#8217;s what I&#8217;m going to build: a web app to keep track of job applications, [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Welcome back.</p>
<p>Ready for Day Two? Did you get your &#8220;hello world&#8221; app running on your host?</p>
<h3>Where We Stand</h3>
<p><a href="http://blog.bstpierre.org/five-days-to-a-django-web-app-day-one-get-ready">Yesterday</a> we nailed down our concept, bought a domain name and hosting, set up our toolkit, and deployed a practice app on the host.</p>
<p>Here&#8217;s what I&#8217;m going to build: a web app to keep track of job applications, cover letters, and resumes. The working name for the project is &#8220;resuman&#8221;. Unfortunately, that obvious domain name was already registered and I&#8217;m not up for buying from the current owner. So after trying a bunch of more-or-less obvious combinations, I grabbed &#8220;yresu.me&#8221;, and I&#8217;ll deploy the app at &#8220;trackm.yresu.me&#8221;.</p>
<h3>Notes on Domain Registration</h3>
<p>It&#8217;s worth making a couple of notes here on the domain registration process. I use <a href="http://godaddy.com">GoDaddy</a> for my registrations. In the past I&#8217;ve done registration with my preferred host, but if you end up switching hosts it&#8217;s a hassle to move the domain registrations. Another complication: hosting services like DreamHost only support registrations on the major TLDs (.com, .org, .net, .info), while a full-service registrar like GoDaddy supports alternatives like .me.</p>
<p>Lastly, I like the bulk domain search service from <a href="http://dotster.com/">Dotster</a>. You can search for up to 50 names at a time. So if your first choice is unavailable, use Dotster&#8217;s bulk search tool to enter a whole mess of variations and see what&#8217;s available. This is the process I used to find yresu.me — the search included resu.me, esu.me, su.me, and myresu.me, all of which were taken.</p>
<h3>Make Some Mockups</h3>
<p>Before we commit any design ideas to HTML, let&#8217;s take some great advice from 37signals: <a href="http://gettingreal.37signals.com/ch06_From_Idea_to_Implementation.php">sketch a bunch of drafts on paper first</a>. To back up this idea, check out this story posted by Jeff Atwood about <a href="http://www.codinghorror.com/blog/archives/001160.html">quantity vs. quality</a>:</p>
<blockquote><p>The ceramics teacher announced on opening day that he was dividing the class into two groups. All those on the left side of the studio, he said, would be graded solely on the quantity of work they produced, all those on the right solely on its quality. His procedure was simple: on the final day of class he would bring in his bathroom scales and weigh the work of the &#8220;quantity&#8221; group: fifty pound of pots rated an &#8220;A&#8221;, forty pounds a &#8220;B&#8221;, and so on. Those being graded on &#8220;quality&#8221;, however, needed to produce only one pot &#8211; albeit a perfect one &#8211; to get an &#8220;A&#8221;.</p>
<p>Well, came grading time and a curious fact emerged: the works of highest quality were all produced by the group being graded for quantity. It seems that while the &#8220;quantity&#8221; group was busily churning out piles of work &#8211; and learning from their mistakes &#8211; the &#8220;quality&#8221; group had sat theorizing about perfection, and in the end had little more to show for their efforts than grandiose theories and a pile of dead clay.</p></blockquote>
<p>So my advice to you is to produce no fewer than five different designs on paper. It only takes a few minutes to sketch something out and see what it looks like. I did a handful of drawings on paper with my kids&#8217; crayons, and then some refinements on my whiteboard once I had chosen the general design. So use whatever media you have handy, and don&#8217;t worry about getting it perfect. Run your sketches by a couple of innocent bystanders for some feedback.</p>
<p><img class="size-medium wp-image-147" title="Mockups on my whiteboard." src="http://blog.bstpierre.org/wp-content/uploads/2009/02/whiteboard-mockup-300x203.jpg" alt="Mockups on my whiteboard." width="300" height="203" /></p>
<p>Once you&#8217;ve got a good design on paper, make mockups in HTML and CSS. Steve Dennis at subcide.com has a great walkthrough on <a href="http://www.subcide.com/tutorials/csslayout/">creating a CSS layout from scratch</a>. If you don&#8217;t have an established process for building up a design, follow his tutorial. Putting together the HTML+CSS takes a little more time than sketches on paper, but it&#8217;s still worth doing a couple of different designs to see what grabs you. I worked up two different CSS layouts on top of the same HTML. Run these designs by some people — now that you&#8217;ve got some code, you can upload it to your site and email a link to some friends. Pick the better of the two (or three).</p>
<p>Better yet, upload the mockups to your host and leave a comment here with a link to them. Traffic here is low enough that I should be able to reply with feedback. (Although feel free to circulate a link to this series to a hundred of your friends, or post it to digg. I&#8217;ll at least reply to the first 50 comments&#8230;)</p>
<p>Tomorrow we&#8217;ll start writing some code.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/ssh-forward-multiple-protocols-to-multiple-machines' rel='bookmark' title='Permanent Link: Use SSH to Forward Multiple Protocols to Multiple Machines'>Use SSH to Forward Multiple Protocols to Multiple Machines</a> <small>Let's say you have a half-dozen...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/five-days-to-a-django-web-app-day-two-mockups/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
