This blog is now hosted at consciou.us

Monday, March 24, 2008

Singletons in Python

Since the project that I'm working on has a whole lot of nasty, boil the oceans, SQL queries, I thought it'd be best to cache information. Caching is great, but what I really need is an application-wide cache (not tied to a specific instance object).

Normally I use Singletons (from _Design Patterns_) to provide this functionality. Here's how to implement them in Python:

from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 (in the comments):

class Singleton(object):
def __new__(cls, *p, **k):
if not '_the_instance' in cls.__dict__:
cls._the_instance = object.__new__(cls)
return cls._the_instance

all you have to do then is inherit from Singleton, and it just works. This is actually cleaner than some other languages I've implemented Singletons in.

The real bonus, however, is the actual article that the posting above was about:

class Borg(object):
_state = {}
def __new__(cls, *p, **k):
self = object.__new__(cls, *p, **k)
self.__dict__ = cls._state
return self

That will share the state of the object across instances. No thinking about it.
Read more...

Alembic Pictures

We had a spot of sun this weekend, so I decided to take a break from work, and take some pictures.

Hit the link to see pictures of my 6-string Alembic Series II Balance K.










Read more...

New Classes vs. Old Classes in Python

I found a bit of daftness in Python today:


class A:
def __init__(self):
print "Rutabaga!"

class B(A):
def __init__(self):
super(B, self)

causes:

TypeError: super() argument 1 must be type, not classobj


Changing the first line to:

class A(object):


fixes it.

Now, forgive me if I think that's completely stunted. You could have at least said:

TypeError: to use super(), the superclass must have one of the built-in base classes in its inheritance path.

Read more...

Friday, March 21, 2008

Guest Blogging at Archiving 101

I'm guest blogging over at Archiving 101. Jump on over to view some of my thoughts on the need for proactive email categorization.

This will be a two part series: look for a follow on article next week. Read more...

Thursday, March 20, 2008

More Python

Some more thoughts on Python...

The fact that there don't seem to be any adjectives in the language is a bit wierd: as a Perl programmer, I'd expect to be able to declare a variable as local (I go back to Perl 4) or my, but nothing equivalent in python.

Declaring static methods is wonky, but at least they are there, so I can make Singletons.

For those of you who haven't read Design Patterns, a Singleton is a way to implement classes that you only load once. For instance, when the startup costs for the object are very expensive. In my case I'm doing a dozen or so nasty, full table-scan (on hundreds of thousands or millions of rows) SQL queries. You might guess I want to do this as few times as possible. :)

Anyhow, the lambda expressions and first class functions more than make up for it. Very nice.
Read more...

Tuesday, March 18, 2008

Game Programmers

My brother is an accountant in Silicon Valley, and this email from him nearly made me fountain Diet Dr. Pepper:

So I've serviced several of the players in Silicon Valley, from semi-conductors to networking to software. Along the way there have most certainly been some interesting characters, but none as interesting as today when I arrived at a well known gaming software company.

Gaming programmers take the cake, from thug looking kids to your classic unkempt, pale pony-tailed man that you envision casting "intimidating shout" in a battle playing World of Warcraft. I wanted to cry out "Leeeeeeeerrooooooooy Jeeeenkiiiiiiiiiiiiins" just walking into this place.
Read more...

Learning Python

I've avoided it for at least 10 years, but I finally bit the bullet.

I am developing an application in Python.

Read on for my take on what I like about Python, and what I didn't like so much.

Great stuff:

  • Functions are first class

  • Great support for object oriented programming

  • Basic feature parity with Perl

  • Great library support (I'll cover some of these in a later post)

  • Closures (all the cool kids have them)


Not so great stuff:
  • Scoping is wierd, but maybe I just need to get used to it

  • Feels wrong to not close blocks explicitly

  • Wierd __foo__ special functions, etc. (although I don't have much room to talk since I like Perl)

  • No autovivification


Random thoughts:
  • Anyone who says it has "cleaner" object orientation than Perl probably just doesn't "get" Perl.

  • Somehow, it reminds me strongly of Javascript. They are just somehow similar.

Read more...

Google Desktop as a crude forensics tool

Raise your hand if you've become de-facto tech support for your family.

I certainly have.

One of the questions I am periodically asked is: how can I get to files that have been deleted/check web browsing history/check deleted emails?

And I have the answer: Google Desktop Search (GDS)!

Read on for how it works.

You see, GDS actually keeps copies of basically everything that you do.

Your emails
Your web browsing history
Your files

And it can even present these in a timeline view.

Pretty amazing, although it might create some surprises if you, say, "thought you deleted that email".
Read more...

Friday, December 28, 2007

Priceless

Going to the Apple Store ... $0
Looking at iPhones ... $0
Logging into your personal email account with a demo iPhone ... $0

Leaving 100 of your private messages, including receipts and private correspondence on said demo iPhone? Priceless.

Yes, I did actually see this. Maybe it says something about the core demographic for the iPhone (I kid!)?
Read more...

Wednesday, December 5, 2007

How not to Monitor Email

This is inspired by an article over at Worse Than Failure.

If you really want to fail at email monitoring, here are some ideas:

  1. Don't tell the employees.
  2. Don't create any policies that outline acceptable use.
  3. Don't create any policies that outline acceptable monitoring.
  4. Make sure the monitoring is as intrusive as possible, bonus points for trying to be covert, but telegraphing everything to the people being monitored.
  5. Cause mail delays or blockage.
  6. Be inconsistent.
  7. Use people to review every email-- better yet, outsource it to somewhere that doesn't care about your intellectual property.
  8. Implement it without much thought towards what you wish to accomplish, a vague feeling of "we should be monitoring" is enough to start.
  9. Don't talk to the HR department.
  10. Don't talk to the Legal department.
  11. Don't talk to IT, just foist it upon them at the last possible moment.
Read more...