Feb
29

Must Read This Later

A comparison of scripting languages.

Aug
29

Bad Error Message is Unhelpful

So, I’m still learning Django and have a long ways to go, but the following error is extremely unhelpful:

“TemplateSyntaxError: Invalid block tag: ‘else’, expected ‘else’ or ‘endif’”

The problem is, Django doesn’t do else if, but my editor does highlight it as if it’s correct. You then get this error message, but have to run through the docs to figure out that they want you to nest if/else blocks to create “else if.” Slightly frustrating, and causes me to write some questionably ugly code. Blegh.

Jul
21

__new__ vs. __init__

While running around debugging some timeouts with a coworker we came across __new__. Of course we were then curious as to what __new__ was and how it was different than __init__.  There was a good explanation on StackOverflow.  Although I understand it now, I’m not sure when I would need to subclass an immutable type.  Anyone?

Jul
06

I’m going to waste so much time with this

http://www.incredibox.fr/bigbox_en.swf

IT MAKES MUSIC!!!

Jul
06

The Balloonist

Not my joke, but hilarious:

A woman in a hot air balloon realized she was lost.

She reduced altitude and spotted a man below. She descended a bit more and shouted: ‘Excuse me, can you help me? I promised a friend I would meet him an hour ago but I don’t know where I am..’

The man below replied, ‘You’re in a hot air balloon hovering approximately 30 feet above the ground. You’re between 40 and 41 degrees north latitude and between 59 and 60 degrees west longitude.’

‘You must be an Engineer,’ said the balloonist.

‘I am,’ replied the man, ‘how did you know?’

‘Well,’ answered the balloonist, ‘everything you have told me is probably technically correct, but I’ve no idea what to make of your information and the fact is, I’m still lost. Frankly, you’ve not been much help at all. If anything, you’ve delayed my trip by your talk.’

The man below responded, ‘You must be in Management.’

‘I am,’ replied the balloonist, ‘but how did you know?’

‘Well,’ said the man, ‘you don’t know where you are or where you’re going. You have risen to where you are, due to a large quantity of hot air. You made a promise, which you’ve no idea how to keep, and you expect people beneath you to solve your problems. The fact is you are in exactly the same position you were in before we met, but now, somehow, it’s my f**king fault.’

May
31

MacVim BClose

There are two ways to close buffers in MacVim:

1) :bd (Buffer Delete)
This deletes one buffer, but the problem is, it won’t open it again during that session.

2) :q (quit)
This closes ALL the buffers and the app.

Neither does what I want most of the time, but I found this: http://vim.wikia.com/wiki/Deleting_a_buffer_without_closing_the_window

It’s a small plugin to allow you to close buffers without closing the window or not being able to get back to hit. Saweet!

May
16

Git Is Finicky

So, we have a release happening soon, and I needed to cherry-pick a few essential changes into the release candidate and upon trying to push them, I was told everything was up to date. ORLY NAO? Apparently, every now and again Git decides it wants to mess with me, and today is one of those days. Local branches created from the release candidate just don’t want to push without this workaround from stackoverflow.

99% of the time I love git. 1% of the time it makes my life hell. Could be a PICNIC error.

Apr
28

Tweepy – Python Twitter Library

It‘s pretty awesome and easy to use.  The whole oauth circle is a nice thing to know, but it’s major headache the first time around.  Tweepy hides a lot of the not so fun parts and sets up a simple interface.  So, I’ll assume we can forward past the whole registering a Twitter account in order to get a consumer and secret key and move on.  So in order to hook up your user to their Twitter account for a web app, it’s just these easy steps (note, the code is chopped from some prod code, so a few things have been pseudo-coded for generic reasons):

1) Get the auth url:


def get_authorization_url(user_id):
    auth = tweepy.OAuthHandler(consumer_key, secret_key)
    url = auth.get_authorization_url()
    return url #or redirect to it, or whatever you want

2) Receive their token and verifier, then store for later use:


def authorize(user_id, token, verifier):
    auth = tweepy.OAuthHandler(consumer_key, secret_key)
    try:
        auth.set_request_token(token, secret_key)
        token = auth.get_access_token(verifier=verifier)
        attach_token_to_user(user_id, token.to_string())
        return WHATEVERYOUWANT
    except tweepy.error.TweepError as e:
        log.exception("some exception")
        raise InvalidAuthorizationError() #my custom error

3) Use later:


def post_to_my_feed(user_id, twitter_username, tweet):
    try:
        token_string = get_auth_token_for_user(user_id)
        if not token_string:
            raise AccountNotLinkedError()
        token = tweepy.oauth.OAuthToken.from_string(token_string)
        auth = tweepy.OAuthHandler(consumer_key, secret_key)
        auth.set_access_token(token.key, token.secret)
        api = tweepy.API(auth)
        api.update_status(tweet)
        return WHATEVERYOUWANT
    except tweepy.error.TweepError as e:
        log.exception('Something went wrong: appropriate error message')
        raise SomethingWentWrongException("some good message")

Apr
05

MacVim PEP-8 Helper

To follow along with PEP-0008 standards, there is a command that will highlight any characters beyond the 79 char limit.  It’s a useful little reminder that you’ve reached your limit.

:match ErrorMsg '\%>79v.\+'

Mar
30

Sphinx Docs

So we’re adding auto-doc’ing capabilities to Nudge, and I’m in charge of Sphinx docs right now.  They’re a PITA…  One space is off? FFFFFFUUUUUUUUUUUUUUUUUUU.  Yup about that awesome.  They also don’t like having table items be longer than the column separators.  I’m not sure what they’re really called, but they’re the set of = signs used to surround the column headers and the data.  SO, given the varied length data in a table, you have to do some fancy trickery to get them to line up perfectly.  TIL you can multiply a char (C) by an int (N) and get a resulting string of length N filled with C.

SO:
"x" * 2 = "xx"
and
"c"*4 = "cccc"

 

Fancypants! Any other language and it would probably barf on you saying you can’t multiply things of char type with things of int type.

 

Older posts «