TIL #121 – uv escape hatch
Mathspp Blog » Json
by Rodrigo Girão Serrão
2w 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
Visit website
TIL #120 – Circle vs rectangle collision detection
Mathspp Blog » Json
by Rodrigo Girão Serrão
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
Visit website
Binary search as a bidirectional generator
Mathspp Blog » Json
by Rodrigo Girão Serrão
3w 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
Visit website
JavaScript 2D scrolling game tutorial
Mathspp Blog » Json
by Rodrigo Girão Serrão
3w 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
Visit website
TIL #119 – Co-authored commits
Mathspp Blog » Json
by Rodrigo Girão Serrão
3w 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
Visit website
TIL #118 – git checkout -
Mathspp Blog » Json
by Rodrigo Girão Serrão
3w 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
Visit website
TIL #117 – Publishing a Python package with uv
Mathspp Blog » Json
by Rodrigo Girão Serrão
3w 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
Visit website
Beating LinkedIn “Queens” with Python
Mathspp Blog » Json
by Rodrigo Girão Serrão
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
Visit website
Building a Python compiler and interpreter – 10 elif and else
Mathspp Blog » Json
by Rodrigo Girão Serrão
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
Visit website
Using uv to build and install Python CLI apps
Mathspp Blog » Json
by Rodrigo Girão Serrão
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
Visit website

Follow Mathspp Blog » Json on FeedSpot

Continue with Google
Continue with Apple
OR