-
posts
-
Django template2pdf
This is cool Django application from Yasushi
Masuda which allows you to render data to
a pdf using trml2pdf.
template2pdf provides a
generic view called direct_to_pdf which will render a rml template
directly to pdf.
# coding: utf-8
from django.http import HttpResponse
from django_trml2pdf import direct_to_pdf
from django.shortcuts import render_to_response
def myview(request, template_name='trml2pdf/mytemplate.rml'):
params = {}
return HttpResponse(
direct_to_pdf(request, template_name, params),
mimetype='application/pdf')
-
How to be a 10x programmer
I recently read a blog post that is a satirical look at how to gain a reputation as a guru programmer by converting code to your own code and making it hard for other programmers to get their work done. It’s called 3 Simple Rules That Will Make You a ‘Superstar’ Developer and it’s very tongue in cheek. It outlines 3 simple rules to be a superstar programmer. Rule 1: Write lots of code. i.e. Rewrite large amounts of the codebase to your own code since you will be more productive fixing bugs and others will have a harder time....
-
Walled Gardens Suck
I recently read a couple of posts on the openness of the iPad and the effect it will have on tinkering and computer hacking. One was a post by al3x of twitter fame and one was a response, perhaps not directly to al3x, by Rory Marinich called I Love Walled Gardens. The gist of al3x’s post is that the iPad is closed but simple enough to be usable for most people so that may mean that hacking might suffer, and Rory says that’s a “good thing” and that hacking the computer to do stupid stuff is a waste of time....
-
Writing Schema migrations for App Engine using the Mapper Class and the deferred Library
One thing that many people using App Engine know is that writing schema migrations is hard. Improving performance on App Engine often revolves around getting objects by key or key name rather than using filters, however altering the makeup of an objects key requires pulling all the objects and saving them in the datastore anew. This also requires modifying the ReferenceProperties of any objects pointing to your changed object. On top of that, schema migrations generally require modifying lots of data and you have limits on the number of objects returned by a filter, and request timeouts to worry about....
-
Running django with daemontools
Running django fastcgi with daemontools is rather easy but getting it to run in the foreground with the proper user takes a bit of knowledge about how bash works and the tools in daemontools. In order to run the fastcgi daemon in the foreground you need to specify the daemonize=false option to the fastcgi command. Next the daemon will be started as the root user unless the daemon has an option to change the user itself. The fastcgi daemon doesn’t so we will use a tool from daemontools called setuidgid to set the user to www which is the user...
-
How to Hide Inactive Branches by Default with Mercurial
mercurial usually shows inactive branches when running “hg branches” but that’s kind of annoying if you have lots of old inactive branches. So I recently set up my personal .hgrc to hide inactive branches by creating an alias. [alias] branches = branches -a Normally you get this kind of output. ian@laptop:~/src/prj$ hg branches default 1662:1fa310d3052a hoge 1661:62d737e7146e hoge_inactive 1623:ba27ba59a257 (inactive) hoge_closed 670:1c3134ca4a95 (closed) But after setting up the alias inactive branches aren’t shown. ian@laptop:~/src/prj$ hg branches default 1662:1fa310d3052a hoge 1661:62d737e7146e This way though there isn’t a good way to show all branches if you have set up an alias so...
-
Testing HTTPS with Django's Development Server
Django’s development server doesn’t normally support HTTPS so it’s hard to test applications with HTTPS without deploying the application to a real web server that supports HTTPS. The secret is to use two development server instances, one for http and one for https, and to use a tool called stunnel to can create an ssl tunnel to the development server to support HTTPS. First we need to set up stunnel using the documentation . After it’s installed you can create a pem for stunnel. openssl req -new -days 365 -nodes -out newreq.pem -keyout /etc/stunnel/stunnel.pem After that we create a settings...
-
Importing an svn repository into mercurial
Recently I’ve been forking Subversion (SVN) repositories by converting them to mercurial repositories and uploading them to Bitbucket. It’s fairly easy with the Mercurial convert extension. Convert is distributed with Mercurial so if you have a recent version all you should have to do is put the following in your hgrc. [extensions] hgext.convert= Converting a repository over HTTP by running convert using the repository URL can be very slow so it’s generally much faster to sync the SVN repository locally and then convert it to Mercurial. First you need to use svnsync to copy the repository. $ svnadmin create foomirror...
-
Minimum cost for warming-up various frameworks(and more)
My good friend Takashi Matsuo wrote an
interesting blog about start up times of various frameworks on App Engine.
Because App Engine kills your server process it often needs to load your
application into memory from scratch. This can take a lot of time if a lot of
modules are loaded.
http://takashi-matsuo.blogspot.com/2009/10/minimum-cost-of-various-frameworks-cold.html
-
Testing using a mocked HTTP server
Recently I got some tests working for my django-lifestream project. The lifestream imports data from RSS/Atom feeds so there isn’t a good way to run tests without creating a test HTTP server to serve up your RSS/Atom. The tests start up an HTTP server in a separate thread which serves RSS/Atom/XML files from a set test directory. I copied the test HTTP server which was used for feedparser’s tests. The code is entirely unreadable but the important thing that it does is read information about what to supply in response headers from the xml file (This is useful for testing...