Macromap
Something I just found in my code archive. A Starcraft 2 build order creation tool!
Github link: http://github.com/skid/macromap
Something I just found in my code archive. A Starcraft 2 build order creation tool!
Github link: http://github.com/skid/macromap
I just published a project on github. It's a clone of the django templating engine for Node.js. Check it here: http://github.com/skid/strobe-templates
Here's a Tetris game I wrote during my spare time in the weekend. It's one HTML file and it uses the HTML canvas element only.
You're gonna need a HTML 5 browser to see it in action. That means Firefox 3.5+, Safari 4 or Google Chrome.
I would very much appreciate remarks on the code :)
Here's the link
This is an attempt to make a non-biased comparison between Django and Pylons. I did a brief comparison of the two at work since we needed a web framework for our new project.
We are making a web application that will serve as a frontend to a bank database. The application is going to allow bank employees to insert and track interbank loans and their repayments. The database is actually abstracted behind a layer built with Twisted, so the web application will only use XMLRPC calls to communicate with the database, hence no ORM.
As of the moment of writing, Django is in version 1.1 and Pylons is in version 0.9.7. Both of the frameworks are mature and tested in production in some major websites. Django has Washington Post and pylons has Reddit.
The frameworks are quite different in philosophy, although both follow the same MVC paradigm. Django has more magic and less code, while pylons has more code and less magic. Pylons is essentially a bare-bones wrapper around the WSGI specification that uses 3rd party modules for templating, database interaction, routing and just about anything else, while Django is aimed towards rapid development of web applications and has everything packed inside of it - it's own template system, routing and ORM. This allows Django to establish high reusability for code between different projects. On the other hand, the developer is limited to one ORM and templating system.
Let's go point by point. These are not all the relevant features in a web framework by any means, but they should give the reader a general overview of the differences and the strengths of the frameworks in the most important areas.
Attention to details can make or break a product. I was just downloading dropbox and I noticed a facinating thing. On the download page there are instructions for installing. It's just a few images of your browser download window and the installation confirm popup telling you where to click. Now the fascinating thing is that those are images of YOUR browser. They change depending on the browser or operating system you use to visit the site so that there are no confusions. Now this is what I call attention to detail. That is why Blizzard is making the finest games and Microsoft is making crappy OS-es. Kudos Dropbox!
Maybe I got a bit rusty on my 1 month vacation, but today I ran into a simple problem that I spent 2 hours solving. I Am working on a website made in Django and I decided to make some changes to the model in one of the apps in the project. I currently have 3 apps - game, content and members. One of the classes of the content model imports a class from the game model, but I decided to remove that particular class.
After syncing the DB I noticed that the database tables for the content app are missing.This was strange, because no errors were reported. I tried to do a "python manage.py sqlall content" and the shell threw an error that it couldn't find the content app on my PYTHONPATH.
Error: App with label content could not be found. Are you sure your INSTALLED_APPS setting is correct?
I tried all kinds of different stuff until i found a mailing list that said that if you have import errors in some module, you cannot import it, which is to be expected, but the error messages that come up are all but informative. The message that my PYTHONPATH is incomplete in no way suggests that I have an import error.
What does this have to do with exceptions ?
Well, I'll talk about another example first: While I was writing a screen scraper, I used a lot of regular expressions. The regular expressions return a match object if they successfully make a match and None if they don't. If you try and call the .group() method on a Match object - it does the job, but calling it on a None object throws and AtrributeError. I used to catch this exception in the upper layers of my program in order to avoid crashing the script on invalid input. This turned out to be a bad idea since all kinds of other stuff throws an AttributeError and makes the debugging a living hell.
I suspect that the same thing is going on in Django. Failure to import inside a module throws an ImportError which Django interprets as a missing module - only the module isn't missing - its a "submodule" that is missing. But the exceptions are the same, no matter on which level they happen.
Using exceptions correctly requires defining your own classes for every particular error that you may run into. This is a lot of extra code and need's to be weighed against the old-fashioned error codes.
Here is my attempt to create a "silver bullet" tag for printing tree structures with the Django templating language. It's far from a silver bullet, tho, but it can do basic stuff:
It's a modification of the standard "for" tag and i have kept the counter, counter0, first and last variables, only this time they are not attributes to forloop, but rather to recurseloop. Check the docstring for more info.
For example, if you need to print comments that have other comments as replies, you would want the comments to appear one below the other, but the replies to be indented a bit. Let's say 20 pixels per level. So the code would be:
{% load file_that_contains_recurse_tag %} {% recurse comment in comments children="replies" indent=(0,20) %} <div style='margin-left:{{indent}}px;'> {{ comment.text }} </div> {% endrecurse %}
This tag will expect a list of comments (top-level) that have a property named 'replies' which contain other comments.
indent is an argument that will start with the float value of 0 and get increased by 20 on each depth level of the recursion. You can pass as many variables like indent as you like. They must be in the form
name=(float,float)
or strings will also work but must be enclosed in quotes
name=("string","string")
Caveat: You must not leave blank spaces between the equal signs when assigning children and additional incremented arguments. I will fix this later.
A second scenario is when you need the parent element to contain the children, like in unordered/ordered lists. In that case you can use the {% yield %} tag inside the recurse block. This tag will output the HTML between the recurse and endrecurse tags if there are any children in the current iteration item, or it will output nothing if there are no children.
{% recurse comment in comments children="replies" indent=(0,20) %} <div style='margin-left:20px;'> {{ comment.text }} {% yield %} </div> {% endrecurse %}
The yield tag (as for now) can only be used directly inside the recurse block, much like the {% else %} tag can only be used directly inside the if-endif block. This means that you can't make code like
{% recurse comment in comments children="replies" indent=(0,20) %} <div style='margin-left:{{indent}}px;'> ({{ comment.text }}) </div> {% if cond %} {% yield %} {% endif %} {% endrecurse %}
This will fail with an invalid block tag exception. You can check the docstring of the do_recurse function inside the code for more info. Also, you may want to check this code for errors since I just wrote it today, and haven't had much time to test it.
I installed the 10.5.7 update for Mac OS X Leopard and after logging in i got a prompt that the system date was reset (to 1990-something). I am using the automatic date setting which gets the current date and time from apple.com so I figured that it was no biggie. But after a short while I noticed that I have no wireless network connection and that the password for the network was blank, which is odd, since I am supposed to have this password saved in the keychain.
I opened up the keychain access and checked the "show password" on the wireless network in my office (I don't remember it, ofc ) and i got a message that "Access to this item is restricted.".
After a lot of digging around (on another laptop) I found out that if the current system date is earlier than the creation date of your keychain file (~/Library/Keychain/login.keychain) you cannot view the items in it. So here's a loophole: No internet - can't set correct system date - no correct system date - no internet ....
Luckily for me, I devised an extremely clever plan - I manually set the date to today, got the keychain working, and then switched back to auto-date. Ha-ha.
Psycopg2 is the postgreSQL adapter for Django. If you are trying to set it up on Mac OSX (using the supplied setup.py script) you may run into an error saying
File "setup.py", line 219, in finalize_options
NameError: global name 'w' is not defined
This is a simple thing to fix: open the setup.py file coming with psycopg2 and edit the line 219 like this:
except (Warning, w):
Remove the braces
except Warning, w:
In python 2.6 (at least) putting exceptions in brackets will catch multiple exceptions in this case Warnings and 'w's. The author clearly meant to get the Warning instance as 'w'. Also, do not forget to edit the setup.cfg file on line 28 and type in your pg_config path. Mine is
pg_config=/Library/PostgreSQL/8.3/bin/pg_config
and so should yours be if you used the default installer package for mac OS X. Oh, yeah, you need to install postgres before installing psycopg2.
This piece of python code is going to draw some mazes in a .PNG format. It's a side-product of the solution to the Google Code Jam practice problem B called "Always turn left". The script takes the input data sets and draws the mazes described with every test case. You will need Python with Python Imaging Library (PIL) installed. If you're working on OS X like me, check out this link for some tips on how to install PIL.
To run the script type "python left.py" and it will ask for a file path containing the test cases. It will create a png image for each test case in the directory from which the program is run.