Posts Tagged ‘Python’

Easily adopt Django’s new {% url ‘…’ %} template syntax

Thursday, March 24th, 2011

If you want to adopt the new recommended syntax but don’t want to add {% load url from future %} to every single template you have, you can simply add the following to your settings.py file:

import django.template
django.template.add_to_builtins('django.templatetags.future')

Now if you just change your {% url %} tags to the new syntax (see here), everything will work fine and will be compatible with Django 1.5 when it is released.

Some wtf Python float arithmetic

Friday, October 8th, 2010

Prof. Dominic Lemelin is about to try to prove that 7n + 2 is a multiple of three for all n in math class at the moment, and before I tried proving it myself I decided to do a few tests in Python to make sure I wasn’t wasting my time. It was doing pretty well until it 7365 + 2 caused it to overflow, but there was some weird stuff going on in the float arithmetic. I don’t know why I was using float arithmetic, maybe it’s still too early to be programming.

>>> x = 11398895185373145
>>> x/3
3799631728457715
>>> float(x)/3
3799631728457714.5
>>> wtf()

Update: By the way, x/3 actually gives the right answer, 3799631728457715. This is a key piece of information in recognizing that I’m not just an idiot who forgot that integer division rounds in Python.

From “removeUnexpectedACL” to “ACLr8″

Wednesday, July 8th, 2009

I just received a huge shipment of cheese and I don’t know what to do with it. So, I’ll be changing the name of the ACL tool from “removeUnexpectedACL” to “ACLr8″. But who cares?

Download ACLr8 here.
Update: ACLr8 now has its own page here.

Getting rid of “ACL found but not expected” errors when repairing permissions

Monday, June 15th, 2009

I’ve seen quite a lot of people complaining about these errors, and even though they don’t really hurt anything they can be very annoying.

So, in my very expansive free time I devised and wrote a program that will take the error messages from repairing (or verifying) permissions and remove all ACL from the files that are reported.

It is written in Python, and runs through from command line. As you shouldn’t trust any random person’s code to just run on your computer, I recommend opening the script in your favourite text editor before letting it steal all your passwords, just to be safe.

Disclaimer: I take no responsibility for anything the program does, use it at your own risk. It’s very likely to reduce your computer to a smoldering pile of melted plastic and spare parts.

Download removeUnexpectedACL.zip (outdated, see below)

All kidding aside, it’s pretty harmless, and damn are those ACL errors ever annoying.

Update: I changed the name. Download it here instead.

Update #2: removeUnexpectedACL has been renamed “ACLr8″ and now has its own page here.