Today’s blog post is going to contain fairly advanced Python hackery. We’ll take two functions — one is a wrapper for the other, but also adds some positional arguments. And we’ll change the signature displayed everywhere from the uninformative f(new_arg, *args, **kwargs) to something more appropriate. This blog post was inspired by F4D3C0D3 on #python […]
Author: Chris Warrick
Python Virtual Environments in Five Minutes
In Python, virtual environments are used to isolate projects from each other (if they require different versions of the same library, for example). They let you install and manage packages without administrative privileges, and without conflicting with the system package manager. They also allow to quickly create an environment somewhere else with the same dependencies. […]
Pipenv: promises a lot, delivers very little
Pipenv is a Python packaging tool that does one thing reasonably well — application dependency management. However, it is also plagued by issues, limitations and a break-neck development process. In the past, Pipenv’s promotional material was highly misleading as to its purpose and backers. In this post, I will explore the problems with Pipenv. Was […]
Spawning subprocesses smartly and securely
As part of your code, you may be inclined to call a command to do something. But is it always a good idea? How to do it safely? What happens behind the scenes? This article is written from a general perspective, with a Unix/C bias and a very slight Python bias. The problems mentioned apply […]
Gynvael’s Mission 11 (en): Python bytecode reverse-engineering
Gynvael Coldwind is a security researcher at Google, who hosts weekly livestreams about security and programming in Polish and English). As part of the streams, he gives out missions — basically, CTF-style reverse engineering tasks. Yesterday’s mission was about Elvish — I mean Paint — I mean Python programming and bytecode. MISSION 011 goo.gl/13Bia9 DIFFICULTY: […]
Setting up a Python development environment
Setting up Python is usually simple, but there are some places where newcomers (and experienced users) need to be careful. What versions are there? What’s the difference between Python, CPython, Anaconda, PyPy? Those and many other questions may stump new developers, or people wanting to use Python. Note: this guide is opinionated. Contents Glossary and […]
Unix locales vs Unicode (‘ascii’ codec can’t encode character…)
You might get unusual errors about Unicode and inability to convert to ASCII. Programs might just crash at random. Those are often simple to fix — all you need is correct locale configuration. Has this ever happened to you? Traceback (most recent call last): File “aogonek.py”, line 1, in <module> print(u’u0105′) UnicodeEncodeError: ‘ascii’ codec can’t […]
Structuring and automating a Python project with the Python Project Template
To create a project that other people can use and contribute to, you need to follow a specific directory structure. Moreover, releasing a new version should be as simple and painless as possible. For my projects, I use a template that has the structure already in place, and comes with automation for almost every part […]
Code writing code: Python and Vim as development aids
Recently I was working on some C# and Java code. And along the way, I used Python and Vim to (re)write my code. A small Python script and a 6-keystroke Vim macro did it faster and better than a human would. Every programmer should learn a good scripting language and use a programmable editor like […]
Deploying Python Web Applications with nginx and uWSGI Emperor
You just wrote a great Python web application. Now, you want to share it with the world. In order to do that, you need a server, and some software to do that for you. The following is a comprehensive guide on how to accomplish that, on multiple Linux-based operating systems, using nginx and uWSGI Emperor. […]
Rewriting a Flask app in Django
I spent Saturday on rewriting a Flask app in Django. The app in question was Nikola Users, which is a very simple CRUD app. And yet, the Flask code was a mess, full of bugs and vulnerabilities. Eight hours later, I had a fully functional Django app that did more and fixed all problems. Original […]
Static Site Generator Speed Test (Nikola, Pelican, Hexo, Octopress)
I tested the speed of four static site generators: Nikola, Pelican, Hexo and Octopress, in a clean environment. Spoiler alert: Nikola won. Disclaimer: author is a developer and user of Nikola. The test environments used were the same for all four generators. Generators tested Nikola v7.6.1, by Roberto Alsina, Chris Warrick and contributors; Python; MIT […]
New project: upass — console UI for pass
pass is the standard Unix password manager. And I just wrote a slightly friendlier, clickier interface with urwid and Python. Project page Screenshots GitHub Downloads (PyPI) upass is using urwid, which means it has a friendly full-screen console interface. It shows your directory structure (with flattened subdirectories) and calls pass when requested. (It does not […]
New project: think (Terminal Think Music)
Are you executing a process that takes a long time? Do you want to know that it’s still working while you are in another terminal/making coffee? Do you have a favorite game show tune to play while doing something? If yes: think is just for you. For more details, read on or hop onto the […]
Revamping My Projects Page with Nikola
A week ago, I was inspired to produce a new projects page for myself. The previous one was a trainwreck with a lot of hacks. Also hosted on GitHub Pages for some reason. So, considering I’m so invested in Nikola already, I produced the projectpages plugin and also made it publicly available. The plugin produces […]