1. Got lightblue+bluez set up on the raspberry pi, successfully paired and connected with Macbook. Not so much success communicating, sockets only worked one way, and the OS X doesn’t seem to be able to connect to services advertised on the pi despite being able to see that they exist. Also got started with USB programming in python with pyusb — is complex, but less so than I expected.

  2. When using to send content-disposition: attachment responses, you MUST explicitly set the response encoding (charset) otherwise windows will assume the response is in whatever-weird-encoding-windows-uses, rather than UTF-8 (you are using UTF-8, aren’t you?).

    CSV example code:

    response = HttpResponse(utf_8_encoded_csv_text, status=200, mimetype="text/csv; charset=utf-8")
    response['Content-Disposition'] = 'attachment; filename=data.csv'
    

    It seems that some weird old applications like SPSS need a BOM in there as well, even though UTF-8 doesn’t have a BOM. Add that like this

    response.content = '\xef\xbb\xbf' + response.content
    

    before sending the response

    return response
    
  3. Had many basic software development lessons hammered in by personal experience over the last couple of years: hierarchy bad. side effects bad. many moving parts bad. undue complexity bad. inconsistency bad. SQL databases fragile. always be reducing.

    It’s amazing just how seductive complex, unproductive tools can be. Successfully overcome+abandoned:

    • Codeigniter
    • Doctrine ORM
    • Bootstrap
    • Backbone, Ember, Angular
    • Symfony Security component

    PHP remains productive and speedy (with composer, delightful dependency management), python nice with some irritations. jQuery useful when absolutely necessary, plain with small libraries loaded via requirejs handle most progressive enhancement concisely. node.js nice for some things, preferring go’s approach to async programming but still not much everyday need for it.

    Avoiding middlemen: LESS, SASS, Coffeescript. Unnecessary for most of my work, and more moving parts is bad.

    Now bothering me is the frameworky nonsense accumulating in . Need to cleanse.

  4. @|p^): Here I am at 5am, deciding to learn recursive functions in python, @gakera & @Hvitur_Hrafn I blame you both!

    @w03_ recursive functions are fun. Once you’ve figured them, closures and first-class functions out you’re pretty much there :)

  5. django.test.TestCase and subclasses don’t warn you if the fixtures specified in their fixtures list don’t exist — double check naming if your tests mysteriously start failing or run suspiciously quickly

  6. Watch out for dict-based string interpolation examples which look like this:

    'Hello, %(name)s' % {'name': 'Otter'}
    

    That s after the brackets isn’t pluralising one adorable aquatic mammal into a whole bunch of them, it’s actually part of the interpolation placeholder — the equivalent of

    'Hello, %s' % 'Otter'
    

    Note also that for some reason, python lets you put spaces between the closing bracket and the type signifying character. This can cause extremely weird bugs when the string being interpolated is also being translated. For example:

    _('%(customer) shared a thing') % {'customer': 'Mr. Bean'}
    

    If not translated, this will produce this confusing but fairly easy to debug output

    'Mr. Beanhared a thing'
    

    But if 'shared' is translated into a word beginning with, for example, d, you’ll just get an exception like TypeError: A float is required

  7. Also in today: learning about I2C communications. Tips+resources:

    • @adafruit have a helpful guide to Setting up your Pi for I2C — remember to reboot after enabling I2C modules
    • All commands which access I2C need to be run as root using sudo
    • If you’re not sure which address a particular device is at, run sudo i2cdetect before and after plugging it in and see which address changed
    • If there are libraries available for easily talking to the device you’re using, make use of them. Do this first even if you want to learn about the lower level communications too to ensure that your device is working correctly.
    • Get to know i2cdump, i2cset and i2cget, they’re super useful for poking around in I2C devices

    I cobbled together a class for communicating with the ADXL345 by cross-referencing between the Arduino library for that chip and Adafruit’s I2C library, only to find that someone else had done so only hours earlier!

  8. I get a little annoyed at every now and again (grr package management) but then I come across things like nested tuple unpacking which are just so lovely they make up for it:

    for i, (key, value) in enumerate(list_of_tuples):
        print i, key, value
  9. Loving Django’s prefetch/select_related — that, along with a few small changes, reduced a task which was taking > 500,000 queries to 4558

  10. tip: if you come across weird inconsistencies between apps when trying to serve static files in dev, run with runserver --insecure even if you have DEBUG=True

  11. Spent ~3 hrs with the office arduino+ethernet shield and my old favourite pyo and I’ve got a light/flex controlled synthesiser over OSC. I dread to think how many weeks it would have taken me to implement this on a PIC.