Coding Projects Python

asyncio: an interlude

Published · 3min

Yesterday’s entry contained some issues I didn’t notice until later. The main one is that after the initial successful test, I’d notice that the client would start to disconnect. There’s no explicit timeout on the connections, so this might be either some underlying socket timeout or …

Coding Projects Python

A simple asyncio client

Published · 2min

In the last entry, I implemented a ‘chat’-style protocol. Using loop.create_connection(), I can reuse ChatProtocol, but with a different client implementation to allow some interactivity. I’m assuming the server is in the same directory as this file so ChatProtocol can be imported from it.

import asyncio

from …
Coding Projects Python

Exploring asyncio protocols

Published · 4min

In the last entry, I managed to get a very basic daemon running. Now I need to flesh out the initial Protocol implementation to first turn it into a proper echo server and then implement a simple parser for a ‘chat’-style protocol.

The first bit is at least easy …

Coding Projects Python

Starting with asyncio

Published · 3min

I have an old project called uwhoisd from a previous life. It’s been about eight years since I last did anything significant with it. It’s now largely obsolete owing to the ICANN policy changes partially forced by the GDPR, but I’d like to use it as a …

Coding

A TOTP implementation

Published · 3min

Here’s a TOTP (RFC 6238) implementation I submitted to a library. The PR was rejected because the maintainer considered it out of scope, but the implementation is fine.

I’ll be deleting the branch, but I figured I’d might as well store it here for posterity.

import base64 …
Coding

Notes from Real World OCaml, chapter 7, part 2

Published · 4min

Covering the second part of chapter 7, which deal with exceptions and backtraces.

Coding

Notes from Real World OCaml, chapter 7, part 1

Published · 4min

Covers the first prat of chapter 7: error-aware datatypes and exceptions.

Coding

Notes from Real World OCaml, chapters 4 and 5

Published · 2min

Covers records and program structure (files, modules, and programs).

Coding

Notes from Real World OCaml, chapter 3

Published · 2min

Covers lists and patterns.

Coding

Notes from Real World OCaml, first edition

Published · updated · 17min

Because it’s been so long since I’ve done anything in OCaml, I’m going through Real World OCaml. I have the first edition, and though the second edition came out earlier this month, it’s the original that I’m going through. I’m hoping this is useful …

Coding

Picking up Lua again

Published · 3min

I recently resurrected my old original Raspberry Pi B+ and installed NetBSD on it. Currently, it’s acting as a bastion for my local network, but I’ve been thinking of other projects I could do with it. One of those is to build something like Pi-Hole with it, as …

Coding

Creating AWS Lambda functions in Python with dependencies

Published · 1min

This assumes you have a package called mylambda and a requirements.txt file listing your dependencies.

build.sh:

#!/bin/sh

tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT

pip install -r requirements.txt -t "$tmp_dir"
cp -R mylambda "$tmp_dir/mylambda"

here=$(pwd)
(
    cd $tmp_dir
    zip -r -9 $here/lambda.zip …
Coding

Custom attribute values in Django form field widgets

Published · 1min

This has frustrated me for so long.

If you want to use checkboxes in a form in Django, the obvious choice is BooleanField. There are times it would be really useful to have the value attribute filled out, but by default, Django just checks for the presence of the field …

Coding

What monads are

Published · 2min

It’s almost like a rite of passage for a developer to write a monad tutorial.

Well, this isn’t a monad tutorial. This is simply an effort to put an end to some of the nonsense that leads to monad tutorials being written in the first place and all …

Coding

How I use git

Published · 3min

My git workflow for anything non-trivial is pretty straightforward, but a little different from what I’ve seen others describe. I’m almost certainly not the only person out there who uses this workflow, so I’m certainly not claiming any originality.

There seem to be two camps, both based …

Coding

type() vs. isinstance() in Python

Published · 1min

One elementary error people make is using the type() function where isinstance() would be more appropriate1.

If you’re checking to see if an object has a certain type, you want isinstance() as it checks to see if the object passed in the first argument is of the type …

Coding

Scoping and use of the ‘global’ keyword in Python

Published · 3min

[Here’s something I knocked up for one of my co-workers who’s an experienced developer, but a Python neophyte. It may be useful to others.]

As in PHP, the global keyword in Python declares that any reference to a given variable name within the scope of a function or …

Coding

Minesweeper Kata

Published · 2min

I did the minesweeper kata a few days back. It was a bit too easy, though it’s quite possible that this is more an artifact of how I approached it. Given that it’s a simple one, it might be an idea to see if I can take it …

Coding

Harry Potter Kata

Published · 4min

I did the Harry Potter Kata earlier because I was feeling a little bored. Here’s the result. I use cents rather than euros as my unit of currency here.

I’d a start when I was thinking about how I’d solve the problem. I thought that being greedy …

Coding

Quick hacks: Python netstring reader

Published · 2min

I’m writing a proof-of-concept server for a less jokey version of the SRGP. The protocol is more or less SRGP, but it doesn’t use MIME-style headers each request is made up of a series of netstrings. The header and body sections are terminated with empty netstrings, i …

continue   →