TIL #105 – pytest selection arguments for failing tests
Mathspp Blog
by
5d ago
Today I learned about 5 useful pytest options that let me control what tests to run with respect to failing tests. pytest selection arguments for failing tests Florian Bruhin shared a pytest tip on X / Twitter the other day regarding command line options that pytest accepts and that control how pytest handles failed tests. He shared the following very illustrative diagram: Diagram by Florian. I think the diagram is so good that I could essentially stop the article here and we all would've understood the options. But I'll be just a little bit more verbose and explain how each option works. --m ..read more
Visit website
Teaching the world's largest programming lesson
Mathspp Blog
by
1w ago
This article goes over the content I taught at the world's largest programming lesson that broke a Guinness World Record with 1668 students. Teaching the world's largest programming lesson On the 12th of October of 2024 I was part of an attempt to break the Guinness World Record of the largest programming lesson in the world. The previous record was at 724 students and we managed to surpass it by giving a programming lesson to 1668 students. This incredible lesson was organised by Magma Studio, a company I worked at (and whose partners take random ideas I get waaaay too seriously) and Institu ..read more
Visit website
How I prepare a technical talk
Mathspp Blog
by
1M ago
This article outlines the steps I follow to prepare my technical talks, including notes on slide design, engaging with the audience, how to prepare the delivery, and how to manage the Q&A. How I prepare a technical talk I have a lot of fun giving talks at conferences. I am not the best speaker ever and I am far from being a prestiged speaker. However, I have had enough positive feedback from enough talks to claim with some confidence that I am a decent speaker. The article will be split into five sections outlining my thoughts on: slide design; audience engagement; talk delivery; how to ..read more
Visit website
TIL #104 – nested makefiles
Mathspp Blog
by
1M ago
Today I learned how to call a makefile from within another makefile. Nested makefiles I like to use make and makefiles on my projects and today I needed to call a makefile from within another makefile... I was pretty sure there was a “proper” way to do it, so I went ahead and looked it up. A quick search revealed I should use $(MAKE) instead of typing make and that I could also use the option -C to change the directory from where I'm reading my makefile. As a simple example, consider the following directory structure: - root |- Makefile |- subfolder |- Makefile Paste the following ..read more
Visit website
Mutability and random.shuffle
Mathspp Blog
by
2M ago
The function random.shuffle relies on the mutability of the argument and mutability is a pain in the arse, so we propose an alternative. Mutability and random.shuffle The function random.shuffle shuffles its argument in place, which means it relies on the mutability of the argument. This can introduce bugs if care is not taken. Consider the snippet of code that follows: def generate_maze(base_width, base_height): width = 2 * base_width + 1 height = 2 * base_height + 1 # Initialize the grid with walls maze = [[0 for _ in range(width)] for _ in range(height)] DIRECTIONS ..read more
Visit website
Problem #066 – regex crossword
Mathspp Blog
by
2M ago
Can you solve this crossword where all hints are regular expressions? Problem statement The regex crossword puzzle grid. At EuroPython 2024 I watched a lightning talk about the art of puzzle solving. In it, the speaker showed the regex crossword puzzle that you can see above, that I took from this URL. You are supposed to fill the hexagonal grid with letters so that all of the regular expressions shown match. If you don't know regular expressions, the puzzle only uses a simple subset of the syntax: literal character matches; wildcard matches with .; alternatives with |; the quantifiers ..read more
Visit website
Automatic site updates with cog and pre-commit
Mathspp Blog
by
2M ago
This article outlines how I use a pre-commit hook and cog to keep my blog stats updated automatically. Automatic site updates with cog and pre-commit Some months ago I introduced some basic stats in my blog that show how many articles I've published, along with how many words and lines of code those articles contain. I wrote an article explaining how I wrote a script that gathers these blog stats for me but that's a script I still need to run and then manually update the stats. I wanted to automate this process but I couldn't bring myself to do it. And then, I came to the silly realisation th ..read more
Visit website
Customising object creation with __new__
Mathspp Blog
by
3M ago
The dunder method __new__ is used to customise object creation and is a core stepping stone in understanding metaprogramming in Python. Customising object creation with __new__ The dunder method __new__ is a static method that creates new instances of your class and, therefore, can be used to customise that process. The dunder methods __init__ and __new__ can look quite similar at first sight. The dunder method __init__ will initialise your instance of your class, but that instance must be created before it can be initialised, and that's the job of the dunder method __new__. Arguments of the ..read more
Visit website
Case-insensitive string class
Mathspp Blog
by
3M ago
This article shows how you can create a case-insensitive string class using some basic meta programming with the dunder method __new__. Case-insensitive string class In this article we want to implement a case-insensitive string class, that we will call CIStr, such that the comparisons between an instance of CIStr and a regular string, or between two CIStr instances, are done in a case-insensitive way. Here are two examples of what we're looking for: >>> CIStr("Hello") == "heLLO" True >>> "heLLO" == CIStr("Hello") True Case-insensitive equality comparison To compare two st ..read more
Visit website
Module itertools overview
Mathspp Blog
by
3M ago
This article briefly describes the iterators available in the Python module itertools and how to use them. Module itertools overview The Python module itertools contains 20 tools that every Python developer should be aware of. We divide the iterators from the module itertools in 5 categories to make it easier to learn them and we also present a short list of the generally most useful ones. All the iterators from itertools Category Iterators Reshaping iterators batched, chain*, groupby, islice, pairwise* Filtering iterators compress, dropwhile, filterfalse, takewhile Combinatorial i ..read more
Visit website

Follow Mathspp Blog on FeedSpot

Continue with Google
Continue with Apple
OR