Blog Posts by Date
Concurrent Python programming with async, threading, and multiprocessing
February 07, 2024 / 48 min read / 9,302 , 3 , 4
One of the best ways to achieve significant speed improvements in Python code is through concurrency: doing several tasks simultaneously. In this article, I describe concurrency in Python and give some examples of running Python code concurrently with “async” functions, “threading,” and “multiprocessing.”
How to hot reload FastAPI and Flask apps on HTML, CSS, and Javascript changes
November 16, 2023 / 5 min read / 7,894 , 1 , 1
In this tutorial, I'll show you how to automatically hot-reload your FastAPI and Flask projects that use template engines like Jinja with web servers like uvicorn or gunicorn. After reading, you will be able to automatically restart your server and refresh your browser when Python, HTML, CSS, and other files change—no manual intervention required.
Better parameterized pytests with dataclasses
September 14, 2023 / 23 min read / 5,915 , 7 , 0
Parameterization is a powerful tool in pytest (the most popular Python testing framework). It allows us to write a single, simple test that can dynamically expand to become many similar tests with minor input differences. In this blog post, I will describe how to write parameterized pytests and why they are such a powerful tool. And then, I'll show you how to re-write parameterized tests more effectively using dataclasses.
Python web scraping with Playwright
December 14, 2022 / 22 min read / 5,917 , 1 , 0
Web scraping is the concept of programmatically collecting data from a website. This article will discuss using Playwright for python web scraping. The most popular web-scraping packages for python are requests and Beautiful Soup used together. This combination is potent and straightforward to use for most web pages. However, the use case has limitations because the combination relies on making server requests and reading the static HTML returned. It can be challenging to scrape single-page applications (SPAs) or websites where the objects to scrape are only available after some javascript interactions. Playwright circumvents these limitations by interacting with web pages like humans to find the data that needs scraping.
Cookies with the Flask web framework
October 18, 2022 / 12 min read / 5,178 , 1 , 0
Cookies! 🍪🍪 Tasty snack or valuable web development tool? 🤷♂️ For our context today, cookies are small pieces of data sent from the server to the client. The client's browser stores cookies locally and then sends the cookies back to the server with every request. Cookies are used for a variety of purposes, including session management (who's logged in?), keeping track of user settings (use dark mode?), and tracking user behavior (website analytics, ad targeting). In this tutorial, we'll talk about how to manage cookies with the Flask web framework. We'll go over setting, updating, retrieving, and deleting cookies in Flask routes.
How I went from no coding experience to coding for a living in one year (a guide)
September 15, 2022 / 85 min read / 12,019 , 5 , 4
At the start of June 2017, I was a lab technician at the University of Colorado and had no coding experience. A year later, in June of 2018, I started my first job as a full-time software developer. And I've loved my new career choice ever since. In this article, I'll talk about how I made that career pivot, and I'll give you some ideas about how you could make a similar career pivot if it interests you.
End-to-end website testing with Playwright
July 20, 2022 / 26 min read / 7,474 , 3 , 0
We all know testing our code is important, right? Automated tests can give peace of mind that our code is working as expected and that it continues to work as expected, even as it is refactored. Python has the pytest framework that offers great tools for testing our backend python code. You can check out my blog post, 9 pytest tips and tricks to take your tests to the next level, to get yourself jump-started testing in python. And javascript has several libraries to test front-end code. But in website testing, how can we write automated tests to ensure that our back-end code (be it python or something else) is working with our front-end code (javascript, HTML, and CSS)?
Introducing Playwright, a fast, easy-to-use, and powerful end-to-end browser automation framework. Similar to the Selenium framework, the Playwright framework has tools that allow us to write tests and scripts that act similar to an actual, human website user. And Playwright has API endpoints in javascript, java, .NET, and python! Sound useful? Read on as we use Playwright with python and pytest to write scripts and end-to-end tests for our Connect 4 game web page.
How I built a Connect 4 AI
May 28, 2022 / 36 min read / 10,895 , 5 , 1
I wrote the board game Connect 4 for my website! 😀 Here's a link to it if you want to check it out. The game can be played against another human or an AI opponent. It can even be played AI-vs-AI, which I find kind of fun to watch -- and which made testing the AI out much easier and more scientific (more on that later). This is the story of how I wrote the AI for the game intuitively, through some trial and error. This post was updated with a significantly enhanced AI version 6 a couple days after the initial release.
How to use git pre-commit hooks, the hard way and the easy way
September 15, 2021 / 12 min read / 119,987 , 34 , 12
If you've heard of git pre-commit hooks, but you aren't sure what
they are or how to get started with them, you are in luck! In this guide,
we'll talk about what git pre-commit hooks are and why you should consider
using them. We'll then talk about how to write your own git pre-commit hooks,
and then we'll talk about the pre-commit
framework which can make
setting up git pre-commit hooks easy.
How to git rebase main/master onto your feature branch even with merge conflicts
September 04, 2021 / 2 min read / 202,640 , 35 , 30
Does your project prefer git rebase
instead of git merge
? Has your branch
fallen out of sync with the main
branch and you are unable to automate
your rebase due to conflicts? If so, you might have run into rebase hell.
This happens when you try to git rebase
, solve your conflicts, and push to the
main
branch, only to find that the main
branch is now, once again, out of
sync in a never-ending loop. Let's break out of rebase hell with
this short guide to rebasing.
My Top 20 Favorite VS Code Extensions
August 02, 2021 / 15 min read / 3,807 , 3 , 0
Microsoft released VS Code (Visual Studio Code) in 2015, and since then it has become one of the most popular text editors on the market. What has led to that popularity? It is free and lightweight, with a beautiful and intuitive user interface and it is fully customizable through extensions. Extensions can bring nearly any look or functionality you like to VS Code. But with so many extensions to choose from, which ones are right for you? I'm here to guide you with my top 20 favorite VS Code extensions.
Vim beginners guide and cheat sheet
July 14, 2021 / 12 min read / 2,478 , 1 , 0
The command line text editor vim
is popular in the world of programming,
and for good reason. It can be found on nearly any Unix (and often Windows)
system, making it ideal for loading into remote machines and making quick edits
to files. It is also very powerful in the right hands. If you watch an
expert vim
user code with vim
, the cursor is bouncing all over
as they quickly write or edit their files, all without ever touching a mouse...
I am not one of those people. I picked up vim
out of necessity while
working on remote hosts without access to a GUI text editor (I'm partial
to VS Code). But since I needed to use vim
, I wanted to get better at it, so I
took a
vim Udemy course,
and I've been using what I've learned to get a little more efficient in vim
.
If you're a vim
beginner, this post will teach you the commands I found
most useful while learning vim
. And if you're a casual vim
user
like me, this post can serve as a cheat sheet reminder for all the vim
commands you and I will continue to forget.
9 pytest tips and tricks to take your tests to the next level
July 12, 2021 / 34 min read / 17,760 , 10 , 5
Are you a python developer looking to improve your testing abilities with pytest? Me too! So I've put together a list of 9 tips and tricks I've found most useful in getting my tests looking sharp. Here are the features we're going to be covering today:
- Useful command-line arguments
skip
andxfail
- Mocking with
monkeypatch
tmp_path
andimportlib
fixture
s and theconftest.py
file- Testing python exceptions
- Checking stdout and log messages
- Parameterizing tests
- Using pytest-cov
Easy and flexible flask login with authomatic and mongoengine
July 12, 2021 / 47 min read / 7,904 , 6 , 3
Many users like the simplicity of clicking one button to register and/or
log into a website using one of their existing logged-in accounts on another
website such as Facebook
or Google
. This is OAuth user authentication. But
sometimes users don't have those other accounts so it's good to provide them
with a full-proof means of logging in to a site. That's username/password
authentication. Well for your site why don't you give users both options?
In this article, I'll talk about how you can log in and register users for your flask application with flexibility by allowing either OAuth2 or username/password authentication. We'll be using Flask for our web framework, MongoDB for our database, and authomatic for our OAuth authentication framework. But if those don't apply to you, don't fret! Many of the concepts discussed here can be applied to your web stack too!