Skip to content

Instantly share code, notes, and snippets.


Herbert Shin initbar

View GitHub Profile

Comments on optimizations around string concatenation.

Note: The code links are to CPython 3.8.5, the most recent release when this was written.

I was recently asked about a performance optimization in CPython around using += and + for string objects. As some people may already know, if you use += or + a string, it can sometimes be just as fast as ''.join. The question was to explain when that optimization couldn't be performed.

We will be going through the following example scenarios:

nadavrot /
Last active Nov 20, 2022
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).


Matrix multiplication is a mathematical operation that defines the product of

anonymous /
Created Dec 21, 2017
Face alignment scripts based on 1adrianb/face-alignment
import argparse
import cv2
import dlib
import json
import numpy
import skimage
from pathlib import Path
from tqdm import tqdm
from umeyama import umeyama
georgexsh /
Created Sep 18, 2017
python goto with system trace function
import sys
def j(lineno):
frame = sys._getframe().f_back
called_from = frame
def hook(frame, event, arg):
if event == 'line' and frame == called_from:
frame.f_lineno = lineno
simonw /
Last active Oct 23, 2022
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using and

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
dbehnke /
Created Mar 18, 2014
Python AsyncIO Client and Server Example using StreamReader and StreamWriter
""" - AsyncIO Server using StreamReader and StreamWriter
This will create 200 client connections to a server running
It will handshake and run similar to this:
Server: HELLO
Client: WORLD