Frozen: A Scary & Innovative Horror Flick

Go see this movie.

Watch the trailer for Frozen, and then check out the official site.

I had the pleasure of meeting the writer & director, Adam Green, this past weekend. My friend Robert and he are old buddies from college who just reconnected. Adam invited us to go to a screening in Santa Monica on Saturday after which there was a meet & greet with the cast & crew. After that we went out for drinks and I had a really good time. Ahhh, schmoozing, the second-oldest profession.

So, not only do I like the guy and want to see his movie succeed, but I genuinely thought the movie was a good time and I want to get more people out there to see it!

It’s an independently produced horror movie, which already stacks the odds against it. It is also an original production, not a remake, which further hardens the sell. It seems most horror fans out there cry for new original stories over remakes, but when it comes time to show their support, movies like Frozen get overlooked. This is sad.

I am a huge horror fan, and I am one of those people who is disappointed with the glut of remakes out there. So I am taking some of my time to get the word out there about Frozen because we need more movies like it!

It was an intense flick that had me gripping the edge of my seat for most of the movie. It grabbed me and didn’t let go, had me cringing and going “OHHHHHH” at some of the gory scenes. At a few moments I was so uncomfortable that I had to disengage by looking away or pretending I was in a happy place. To me, that is a sign of a good movie. It affected me. It wasn’t hum-drum, boring, or predictable. It still had a few of those campy, horror movie moments and I think that is where its charm is. If a horror movie can be charming, that is.

The acting was really good, and I think that Adam’s directing style had a lot to do with this. The entire movie was shot “practically” which means “on location”. There was no green-screen, no studio, no tricks. It was all filmed outdoors, on a ski slope, with the actors IN the gondola.

During the meet & greet they said that the actors had to be up on the gondola for six hours at a time. The filming was done on a ski resort in Utah and the lift was so long that to get off they had to ride all the way to the top of the mountain and all the way down, which took over an hour. So they had to limit the amount of interruptions in order to maximize filming time.

All the scenes in which it is snowing outside are real. When you can no longer see the actors’ breath, that’s because they are running out of body heat. That seems brutal to have endured that during filming for the actors, but I don’t feel too bad for them. THIS IS HORROR!

I felt like some of the scenarios were a little over-the-top, but I am ok with it. Isn’t that the point of a good horror film? Personally, I don’t want too much realism. I want fear, death, blood, and other delicious things that would probably never happen in real life. I definitely wouldn’t enjoy seeing people die in real life, I promise.

If you’re in for a good thrill, check your local movie listings and check out Frozen. I mean, come on, being that the majority of the Northeastern U.S. is under feet of snow & ice right now, how appropriate is this film?

VERY.

On Using eval() in Python

Originally posted on StackOverflow.

I have used eval() in the past (and still do from time-to-time) for massaging data during quick and dirty operations. It is part of the toolkit that can be used for getting a job done, but should NEVER be used for anything you plan to use in production such as any command-line tools or scripts, because of all the reasons mentioned in the other answers.

You cannot trust your users–ever–to do the right thing. In most cases they will, but you have to expect them to do all of the things you never thought of and find all of the bugs you never expected. This is precisely where eval() goes from being a tool to a liability.

A perfect example of this would be using Django, when constructing a QuerySet. The parameters passed to a query accepts keyword arguments, that look something like this:

results = Foo.objects.filter(whatever__contains='pizza')

If you’re programmatically assigning arguments, you might think to do something like this:

results = eval("Foo.objects.filter(%s__%s=%s)" % (field, matcher, value))

But there is always a better way that doesn’t use eval(), which is passing a dictionary by reference:

results = Foo.objects.filter( **{'%s__%s' % (field, matcher): value} ) 

By doing it this way, it’s not only faster performance-wise, but also safer and more Pythonic.

Moral of the story?

Use of eval() is ok for small tasks, tests, and truly temporary things, but bad for permanent usage because there is almost certainly always a better way to do it!

Dynamically Determining the Variables for a Django Template

This is something that came up on StackOverflow, and I took the time to provide a very detailed answer. I haven’t posted in a while, and since I spent time on this answer, here it is verbatim. Enjoy!

Original Question

I’d like to be able to instantiate a template from a file (presumably using the django.template.loader.get_template(filename) ), and then determine the set of variables that should be defined in whatever context it is passed.

(snip)

I tried synack’s answer and found that (with the replacement of filterexpression.token by filterexpression.var, to get the actual name of the variable without tags and so on) it returned the variables that are defined locally in the template, but did not work for variables that are defined in the parent that it extends.

So for example, suppose I have templates in two files:

toyparent.html:

{%block base_results%}
Django is {{adjective}}
{%endblock base_results%}

toychild.html:

{% extends "toyparent.html" %}

{%block base_results%}
{{block.super}}
I {{verb}} it.
{%endblock base_results %}

And I load the child template:

>>> toy=django.template.loader.get_template('toychild.html')

This renders properly:

>>> toy.render(django.template.Context(dict(adjective='cool',verb='heart')))
u'\n    \nDjango is cool\n\n    I heart it.\n\n'

But I can’t get the two variables from it:

>>> v=toy.nodelist.get_nodes_by_type(VariableNode)
>>> for k in v: print k.filter_expression.var
...
block.super
verb

My Answer

You are able to visually inspect a template and observe the presence of any “Variable Node” objects in that template’s nodelist:

>>> from django.template import Template, Context
>>> t = Template("Django is {{ adjective }} and I {{ verb }} it.")
>>> t.nodelist
[<Text Node: 'Django is '>, <Variable Node: adjective>, <Text Node: ' and I '>, <Variable Node: verb>, <Text Node: ' it.'>]

These are of the type VariableNode, which is a class that can be directly imported for use in comparisons. Any Node instance has a get_nodes_by_type() method that can be called against a nodelist, which return all nodes of that type for the template. Example:

>>> from django.template import VariableNode
>>> varnodes = t.nodelist.get_nodes_by_type(VariableNode)
>>> varnodes
[<Variable Node: adjective>, <Variable Node: verb>]

So now you have a list of the variables for the template. This will need to be taken a step further to extract the actual name of each variable without peforming stupid string-slicing tricks on their repr names.

The variable name itself is stored in filter_expression.token for each VariableNode:

>>> varnodes[0].filter_expression.token
u'adjective'

And so a simple list comprehension gets us all of the variable names for the template:

>>> template_vars = [x.filter_expression.token for x in varnodes]
>>> template_vars
[u'adjective', u'verb']

So, not the simplest solution, but if there is a better way I don’t know about it.

Bonus: A function!!

from django.template import VariableNode
def get_template_vars(t):
   varnodes = t.nodelist.get_nodes_by_type(VariableNode)
   return [x.filter_expression.token for x in varnodes]

Ok, it’s not so complex after all!

Follow-up Edit: Getting variables from parent templates

(This follow-up is using the information from the updated question).

This is where it does actually get complex because the nodelist of the toy template is a single ExtendsNode (in this case).

>>> toy.nodelist
[<ExtendsNode: extends "mysite/toyparent.html">]

I would imagine that in larger templates there could be multiple ExtendsNode objects. Anyhow, if you inspect the ExtendsNode, and extract the parent template from it, you are able to treat the parent the same as my original example:

>>> enode = toy.nodelist[0]
>>> enode.parent_name
u'mysite/toyparent.html'
>>> parent = enode.get_parent(enode.parent_name)
>>> parent
<django.template.Template object at 0x101c43790>
>>> parent.nodelist.get_nodes_by_type(VariableNode)
[<Variable Node: adjective>]

And there is your adjective variable extracted from the parent template. To perform a test against an ExtendsNode you can import the class from django.template.loader_tags:

>>> from django.template.loader_tags import ExtendsNode
>>> ext = toy.nodelist.get_nodes_by_type(ExtendsNode)
>>> ext
[<ExtendsNode: extends "mysite/toyparent.html">]

So, you could do some tests against templates for the presence of an ExtendsNode and walk backwards to the parent template and individually get those variable names. However, this is starting to seem like a can of worms.

For example, if you were to do this:

>>> toy.nodelist.get_nodes_by_type((ExtendsNode, VariableNode))
[<ExtendsNode: extends "mysite/toyparent.html">, <Variable Node: block.super>, <Variable Node: verb>]

Now you’ve got the ExtendsNode and VariableNode objects and it just starts to get confusing. What do we do then? Do we attempt to ignore any block variables returned from such tests? I don’t know!!

In any case, this is the information you wanted, but I don’t think that this is a practical solution. I insist that there is still probably a better way. It might be worth looking into what you are trying to solve and see if there is another approach you can take.

Logical Meltdown

I have been totally unable to accomplish any coding this week.  I’ve been rewriting this application at work and while I’ve made some decent progress, I haven’t gotten a damn thing done this week and it’s frustrating as hell!

Of course now that it’s Friday and I’m feeling the urge to start writing more code having to do with dongs.  What the fuck is wrong with me?  Don’t answer that.

I figured that by explaining some of what I’m struggling with, some magic will happen.  I need to blog more and work on my “explaining complex shit in a meaningful way” skills, so if this in any way interests you please read on.

WARNING: TECHNICAL SHIT BELOW!

The application I am rewriting is a MySQL database-driven app that has two interfaces:

  1. A command-line interface (CLI) utility written in Perl for direct manipulation (addition/removal of records) and querying (searching) of the database. Only engineers have access to this tool.
  2. A web application written in PHP for searching the database for non-engineers.  Mostly support and operations staff use this. This also provides a hacked up “API” that returns a list of comma-separated values (CSV) of matching records.
It’s something I wrote years ago using PHP & MySQL that is way more complex than I remember it and double-dog dare you more complex than it needed to be. It’s strange going back in time with my code, especially PHP (shame), and realizing how competent I was even then, but how unnecessarily convoluted I made some things.

There are a shit-ton of logical pitfalls in that code that have really thrown me off.  Being that we have a Perl CLI tool and a PHP web app, the much of the code is duplicated for each language. The tool was originally written in Perl with the web app piece tacked on as an afterthought.  At the time I was really into PHP’s native support for MySQL but was pretty much a novice so ended up making some downright lazy and bad choices.

With PHP and it’s bloated cousin Perl, there are so many ways to do the same thing that there really isn’t one right way to do things.  Typically that means there are that many more wrong ways to do them.  For example, horrible crap like this where we have PHP making a system() call to execute a Perl script from within index.php:

<table>
  <tbody>
    <tr valign="top">
      <td>
        <?
          system('perl body.pl column="' . $POST['column'] . '" value="' . $POST['value'] . '" netmask="' . $_POST['method'] . '"');
        ?>
      </td>
    </tr>
  </tbody>
</table>
Couple that with my prior lack of regimented programming style because I originally learned to code from the back of a Cracker Jack box (aka the internet), and what I am working with is pretty much a nightmare.

“Why is that?”, you ask?  Well let me tell you!

First things first, the primary users of the app (aka the stakeholders) have been requesting some new features for a long time and with everything else going on it hasn’t really been a high priority for me.  Especially because it was written in Perl, which I have grown to hate passionately since I started using Python.

Next, the systems from which the CLI tool runs are being replaced, which means the app has to be moved to the new systems. We run a Red Hat offshoot distribution of Linux, so we use RPMs to manage what gets installed on machines.  What this means is that any Perl module dependencies need to be installed via RPM. With RPM and Perl there are always dependencies of your dependencies, and you can bet that some of those won’t be available in the repository. This opens a massive can of worms of having to download the module source and convert it to RPM.  For those of you who are familiar with Perl’s CPAN and RPM, you’re probably thinking “Just use cpan2prm!”. Right, if only it were that simple…

You see, the new hosts are running a 64-bit kernel, which means that the subset of available packages is even smaller because packages have to be specifically built (or rebuilt) for 64-bit installation. Even if it’s the same files inside of the package, it still has to be re-packaged for 64-bit.

So, I was left with the choice of either uprooting the tool from its current location, wrangling package dependencies, rebuilding packages, modifying the Perl code to shoehorn it into the new systems all the while overlooking the implementation of the requested features; or rewriting it using Python & Django.

Naturally, I chose to rewrite it because the thought of having to trudge through antiquated Perl hackery gave me diarrhea and I really don’t want to ever touch Perl or PHP again if I can help it. By rewriting the app in Python, I can implement the new features and bring the code into the present at the same time without having to go through bouts contemplating suicide. Annnddd… That leads us back to the nightmare that is Perl and PHP.

As I mentioned above, with Perl & PHP there are so many ways to do things that most of them are convoluted, confusing, hard-to-read, and just plain fucking wrong. With Python–and Django for that matter–there is usually only one right way to do things, and that way is pretty much always elegant.  Plus, one of the most beautiful things about Django is that it wholly and completely abstracts the database interaction from the source code.  That means not having to write complex SQL statements manually, and the less SQL I have to write, the better.

In meeting with the stakeholders on rewriting the application, we decided that all of the energy should be invested in replacing the web app with a real API with a RESTful interface. If you don’t know the basic premise of REST (which is a methodology, not a protocol), it’s that URLs should be easy-to-read, self-describing and beautiful. Beautiful URLs? WTF? How can a URL be beautiful?  I’m glad you asked!

The old PHP version of the API is very heavy on the query string, requiring GET variables to be passed in the URL itself which is not only cumbersome, but can get confusing and hard to read very quickly:

http://server.whatever.com/api.php?show=all&user=jathan

Compare that to a RESTful version of the same:

http://server.whatever.com/api/show/all/jathan/

This is where Django excels because it encourages pretty URLs by making it easier to use pretty URLs than not to.

So, cutting this post off at the knees, I’ve been pounding on this for the past few weeks, learning a lot about how NOT to do things from my old code and how TO do things using Django as my guide.  I made a lot of progress, got the API working, and a basic search interface that returns stuff all using the same code.

But this week, I’ve been stuck.  I haven’t made any progress, have been getting really confused, and just generally bashing my skull into the keyboard.  I think I’m just fried from trudging through all of Perl’s curly braces, semicolons, ampersands, dollar signs… OMG THE SYNTAX!  KILL ME NOW!!

Besides, it’s Fried-day anyways, so I hope that just by spelling this all out here that I’ll be able to dig back into the code after the weekend with a renewed perspective.

p.s. Fuck Perl.

p.p.s. Fuck PHP too, but wrap that rascal. She gets around!

Positive Thinking is Awesome

This is me in 2  years if I continue to make posts like this.  I'm the one on the left.

This is me in 2 years if I continue to make posts like this. I'm the one on the left.

Recently I’ve been feeling pretty good about myself in a way that only a man can… In my pants. Ok just kidding, I always feel pretty good about myself there. But seriously, I made up my mind to focus on the positive things in my life instead of dwelling on the negative.

Despite the undertow of self-doubt I’ve made a decision to continue to feel good about my life. Fundamentally that’s really all there is to it. It comes down to making a simple decision: Am I going to be happy or not? And so my mind is made up. I am.

I insist on feeling good about what I’m doing with my life and to be okay with where I am at. I will no longer beat myself up for not doing the things I think I should be doing, or want to be doing. Like blogging. (Or not blogging.)

Getting to this point hasn’t been easy and this seems really gay now that I’ve posted it. I am grossly oversimplifying the whole process but whatever, just go with it.

More Dongs on a Friday. Surprise!!

Due to popular demand, mkdong has been modularized!!  I present to you dong.py version 0.0.1.

Enjoy:

#!/usr/bin/env python

''' MKdong turned into a module. I think I was smoking crack and/or high on Red Bull this day.

Dong goes into underpants Dong goes into boxers Dong goes into vagina Sperm comes out of dong Sperm goes into vagina Sperm goes into egg Dong goes into mouth Pee comes out of dong Pee goes into toilet Why am I iterating this crap? '''

import os, sys

blue = '\\e[0;34m' # blue

class Dong:

def __init__(self, maxlen=40, color=blue):
    self.maxlen = maxlen
    self.color  = color
    self.dong   = None

def mkdong(self):
    self.dong = '(_)/(_)'
    for i in range(self.maxlen): self.dong += '/'
    self.dong += 'D'
    os.system('echo -e "%s%s"' % (self.color, self.dong))

class Sperm(Dong): def init(self, count=500): self.count = count self.spermcount() Dong.init(self)

def __repr__(self):
    return '' % self.count

def tighty_whities(self):
    print 'Tighty Whities lowered your sperm count!'
    self.count -= 50

def boxers(self):
    print 'Boxers raised your sperm count!'
    self.count += 50

def spermcount(self):
    print 'Sperm count is %d' % self.count

def bike_seat(self):
    print 'asdjfoisadjs'
    pass

def radiation(self):
    print ':-x'
    pass

def castration(self):
    print ':('
    pass

def smoke(self):
    print 'awwww yeahhhhh.'
    pass

class Egg(Sperm): pass

if name == 'main':

try:
    donglen = int(sys.argv[1])
except:
    print "usage: mkdong "
    sys.exit()

if donglen &gt; maxlen:
    print 'warning: a %s" dong is too big! cannot be longer than %s"!' % (donglen, maxlen)
    sys.exit()
else:
    d = dong(donglen)
    d.mkdong()</pre>

There's really no excuse. I should be ashamed of myself but I'm not.

Virginia Blows

That is all. Been here a week and while I’ve had fun, it feels like it’s been a month.

I miss my friends and my family that are in this area, but that’s still not enough for me to want to stay here for any meaningful length of time.  But hey, it’s been like 13 months since last time, so it’s not all bad.  I have a gracious host, fun coworkers, and also the internet.

But despite that, when I’m here it feels like I’m not living my own life. Maybe it has something to do with the fact that I couldn’t wait to leave when I moved away over two years ago, and now every time I come back that feeling quickly returns.

Blah… Whatever, bitches.

Actually, I think it’s your fault. Yes, you!

Here enjoy this: Someone ported mkdong to Perl. Not sure how I feel about that. Bittersweet?

Taking over the internet, one dong at a time.

Using Caps Lock on Your iPhone

I’ve had an iPhone for over a year and still hadn’t learned how to use the mysterious caps lock feature.  I enabled it in the settings, but had no idea how the hell to make use of it!  Of course it turns out to be just as intuitive as everything else on the iPhone. I just figured this out today so I thought I would share it.

Step 1:  Enable Caps Lock

Navigate to Settings > General > Keyboard and switch “Enable Caps Lock” to “ON”.

Enable Caps Lock

Enable Caps Lock

Step 2: Use Caps Lock

To use caps lock, all you have to do is double tap the shift key on the lower left of your keyboard.The key will turn blue indicating that you have successfully engaged CAPS LOCK.

CAPS LOCK ENGAGED

CAPS LOCK ENGAGED

To turn it off, just tap the shift key once more.

Your life has now been enriched, and I can move on with mine.

Did Glenn Beck Rape and Murder a Young Girl in 1990?

That’s a good question.

I read an article on Ars Technica today posing the question of whether of registering domain names such as didglennbeckrapeandmurderayounggirlin1990.com in the name of parody or satire can be considered slander or defamation. To me the answer is clearly no, because the only way someone would register a domain like that in the first place is if you were a total douchebag. Of course whether or not someone is truly a douchebag would hardly hold up in court, and that is why I am not a lawyer.

But come on… We’re talking about Glenn Beck here, the dude who called Obama a racist.  He is one of the largest proponents of all of the unfounded idiocy and willful ignorance (two things I really can’t stand) driving the ridiculous frenzy of misinformation that you have to go out of your way to avoid lately, ranging from cries of “democracy” equating to “communism” and comparing Obama to Hitler.  facepalm

On one hand I frown on giving someone like him more publicity and–indirectly–more relevance.  But on the other hand, I just can’t pass up a perfectly good opportunity to keep this gag going strong as long as possible.

They’re poking fun at the fact that he makes these baseless statements and then says things like “prove me wrong”.  So the joke is now on him and he is being challenged to address allegations that he may or may not have raped and murdered a young girl in 1990.

Folks, the word is out.  Did he or did he not?  You decide!