<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: code</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/code.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2010-01-01T16:24:30+00:00</updated><author><name>Simon Willison</name></author><entry><title>countdown_to_newyear.py</title><link href="https://simonwillison.net/2010/Jan/1/countdown/#atom-tag" rel="alternate"/><published>2010-01-01T16:24:30+00:00</published><updated>2010-01-01T16:24:30+00:00</updated><id>https://simonwillison.net/2010/Jan/1/countdown/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://gist.github.com/267147"&gt;countdown_to_newyear.py&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
A quick Python / OS X script I knocked up last night to count in the new year (using the OS X “say” command).


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/code"&gt;code&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/macos"&gt;macos&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/newyear"&gt;newyear&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/projects"&gt;projects&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/say"&gt;say&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/scripts"&gt;scripts&lt;/a&gt;&lt;/p&gt;



</summary><category term="code"/><category term="macos"/><category term="newyear"/><category term="projects"/><category term="python"/><category term="say"/><category term="scripts"/></entry><entry><title>csrf_protect.php</title><link href="https://simonwillison.net/2008/Sep/24/csrfprotect/#atom-tag" rel="alternate"/><published>2008-09-24T14:52:36+00:00</published><updated>2008-09-24T14:52:36+00:00</updated><id>https://simonwillison.net/2008/Sep/24/csrfprotect/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://simonwillison.net/static/2008/csrf_protect.php.txt"&gt;csrf_protect.php&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
A PHP class for applying CSRF protection to existing PHP applications, using output buffering to rewrite any POST forms on a page. Heavily inspired by Django’s CSRF middleware. Tell me if you spot any bugs!


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/code"&gt;code&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/csrf"&gt;csrf&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/middleware"&gt;middleware&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/outputbuffering"&gt;outputbuffering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/php"&gt;php&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/projects"&gt;projects&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/security"&gt;security&lt;/a&gt;&lt;/p&gt;



</summary><category term="code"/><category term="csrf"/><category term="middleware"/><category term="outputbuffering"/><category term="php"/><category term="projects"/><category term="security"/></entry><entry><title>Django snippets: RequestFactory</title><link href="https://simonwillison.net/2008/Aug/12/django/#atom-tag" rel="alternate"/><published>2008-08-12T12:40:01+00:00</published><updated>2008-08-12T12:40:01+00:00</updated><id>https://simonwillison.net/2008/Aug/12/django/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.djangosnippets.org/snippets/963/"&gt;Django snippets: RequestFactory&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
I’ve been wanting this for ages; when I finally got around to writing it it turned out to only be a dozen or so lines of code. Makes it easy to create mock request objects in Django, which you can then use for testing view functions directly (bypassing the current test client mechanism which requires views to be assigned to a URLconf before they can be tested).


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/code"&gt;code&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/django"&gt;django&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/httprequest"&gt;httprequest&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/requestfactory"&gt;requestfactory&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/testing"&gt;testing&lt;/a&gt;&lt;/p&gt;



</summary><category term="code"/><category term="django"/><category term="httprequest"/><category term="python"/><category term="requestfactory"/><category term="testing"/></entry></feed>