Posts Tagged code

Surprising Change in Python 3.7.6

Here's a surprising change for you: Python 3.7.6 (ostensibly, a patch bugfix release) totally changed how URLs are parsed by Python programs.

As of Python 3.7.5, a URL like foo:8888 would be parsed into the following:

>>> urllib.parse.urlparse('foo:8888')
ParseResult(scheme='', netloc='', path='foo:8888', params='', query='', fragment='')

As of Python 3.7.6, foo is now detected as the scheme:

>>> urllib.parse.urlparse('foo:8888')
ParseResult(scheme='foo', netloc='', path='8888', params='', query='', fragment='')

This will cause massive chaos if you are ever parsing URLs with ports in them but without schemes …

read more

Serialization Format Performance

Most of the work done in actual programming jobs is taking structured data in some particular format from one system, slightly tweaking it, and sending it off to some other system. When exchanging data between different processes, it's almost always necessary to serialize it into a series of bytes which can be sent across a dumb byte-oriented transport (such as TCP). There are hundreds upon hundreds of different serialization formats out there, but I just wanted to talk about a few of the most common that folks use with the Python programming language.

All of these have the following properties …

read more

<3 sed

I wrote a fun sed script today:

sed -E -n -e ':t ; s/(.{21})(.*)/\\bf\{\1\}\n\2/ ; p ; s/\\bf\{(.*)\}\n.*/\1/ ; h ; :q { n ; G ; s/(.{21})(.*)\n\1/\2/ ; tp ; s/(.+)\n.*/\1/ ; bt} ; :p { P ; bq }'

Short, but effective. Can you figure out what it does?

(solution after the break)

Here's an example of what it does:

Sample Input:

000000000000000000000 l0
111111111111111111111 l0.5
111111111111111111111 l0.7
222222222222222222222 l1
222222222222222222222 l2
222222222222222222222 l3
333333333333333333333 l4
333333333333333333333 l5
000000000000000000000 l6

Sample Output:

jbrown% sed -E -n -e ':t ; s/(.{21})(.*)/\\bf\{\1\}\n\2/ ; p ; s/\\bf …
read more

*nix Tip of the Day: Waiting in Scripts

Scripting is what makes Unix-like operating systems great. Every *nix, be it Linux, BSD, OS X, AIX, Solaris, or whatever other random distribution you can come up with, comes with a capable shell (or three) and a good set of basic utilities. Where a Windows administrator has to either fall to the horror that is Batch files, write code in a big, heavy programming language language, or submit to the terrible dominance of “management utilities”, a Unix system administrator has tons of the tools at his disposal to fix and automate things. I could talk about scripting forever (it is …

read more

Github

Brief post. I decided to actually use Github once in a while now (not in the least because I use it for open-source stuff at work). My page is up at github.com/Roguelazer, and the work account which I'm a contributor on is at github.com/Yelp. So, uh, feel free to comment on or improve any code that you see thereabouts.

Also, I am thinking about doing a series on git on this blog, since I get to use it rather quite a lot now, and there definitely aren't enough guides to it on the Internet yet. Yes …

read more