In the dim glow of my computer screen, after hours of wrestling with a
particularly stubborn bug, it finally happened. The lines of code
aligned, the program ran seamlessly, and I felt that rush of triumph.
Join me as I revisit these eureka moments and unravel the mysteries
behind the code.
I write about my experiences and journey as a software developer,
about coding topics that I've struggled with in the hopes that you
don't have to, and about things I've learned that I think are awesome.
This space is a melting pot of tutorials, discussions on tools, and
explorations of intriguing software development concepts. Enjoy!
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.”
Getting instant feedback for code changes is essential when developing a web application. Typical workflows for Python web applications involve a hot-reload functionality for the development web server that will automatically restart the server when changes to python files are detected. However, the server will not automatically restart when changes to HTML, CSS, or JavaScript files are detected. When those files are updated, you must manually restart the server for the changes to occur. Moreover, this typical workflow will not automatically refresh your web browser when you update files, so you must manually refresh the web page to see the changes.
In this tutorial, I’ll show you how to automaticallyhot-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.
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.
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! 🍪🍪 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.
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.
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.
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.
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.
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.