Skip to content

Tag: python

Memory dump formatted like xxd from gdb

I’m trying to inspect a buffer which contains a binary formatted message, but also contains string data. As an example, I’m using this C code: I’d like to get a hex dump of what’s in buf, of a format similar to xxd (I don’t care if it’s an exact match, what I’m really…

Is python zipfile thread-safe?

In a django project, I need to generate some pdf files for objects in db. Since each file takes a few seconds to generate, I use celery to run tasks asynchronously. Problem is, I need to add each file to a zip archive. I was planning to use the python zipfile module, but different tasks can be run in differen…

How do you get the magnitude of a vector in Numpy?

In keeping with the “There’s only one obvious way to do it”, how do you get the magnitude of a vector (1D array) in Numpy? The above works, but I cannot believe that I must specify such a trivial and core function myself. Answer The function you’re after is numpy.linalg.norm. (I reckon…