Golang Diaries I

“Some of the most popular things on this blog have been diaries I’ve written as I explore my way through a new technology or hobby. I’m picking up the Go Programming Language, whose HQ is (significantly) at golang.org and which I’m going to refer to as “Golang” for reasons which should become obvious. Whatever you thing of Golang, it’s apparently got some momentum and some seriously smart people are working on and in it; so this may actually be of service to the community.

At this point, I should tip my hat to Mark Pilgrim, who taught me that a really good time to write about something is while you’re still discovering it, before you’re looking at it from the inside…”


So I Suck At 24: Automating Card Games Using OpenCV and Python

“A friend introduced me to the game 24, a simple game you can play with a deck of playing cards. Over the course of playing the game, I realized that either my friend was really good at this game, or that I wasn’t very good at it!

Given how simple the game was, I figured that while I may not be good at the game, I could write a program that was good at it! Scoping the problem out, it was a perfect weekend hack project, and a good break from all the grant writing, research and administrivia of my job. Also, I have always been fascinated by all the cool things my colleagues in Computer Vision do, so it was a good way to learn about some of the fundamentals…”


New Werkzeug and Flask Releases


  • Werkzeug now pastes traceback into private github gists.
  • Some smaller improvements to make the HTTP exception classes in Werkzeug more useful. They can now carry some payload and aborting with exceptions is streamlined.
  • Werkzeug’s URL module now gained vastly improved IRI support and can properly parse and join URLs. This support is currently intentionally in violation with the RFC to cover real-world cases better and to support parsing of unknown schemes.

    This makes it possible for you to parse things like sqlite:///foo.db without being surprised by the behavior.

  • Werkzeug gained a lot of utility functions to support bridging the differences between PEP 333/PEP 3333 and WSGI on 2.x and 3.x. This includes access to the streams and URLs.
  • Werkzeug’s internal form parsing got vastly improved which now makes it possible to access the stream in all cases. It also no longer relies on content length which makes it possible to finally deal with chunked request bodies assuming the WSGI server provides support for it.
  • Introduced get_data methods as future proof replacement for the old .data descriptor on requests and responses. This allows greater flexibility on dealing with form data. In the future we will remove support for .data at which point attribute access on the request and response objects is largely side-effect free.


  • Flask gained a json module which unifies JSON support for 2.x and 3.x and extends it with useful helpers. It provides safe methods to dump JSON for script blocks in HTML and also automatically serializes some common types like UUIDs and datetime objects.
  • Further work has been done to make the application context more prominent. Templates can now be rendered from the application context only and flask.g is now bound to the application context as well.

    This change might seem tiny but actually simplifies working with Flask from outside web environments. You can now easier maintain database connections that are not bound to a HTTP request’s lifetime.

    The documentation also has started to shift to this new mode of working.

  • Flask’s internal error handling has been improved to make responding to error cases more consistent. This also has the added benefit of making the “commit on success, rollback on error” finally fully reliable. Previously the test client would suppress the error information in some cases.
  • Introduced a get_json method on the request to go in line with Werkzeug’s new get_data method. The plan here is to remove support for the .json descriptor at one point.
  • Added a few configuration options to change defaults for JSON serialization. This includes pretty-printing and ordering of keys. By default JSON objects are now ordered by keys to solve issues with invalidating HTTP caches due to Python’s new randomized hash seed…”