March archive
March 27, 2008
It's no secret that the news business has been dramatically changed by the Web.
My generation and younger rarely "take the paper" the way my grandparent's or
parent's generations did or continue to do. As virtual worlds like
Second Life grow in popularity, yet another
avenue for delivering news appears. I started thinking about this recently, and
especially about how metaphors work in online media. We read Web pages
and visit Web sites, which aren't really made of paper or bound to a
location.
So does the virtual world offer us a way to "take the paper" again? Will this
prove useful and interesting for this or the next generation? I don't know, but I
want to play with the idea a bit and see what I come up with. With that in mind,
I've started my own personal development project to test out some ideas.
"Reading" the paper in Second Life.
I'm doing all my work out in the open and being transparent about the
process, even showing my newbie attempts at coding
LSL. I've added
a Flickr
set to keep track of news-related in world work.
March 19, 2008
In the spirit of all those "my predictions for 2008" posts that we see at
the beginning of every year, here are my my predictions for the rest of this
Democratic primary season. I'm really just writing them down here as an exercise in
fun. I want to be able to look back and see how I did when the primary is over.
My predictions are:
- The primary will not go all the way to the convention
as everyone is predicting.
- Sometime in the next four weeks, between now and the Pennsylvania primary,
an agreement will be reached to seat the delegates from Michigan and
Florida.
- The delegates will not be seated according to the election results, but
rather as some sort of arrangement between the candidates, with Hillary
taking a slight advantage in delegates. Something like a 60/40 split,
but don't hold me to the exact percentage. This keeps both candidates more
or less happy with the agreement.
- Obama is trailing Hillary by 12 points in Pennsylvania as of this posting.
By the Pennsylvania primary, he will cut the lead to somewhere close to the
polling margin of error. Let's say if the margin of error is 4% on the last
poll taken, he will be 4 or 5 points under her by the time Pennsylvanians
vote.
- Obama then wins Pennsylvania by a very small margin. I'll guess 51% of the
vote.
- Hillary then reluctantly withdraws from the race at the insistence of party
leadership.
I'll go on record as an Obama supporter in the interest of full disclosure.
Feel free to accuse me of wishful thinking. However, I have reasons for
each of the points above, having thought about this a lot lately. But again,
I'm just posting this for fun to see if I get close.
March 12, 2008
After posting a link to a
conference on building web apps
with Google this morning, I'm reminded that I haven't written here much
lately about my book. So here's the latest news for those who might be
wondering, "Hey, what ever happened to Deryck's Google book project?"
The short story is that a complete book is just not a possibility for me.
While I lack no dedication to my work, this just wasn't the season for me
to do a book. My career took off right about the time I signed the
book agreement, and now two job changes,
several
projects, and two years of aggressive development while also trying to
write a book have taken their toll on my enthusiasm to see this book completed.
I am also at a different place now, with
different technical and
intellectual interests, so turning back to the topic of Google-driven
development is a little like turning back in time.
I have done quite a bit of work on the book in the last couple years, though.
To keep this from being lost work, I'm working on turning the book material into
3 different shortcut chapters as part of Prentice Hall's
digital
short cuts program. I am really excited about this. The material will see some
published form, and the work is not a complete loss.
I'm finishing the first of these this week, and expect to move fairly quickly on
the other two (on the order of a couple months, I hope.) I'll certainly update here
as these shortcuts are released.
March 7, 2008
While the various twitter apps around are nice for reading tweets,
I'm too lazy to want to fire up the browser or reach for a desktop
menu when I just want to twitter. After a pointer from coworker
Sean Stoops to a Lifehacker article,
Send
Twitters from Command Line in Any OS, I kicked up this little shell
script to make it even that much easier.
#!/bin/bash
if [ $# -eq 0 ]; then
echo 'Usage: twit "STATUS IN QUOTES"'
exit 1
elif [ $# -gt 1 ]; then
echo 'Usage: twit "STATUS IN QUOTES"'
exit 1
fi
STATUS=$1
TWITUSER=yourusername
TWITPASS=yourpassword
curl -u $TWITUSER:$TWITPASS -d status="$STATUS" http://twitter.com/statuses/update.xml
Now it's just -- twit "MY STATUS UPDATES" -- and I'm done.
March 4, 2008
It's not well documented, but there is a way to set a timeout for urllib,
urllib2, and the like. This is done by setting the default timeout on
the global socket. So if you're constantly hanging cron scripts because
some resource you want to scrape is never responding, add the following
to your script:
import socket
# "timeout" is a float and
# is the value you want in seconds.
timeout = 2.5
socket.setdefaulttimeout(timeout)
Any subsequent calls to urllib or any other module based off socket will
now generate an IOError if the response is not returned before
reaching timeout.
How you handle IOError is up to you. :-)
March 3, 2008
I've started hacking away at a personal project of mine around
Second Life. More on that in the days to
come, but I did want to share some code created last night while
playing around with Second Life logins. I've worked up a
Django authentication backend for authenticating users
on a Django-based site against Second Life's login process. I've created a
Google code project for the code, so cleverly named
slauth.
This is code of the "release early, release often" variety. There are no
docs, no tests, not even a README. I just wanted to get this up while I had
5 minutes today. I welcome feedback, and I'm certain I will be working on this
as the larger project evolves. I'm not even certain I'll use this in
the final project. I feel uncomfortable taking username and password for
another "site," but without a proper login API for site-to-site authentication,
this seems to be the only viable route. This uses the same XMLRPC auth process
of the Second Life viewer code, which seemed to legitimize it a little for me
(since this is how third party viewers have to authenticate). It's certainly
better than page scraping the response of the Second Life web site's login
form. If there were a way to register you application with the login process,
I would be totally cool with this. Then, the user could verify a site as being
legitimate -- or at least more legitimate than any joe running this auth backend. ;)
Having said all that, it's pretty easy to authenticate via this package.
Just make sure the module lives on your PythonPath, and then add slauth.backends.SLAuthBackend to your Django AUTHENTICATION_BACKENDS setting. You'll even be able to login through the
Django admin with your full SL username ("Anders Falworth" in my case, as
an example). Of course, you won't get into the admin until you add make
the SL account "staff". (This app creates a stub Django user account
for each successful SL login, and then you can check is_staff, then login again
with the SL account, and you'll see the successful entry into the
Django admin site.)
This is the main class that does all the work:
from django.contrib.auth.models import User
from slauth.utils import valid_sl_login, get_or_create_sl_user
class SLAuthBackend:
"""
A Second Life authentication backend for Django-based sites.
"""
def authenticate(self, **kwargs):
"""
Use kwargs to make the authenticate method more flexible.
Django's admin app assumes username/password logins, so
allow first and last in one username. For example,
username could be 'Bob Smith' and this method will split
that apart into the first and last names SL login expects.
So either of the following would work:
>>> from django.contrib.auth import authenticate
>>> authenticate(first_name='Bob', last_name='Smith',
password='foo')
>>> authenticate(username='Bob Smith', password='foo')
"""
first_name = kwargs.get('first_name', '')
last_name = kwargs.get('last_name', '')
password = kwargs.get('password', '')
if kwargs.get('username', ''):
username = kwargs.get('username', '')
if ' ' in username:
first_name, last_name = username.split(' ')
authenticated = valid_sl_login(first_name, last_name, password)
if authenticated:
user = get_or_create_sl_user(first_name, last_name)
return user
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
You could certainly use parts of this without using Django, even though it's
written with Django in mind. There is a utils module that has sl_login and valid_sl_login which returns the
response from a login attempt or a True/False on success or failure of a
login attempt.
Please have at the code at it's Google project home if you
have need for or want to play with Second Life logins via Django or Python.
Comments, suggestions, and of course, contributions are always welcome. This
code is released under the GNU GPL v2.