Javascript push notifications with Django & Pusher

I've been running into an increasing need for JS push notifications and have played with a few ways of doing it. Recently ran across Pusher API. They use a combo of HTML5 websockets & flash fallbacks. Much easier than Comet, etc.

But their python library didn't support presence. Here's everything you need to make presence work in Django, including an updated library.

My JS


var pusher = new Pusher('MY_PUBLIC_KEY');
Pusher.channel_auth_endpoint = '/api/pusher/auth/'
var channel = pusher.subscribe('presence-meeting-1')

Django dump & restore database

# dump data to send to receiving host
./manage.py dumpdata > fixtures/all.json

# in mysql on receiving host
mysql -uUSER -pPASS DATABASE_NAME;
drop database DATABASE_NAME;
create database DATABASE_NAME;
exit;

# @ shell on receiving host
./manage.py syncdb

# in mysql on receiving host
mysql -uUSER -pPASS DATABASE_NAME;
delete from auth_permission; delete from django_admin_log; delete from django_content_type;

# @ shell on receiving host
./manage.py loaddata fixtures/all.json

debugging email with django

an easy way to get django to send emails direct to stdout ( and avoid connection refused errors )

in settings.py:

EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

and at a shell:

python -m smtpd -n -c DebuggingServer localhost:1025

Sonicwall router RTMFP fix

If you have a Sonicwall router and want to make RTMFP P2P connections, you need to enable "consistent NAT": http://www.fuzeqna.com/sonicwallkb/consumer/kbdetail.asp?kbid=4320&forma...

rtmfp, comcast, and wasted time

I had been developing a p2p videochat app in flex with rtmfp and had been having video freeze after 2 seconds of playback, but only when using two computers on the same network, and only certain networks. one of them was my house after comcast put in an arris tm722 modem. We were using a POS dynex for a router.

Bought a new motorola sb6010 and a cisco / linksys e2110L, called comcast to provision it, and had it working on the windows 7 netbook i had plugged into the router.

Default FMS paths

A quick reference to commonly-needed default paths for flash media server development: ( the adobe docs don't lay this out simply )

Application logs: /mnt/logs/_defaultVHost_/ {APPLICATION NAME}
FMS config files ( Server.xml , etc ): /opt/adobe/fms/conf
Application files: /mnt/applications/

Quickly starting django development server on local IP

I am frequently running ./manage.py runserver SOME_IP:8000 , so I can run django dev on my local IP address, so it can be accessed by other computers on the network for testing. Here's a shell script to automate the steps it takes to do that:


#!/bin/bash

# virtualenv
source bin/activate

# get the local IP
IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;

# write the IP for use in settings module
echo "IP='$IP'" > local_settings_ip.py

# launch window in firefox ( will need to refresh )
firefox http://$IP:8000

handling datetime conversion in python with pytz

assuming "time" is the datetime object stored in the local time and "tz" is string name of the foreign timezone..this works with daylight savings time, which can get tricky

    def as_tz(self, time, tz):
        local_tz = pytz.timezone(settings.TIME_ZONE)
        local_dt = local_tz.localize(time)
        foreign_tz = pytz.timezone(tz)
        foreign_time = foreign_tz.normalize(local_dt.astimezone(foreign_tz))
        return foreign_time

ubuntu slow lookup speeds

Comcast's DNS nameservers were really slow, so I switched to Google's DNS nameservers by changing the settings in my router.

Couldn't figure out why my lookups were still really slow.

Turns out Ubuntu's Network Manager was keeping old DNS info around, causing the issue. Replacing the nameservers and marking the file as unwritable by network manager fixed it:

sudo nano /etc/resolv.conf
sudo chattr +i /etc/resolv.conf

os x users can't click flash security panel

This is a really irritating bug caused by some obscure issue between Firefox and Flash.

When my Flex app loads up the Security Settings Panel (trying to grab the camera), OS X users weren't able to click the 'allow' button in the panel. Or anything in the panel, for that matter.

The fix? An absurd, hack-y JS workaround. I'll post when I get the time to figure out something better. This works for me for now, though.

1) Positioning the containing element of the flash as "fixed":
2) Making sure there is no scrollbar on the browser window.

Syndicate content