Monday, August 20

Pencils Down!

It's that time. The google summer of code program is winding and all of our code is expected to be completed by today. In preparation for code uploading I've tagged all the code that's been written up to August 20th. You can check out the tagged code at http://seddit.googlecode.com/svn/tags/pencils-down/. There is also a zipped up snapshot that you can download on Seddit's project page. Here's a quick report on what's been implemented, and what hasn't been implemented yet.

Implemented Features:

  • multiple rooms

  • threads for rooms (questions)

    • asking a new question


  • user accounts

    • thread history


  • searching

  • archived rooms

    • commenting system for the archives




Planned Features

  • alerts

    • jabber, aim, yahoo, twitter

    • mailing list, irc


  • social networking

    • private messaging

    • friends


  • smart content push

    • have seddit determine which users are experts at with what topics

    • push the content to the user via the dashboard depending on expertise


  • threaded commenting?

  • comet implementation as opposed to ajax poll.

    • this would be a very very interesting rewrite


  • OpenID support

  • guest users



As the day progresses, also be sure to check out the bug tracker. I've been working on updating that with all the features I didn't have time to implement over the summer, and any withstanding bugs.

Wednesday, July 18

Slice Notes

Setting up a fresh Slice (Ubuntu 6.0.6.1) Everything here is pretty rough, so don't try and follow this command by command, just be smart about what you're doing, and this should lead you in the right direction. If anyone's got any questions, I'd be happy to clarify.

Just as a side note, I'm using Slice Host to host my slices. I highly recommend it for anyone looking for a high quality vps, their support is great, and I haven't had any problems with uptime.

Change our default root password

% passwd


Also, you should probably add a new non root user.

Upgrade to Edgy

In order to upgrade our slice to the latest version of Ubuntu it must be done incrementally. First it much go to Edgy, then from Edgy you can upgrade to whatever you desire.


sed -e 's/\dapper/ edgy/g' -i /etc/apt/sources.list
apt-get update
apt-get dist-upgrade
apt-get -f install
dpkg --configure -a
reboot


Upgrade to Fiesty


sed -e 's/\edgy/ feisty/g' -i /etc/apt/sources.list
apt-get update
apt-get dist-upgrade
apt-get -f install
dpkg --configure -a
reboot


Check for Success!


root@slice:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 7.04
Release: 7.04
Codename: feisty


Postgresql Notes


% sudo apt-get install postgresql-8.2


I like being able to use my own username to work in the postgresql command line and whatnot. Make sure the role is the username that you want. (In my case I want it to be dnewberry)


% sudo su postgres -c createuser dnewberry

Enter name of role to add: dnewberry
Shall the new role be a superuser? (y/n) y


Make sure that postgresql knows about it.


% sudo su postgres -c psql

postgres=# ALTER USER dnewberry with PASSWORD 'password';
postgres=# \q


Setup psycopg2

I found a few gotchas installing this package. For more information check out http://www.initd.org/tracker/psycopg/wiki/PsycopgTwoInstall. With Ubuntu you really can't install using easy_install.


% sudo apt-get install python2.5-dev
% sudo apt-get install gcc
% sudo apt-get install libpq-dev
% wget http://initd.org/pub/software/psycopg/psycopg2-latest.tar.gz

* Note: you must edit setup.cfg and uncomment the line adding the following include dir
/usr/include/postgresql

% sudo python setup.py install


Lighttpd

% sudo apt-get install lighttpd
% sudo apt-get install flup


My Config File

I've snipped everything that isn't relevant to setting up web.py as an application. Make sure you make application.py executable using (chmod +x application.py)


server.modules = (
"mod_access",
"mod_alias",
"mod_fastcgi",
"mod_accesslog",
"mod_rewrite",
"mod_evhost",
)

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root = "/home/dnewberry/sites"

$HTTP["host"] == "blah.com" {
server.document-root = "/home/dnewberry/sites/blah.com"
fastcgi.server = ( "application.py" =>
((
"socket" => "/tmp/fastcgi-seddit.socket",
"bin-path" => "/home/dnewberry/sites/blah.com/application.py",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => "" ),
"check-local" => "disable"
))
)

url.rewrite-once = (
"^/(.*)$" => "/application.py/$!",
)
}

Monday, July 2

Some Prototype Notes

Yes, I'm still alive, don't worry. The most important component to this entire project is the Ajax code used to retrieve chat messages from the database. Initially when you join a chat room, the entire chat history for that room will be repopulated into your window. When loading that chat, we just have an Ajax request grab the entire log from a JSON feed. That JSON feed can get pretty long depending on how busy the room is, so we store the entire log in the response body of the page.

However when the user is already in the chat, and we're updating the current chat, only a few messages are being pulled at a time, and not the entire updated log. There's a neat trick with Prototype that we can use to send smaller bits of message logs. For smaller tidbits of JSON (<8kb) it's possible to place the JSON object into a "X-Json" header, instead of the usual response body that everyone's used to.

You can download a quick python script I wrote up demonstrating this feature here.

Here's the headers to a page taking advantage of the X-Json feature.


Response Headers

Content-Type text/x-json
X-JSON {"messages": {"message": [{"text": "hey, this is pretty neat" ... snip
Transfer-Encoding chunked
Date Mon, 02 Jul 2007 13:55:29 GMT
Server CherryPy/3.0.1


The response body is empty.

The code is too long to post in full, but I'll annotate the import prototype/javascript bits. I tried to take advantage of all of the prototype features I could, I'm new to programming in prototype, but some of this code demonstrates some pretty nifty stuff that you can do with prototype.


new Ajax.Request('/json_feed', {
method: 'get',
onSuccess: function(transport, json) {

json.messages.message.each(function(message) {
$('messages').innerHTML += "[" + message.time + "] " + message.user;
$('messages').innerHTML += ": " + message.text + "
";

console.log(message.text);
});

},

onFailure: function() {
console.error("there was an error loading the messages...");
}
});


That's it! That's all the javascript we need to grab a JSON object, parse it, and display it on a page. Of course, we need to write callbacks and whatnot if we want the javascript to continually check for updates to the JSON feed.

The key to using the X-Json header is in the onSuccess portion of the code.


onSuccess: function(transport, json) { ....


By adding the second parameter (json), Prototype will look in the X-Json header to see if there's any data there that it can use, if there isn't it will just return null. Adding the X-Json header, and changing the Content-type in webpy is very simple. To do this we just change the web.header dictionary.


web.header('Content-type', 'text/x-json')
web.header('X-Json', simplejson.dumps(message_list))


I also had a bit of fun fooling around with the each method that is used to iterate through lists. You can check the out relevant code here.


json.messages.message.each(function(message) { ....


While this example is very simplistic, there are plenty of more useful and complicated cases you can use it in. What the each method allows you to do is iterate through lists in a much more elegant fashion than using your basic for(int k = 0; k < node.length; k++) rigamarole.

I'm going to take an example from Andrew Dupont's Prototype/Scriptaculous Crash Course, where you can apply a function to every single item in a list.


function makeRed(node) {
node.style.color = "red";
}

nodes.each(makeRed);


With this kind of functionality I could have made a function to auto-magically add each of the messages into the page, as opposed to writing the code inside of the each loop.


function addMessages(message) {
$('messages').innerHTML += "[" + message.time + "] " + message.user;
$('messages').innerHTML += ": " + message.text + "
";
}

json.messages.message.each(addMessage);



For more information about using the X-Json header check out prototype's official documentation here, and for more about using prototype's each function you can look at the api as well.

Monday, May 28

Official Start of Coding!

Today is the official start of coding for Google's Summer of Code. In lieu of that, I've posted some mockups of how I hope seddit will look. While I'm sure that the style of the application will change significantly , the general direction of the application should stay the same.

I've uploaded the mockups to the projects subversion repository. You can check the code out of subversion by running:
svn checkout http://seddit.googlecode.com/svn/trunk/ seddit
And navigating to the mockups directory. The starting page is default.html. Right now I still need to work on the chat layout (active.html) and the archived view (archive.html) but you can still get a feel for the application. If you have any criticism or ideas for the layout then please let me know! You can email me, submit a bug report or leave a comment. I'd love to get some feedback.

Enjoy.

Friday, May 25

Welcome to Seddit

It took me long enough, but I’ve finally got a post going on this blog. School has been hectic and whatnot, but I’ve actually got some breathing room now. Sort of…

So onto Google. I’ll be participating in Google’s Summer of Code under the Python Software Foundation and my mentor is Aaron Swartz, who I’m sure needs no introduction.

What exactly will I be doing? I’ll be working on a project called seddit. Seddit aims to provide the best of mailing lists, IRC and forums.

How exactly will it work? Let’s run through a quick scenario. You have a question about web.py. You could ask the question on IRC, but it’s hard to get questions answered through all the chatter on the channel, you could ask it on the mailing list or on the forum, but registration, or subscribing to the list is difficult, and you won’t get an answer quick enough. Seddit seeks to provide real time answers, but it’ll break the chats up into separate discussions. There is no registration barrier, and there is no chatter in your thread that doesn’t pertain to the topic at hand. If you ask a question that’s already been asked, Seddit will try and intelligently point you to the archived chat that answers you question. If you wish to add more content to the archived log, you may do so similar to wiki page.

Ultimately the project is trying to provide a medium of support that is easier to use for both the developers and users of any given project.

For information about Seddit, there is a google project setup at http://code.google.com/p/seddit. You can also check out the Overview for more information about the project.