Posts for May 2011

Game of Thrones, You Win or you Die

HBO's Game of Thrones has definitely been delivering on it's promise of expressing all the brutal politics from the books and the latest episode is probably the most pivotal of the series so far. EPISODE SPOILERS AHEAD..

Tyrion continues to be my favorite character in the series and the Emmy Awards better be thinking about putting a milk crate next to the acceptance stand this year for Peter Dinklage. It's a particular testament to his performance so far that the character's absence brought the quality of the episode down a bit.  Other than that I have few complaints with it and it's probably obvious to anyone who has seen it that the game is on now and things take an uncontrolled slide from here on out.

I continue to really enjoy Jon and Sam, their performances are fantastic as is the performance of Danny and Drogo.  I'm still fascinated to see how these storylines will hold up against the one in Kings Landing as the series progresses.  It feels like sooner or later one has to emerge in the series as the "lead" storyline and I just don't see how the series can maintain it's integrity if that happens.  It's going to take some brilliant writing and filing to keep that from happening but if they keep the level of talent they've displayed so far I think they can pull it off.

I'm loving and hating the same characters as I did in the book despite some apparent changes in how they develop so It'll be interesting to see how I feel a few seasons in.  

Good Riddance to Robert btw.  Again a great performance because the character felt exactly like he should, like he ...

(Read More)
Gunshots by Computer

The Pentagon issued a much needed policy on cyber-attacks against the U.S. today, putting it in the same category as any other attack on the infrastructure.  Linked and quoting the opening below from the AFP for reference...

US 'to view major cyber attacks as acts of war

The Pentagon has adopted a new strategy that will classify major cyber attacks as acts of war, paving the way for possible military retaliation, the Wall Street Journal reported on Tuesday.

The newspaper said the Pentagon plans to unveil its first-ever strategy regarding cyber warfare next month, in part as a warning to foes that may try to sabotage the country's electricity grid, subways or pipelines.

Every nation is eventually going to have to express a policy related to cyber-warfare but this is less than half the picture.  It's not enough to just issue a policy related to acts against the country and we're going to struggle culturally with what we're ethically comfortable with in terms of launching cyber attacks.

The world breathed a collective sigh of relief when the STUXNET worm infected Iranian uranium enrichment plants, setting their nuclear program back a several years.  The mysterious originators of the virus were applauded for their innovation and service done to the world.  Following the pentagon policy however, this is an act of war and had Iran retaliated as such would they have been within their rights under international law?  That doesn't feel right of course but I think it expresses the fact that we're going to have to fully realize the implications of any policy related to cyber-attacks.

One of the great benefits of the internet and the information age is that it allows individuals or small groups to act on a scale previously reserved for ...

(Read More)
Single simple view for Django form processing

I always feel a bit dissatisfied with the amount of code I have to put in to process forms in Django views. Like most python developers it feels like I've gotten too complex it if takes me more than 5 or 6 lines of code to do something.   Previously I had coded seperate create and update views for form processing, partially this was to better control permissions but also because of the differences in dealing with bound and unbound forms as well as model instances.

This is my first stab at implementing that simple logic based on several examples I've seen out there in other blogs. 

@login_required
def post_edit(request, id=None):
    """
        Handles creating or updating of individual blog posts.

        :parm request: request object being sent to the view.
        :param id: post id, defaults to None if new post.
        
       """
    instance = None
    if id:
        instance = get_object_or_404(Post, id=id)

    title = "Create New Post"
    if instance:
        title = "Editing Post"

    # Create the form as needed.
    form = PostForm(request.POST or None, instance=instance) # Didn't work for me unles I passed k,v pair in instance.

    # Save the edited form if needed
    if request.method == 'POST' and form.is_valid(): # Validate and correct fields if needed.
        tmp_form = form.save(commit=False)
        # Set author to current user if none set.
        if not tmp_form.author:
            tmp_form.author = request.user.id
        # Set pub_date if none exist and post is published.
        if tmp_form.status == PUBLISHED_STATUS and not tmp_form.pub_date:
            tmp_form.pub_date = datetime.now()
        tmp_form.save()
        return HttpResponseRedirect(reverse('blog:post-edit', args=[tmp_form.id]))
        
    return render(request, 'blog/post_edit.xhtml', {
        'title': title,
        'form': form,
    })

So this allows me to call the same view in blog/urls.py and passing a post ID tell it if it's a new post or editing an old post.  The entry ...

(Read More)
Reading Site Domain into Django Templates

There are a number of great new features in Django 1.3 for template developers.  Not the least of which is the addition of the STATIC_URL attribute in settings.py to help with referencing static media.

I found when trying to integrate social media linking in blog posts however that there wasn't a good way to pull the entire site domain into a URL without hard coding into the template.  Something that makes and descent Django developer shiver.

The easiest way around this is to use the .get_current() method of the Site model and access that via a custom template tag in your templates.  

The code itself is very simple:

from django import template

from django.contrib.sites.models import Site

register = template.Library()

@register.simple_tag
def sitedomain():
    '''Returns the URL of the default site.'''
    try:
        return Site.objects.get_current().domain
    except Site.DoesNotExist:
        return None

This makes it pretty easy to call in your template. I was able to use it to forward complete URLs onto some javascript functions that provides social linking in posts.

Pre Code before I can Post Code

Impatience is a vital in my profession but, barring I don't discover I live backwards in time , I have to take it one step at a time and not expect to start out having it all done.

I really want to use the new MetaRho codebase to post come code examples and talk about fun snipets of code or examples of stuff I'm currently working on.  I'm a manager so I have to take these times to show my stuff and get into a conversation where I can.

The frustrating part is that to really post meaningful code here I'm going to have to wait until I can switch over to CKEditor or some other WYSIWYG editor for the blog.  Not terribly difficult but I have to exercise some discipline at 1 am to go to bed instead of switch the app over.  Breath Scott, breath my friend.

Having just release arbitary-version-number-for-hey-look-I-think-it-works of MetaRho there are a ton of things I want to do and do them now.  Prioritization is the key though.  I want to move onto updating the django-tagging app but instead I'll get code working here for the new editor in the django admin backend.  Maybe my first post will be about that since I had some trouble with CKEditor in the past.  

For the record I'm using TinyMCE and while it's a great editor I run into a barrier for posting code since it insists on wrapping every individual line of code in <pre> tags when I'm trying to format lines of code.  That wont do so CKEditor here I come.

The Flagon With the Dragon as the brew that is true!

I did manage to overcome the appauling inertia that's been plaguing me the last few months and get my domain switched over to my new web host.  You're looking at it in all it's gory glory!

As mentioned in my previous post I've decided to move my site over to a django app and out of wordpress because I want to experiment a bit and need a probject to do that with.  So I've begun the process of cleaning MetaRho up, get it minally functional and then start marching forward and adding features where it pleases me.  If you're looking at it right now then the minimal thing is pretty apparent.  I'll grab a screenshot of the site for posterity and hopefully to show a comparison of it in a few month.

On a side note I've switch to GitHub for my repository playground and it's amazingly impressive so far.  I love you and all Mercurial, but don't like that Bitbucket dress you've been wearing.  Webfaction is also turning out to be a pretty useful hosting service and so far I'd recommend it to anyone looking for a good and flexible site host.  

All 2000+ of my previous blog posts are still live on a wordpress install here.  I'm saving them there until I get caching working properly on this site and django-tagging integrated properly. 

Right now I can basically post things and the RSS feed should work, let me know if it doesn't.  Expect to see more soon.

That Code it Jingle Django Jingles

Wordpress is for sissies... 

Well really it's for people with brains or a greater sense of sanity than me.  I brought up the minimal code to get this site working today, just now in fact.   I want to take my blog over to a Django as a play space, place to experiment, expand and all that.  Either way it's just coming together and I'm doing what I can to get it running as bug free as I can so so I can start adding some actual features I might enjoy.

I've had to overcome a lot of inertia in thinking I should just do wordpress but I figure I can always port it back if I want.

Because the code is just coming together and there's no caching I don't want to import the 2000+ posts from my previous blog so that IS still being served in wordpress and you can find it here in all it's former glory.

Also I have to get my domain switched over to here, so you're seeing this today at whatever temp domain my provider gave me.  At the time of this writing that is 'streamweaver.webfactional.com' but expect to see good old 'www.flagonwiththedragon.com' back poisining the bandwith soon.  

Expect to hear more soon.