Posts Tagged ‘Programming’

friendfeed.py Patch for use on Google App Engine

Thursday, May 29th, 2008

Ask and ye shall receive.  Attached is a patch for using friendfeed.py on Google App Engine.  You need to also have demjson available.  Google App Engine does not allow use of many C modules (like cjson) and both json and simplejson will throw decoding errors from time to time. demjson is slow but won’t throw errors around (I really wish we could use cjson; it’s so much faster).

Basically the differences are:

  1. Use urlfetch instead of urllib2
  2. Use Django’s urlencode which will work with unicode (letting you comment/share in languages like Chinese)
  3. Use demjson instead of cjson (which cannot be used on Google App Engine), simplejson, or json (which both throw decoding errors from time to time)

Enjoy!

Update:

You don’t need to use demjson anymore; simplejson will work just fine.  I just got an email from Sanjeev saying that they fixed the issue (’\x’ is not valid JSON).  This makes things even easier because simplejson is included in Django (from django.utils import simplejson) which is included in Google App Engine.

Tweet 2 Tweet

Sunday, May 18th, 2008

Announcing my latest (tiny) project: Tweet 2 Tweet.

You know when you see someone’s Twitter update with an @ reply in it to someone you don’t know and are completely confused about the topic?  Tweet 2 Tweet is an effort to solve that.  You can put both of their names into Tweet 2 Tweet and see their conversation on one page much like Facebook’s “Wall-to-Wall” feature.

It’s just a dumb, fun project.  Nothing made to be a big splash; just something I’ve been meaning to do.  It uses Django + App Engine + Summize to power it.  Django mainly for the templates, App Engine so my server doesn’t get anymore overloaded, and Summize so I don’t even need a database.

Plus it was an excuse to whip out my old algorithms book so I could implement a quicksort.

Thanks to everyone who’s covered it already; I’ll be making minor improvements from time to time.

How To: Dynamic Slide Down Disqus Comments

Monday, March 3rd, 2008

RSSmeme now has dynamically generated slide down Disqus comments for every story (see it in action by clicking the comment link next to “Contribute”).  I had to hack around a bit with the Disqus provided embed.js to get it working, here’s how:

  1. Copy embed.js locally and remove the document.write() where the style information is written.  Dynamically calling this script with the style writing will blank out your screen for some reason (I’m not a javascript expert so don’t ask me why).
  2. Right BEFORE you call embed.js search for any div with the id ‘dsq-content’ and rename the id to something else (I used ‘dsq-content-old’).  This is because thread.js (which is called by embed.js) searches for #dsq-content to attach the thread to.  Really it should be looking for #dsq-content WITHIN the user defined (defaults to ‘disqus_thread’) disqus_container_id but alas it does not.  I thought about copying thread.js locally and making this enhancement but decided against it.

So here is how my code looks (the hack() function is where I locally copied embed.js):

commentLink.click(function(e) {
    $('#dsq-content').attr('id', 'dsq-content-old'); //Rename the old #dsq-content so thread.js can find the new one
    var contribute = container.find('.details .contribute');
    var thread = $('#thread_' + id);
    disqus_url = 'http://www.rssmeme.com/story/' + id + '/'; //Set the required global variables for embed.js to work
    disqus_container_id = thread.attr('id');
    contribute.slideUp('normal');
    hack(); //Call embed.js minus the document.write()
    thread.slideDown('normal');
    return false;
});

There are some side effects that need to be fixed too:

  1. Make sure that disqus_url and disqus_container_id are global variables. Yuck, I know, but I could probably get around this too by making them arguments to hack().  For now it works for me.
  2. You need to make a stylesheet for the comments because you removed the document.write().  I copied everything out of it and placed it into its own stylesheet.
  3. You need to modify the stylesheet because it looks for #dsq-content but I just had you change it to #dsq-content-old after you load the next set of comments!  This should be easy, just change #dsq-content to whatever the next highest div that encompasses every disqus_container_id (which you’ll need for the slide down effect anyway)

That’s it!  If you have any questions feel free to ask.  You can look at my complete (production) javascript here.

RSSmeme – Javascript Love

Friday, February 15th, 2008

RSSmeme is now even more Web 2.0 with the addition of Javascript events.  When Brian Beck gave RSSmeme a makeover he also threw in the ability to shrink down the tag/shared user list by using jQuery.  This got me interested in jQuery and I found myself not completely hating it.  I have had bad experiences with Javascript before but jQuery makes it fun and easy.  RSSmeme can now:

  • Hide a story by clicking the “hide” link next to the “share!” link.  This is basically fluff but I could imagine you could use it to hide stories as you read.  It then becomes a “show” link to show the story again.
  • Load the next level up in details for an individual story without changing your global preview setting.  If you find a story interesting you can click the “read more” link in the “Explore” subsection next to the “similar stories” link.  This will ask RSSmeme for more details about the story.  For example: if you are currently set to preview “none” then it will load “some”.  Click it again and it will load “all” and hide the link (there isn’t any more to see!).

There are probably more important things I can work on but this was fun for my first excursion into jQuery and JSONDjango and jQuery made it painless.

Readable URLs matter (to me at least)

Saturday, February 9th, 2008

Attention web developers; I never ever want to see this in your URLs every again:

?u=123&id=456&s=l&preview=1&blahblahblahblahblah

Sometimes it might be required to throw some GET parameters into the mix (pagination and search come to mind) but most of the time it is not necessary.  Make urls that are human readable:

 http://www.rssmeme.com/story/17881/similar/

What might that URL point to? To me it reads “Similar stories to story number 17881″. That is a lovely url. Every single framework out there supports this; and if you don’t want to use a framework you could just download a framework’s code, glance over how they handle it, and implement in yourself (this would probably only take you an afternoon to solve).

Am I the only one who cares about having readable URLs? I’m pretty sure that human readable URLs are likely to see better Google results too. Do it!