Developing asynchronous networking applications is an interesting problem with unique challenges and no shortage of solutions for, particularly in Python. But the way you’ve traditionally had to write your code to make it work well could leave you with a codebase that, while solid, could be challenging to read or follow.
I’ll take you through a quick introduction to what asynchronous networking is, show you a callback-based asynchronous implementation using the venerable and excellent Twisted, and then finally show you how Python’s new asyncio library uses coroutines to solve the problem in a whole new way.
Read more on Turning Asynchronous Networking Inside-Out…
Often times, when writing Python, I run into a situation that requires me to write a simple validation function.
return item.value_to_check > 0
This function is easy to test, and it’s clear what it’s supposed to be doing. But as so often happens, I may need to validate more than the single attribute I originally checked.
Read more on Using the Command Pattern to Write More Testable Python…
Functional programming has a lot of advantages that have been enumerated over the years. Being a bit of a Pythonista, myself, I can’t help but introduce functional concepts into my Python code. Though Python is not a functional language, it doesn’t mean that your Python code can’t benefit from some of these concepts.
Perhaps one of my favorite illustrations of functional Python comes in the treatment of loops — or more accurately, their removal from my code. Before I demonstrate how to do that, allow me to introduce a very contrived example.
Let’s say you’ve parsed a configuration file into a list of lists, and you need to be able to access a particular settings by keyword. The following snippet does exactly that in a traditional format.
configurations = [["name","Bob"], ["email","email@example.com"], ["template","dark"]]
def get_config_value(desired_key, configs):
for key_value in configs:
if key_value == desired_key:
print get_config_value("name", configurations)
This code works well, but I find the nested statements less than ideal. Read more on Writing Functional Python…
There’re a couple of ways to distribute iOS apps. Everyone knows about the App Store, but the more obscure modes of internal distribution are less common and more opaque. For instance, if you’re experimenting with Enterprise in-house distribution, you’re likely using some sort of mobile device management software. But what if you are a developer trying to test out builds for in-house distribution?
While my favorite way to distribute apps while testing is with TestFlight, device provisioning becomes a pain past a handful of testers. Another way to test a production distribution artifact is to simply sync a device through iTunes after adding your app. The problem I ran into with this method is that it seems to require that you wipe and sync the device as your own… not something I want to do with company-owned testing devices, nor my client’s devices.
Read more on Testing In-House iOS Apps with a Simple Python Web Server…
This semester I’m enrolled in a Visual Computing class at Oakland University. The class is centered around the theory of digital image processing, however I was craving some implementation. During our lecture on bit plane slicing, I became intrigued with its application to image compression and was curious about what sort of performance it could achieve.
Grayscale digital images can be thought of as a matrix of pixels with intensities (values). In an 8-bit image, these values range from 0 to 255. The bit planes of an 8-bit grayscale image can be thought of as the stack of 8 binary images, containing only white or black pixels. Each pixels value is determined based upon the binary representation of its intensity. The first bit plane contains a set of pixels whose least significant bits are on, and the 8th bit plane contains the set of pixels whose most significant bits are on.
Read more on Novel Image Compression Using Bit Plane Slicing…
Recently I’ve been working on a .NET app that communicates with multiple internet end points. Each end point is a data collector, and numeric data is retrieved over these connections in real time.
It is important for the app to be able to do some analysis of the data, such as minimum and maximum value, or the rate of change of a value. In order to write meaningful system tests over this functionality, I needed to simulate the data that will be generated by the end points.
Read more on Real-time Generation of Numeric Data Fixtures in IronPython…