Codesarray (@codesarray) header
Codesarray (@codesarray) profile picture

Small games and the code behind them. Short coding lessons with real code and real output.

New Delhi
Joined January 2021
Photo by Codesarray (@codesarray)Photo by Codesarray (@codesarray)Photo by Codesarray (@codesarray)Photo by Codesarray (@codesarray)Photo by Codesarray (@codesarray)
Python strategy pattern: just pass a function. 🐍 checkout(40, sale) -> 32.0 checkout(40, lambda p: p - 10) -> 30 #Python #Coding
1
Python design patterns, in 4 images. 🐍 Strategy is a function you pass in. A factory is a dict from a name to a function. Observer is a list of functions. #Python #Coding
1
2
Python timeit.repeat: take the min, not the average, in 4 images. 🐍 #Python #Coding
1
1
Full video, Profiling and performance: youtu.be/N79j7oO-pjc
3
Python timeit.repeat: take the min, not the average. 🐍 repeat(..., repeat=5) -> 133, 108, 193, 155, 141 ms min(runs) -> 108 ms #Python #Coding
1
1
Full video, Profiling and performance: youtu.be/N79j7oO-pjc
3
Python profiling and performance, in 4 images. 🐍 timeit compares small pieces of code. cProfile shows where a program spends time: read tottime first. #Python #Coding
1
2
Python lazy import (3.15) loads a module on first use, in 4 images. 🐍 #Python #Coding
1
1
9
Python lazy import (3.15): the module loads on first use. 🐍 lazy import json "json" in sys.modules -> False json.dumps([1, 2]) "json" in sys.modules -> True #Python #Coding
1
2
Python import system in one idea: import checks sys.modules first, so a module runs once. 🐍 → then sys.path, first match wins → circular import? import the module, use it later → lazy import is coming in 3.15 #Python #Coding
1
Python @property is a descriptor: a class with __get__, in 4 images. 🐍 #Python #Coding
1
Full video, Descriptors and metaclasses: youtu.be/QjVUz2wXxqI
Python @property is a descriptor: a class with __get__ you can write yourself. 🐍 def __get__(self, obj, owner): return self.fget(obj) Runs on every read. #Python #Coding
1
6
Full video, Descriptors and metaclasses: youtu.be/QjVUz2wXxqI