Here lies the last 25 entries in my weblog. Follow the yearly archives to the right for more.

An if-substring-in-string Django Template Construction

Here's a quick tip for Django template hackers. It's a known fact of Django templates that the syntax is purposefully limited. I've been living with the need for an if-substring-in-string construction. Of course, I could write a custom template tag, but work is quite busy. So on a whim and a 10 minute break I tried this yesterday, and it worked well for me. Take a look and let me know what you think.

First, the problem.

Bookmark Formatting

I have a custom app for pulling in my Delicious bookmarks and formatting them as link posts here on this site. I include the HTML I want in the original bookmark and have a bit of template code to insert preview images generated by ShrinkTheWeb. When I link a YouTube video, I do a quick cut-n-paste of the video to embed the player, and in these cases, I don't want to include the preview image. In Python, this would be super simple:


if 'http://www.youtube.com/' not in link_url:
    show_thumb()

However, Django templates don't have a similiar syntax.

A Solution Using {% with %}

So here's what I did:


{% with link_url|slice:":23" as short_url %}
  {% ifnotequal short_url "http://www.youtube.com/" %}
    My ShrinkTheWeb image goes here.
  {% endifnotequal %}
    Other HTML common to all links goes here.
{% endwith %}

What do others think? A decent solution? There are some issues; if I want to use multiple video sites, for example. At that point, I would be better to use link categories or a custom tag. But for a 10 minute fix, I think it's quite nice.

Link | Posted by deryck on July 3, 2009 | 3 comments

When JavaScript Attacks, errrr, Hacks

I've been doing a lot of JavaScript coding in my recent work on Launchpad. I mean, a lot! We're pushing to get every aspect of a bug page editable within the page itself, hopefully making it easier to manage bugs without being directed to another web page. Everyone on the Launchpad bugs team is working on some part of this. I haven't previously done any JavaScript coding like this, and now I'm sitting with a 1400 line JavaScript file that has grown unwieldy and needs to be tamed. I'm starting on that refactor this morning and thinking on the things I've learned as this file has grown seemingly with a mind of its own.

I should note some of the conditions that led to this. I wrote that I haven't done JavaScript like this before, but it's not as if I lack experience with js. I've done a lot of JavaScript coding both in previous jobs and for fun, everything from minor usability improvments to extensive page functionality in JavaScript. I've taught conference tutorials on AJAX and was even working on a book on Google's use of JavaScript in it's apps. (Yes, I'm a failed tech book author at this point, but the point is still valid, I think.) But all the work I've done previously either started in JavaScript and added server components as needed, or started with the server-side and added JavaScript in targeted areas. This work we're doing on Launchpad bugs has an existing, sophisticated server component -- the bug tracker -- and now needs an extensive JavaScript application built on top of that. Adding complexity is that the JavaScript component is being built piece-by-piece in small branches, rather than with a cohesive architecture. And by several developers at once.

It's this part about building an extensive JavaScript application in pieces that is really the new part for me, and I've learned some things I'll carry foward in terms of how to build a nice JavaScript module in small bites.

Global Module vars

Sticking variables into the global namespace of a module (so multiple functions have access to the variables) is now my sure sign that I need to refactor. From here on, I'll create an object rather than doing this.

This seems obvious but we're using YUI3 where each module is akin to an object itself, so it wasn't that clear to me. I would avoid module-level globals, even inside the module pattern itself, and create distinct objects the moment I begin to need state across objects or functions.

Closures

Again, YUI's module pattern and the way our Launchpad API is designed encourage callbacks via anonymous function closures, especially when dealing with XMLHttpRequest. And really this is a fine thing, and a common pattern when doing async js coding. But it's easy to let the closures get out of hand, which makes the code harder to read and maintain and makes debugging a bit harder, too. So I'm trying to use closures only as I have to.

Custom Events

Given the previous point, I think it's good to fire custom events to signal when to do some work. A custom event when an XHR has completed, or a custom event when it's time to update the DOM. A custom event when some state is initialized, and so on. Custom events are my new mantra going forward.

Perhaps I'll look back after this refactor and feel I've abused this pattern as well, but I think it will be cleaner and will be easier to test.

Patterns for Reuse

And finally, the next time I get into some extended bit of JavaScript work, I'm going to think about the patterns I'll be using and about the overall architecture earlier. Even though I'm sure I'll still be doing small branches that add small bits of functionality, I'll try to look ahead more to where this code might be reused across Launchpad, where this pattern of functionality or interaction might be repeated, and where the code I'm working in is likely to go over the next two cycles.

Link | Posted by deryck on June 26, 2009 | 0 comments

The Early Morning Internets

Most everyone I work with knows this, but friends and family may not -- so just in case you haven't heard -- my work schedule (which means the time I am available online) has changed since I joined Canonical. I am now up very early to better match European time zones, where the other members of the Launchpad bugs team are located. How early, you ask?

I wake at 4:30 am, and I'm at work by 5:00.

A pause while that sinks in on all my musician friends.

Work hours are now 5:00am-2:00pm, but in practice I knock off closer to 2:30 or 3:00. I try to avoid being online after that. I usually spend the afternoons playing with kids, cleaning the house or yard, or other such family/home activities. I usually come back in the evenings for an hour or two of work before I go to bed, but I rarely jump on IM or IRC in the evenings -- evenings are for quite work. Note the usually in the previous sentence. This is not a work requirement -- have I mentioned Canonical really is the best employer! -- and in the summer I'm finding it harder to find time in the evenings with the kids out of school and staying up later. Usually, the girls collapse by 7:00-7:30 on school nights, so I enjoy coming back to the laptop for an hour or two to unwind. Sometimes this is work-related, and sometimes it's just for fun hacking (which may even be work-related still, believe it or not!)

So all of this is to say, if you want to or need to catch me online via IM or IRC, make it happen from 5:00am-2:00pm CST. For you west-coasters I may never see you online again, so ping me out a day early if I need to stay around to catch up with you. :)

While the schedule is different for me in terms of my time online, it really is the perfect schedule for me. I'm focused early, getting a lot of work done, and enjoying working on Launchpad a whole lot. And then there's still time in the day for doing the things a husband and father likes to do.

Link | Posted by deryck on June 24, 2009 | 0 comments

Book review: Saturday

Saturday

Saturday by Ian McEwan

My review at Goodreads

Rating: 5 of 5 stars

Ian McEwan never disappoints, and this novel is no exception. While I found the build up to the final third of the book carefully constructed, if sometimes seemingly a bit slow moving, all of this was to lend greater wait to the final moments of conflict in the novel. I took my time reading this and enjoyed every moment. I finished this on my plane to Barcelona, Spain for Canonical AllHands, and the book really caused me to think on conflict and generosity among various peoples on the planet. I would highly recommend this book.

View all my reviews.

Link | Posted by deryck on May 24, 2009 | 0 comments

Working from Barcelona!

I've just finished my first night in Barcelona, Spain. This was a fun night, a good night for catching up with people in person whom I normally only see online. And, of course, Canonical is steadily growing, so there are many people still to meet or get to know. This should be a nice couple weeks.

That's right -- two weeks. This first week is for the Canonical AllHands meeting; next week is for UDS. . It's a long time to be away from my family, but I really feel it's time well spent.

I've been with Canonical for a little over a month now, and it's been a busy few weeks. We're mid-cycle now on the 2.2.5 release, and looking at our 2.2.5 progress page, you can get a good idea of what sort of work is going into Launchpad Bugs this next release. Lots of words like "UI" and "inline" on the page. I've been doing work on making subscribing to bugs happen on a bug page, rather than having a user taken away to a "subscribe to bug XXXX" page and redirected back again after confirmation.

This is the last week to land code this cycle, and with AllHands, I don't know how much more I'll really get done. But I'm going to try to get in some coding time this week. I would like to finish all of the subscribe-to-a-bug-inline tickets this cycle, but I'm sure that's a bit unrealistic this time. But tomorrow, tomorrow we'll see what happens.

Just not tonight... tonight, I'm dead. I need sleep. now.

EOD

Link | Posted by deryck on May 19, 2009 | 0 comments

Starting Work at Canonical Tomorrow

I'm writing this from a plane, somewhere over New Mexico, headed home from a few days working in Las Vegas. My last few days, actually. As I write it's Friday (the posting of this is now Sunday), and on Monday (tomorrow), I'll start work for Canonical, the company behind Ubuntu. I will be working on Launchpad, specifically joining the team working on the app's bug tracker component.

While I have great friends I'm leaving behind at Greenspun, I know the time is right for me to move on. My heart has always been in free software first and media somewhere after that. The group I've worked with is a progressive segment of the news/media world, but at the end of the day, I've been doing closed, proprietary development for the last few years. I'm excited to lend my hand to free/open source software development again. I feel a bit like I did when I joined the Samba Team, though experience has given me a different set of eyes through which to view this coming change. There will be plenty of challenges and new things to learn, certainly, and I plan to just dive in, work hard, and contribute whatever I can to Launchpad.

I will continue to work from home. Most of Canonical works from home offices, and that will be a nice change, having so many peer telecommuters. My day will be time shifted, with me starting earlier, to better sync with my largely European teammates. This is a positive for me, since I'll finish work earlier and have some time in the afternoon with the kids after school. Because I'll be starting so early, I don't plan to work from the attic office I was using, the one that also houses my wife Wendy's business.

So there is the new job to start in the next few days, but also a whole world of changes happening around that, all of which are positive and exciting, and I truly can't wait to log on IRC Monday and get started.

Link | Posted by deryck on April 12, 2009 | 0 comments

Scripting Simple Shell Commands

I'm setting up a latop with a fresh install of Ubuntu. I haven't done a clean install on a real machine in who knows when, and over the last 3 months or so I've become a huge fan of PPAs. I have several PPAs to keep up to date with packages I use that have frequent updates beyond what's available from Ubuntu updates. Since I'm adding several at once, I'm adding a lot of PPA keys. Doing this reminded me of a simple trick I use when running a frequent command. (Some form of this is common among developers or sys admins, but if you're less experienced with a shell or Linux this may be useful to know.)

First, the command for installing a PPA key is...


sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com [KEY]

...where [KEY] is the PPA's key finger print.

So the easiest way to use this is to cycle back through your bash history and replace the previous run with the new key and run again. For me, I know I won't remember the particulars of this command in a month or two when I need to run it again and it's no longer showing up in my bash history. I'll end up having to consult a man page or the Launchpad help pages. Not a big deal, but with things like this -- commands I use semi-regularly but not enough to keep in memory -- I usually add a little bash script. For example, with this command I created a script called add-ppa-key:


#!/bin/bash

if [ $# -eq 0 ]; then
    echo "Usage: add-ppa-key KEY_FINGERPRINT"
    exit 1
else
    FINGER=$1
fi

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com $FINGER

I always add the usage test with each command like this, just so I can use tab completion to find the command, run it with no arguments, and get back a statement of what I need to do. I have a "bin" directory in my home directory and append $HOME/bin to $PATH in my .bashrc. I have several of these type of scripts in this bin directory, for building software or even for simple to remember but frequently used rsync commands or PythonPath export statements. Not only does this make commands reusable without having to completely remember them, it's also nice for documenting commands. So the next time someone asks me what the command for installing a PPA key is, I can do cat ~/bin/add-ppa-key and paste the output into IRC, IM, or what have you.

Link | Posted by deryck on April 1, 2009 | 0 comments

Moderate FUD

When Bush was President all my liberal friends on Facebook constantly spammed my news feed with posts that had as their point, "Bush is (or will be) the downfall of America." Now that Obama has become President, all my conservative friends are filling my news feed with posts that say the exact same thing, with one minor difference, "Obama is (or will be) the downfall of America." This is why I've never taken to the liberal or conservative label, or the Democratic or Republican label -- I just don't care enough to spam my Facebook friends with FUD. Except for now. Now, I've found a cause worthy of a Facebook wall post. Moderates of the world unite!

What does it means to be a moderate, you ask? It means you have enough of both liberal and conservative friends that you can see how silly both sides look. Conservatives and liberals -- and here, I mean those of you who feel so strongly about that label that you have to post crap on the Internet to prove why you are the one who is correct -- you two are not that different from each other. You both want the other to wake up and become sensible and take up your obviously superior point of view. And if the other does not, then THE WORLD AS WE KNOW IT WILL COME TO AN END (emphasis yours).

So let us moderates unite in our laissez-faire wall post attitude and say to our liberal and conservative friends alike that we are tired of your anti-socialist or anti-anti-socialist messages. You are our news feed terrorists pals, yet we still love you. But we refuse to take sides in online pissing matches. The reason you don't know it's a pissing match is because you only have friends of the same political persuasion. And moderate friends, who of course never speak up.

So here we are, we are not loud, we are not proud. Not usually, anyway. We want to be friends with both conservatives and liberals, with both liberals and conservatives (see you both got top billing there, now be quiet) because there's something about each of you we like. We refuse to choose sides, and we're not backing down! And yes, just this once we moderates should post to Facebook so our bi-partisan, fearful friends can see how silly they look. Indeed, I am posting this to Facebook now, feel free to join me in my honest mediocre dissent. Moderates unite! If we don't stop the world-as-we-know-it-will-end-tomorrow wall posts then the world as we know it will end tomorrow. I'm only writing this because I don't care, not because I care. I am not afraid, and you can't make me be afraid.

Seriously, I'm sorry to offend, but if your political perspective requires me to live in fear, I just can't join your movement. I will forever remain moderately unaffiliated.

Now, where is that "post to Facebook" link...

Link | Posted by deryck on March 17, 2009 | 1 comment

How the Web Supplants Traditional Authority

I recently linked to a NY Mag article on the New York Times, citing it as a nice piece on the Web efforts at the Times. I also posted some questions about a quote by the Times' Aron Pilhofer. Aron noticed the link and in turn posted a question back to me. Thanks Aron for taking the time to do that, and what follows here is my response. Here's my take on why I suggested that the Web "supplants and undermines any notion of 'authority.'"

On the point that the Web undermines authority on the Web, Aron and I are in agreement (based on his comment on this site.) But what is it about the Web that supplants authority?

By supplant, I mean that the Web substitutes one kind of authority for another, that the Web itself is a system of authority, although a different kind of authority. So not only does the Web remove barriers to publishing and communication -- the barriers that others use to make claims of authority -- but the Web also institutes another kind of authority, although I like to think of it as a kinder, gentler authority. This authority is based on consensus among peers. It is relational authority -- many objects pointing to another and confirming the legitimacy and authority of the other.

This authority is clearing typified in Google's PageRank algorithm. I do think, however, that the concept is writ large across the Web in all kinds of ways. Social relationships on the Web are confirmed by the relationships between sites on the Web -- i.e. my personal site points to my Twitter page, my Facebook, etc. The same circle of "friends" show up across various sites. My GPG key has been signed and verified by other people's GPG keys, confirming my identity and creating a trust ring. Using relationships as a structuring principal (and here I mean "relationship" in the most encompassing sense of the word -- personal relationships, link relationships, relational properties of data, etc.) creates a system of authority, one in which a given object is deemed authoritative based on its relationship to other objects.

To take this back to the news industry, which is where this discussion began, something isn't really news on the Web only because it appears on a news site. Something becomes news on the Web because of the ground swell of linking that occurs around something when it becomes popular. And think more than just backlinks from other web pages a la PageRank. Think emails sent to friends, Facebook wall posts, tweets, IRC, and on and on. News isn't news on the Web because it appears on nytimes.com or washingtonpost.com or any other news web site. News is news on the Web when the right places begin pointing to said object and declaring it news.

The only people for whom appearing on a major newspaper's Web site is a prerequisite for being considered news is fellow journalists. And I would argue that even that reinforces the notion that authority is derived from relationships, i.e. this group of people agree that this thing is authoritative as news, which is completely different from previous systems where authority is claimed as divine right or as some function of one's position in society or control of the means of publication.

This is nothing new, really. Oral tradition gave way to the written word. The written word gave way to the printed page. The printed page gave way to the computer screen. And now here we are. Just the way mass-produced Bibles in the vernacular killed the hand-written priestly Bible's claim to authority so the Web kills the printing press's claim. The shift in authority from page to pixel is much the same as the shift from a priestly class to a publishing class. So if we're going to reinvent ourselves in this age, let's don't stake our claim on trying to transition old models to a digital age. Let's fully embrace the age for what it is, new system of authority and all that such a thing means.

Pop-culture Bibles FTW!

Link | Posted by deryck on January 29, 2009 | 2 comments

Comments Back Online and a New Combined Weblog Feed

I have made a few updates on the site here. I know have comments enabled again, and I also have combined my links (which are really like mini-blog posts) into the weblogs feed. Eventually, I'll break all these out -- one feed for blog entries, one for links, and one which is a combined feed -- but for now, it's all one feed.

If you're subscribed to me, you should start seeing link posts appearing in the feed as well.

Link | Posted by deryck on January 15, 2009 | 0 comments

Ok, So What am I doing For Halloween?

Another day in the telecommuting office, even if it's Halloween. What's on tap for today? "Dad" costume, lunch, and iGoogle widgets, errr, gadgets.


Ok, So What am I doing For Halloween? from Deryck Hodge on Vimeo.

Link | Posted by deryck on October 31, 2008 | 0 comments

End of Day on the Internets

The best part of my day ending is my little girl climbing up the steps to tell me it's time to go. We "signed off" of work together today via video.


End of Day on the Internets from Deryck Hodge on Vimeo.

Link | Posted by deryck on October 30, 2008 | 0 comments

Cold Morning in the Office

Video blogging: It's a cold morning here in my office in Alabama.

Link | Posted by deryck on October 30, 2008 | 0 comments

The World is too Much with Us

There's been so much going on in the world and in my life lately that finding time to post here has been tricky. This Wordsworth poem has been on my mind for awhile now, so I thought I'd post it just to dust the cobwebs from this site and my mind.


The world is too much with us; late and soon,
Getting and spending, we lay waste our powers;
Little we see in Nature that is ours;
We have given our hearts away, a sordid boon!
This Sea that bares her bosom to the moon,
The winds that will be howling at all hours,
And are up-gathered now like sleeping flowers,
For this, for everything, we are out of tune;
It moves us not.--Great God! I'd rather be
A Pagan suckled in a creed outworn;
So might I, standing on this pleasant lea,
Have glimpses that would make me less forlorn;
Have sight of Proteus rising from the sea;
Or hear old Triton blow his wreathed horn.

Now that the cobwebs are stirred and the dust settled, over the next few days, I'll post about a couple new things at work and a new personal site I've recently put up. Til then...

Link | Posted by deryck on October 28, 2008 | 0 comments

A New Blog From Me: Paperlate.org

This site, Devurandom, is my work/tech-related presence on the web. It is a site that came to life as I was getting into professional web development. It’s never been a very personal site and has always existed purely as a testing ground for my technical interests. I’ve always kept the topic loosely on web development and media because that’s what I do for living, though honestly, I’ve just not put much thought into it. This is just my little playground on the net.

I have started a new site that is a more personal site for me. It can be found at Paperlate.org. Let me tell you a bit about this new site.

Paperlate is coming out of an interest in writing about a particular topic. I’m now at a point in my life where I want to write about some very personal things for me — my love for music, my faith in Jesus Christ, and the combination of the two, music in the church. And, I suppose, I’ll end up writing on being a Christian and artist more generally, too (where “artist” means someone involved with creating and appreciating art).

I've not ever written about my faith on this site (Devurandom) because I've recognized that a lot of people come here with interests in technology and media, and I wanted to respect that. It's not that I've been hiding my faith as some in the church might infer from that last sentence; most people who work with me have a clear picture of who I am and what I believe. I just have kept my personal and professional lives separate in regard to this site. Now that I fell compelled to write about some personal things (due to many new things happening in my life), I've decided to break the personal out into this new blog, Paperlate.

I mention the new site here only to call attention to the new, more personal blog, thinking that some who know me from my work might have an interest in these other topics. And also, just to explain why the new blog is so different from this site. So check out Paperlate if you have an interest in the topics I mention above, or in how those topics relate to my life.

Link | Posted by deryck on August 6, 2008 | 0 comments

Comments Temporarily Disabled

I'm closing comments on blog entries and links to stop a spam problem. I will reopen comments once I have better spam prevention measures in place.

Link | Posted by deryck on July 31, 2008 | 0 comments

A Brief Update: Where I've Been and What's Happening

I know I've been quiet around here lately, but I'm still settling in at the Sun. I was also on vacation week before last. It might be odd to take a vacation after only being with the company a month, but I had this vacation -- an annual event for my family -- planned months before I started at the Sun. I worked all this out with Rob before starting work. Then after vacation, I've been busy trying to get some hanging projects polished off. I'm still in limbo a bit on some of these, so I'm hoping next week will be quite productive in terms of the number of things I see go live that I've been working on.

Also, my Zoe started kindergarten this week.

(Dramatic pause as I wipe the tears from my eyes.)

It's been a shock to Wendy and I, and also, Zoe has had a hard time adjusting to it. Wendy and I have really smoothered Zoe, we can admit that much. She hasn't had to go to day care, spending most of her free days with either Wendy or Wendy's sisters. So it was a bit of a shock for her when she's just one among a big group of other kids. Today, however, she had a great day, and didn't even cry once for us.

I've also had my work schedule flipped upside down. I'm up at 5, and I work an hour to catch up on email. Then, I'm working by 7:45 after dropping Zoe off at school. With the time change for my coworkers on the West Coast, I've usually already put in 5 or 6 hours when I see everyone appear on IRC or IM. There is some drama with Zoe after work -- "Please don't make me go back!!!" -- then bedtime, and another check of email and work stuff after that.

Needless to say, I'm whooped on this Friday, and haven't had much time for writing or linking here. I should have a nice relaxing weekend, though, and next week will certainly be better.

Oh, and congrats to my coworkers on moving into a new building this week. Here's to a new week for us all next week.... Cheers!

Link | Posted by deryck on July 25, 2008 | 0 comments

New Job at the Las Vegas Sun

I've been trying to write something clever about this for weeks now. I mean with the blogging attention paid to Loudoun Extra and Rob Curley and members of our group leaving the Post, I almost fell compelled to write something clever. But I've been working, and working hard. And enjoying the work, and the time just keeps slipping away. So now it's been three weeks I've spent on a new job at the Las Vegas Sun, and I haven't even mentioned it here yet.

It has indeed been an amazing few weeks. I'm feeling as productive as I've ever felt. I'm writing a lot of code and really enjoying work, and I still have time for life outside of work. If you look for me on YouTube and Flickr, you can get a hint of the kinds of things I'm working on these days. See our call for July 4 photo submissions to get an idea, too.

As new projects surface and time allows, I'll post about new things here. Hopefully, even more so than I did at the Post. But no gaurantees, in case the work is too fun to take time to write about.

Link | Posted by deryck on July 4, 2008 | 0 comments

Why Not?

I saw Eric do a me too today, so why not join in:


naminanu:~/projects/wpni deryck$ history|awk '{a[$2]++} END{for(i in a){printf "%5d\t%s\n",a[i],i}}'|sort -rn|head
  128   vi
   76   python
   52   ls
   46   svn
   27   cd
   21   psql
   17   grep
   10   mv
   10   clear
    9   sudo

Link | Posted by deryck on April 16, 2008 | 0 comments

How Do We "take the paper" in Virtual Worlds

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 News "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.

Link | Posted by deryck on March 27, 2008 | 0 comments

Democratic Primary Predictions

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.

Link | Posted by deryck on March 19, 2008 | 0 comments

Status Update on Google-driven Web Development Book

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.

Link | Posted by deryck on March 12, 2008 | 0 comments

Lazy Man's Twitter Updates via CLI

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.

Link | Posted by deryck on March 7, 2008 | 2 comments

Quick Python Tip: Socket Timeouts for Page Scrapers

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. :-)

Link | Posted by deryck on March 4, 2008 | 0 comments

A Django Auth Backend for Second Life

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.

Link | Posted by deryck on March 3, 2008 | 0 comments

For older posts, see the writing archives in the sidebar above.