http byte range requests

Here are some example of http byte-range requests–they request a piece of a file at a time. Very useful for downloading files piece-wise 🙂

----Header Sent----
GET /sounds/WAV/ HTTP/1.1
Range: bytes=60527-
User-Agent: GetRight/3.02
Accept: *.*, */*
Range-If: Fri, 25 Apr 1997 20:28:04 GMT

----Header Recv----
HTTP/1.1 206 Partial Content
Date: Sun, 23 Nov 1997 21:20:17 GMT
Server: Apache/1.3b3 mod_perl/1.06
Last-Modified: Fri, 25 Apr 1997 20:28:04 GMT
ETag: "4b46f-1a80fb-336113d4"
Content-Length: 1676428
Content-Range: bytes 60527-1736954/1736955
Content-Type: application/zip

Note that the final number of “content-range” is the file size -1 (I believe)
Note that this is also valid

Range: bytes=500-999

RoR hidden fields

How to use a hidden field

<%= hidden_field 'filter', "id", :value => %>

This generates filter[id] = value yeesh!
To use it:

@filter = Filter.find(params[:filter_to_use][:id]) # retarded

How to use an “interior” field to specify another DB entry

<%= text_field 'filter_assignment', 'parameter1_setting', "size" => 10, :value => 61 %>

now in the “receiving” model of the post…

@filter = Filter.find(params[:filter_to_use][:id]) # retarded

newFilterLink =[:filter_assignment])

mod_rewrite woes

So to setup django and/or RoR sometimes you need to have mod_rewrite installed.  Sometimes those other “locationmatch” directives in the apache conf files aren’t flexible enough.  So…what if it’s not?  I think that if you had the original source of the apache you installed, then recompiled it with –mod-rewrite (or whatever it is), then you might be able to drop into the apache/modules folder.  But if not then I didn’t figure out how to not recompile it.  You may be able to compile it to another location, then copy into your apache/modules folder (then edit httpd.conf to use it).  I never got it to work. If you find out how let me know!

Django User

So…you want to mess around with the default Django”User” profile?  I’m not sure if inheritance will work (it might but…might not).  Typically I just

1) copy the python25\lib\django files to my project

rename the original “django” directory as “django_clean” or what not.

add the new django file (that I copied to my project) to PYTHONPATH environment variable.

Edit django/contrib/auth/ and change User to your hearts content.  Have fun!

installing apache flood

Apache flood is a…reasonable load tester for HTTP servers.  You give it an xml files which says “get this page then this one then this one” then spawn some processes to do so.  A little bit non user friendly, as I was never able to get the tests to really…run the way I expected them to.  Turns out that installign apache flood has some…difficulties, but is not too bad.  Here is my post on it in case others run into the same difficulties.  Let me know if you have any feedback on this!

django passwordinput

So you want to use a django.newsforms for passwords? Turns out to be all right…once you figure it out

from django.newforms.widgets import * # passwordinput
class UserEditVitalsForm(forms.Form):
 previousPassword = forms.CharField(widget = PasswordInput)

Then it should display right 🙂
Note if you want a partial field to work with django newforms and a database entry, let me know, I have some code to help.

python sending email with TLS

So…you want to email? and your SMTP server requires TLS? No worries.
Download ssmtplib from
then use it thus:

from ssmtplib import * 
def emailSSL(fromy, to, subject, body): 
    # Add the From: and To: headers at the start! 
    msg = "From: %srnTo: %srnSubject: %srn%sn" % (fromy, to, subject, body) 
    conn = SMTP_SSL('') 
    # From here, you can use any method in smtplib 
    # sender is first 
    conn.sendmail(fromy, to, msg) 

Much thanks to for help knowing how to do msg.

doing queries in django templates

Well it seems that you can’t do ‘generic’ queires from within a template — the only reason being as I can tell– that functions don’t take parameters when you call them from within a tempalte. Pity.

Therefore the way to query within a template is to make a ‘helper function’ that will do your query for you, if possible.

I think. According to this post
* Attribute access of a related object which hadn’t previously been
accessed (and select_related will work around that for you so you get
all the queries up-front).
* Method accesses which fetch data (these should be documented in your models).
* Template tags which execute SQL (these should be documented in the
template tags which are executing the SQL).

So just build a helper function and hope it helps 🙂

how to display forms only data

So say you want to just display a form — plaster it on the screen, without any boxes?

Add this to django/newforms/

    def as_data_only(self): # lodor tell world, django :)
        if not self.form.is_bound:
            data = self.form.initial.get(, self.field.initial)
            data =
        return data

and in the view template:

{% for field in userForm %}
{{ field.label }}:
{{ field.as_data_only }}
{% if field.help_text %}<dd>{{ field.help_text }}</dd>{% endif %}
{% if field.errors %}<dd class=”myerrors”>{{ field.errors }}</dd>{% endif %}
{% endfor %}

Roger's meanderings, notes to himself, bug reports, and other things