…does nerdy things.

Django Encryption – An Updated How-To

Filed under: Boring Stuff — Tags: , , , — Bryan on Oct 16th, 2009 @ 12:56 am

I love Django, and I love Django Snippets, but I’ve noticed some snippets are out of date, most notably for me, Django snippet 1095 or Django Encryption. Unfortunately, some folks are hitting a few snags on TypeError: “Non-hexadecimal digit found”.

Luckily, it seems that Django-Fields have solved this problem for us! Here is my (their) technique!

Make a file named encryption.py to go into the same folder as your settings.py containing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import binascii
import random
import string
 
from django import forms
from django.db import models
from django.conf import settings
 
class BaseEncryptedField(models.Field):
    '''This code is based on the djangosnippet #1095
You can find the original at http://www.djangosnippets.org/snippets/1095/'''
 
    def __init__(self, *args, **kwargs):
        cipher = kwargs.pop('cipher', 'AES')
        imp = __import__('Crypto.Cipher', globals(), locals(), [cipher], -1)
        self.cipher = getattr(imp, cipher).new(settings.SECRET_KEY[:32])
        self.prefix = '$%s$' % cipher
 
        max_length = kwargs.get('max_length', 40)
        mod = max_length % self.cipher.block_size
        if mod > 0:
            max_length += self.cipher.block_size - mod
        kwargs['max_length'] = max_length * 2 + len(self.prefix)
 
        models.Field.__init__(self, *args, **kwargs)
 
    def _is_encrypted(self, value):
        return isinstance(value, basestring) and value.startswith(self.prefix)
 
    def _get_padding(self, value):
        mod = len(value) % self.cipher.block_size
        if mod > 0:
            return self.cipher.block_size - mod
        return 0
 
 
    def to_python(self, value):
        if self._is_encrypted(value):
            return self.cipher.decrypt(binascii.a2b_hex(value[len(self.prefix):])).split('\0')[0]
        return value
 
    def get_db_prep_value(self, value):
        if value is not None and not self._is_encrypted(value):
            padding = self._get_padding(value)
            if padding > 0:
                value += "\0" + ''.join([random.choice(string.printable) for index in range(padding-1)])
            value = self.prefix + binascii.b2a_hex(self.cipher.encrypt(value))
        return value
 
class EncryptedTextField(BaseEncryptedField):
    __metaclass__ = models.SubfieldBase
 
    def get_internal_type(self):
        return 'TextField'
 
    def formfield(self, **kwargs):
        defaults = {'widget': forms.Textarea}
        defaults.update(kwargs)
        return super(EncryptedTextField, self).formfield(**defaults)
 
class EncryptedCharField(BaseEncryptedField):
    __metaclass__ = models.SubfieldBase
 
    def get_internal_type(self):
        return "CharField"
 
    def formfield(self, **kwargs):
        defaults = {'max_length': self.max_length}
        defaults.update(kwargs)
        return super(EncryptedCharField, self).formfield(**defaults))

And then in your models.py:

1
2
3
4
5
6
7
8
9
10
from encryption import EncryptedCharField
...
class Example(models.Model):
    secret = EncryptedCharField(max_length=255)
 
    class Meta:
        ordering = ('secret',)
 
    def __unicode__(self):
        return self.secret

This should be pretty explanatory! Have fun!

PS: You need PyCrypto! Google much?

Antares AutoTune Review

Filed under: Interesting — Tags: , , — Bryan on Aug 13th, 2009 @ 12:06 am

antares autotune review saxaphone trumpetI never thought I’d cross into the dark side. Using AutoTune? On jazz?! What?!?

Oh, I know how wrong it is. The “Trane” would roll over in his grave. Wes would be shocked. Miles would not approve. But, I don’t think those guys would listen to our records anyways (even if they were still alive). Besides, I think I speak for everyone when I say I am tired of doing 800 takes. We aren’t professionals who spend their lives playing live and in the studio. This is for fun. So here is my two bits about Antares AutoTune on woodwind and brass instruments.

Holy shit, it worked!

That was my first reaction. I snagged a copy (v5), installed it, and was thinking I just wasted time and money. Like we need Cher or T-Payne style AutoTuning on our sax duets. Right…  All I did was throw it on the tracks, leave it on the “Auto” setting. 10 seconds later… Well, holy shit, it worked!

Alright, so you know it worked, but how did it sound? Here’s a little excerpt on a song by Adam Loftin, named “Out Of The West Wood”. It’s a very angular jazz tune, slow and ballad like. You can hear our two sax players (who are quite talented), stray off on this strangely angular melody.

Now, that may not sound that different, but listen closely to the last note. The warble is gone. The harmonic dissonance is still there (this is jazz, remember). This is actually a pretty good example, hopefully you aren’t trying to fix horribly out of tune performances, just slightly out of tune.

Anyways, it was literally as easy as installing the software, attaching it to the track, and selecting the instrument setting. We could probably fix the slightly out of tune note pickups, but seriously, its so much better, we don’t even care.

Have you used it?

Just curious about your experiences with AutoTune and your stories. What genres did you use it on? What’s the strangest track you’ve run through AutoTune?

PS: If you care, the band’s name is Glass Cannon. The album is due out whenever it is done, which, at this rate, might be a while…

Bing, Yahoo!, Google and the Ad Serving Internets

Filed under: Work — Tags: , , , — Bryan on Jul 1st, 2009 @ 4:27 pm

I run a few websites (lets just say over a dozen) so I generally spend a lot of my time optimizing and tweaking these sites. My first site, a free guitar lesson resource, survives solely off of Adsense. I like Adsense, its easy to use, is extremely popular, and there are is no shortage of willing advertisers.

I receive decent traffic from all three of the big search engines, and while the night may still be quite young, I can already see which site I am leaning towards as my favorite search engine…

A comparison of revenue earning power.

Thanks to Google Analytics’s handy Adsense integration, I can see exactly which keywords will give me better eCPM, or “the estimated revenue from AdSense per thousand ad page views”. Out of my largest referrers, the highest eCPM earners are…

  1. Bing with 425% of average eCPM!
  2. Yahoo! with 188% of average eCPM.
  3. Direct (no referral) at 98% of average eCPM.
  4. Google with 71% of average eCPM.

Now these numbers should be taken with a grain of salt, I haven’t controlled for other variables, like landing pages, keywords or traffic numbers. However, a cursory overview tells me that any set of numbers with a extreme deviations from the average warrant further investigation. Discuss this, I will.

What’s going on?

Well, Bing and Yahoo! both rank me much, much higher on my target terms than Google (think top 5 vs. top 50). So right off the bat, I am thinking of this in a couple ways:

  1. Bing and Yahoo! are both sending me much more relevant traffic. Therefore the users are more engaged with the site, and are more willing to explore relevant advertising offers.
  2. Bing and Yahoo! are both sending me much less relevant traffic. Therefore the users are less engaged with the site, and want to click away from the site through advertisements.
  3. Google users are more web savvy, and tend to ignore the branding of the the Google Adsense ads (they do have a distinct look).

Well which is it? Well, let me bring in some more information: bounce rates. Bounce rates are great indicators of whether people stick around on your site or not, the lower the bounce rate, the better. Low bounce rates mean users spend more time on your site, time that is likely to translate to favorable actions (bookmarking, ad clicking, etc.), so there might be a little harmonizing amongst the data… Let us explore:

  1. Yahoo! with a BR of 38.06%.
  2. Bing with a BR of 39.52%.
  3. Direct (no referral) with a BR of 45.37%.
  4. Google with a BR of 50.98%.

Anyway you slice it, this doesn’t look good for Google. Google has the highest bounce rate of the bunch, even higher than the site average. Yahoo! and Bing are both neck and neck. And they make me more money per click-through, Win-win! However, in all fairness, they are sending traffic from different search terms. Yahoo! and Bing just seem to be better at choosing relevant search terms at the moment.

The last theory I put forth was one that suggests that Google users are a little less advertisement prone than their counterparts at Bing and Yahoo!. Perhaps this is true since most folks are learning of Bing through Microsoft’s big ad campaign. Sheeple in, sheeple out. Coincidence!? Probably. Who knows.

Why is it so?

Well, in reality, it may not be so. The data isn’t very normalized. In fact, as of right now, both Bing and Yahoo! combined only send about 1/5 of the traffic Google sends. But this number is growing everyday, so we’ll have to come back in a couple months to see if this changes.

But as for now, I am thinking Bing and Yahoo! are both ranking me better for keywords I know my site is good for. Google just seems to be pickier (and a little less efficient in this case). My suggestion would be to get you some Bing traffic and see for yourself.

Whoever is reading this and has a soft spot for statistics of any sort, perhaps you can put forth some clarifications or suggestions. I’d love it.

Edit: Now with the Yahoo!/Bing deal, let’s hope these numbers hold up and more traffic comes pouring through. :-)

Yukon Ho!: A Retrospective

Filed under: Life of Bryan — Tags: , , — Bryan on Jun 9th, 2009 @ 12:52 am

yukon ho!The times I’ve been caught talking to myself I was saying things like “Bryan, you won’t be doing any of that boring personal life blogging will you?“, to which I would answer: “No, of course not“. Please note, I’ve denounced drinking on more than one occasion/morning, and we all know that wagon skipped town long before I got a chance to hop on (“You’ll get hop-on’s“). So, let me just get the relapse out of the way: I vacationed in Alaska/the Yukon and it was a hoot. Let me tell you about it.

Let’s talk a little about our group (we were in a tour group, just like the original Alaskan explorers!). First off, we had the venerable Scott, the twenty something law student leading the charge. With the single exception of some lovely young ladies from Chattanooga, mostly everyone in the tour was old and boring. No offense to old and/or boring people, of course. Who am I kidding, you don’t use the internet anyways.

Though we did stop at every expansive view, where we would all topple out of the bus, the majority of our time was spent riding a bus. I won’t elaborate.

Because lists are easily digested, let’s just list the things we did by the order of coolness:

  1. Plane ride over glaciers. This was just good ol’ fashioned awesome. You really have no idea what you are dealing with when it comes to the great white north until you see it from the sky. Really. Just look.
  2. Kyle’s first three (legal?) beers. They seem to grow up so fast! Especially when you cross a border where the drinking age is lower…
  3. White water rafting in the Nenana river. This was very cool too. I’m man enough to admit I was the only white water virgin on the raft that day. Good thing the Tennessee family went with my little brother and I, otherwise we’d had been the only two in the raft.
  4. Old junk at the gold dredge. I’m a sucker for rustic like junk artifacts (read: not trash). I just love taking photos of old equipment because it’s so freaking cool. It is also easy to do and makes me feel like a big-boy photographer.
  5. Panning for gold. Though I didn’t find much, my little brother found a little. So did my parents. About $30′s worth combined.

You can check out our entire Helmig Family Flickr photostream for the photos, we’ll be adding them regularly. Not sure if any of the tour members will ever run across this, but if you do, drop a comment and say hi!

Let’s J.am – Collaborative Music

Filed under: Work — Tags: , , , — Bryan on May 3rd, 2009 @ 12:36 am

Just this weekend, I launched my take on collaborative music online. I am sure there are already sites out there that do this, but I wanted to focus on the layering concept of creating music with a multitrack editor. Anyone who’s ever recorded with a single microphone knows the process of layering subsequent tracks well. You start with a click track or something similar and build up from that, one layer at a time.

I really think that this process opens up a ton of new possibilities in music creation by allowing people from all musical backgrounds to share and mix increasingly unique songs. We even provide the free drum samples if you can provide the beats.

It’s 100% free and you can check it out at http://letsj.am. I encourage you to log in and post a few tracks or layers yourself. There’s also a tutorial/wiki if you want to learn a little about the process. Feel free to leave a comment or suggestion here, or drop me a message.

Center of Gravity Calculation / Calculator

Filed under: Help — Tags: , , , — Bryan on Mar 31st, 2009 @ 7:11 pm

So I’m doing homework, and this center of gravity thing is pretty cool. In Location Strategy they use it to find the best location for stores and such on an X-Y plane with points that have certain weights or populations. “Well that’s neat,” I thought to myself. “I’ll make a little calculator using AJAX and PHP.” Because I really have nothing better to do.

It’s a pretty simple center of gravity calculator, just put in the weights first, seperated by comma’s, then the X coordinates and finally the Y coordinates. You should have the same number of each, if not, well, it’s just wrong. You should get two numbers back, these are the (X,Y) coordinates of the perfect center of gravity.

Enjoy my fancy “Center of Gravity Calculator” that I wasted 25 minutes minutes creating.

Enter weights here:

Enter X coordinates here:

Enter Y coordinates here:

Tag Description Plugin For WordPress

Filed under: Work — Bryan on Mar 28th, 2009 @ 12:05 pm

This has been added in 2.8! Don’t install this if you have 2.8! Read this instead.

This little plug-in adds a fancy little description field to the “Edit Tag” pane in WordPress. It also adds a function called single_tag_description(); that does just that but only on the tag page. Not really sure why the tag description isn’t available by default, seems like it would be pretty useful. Basically, you can describe your tags and echo that description on each tag page with the above function; pretty simple!

Please enjoy and note that some of the code came from a thread I read on WordPress.org, but some of it came from extracting similar core code, I just made it into a WordPress plugin. Download it now.

Was That Guy In…?

Filed under: Interesting — Bryan on Mar 4th, 2009 @ 12:43 pm

Well, I just put together a little mini web-app with AJAX jQuery goodiness called Was That Guy In…?. The basic is concept is this:

Sometimes I am watching a movie and I notice an actor or actress that I think was in some other movie I had previously seen. Unfortunately, I rarely know thier name and I don’t feel like searching IMDB for the character name to find out. I want to know if he/she was and who they played.

So, I made this app. You just put in the name of two movies and it will tell you who was in both of them. It does a pretty good job going deep in the cast, but isn’t perfect. Sometimes Car Driver #1 (uncredited) is that guy you thought you saw. In that way, it can be pretty powerful.

Also, it has been brought to my that IMDB has already done this common search thing before me. That’s fine. Mine’s prettier and has AJAX and is much more specialized in finding actors. Their’s kind of sucks, no offense.

Vostro 1400 Windows XP Driver Pack

Filed under: Help — Tags: , , , — Bryan on Feb 26th, 2009 @ 9:55 am

I came across this little guy today while I was trying to track down a pesky audio driver for Windows XP. It seems to contain the entire driver profile for the Vostro 1400 so you no longer have to search for each of them individually. Nothing like being punished for not wanting Vista.

By the way, this contains the NVIDIA 8400 driver, and not the integrated Intel video driver. Sorry, that means you have to hunt down *one* driver… (Hint: its right here.)

Why Dell or other manufacturers don’t do this is beyond me. How hard is it to build a system that uses your service tag to zip/bundle the correct drivers on the fly? Maybe I should build something like that, but I’d probably get sued into oblivion by all the overzealous big company lawyers.

Download the driver pack here.

Magatheme: Cool Minimal WordPress Theme

Filed under: Work — Tags: , , , , , — Bryan on Feb 9th, 2009 @ 12:05 am

If you’d like some customization done on the theme, I refer you to the stellar Magatheme Pro Package WordPress Magazine Theme with customization! It’s got all the options you all asked for, built-in! Everything from an awesome tab slider and homepage layout to drop down menus and a couple subtle color schemes are ready out of the box. So check it out!

magatheme minimal wordpress theme screenshootWell, I just got finished with the brand new Magatheme (1.0.5)! Ultimately, I’ll incorporate a full front page outline (Pro Edition), just like your favorite magazine themes have, but until then you’ll just have to enjoy this classy, minimalistic WordPress theme just like any other Plain Jane theme.

But wait! If you download within the next 15 minutes you get…

  • A classy, minimalistic design!
  • 3 column, golden ratio deduced layout!
  • A cool, slightly blue ice color scheme!
  • Six sidebars! Count them, six!
    • Wide Sidebar
    • Left Sidebar
    • Right Sidebar
    • Left Footbar
    • Mid Footbar
    • Right Footbar
  • Completely valid XHTML and CSS!
  • WordPress 2.7 compatibility!
  • Zebra striped comments!
  • Highlighted author comments!
  • (Pro) Selectable magazine or blog style homepage.
  • (Pro) Over 15 widget ready locations.
  • (Pro) 4 color schemes.
  • (Pro) No-edit ad and tracking integration.
  • (Pro) Feedburner integration.
  • (Pro) Drop down menus and fancy homepage tab slider.
  • (Pro) Hide/show author, date, categories, tags, and comment sections.

Leave a comment below and let me know what you think of the theme! I’d love to hear it. Perhaps your suggestions will make it into the next version.

PS: I haven’t tested IE6 yet, let me know if it works for you! It works in IE6!

Download it now! or View the Demo! or View the Pro Demo!

« Previous PageNext Page »
All articles are licensed under a Attribution-Noncommercial-Share Alike 3.0 Unported License. All files/themes are released under the GPL License where applicable. © 2012 Bryan Helmig Hosted on Webfaction.