27
Jan
12

some treetop debug tips


Treetop seems pretty nice, but information on it’s usage is kind of scattered all over internet :) . Here are a few tips that I used to debug grammars:

  1. You can try a specific rule by writing this:

    tree = parser.parse(content,:root => "rule_name")
  2. I usually have my code structured like this, to get some info about where the parser chokes:
    
    if tree
        puts "succesful"
    else
        puts "unsuccesful at #{parser.index}"
        puts parser.failure_reason
    end
    

Hope this helps you as much as it helped me.

23
Jan
12

unknown encoding: cp0


If you receive this when deploying django on apache, it’s because you have something like:


print "Something %s" % value

The fix is to change it to:


print "Something %s" % str(value)

17
Jan
12

easy xml parsing in c#

Just a simple usage example:


using System.Xml;
...
XmlDocument doc = new XmlDocument();
// loading a file
doc.Load("file.xml");

// searching for multiple nodes via XPath; this will select all  elements wherever they may be
XmlNodeList books = doc.SelectNodes("//books");

foreach(XmlNode node in books)
{
   // getting attributes; assuming <book Author="Whatever">
   XmlAttribute author = node.Attributes["Author"];
   string value = author.Value;
}

16
Jan
12

current fitness plan


Monday: complexes ( as shown in T-Nation’s screw cardio article )
Tuesday: stationary bike cardio
Wednesday: running
Thursday: pyramid training
Friday:complexes again
Saturday: stationary bike cardio

28
Nov
11

django create superuser automatically on syncdb


Found the following information here. Here’s how you can automatically create a superuser when syncing your db:


python manage.py dumpdata auth > initial_data.json
python manage.py syncdb

Make sure to modify the initial.json file, if you want to change the name/mail of the superuser.

24
Nov
11

data URI scheme


This ( Data URI scheme ) is very helpful for serving images without storing them on server side.

21
Nov
11

always specify fields for django’s ModelForm as a tuple


So, I had a model that had a FileField called path, for which I wanted a ModelForm. Do not do this:


class MyModelForm(ModelForm):
   class Meta:
      model = MyModel
      fields= ("path")

It led to a strange error, saying django.core.exceptions.FieldError: Unknown field(s) (a, p, t, h). Of course, the fix was to specify the fields like:


class MyModelForm(ModelForm):
   class Meta:
      model = MyModel
      fields= ("path",)

21
Nov
11

django FileField and random names


To ensure that an uploaded file will have a random name, use a custom storage object, like described here.




Blog Stats

  • 102,712 hits

Follow

Get every new post delivered to your Inbox.