
Mathspp Blog
4 FOLLOWERS
Stay up-to-date with the articles on mathematics and programming that get published in mathspp. Mathspp Blog A blog dedicated to mathematics and programming! This blog has a really interesting assortment of articles on mathematics and programming. My name is Rodrigo Girão Serrão, I am from Portugal and I am a mathemagician and a programmer. I studied mathematics at the university level.
Mathspp Blog
1w ago
Today I learned how to use uv to escape uv and go back to using venv and pip for a given project.
Use pip directly from a uv virtual environment
uv comes with the subcommands uv venv and uv pip that let you use your venv + pip workflows, with the commands you already know, while benefiting from the speed of uv. However, I have a specific project in which I need to be able to use pip directly from the virtual environment that uv created.
After I ran uv venv and activated my virtual environment, I tried using pip to install a package with python -m pip install my_package but got an error messag ..read more
Mathspp Blog
2w ago
Today I learned how to detect collisions between circles and rectangles with 100% accuracy.
Circle vs rectangle collision detection
In a JavaScript tutorial I published recently, the game that I presented included some very basic collision detection between a circle and a rectangle, and it used the circle's bounding box. This meant that the collision detection sucked if the circle was close to the corners of the rectangle.
Today I sat down to think about it for a second and figured out how to implement pixel-perfect collision detection between a rectangle and a circle, as the demo below demon ..read more
Mathspp Blog
2w ago
This article proposes an implementation of an ergonomic binary search algorithm implemented as a bidirectional generator.
Binary search as a bidirectional generator
Python generators can be bidirectional and in this article I will use this feature to try to implement the binary search algorithm in an ergonomic way. To this end, I'll write a bidirectional generator that implements the binary search algorithm independent of any use cases. This means the resulting generator can be used ergonomically whenever a binary search needs to be employed.
Bidirectional generators
Python generators support ..read more
Mathspp Blog
2w ago
This tutorial walks you through implementing a 2D scrolling game in JavaScript.
JavaScript 2D scrolling game tutorial
This JavaScript tutorial is for people who know programming (for example, in Python) but have no JavaScript knowledge. In this tutorial we will build a 2D scrolling game where the player (a red ball) will jump to avoid obstacles (black rectangles) that come toward the player at increasing speeds.
You can play a demo of the game below. Click the gray rectangle to start the game and press SPACE to make the player jump over obstacles. (If you click the game area again, it restart ..read more
Mathspp Blog
2w ago
Today I learned how to create co-authored commits on GitHub.
Co-authored commits
On GitHub, co-authored commits allow you to add two or more people as the authors of a commit, effectively marking that commit as a contribution done by multiple users. When a commit has co-authors, GitHub displays those multiple authors next to the commit, as shown in the image below:
A commit with two authors.Adding a co-author
To add co-authors to a commit, the extended commit message should end with a Co-authored-by line, that looks like this:
Co-authored-by: NAME <GITHUB EMAIL>
If you use the co-auth ..read more
Mathspp Blog
2w ago
Today I learned how to quickly switch back and forth between two different git branches.
git checkout -
Suppose you're in a git branch called fix-1523-very-important-high-priority to fix issue 1523 that is very important and high priority. Then, you checkout the main branch to pull the most recent changes, or something like that, with git checkout main. You do what you have to do on main and then you have to checkout the other branch again...
One of two things will happen:
you don't want to type the whole branch name again; or
you don't even remember the exact branch name in the first place ..read more
Mathspp Blog
2w ago
Today I learned how to publish a Python package to PyPI with uv.
Publishing a Python package with uv
Publishing a package to PyPI with uv was quite simple. All I had to do was read the documentation with the steps provided and I was done in less than 2 minutes.
The package I'm publishing is my CLI that solves the LinkedIn Queens puzzle, about which I wrote in a different article.
The first thing I did was make sure I could build my package with
uv build
The next step is to run uv publish. To publish a package to PyPI I needed a token for authentication. To get that, I opened my account sett ..read more
Mathspp Blog
3w ago
This is a short account of how I wrote a program that solves all LQueens puzzles from LinkedIn automatically with Python.
Beating LinkedIn “Queens” with Python
About a year ago LinkedIn started publishing a daily logic puzzle called “Queens”. This puzzle is a crossover between the queen-placing puzzle from chess and Sudoku, and takes place in a square grid with a number of heterogeneous coloured regions, as the image below demonstrates:
Queens puzzle #179.Puzzle rules
The rules for the puzzle are quite simple. You have to place one queen on each coloured region while also making sure that:
t ..read more
Mathspp Blog
1M ago
The 10th article of this series adds support for elif and else statements.
Building a Python compiler and interpreter – 10 elif and else
This is the 10th article of the “Building a Python compiler and interpreter” series, so make sure you've gone through the first nine articles before tackling this one!
The code that serves as a starting point for this article is the tag v0.9.0 of the code in this GitHub repository.
Objectives
The objective for this article is:
to add support for the conditional statements elif and else.
Let's get into it.
Adding support for else
In a conditional statement ..read more
Mathspp Blog
1M ago
This practical tutorial shows how to use uv to build and install custom Python CLI applications globally on your system.
Using uv to build and install Python CLI apps
I find myself writing Python scripts that automate certain parts of my work or life and then I want to turn them into commands in my system. This short tutorial will show you how I do that using uv.
You can build and install a command (that's a Python CLI app) globally in your system in 5 easy steps:
Install uv following the installation instructions from the uv documentation.
Start a Python project managed by uv by running uv ..read more