<?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>Fighting Rabbits &#187; Uncategorized</title>
	<atom:link href="http://fightingrabbits.com/archives/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://fightingrabbits.com</link>
	<description>and herding cats...</description>
	<lastBuildDate>Tue, 25 Oct 2011 20:24:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Install java on an Ubuntu Oneiric instance in EC2</title>
		<link>http://fightingrabbits.com/archives/332</link>
		<comments>http://fightingrabbits.com/archives/332#comments</comments>
		<pubDate>Tue, 25 Oct 2011 20:24:28 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=332</guid>
		<description><![CDATA[Just ran into a small problem installing openjdk in an Ubuntu Oneiric instance on EC2. It took a while to diagnose so I&#8217;m posting this here so I remember next time I have to do it. The problem is with the x11-common package needing a temp directory which is missing &#8211; so running the following [...]]]></description>
			<content:encoded><![CDATA[<p>Just ran into a small problem installing openjdk in an Ubuntu Oneiric instance on EC2. It took a while to diagnose so I&#8217;m posting this here so I remember next time I have to do it.</p>
<p>The problem is with the x11-common package needing a temp directory which is missing &#8211; so running the following command will give us a /tmp directory:</p>
<p><code lang="bash">sudo mkdir /tmp</code></p>
<p>You should then be able to install x11-common and therefore openjdk without problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/332/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Please Support Them</title>
		<link>http://fightingrabbits.com/archives/322</link>
		<comments>http://fightingrabbits.com/archives/322#comments</comments>
		<pubDate>Wed, 23 Jun 2010 12:28:04 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=322</guid>
		<description><![CDATA[I feel that I have I winged a bit today. I don’t want to sound like a moaner, I am just trying to get a cross that this really is a challenge in so many ways. In fact, the cycling is probably the easy bit. This has been far tougher than I had imagined.

I do realise that what I am going through is nothing compared to what someone fighting cancer goes through. And maybe that is just another reason why today has been emotional. Realising, why I am here and why I am doing this.]]></description>
			<content:encoded><![CDATA[<p>A couple of friends of mine are cycling across America &#8211; 3500 miles in  30 Days! &#8211; to raise money for 3 Cancer charities &#8211; Please help them&#8230;</p>
<blockquote><p>I feel that I have I winged a bit today. I don’t want to sound like a moaner, I am just trying to get a cross that this really is a challenge in so many ways. In fact, the cycling is probably the easy bit. This has been far tougher than I had imagined.</p>
<p>I do realise that what I am going through is nothing compared to what someone fighting cancer goes through. And maybe that is just another reason why today has been emotional. Realising, why I am here and why I am doing this.</p></blockquote>
<p><a href="http://www.cycleacrossamerica2010.com/blog">CycleAcrossAmerica2010.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/322/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lightweight Django Thumbnails</title>
		<link>http://fightingrabbits.com/archives/264</link>
		<comments>http://fightingrabbits.com/archives/264#comments</comments>
		<pubDate>Thu, 18 Feb 2010 20:07:53 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=264</guid>
		<description><![CDATA[I needed a good thumbnail solution for a recent Django project but didn't want the overhead of using sorl - I just needed a simple template tag that would let me generate the correct size of thumbnail from the main picture.]]></description>
			<content:encoded><![CDATA[<p>I needed a good thumbnail solution for a recent Django project but didn&#8217;t want the overhead of using sorl &#8211; I just needed a simple template tag that would let me generate the correct size of thumbnail from the main picture.</p>
<p>I found a solution on <a href="http://www.djangosnippets.org/">djangosnippets.org</a> but it needed a little tweeking to suit my needs.</p>
<p>The filter is applied directly to an image field using a template tag such as</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{{ object.image|make_thumbnail:'100x200' }}</pre></div></div>

<p>and supposing the image filename is &#8220;image.jpg&#8221;, it checks if there is a file called &#8220;image_100x200.jpg&#8221;, if the file isn&#8217;t there, it resizes and saves the original image, finally it returns the proper url to the resized image.</p>
<p>The updated filter is given below (you will need PIL installed):<br />
<span id="more-264"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Image
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Library, Node
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Variable, resolve_variable
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">urlresolvers</span> <span style="color: #ff7700;font-weight:bold;">import</span> reverse
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">contenttypes</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> ContentType
&nbsp;
register = Library<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> make_thumbnail<span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, size=<span style="color: #483d8b;">'200x200'</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Example:
    &lt;img src=&quot;object.get_image_url&quot; alt=&quot;original image&quot; /&gt;
    &lt;img src=&quot;object.image|make_thumbnail&quot; alt=&quot;image resized to default 200x200 format&quot; /&gt;
    &lt;img src=&quot;object.image|make_thumbnail:'200x300'&quot; alt=&quot;image resized to 200x300&quot; /&gt;
&nbsp;
    The filter is applied to a image field (not the image url get from
    get_image_url method of the model), supposing the image filename is
    &quot;image.jpg&quot;, it checks if there is a file called &quot;image_200x200.jpg&quot; or
    &quot;image_200x300.jpg&quot; on the second case, if the file isn't there, it resizes
    the original image, finally it returns the proper url to the resized image.
    &quot;&quot;&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">file</span>:
        <span style="color: #808080; font-style: italic;"># defining the size</span>
        x, y = <span style="color: black;">&#91;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> size.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'x'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        <span style="color: #808080; font-style: italic;"># defining the filename and the miniature filename</span>
        basename, format = <span style="color: #008000;">file</span>.<span style="color: black;">path</span>.<span style="color: black;">rsplit</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        baseurl, _format = <span style="color: #008000;">file</span>.<span style="color: black;">url</span>.<span style="color: black;">rsplit</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        miniature_filename = basename + <span style="color: #483d8b;">'_'</span> + size + <span style="color: #483d8b;">'.'</span> +  format
        miniature_url = baseurl + <span style="color: #483d8b;">'_'</span> + size + <span style="color: #483d8b;">'.'</span> +  format
&nbsp;
        <span style="color: #808080; font-style: italic;"># if the image wasn't already resized, resize it</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>miniature_filename<span style="color: black;">&#41;</span>:
            image = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>.<span style="color: black;">path</span><span style="color: black;">&#41;</span>
            pw = image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            ph = image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
            nw = x
            nh = y
            pr = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>pw<span style="color: black;">&#41;</span> / <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>ph<span style="color: black;">&#41;</span>
            nr = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>nw<span style="color: black;">&#41;</span> / <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>nh<span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #ff7700;font-weight:bold;">if</span> image.<span style="color: black;">mode</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'L'</span>, <span style="color: #483d8b;">'RGB'</span><span style="color: black;">&#41;</span>:
                image = image.<span style="color: black;">convert</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'RGB'</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #ff7700;font-weight:bold;">if</span> pw == nw <span style="color: #ff7700;font-weight:bold;">and</span> ph == nh:
                <span style="color: #ff7700;font-weight:bold;">pass</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> pr <span style="color: #66cc66;">&gt;</span> nr:
                    <span style="color: #808080; font-style: italic;"># image aspect is wider than destination ratio</span>
                    tw = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">round</span><span style="color: black;">&#40;</span>nh <span style="color: #66cc66;">*</span> pr<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    image = image.<span style="color: black;">resize</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>tw, nh<span style="color: black;">&#41;</span>, Image.<span style="color: black;">ANTIALIAS</span><span style="color: black;">&#41;</span>
                    l = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">round</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span> tw - nw <span style="color: black;">&#41;</span> / <span style="color: #ff4500;">2.0</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    image = image.<span style="color: black;">crop</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>l, <span style="color: #ff4500;">0</span>, l + nw, nh<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">elif</span> pr <span style="color: #66cc66;">&lt;</span> nr:
                    <span style="color: #808080; font-style: italic;"># image aspect is taller than destination ratio</span>
                    th = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">round</span><span style="color: black;">&#40;</span>nw / pr<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    image = image.<span style="color: black;">resize</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>nw, th<span style="color: black;">&#41;</span>, Image.<span style="color: black;">ANTIALIAS</span><span style="color: black;">&#41;</span>
                    t = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">round</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span> th - nh <span style="color: black;">&#41;</span> / <span style="color: #ff4500;">2.0</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    image = image.<span style="color: black;">crop</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, t, nw, t + nh<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                    <span style="color: #808080; font-style: italic;"># image aspect matches the destination ratio</span>
                    image = image.<span style="color: black;">resize</span><span style="color: black;">&#40;</span>size, Image.<span style="color: black;">ANTIALIAS</span><span style="color: black;">&#41;</span>
            image.<span style="color: black;">save</span><span style="color: black;">&#40;</span>miniature_filename, image.<span style="color: black;">format</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> miniature_url
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>
&nbsp;
register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>make_thumbnail<span style="color: black;">&#41;</span></pre></div></div>

<p>Save it as something like thumbs_filter.py in a templatetag folder in one of your django apps and then use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{% load thumbs_filter %}
{{ object.image|make_thumbnail:'100x200' }}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/264/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Django over HTTPS on Webfaction</title>
		<link>http://fightingrabbits.com/archives/255</link>
		<comments>http://fightingrabbits.com/archives/255#comments</comments>
		<pubDate>Fri, 25 Sep 2009 11:58:48 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fightingrabbits.com/?p=255</guid>
		<description><![CDATA[Webfaction have recently made a change to set the X-Forwarded-SSL header from the main Apache instance for HTTPS connections, this means the using Apache &#038; mod_wsgi HTTPS now Just Works&#8482; However if you are running using the Supervisor + Nginx + Django setup given on this blog you will need to add the following middleware [...]]]></description>
			<content:encoded><![CDATA[<p>Webfaction have recently made a change to set the X-Forwarded-SSL header from the main Apache instance for HTTPS connections, this means the using Apache &#038; mod_wsgi HTTPS now Just Works&#8482; </p>
<p>However if you are running <span id="more-255"></span>using the Supervisor + Nginx + Django setup given on this blog you will need to add the following middleware (available from <a href="http://www.djangosnippets.org/snippets/1706/">here</a>) to your Django setup.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> WebFactionFixes<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Middleware that applies some fixes for people using
    the WebFaction hosting provider.  In particular:
&nbsp;
    * sets 'REMOTE_ADDR' based on 'HTTP_X_FORWARDED_FOR', if the
      latter is set.
&nbsp;
    * Monkey patches request.is_secure() to respect HTTP_X_FORWARDED_SSL.
      PLEASE NOTE that this is not reliable, since a user could set
      X-Forwarded-SSL manually and the main WebFaction Apache instance
      does not remove it, so it will appear to be a secure request
      when it is not.  Usually if they do that, they will be harming
      only themselves, but it depends how you use request.is_secure().
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> process_request<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Fix REMOTE_ADDR</span>
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            real_ip = request.<span style="color: black;">META</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'HTTP_X_FORWARDED_FOR'</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">KeyError</span>:
            <span style="color: #ff7700;font-weight:bold;">pass</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #808080; font-style: italic;"># HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs. The</span>
            <span style="color: #808080; font-style: italic;"># client's IP will be the first one.</span>
            real_ip = real_ip.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;,&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            request.<span style="color: black;">META</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'REMOTE_ADDR'</span><span style="color: black;">&#93;</span> = real_ip
&nbsp;
        <span style="color: #808080; font-style: italic;"># Fix HTTPS</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'HTTP_X_FORWARDED_SSL'</span> <span style="color: #ff7700;font-weight:bold;">in</span> request.<span style="color: black;">META</span>:
            request.<span style="color: black;">is_secure</span> = <span style="color: #ff7700;font-weight:bold;">lambda</span>: request.<span style="color: black;">META</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'HTTP_X_FORWARDED_SSL'</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'on'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/255/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To Do&#8230;.</title>
		<link>http://fightingrabbits.com/archives/1</link>
		<comments>http://fightingrabbits.com/archives/1#comments</comments>
		<pubDate>Thu, 23 Oct 2008 11:59:30 +0000</pubDate>
		<dc:creator>Richard Cooper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http:/?p=1</guid>
		<description><![CDATA[Write some witty banter to go in here! :D]]></description>
			<content:encoded><![CDATA[<p>Write some witty banter to go in here! :D</p>
]]></content:encoded>
			<wfw:commentRss>http://fightingrabbits.com/archives/1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.fightingrabbits.com @ 2012-02-06 06:55:13 by W3 Total Cache -->
