This is my personal website. Here You will find many different things across many different fields (in general computer science). I love to share interesting things about things I’m working on! I Hope you enjoy reading itš
OpenWRT is like magic
Iāve been working in some projects and for a specific problem I needed to have more control in my network. I need to setup more advanced stuff, like more specific routing rules, etc. I could have done that on my router, but it could affect the usage for my family. So, thank god, Iāve got some old TP-Link routers as a gift from a friend, who was trying to get rid of this ājunkā. ...
Wavelets for processing images - Kinda cool I'd say
Well, my course on Wavelets transform is reaching the end, which is pretty sad. When I was choosing the subjects to study this semester, this one was the strangest to me, I had never heard of such a topic like that, actually I had heard of DSP for trading and whatever, but never had a formal knowledge on that. Now, that I have a more solid foundation on the topic, I can say that I have no regrets on choosing it. Itās so interesting in so many ways. ...
Mallat's algorithm with cuda - Everything I've learned with it
As I pursue my masterās in computer science as by now a non-degree/special student, I decided to attend to two different classes this semester: Algorithms (because I like it) Wavelet Transforms (because it seemed interesting) Algorithms is a pretty well know topic in computer science which you may be familiar with. Everywhere and, weird or not, every class may be related to algorithms in some way (even my wavelet class). For this semester, we learned about some ways to calculate and analyze code to find bottlenecks, performance issues, possible improvements. In general, we learned about asymptotic behavior/analysis, so big O notation and its relatives Īø and Ī©. Iād like to talk more about this, so Iāll hold this topic for a future post. ...
Openclaw for Quantum Simulation
Since I did my zeroclaw setup (post: how-i-failed-on-creating-my-own-ai-agent-rxdcmfxqpempm) I was playing around a bit with LLMs in general. Iāve been using a lot of ChatGPT, Gemini and Perplexity for studying and clarification in some topics. I also tested the new Muse Spark model from Meta AI and Github Copilot with Claude Haiku. Vibe coding is something that I always abominate, but after testing I found it very useful for prototyping and doing frontend applications fast, for that I installed Antigravity (take a look at the interface of my app: fngames). Even reported some exposed OpenAI API Keys for some companies. ...
How I failed on creating my own AI agent
So, I suppose that at this point, everyone has heard at least a bit about agents and Openclaw. This buzzy words came out of sudden and became the words of the decade. As a tech guy, Iām loving all the possibilities we have with them and for sure they are great tools. Despite of that, I had never had a grasp on creating my own agents, even though I always wanted. ...
What's Python __future__?
These are the notes I took to do my video about python futures, which is available here: and here: De volta Para o Futuro do Python - Python future - tiktokt video Unfortunately, all the videos are in portuguese. However, my notes are available bellow and the code is open source and available here: https://github.com/Dpbm/video-python-futures. Enjoy :) Notes Allows you to tell the compiler that you want to use a standard that will come in future releases. Is done by simply importing from __future__. Must be added on the top of the file, since it changes the way the file is parsed. Otherwise, it raises a SyntaxError. Tells the compiler you want an specific part of your code to act is it will be the default in the future. division calls __truediv__ instead of __div__. The from __future__ import whatever is a future clause, but you can also import the __future__ module with import __future__. The future itself is an object that contains metadata about the very feature, like versions and etc. Some futures are only supported by specific versions of python2, so older versions may need more workarounds than newer ones. Thatās why future and six are so useful in these cases. Python 2.7 cli had a flag -3 that warned you when there was some statements that couldnāt be trivial to fix using 2to3. __future__ works since python 2.1. There are flags that can be passed to compile() to dynamically use future features. Only feature that requires future statements is annoations. Any code compiled with exec() or compile() will use the new statements when using futures in the module. Interactive session also can use futures. Only docstrings, comments, blank lines and other future statements can appear before it. Future object has 2 elements containing tuples with 5 elements. The first one describes the Optional release, which is the first release the feature was accepted. And the second is the Mandatory Release, describes either when the feature became part of the language, or a prediction of when it will be or can be None if it was dropped. Usually, Optional < Mandatory. six Used to wrap differences between python $2$ and $3$. Is a single python file being easy to copy into a project whenever needed. future A package to make a compatibility layer for python2-3 code. Based on the 2to3 module. Not necessary anymore. Add supports for the standard library. 2to3 A library builtin python. Transforms python2 code into python3 compatible. Was removed from Python3.13. References https://docs.python.org/3.13/library/future.html https://www.reddit.com/r/learnpython/comments/8ialj1/how_does_future_work/ https://stackoverflow.com/questions/7075082/what-is-future-in-python-used-for-and-how-when-to-use-it-and-how-it-works https://pt.stackoverflow.com/questions/126466/para-que-serve-o-m%C3%B3dulo-future https://www.geeksforgeeks.org/python/future-module-in-python/ https://stackoverflow.com/questions/5937251/writing-python-2-7-code-that-is-as-close-to-python-3-x-syntax-as-possible https://six.readthedocs.io/ https://pypi.org/project/future/ https://python-future.org/overview.html https://docs.python.org/3.8/library/2to3.html https://docs.python.org/3/whatsnew/3.13.html https://sources.debian.org/src/python2.7/2.7.9-2/Modules/future_builtins.c https://github.com/python/cpython/blob/main/Lib/future.py http://python3porting.com/noconv.html https://docs.oracle.com/cd/E86824_01/html/E54763/python2-7-1.html https://docs.python.org/3.13/library/future.html https://docs.python.org/3/library/functions.html#compile https://docs.python.org/3.13/reference/simple_stmts.html#future https://peps.python.org/pep-0236/ https://peps.python.org/pep-0563/ https://peps.python.org/pep-0649/ https://peps.python.org/pep-0749/#the-future-of-from-future-import-annotations
The magic behind shebangs!
These are the notes I took to do my video about shebangs, which is available here: and here: Como shebangs funcionam - tiktokt video Unfortunately, all the videos are in portuguese. However, my notes are available bellow and the code is open source and available here: https://github.com/Dpbm/video-shebang. Enjoy :) Notes The name cames from Sharp-bang (#! from music sheet notation). Some say that itās due to its phonetics (hash + bang). It especifies an interpreter for this script. Bash handles the shebang when the underlying system doesnāt do that. Itās usual to set it to #!/bin/bash to ensure that it will use Bash instead of any other shell. Now days itās preferable to use #!/usr/bin/env bash to get bash from $PATH if installed in a different directory. The script fallback to its parent SHELL when no shebang is defined. The shebang is used for portability. When itās not provided, the system raises an ENOEXEC (Exec Format error) error. file command uses the shebang, as well, to see which kind of executable is that. You donāt need a blank after #!. Also accepts relative paths. When a program runs in a unix-like system, it executes a kernel exec()(or any command from this family) function. It take a look at the first 16 bits, searching for a magic number that describes an executable. If itās no signature is found it return an ENOEXEC error. As time went, this magic part of the file also described how to execute it. When the run starts running your script, it first tries to delegate it to the kernel, which search for the shebang and tries to execute the file with a different interpreter. If none was found, the bash itself tries to execute. Explicit calling a script via a shell command (like sh or bash) the shebang is ignored. Using /usr/bin/env doesnāt provide complete portability, but itās a good practice. Arguments can be split differently in different systems, so it may break in some occasions. The path of the script is passed via argv to the interpreter. Calling trace execve -> do_execveat_common -> create a linux_binprm containing data from it (DEFINE_CLASS -> alloc_bprm ) -> bprm_execve -> exec_binprm -> search_binary_handler -> prepare_binprm -> kernel_read (read the file) -> it them iterates over a linked list of formats list_for_each_entry(fmt, &formats, lh) { the exec.c provides an external function `__register_binfmt` that is used by each type in `binfmt_*.c` to register in the lits, calling like: core_initcall(init_elf_binfmt); -> load_binary from struct linux_binprm if it's a script, it loads `binfmt_script.c` that has the method `load_script` which checks for the shebang -> open_exec (from exec.c) -> do_open_execat References https://unix.stackexchange.com/questions/149045/why-is-shebang-called-shebang https://www.gnu.org/software/bash/manual/bash.html#Shell-Scripts-1 https://medium.com/@jcroyoaun/a-deeper-view-into-the-shebang-for-linux-scripting-4a26395df49d https://stackoverflow.com/questions/3009192/how-does-the-shebang-work https://unix.stackexchange.com/questions/268766/what-exactly-happens-when-i-execute-a-file-in-my-shell https://crocidb.com/post/kernel-adventures/demystifying-the-shebang/ https://www.in-ulm.de/~mascheck/various/shebang/ http://www.faqs.org/faqs/unix-faq/faq/part3/section-16.html https://en.wikipedia.org/wiki/Shebang_(Unix) https://github.com/torvalds/linux/blob/v4.8/fs/binfmt_script.c#L25 https://man7.org/linux/man-pages/man2/execve.2.html https://man7.org/linux/man-pages/man3/perror.3.html https://stackoverflow.com/questions/4689724/where-do-i-find-the-source-code-for-execve https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/exec.c#l1376 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/binfmts.h https://github.com/torvalds/linux/blob/master/fs/namei.c#L4849 https://docs.kernel.org/admin-guide/binfmt-misc.html https://github.com/torvalds/linux/blob/master/include/linux/list.h https://github.com/torvalds/linux/blob/master/fs/binfmt_script.c https://homepages.cwi.nl/~aeb/std/hashexclam.html https://www.oreilly.com/library/view/understanding-the-linux/0596005652/ch20s04.html
How does Python handle imports?
This is a topic that I discussed in the following youtube video (unfortunately only in brazilian portuguese) These notes were extracted from my github repo https://github.com/Dpbm/video-python-import-methods, take a look if you want more details and some code ;) Notes C includes headers (.h files) includes the interfaces for external code. including a header into a c source file is the same as copying the definition of the function or whatever to that context, but less prone to errors. #include it reads a file and places it inside the current source code. to avoid errors, use it to only import functions/declarations/definitions/etc from header files. includes using <> looks only in standard system directories. But without it, it first looks into the current path and then starts look for it in other system locations. Wrappers to avoid import the same thing twice use the wrappers #ifndef DEFINITION_OF_HEADER #define DEFINITION_OF_HEADER ... #endif you can also use #pragma once JS Common JS use require and exports. require can load ES modules when the file is .mjs ES modules are more flexible you can define queries, properties, etc. Python import Python uses importlib as the underlying machinary for importing. components of import are available through importlib to make it possible for you to create a custom object. import calls __import__(). importer is a term that refers to a both finds and loads a module. the import command donāt put every single definition directly into the current scope, but only the module name. To access its internals, you must use module_name.<what you want>. is not required to be on the top of the file. it search, create a module object and binds a name, while __import__ only searches and creates the object. when module is not found it raises ModuleNotFoundError. The import statement find a module and loads it. define a name for this module in the current scope. The import statement using from find the module specified in from clause. for each name in import check if the name exists. If not, check if itās a submodule. If not found raise ImportError. Otherwise import to the local namespace. using * it exposes all public data. members with _ are not exposed by default. if __all__ is defined, all names defined are exposed. Otherwise all public members. __all__ is a global variable per module. it imports all names into the current scope (except those which start with _). not recommended. Relative imports only works on packages contained one within the another. . for the current package and .. for one thatās a level up. PYTHONPATH add entries in sys.path. useful when we need to test a package without installing it. affects installed python versions/environments, only use when itās really needed. sys.path first entry is the directory of the current script or the current directory when using -c or -m. sys.modules a dictionary that maps modules that were already loaded. itās a cache. return a module ready to run. maps submodules as well. if an entry value is None python will raise an ModuleNotFoundError. sys.meta_path (meta hooks) Are called before any importing proccess so it can override the sys.path, frozen modules and even builtin ones. To register add a finder object in sys.meta_path if the whole list is check and every finder returns None, so the module cannot be handled, raising an ModuleNotFoundError, otherwise return a spec. itās called multiple times for multilevel packages (foo.bar.baz, 3 times, āfooā, āfoo.barā, āfoo.bar.bazā). python has 3 by default. For builtin modules, for frozen modules and for an import path. by default it can handle .py, .pyc and .so files. sys.path_hooks part of sys.path processing. is registered by adding an importer factory into sys.path_hooks. it checks if a path item can be handled. return an importer when an item can be handled, otherwise return ImportError. is consulted while traversing a package __path__. python uses this list to handle different types of files and locations, like from URLs, zip files, so files, .py files, etc. itās used after python tries every single finder from sys.meta_path. If none works, it iterate over each sys.path_hooks entries and give it each possible value from sys.path. must call sys.path_importer_cache.clear() after adding a new factory to it Modules is a file containing statements and definitions. the module name is the filename, which can be accessed via __name__. can have executable statements that are executed only once when the module is imported. have its private namespace. when executed as a script its name (__name__) becomes __main__. when importing a module, it searches in this sequence: sys.builtin_module_names. sys.path (which includes the directory of the file, PYTHONPATH and the installation dependent directory site-packages). the dir() command is used to list all the names in a module builtins is a module that list everything thatās builtin python every module has a repr (representaion) depending of data like name, origin, etc. __pycache__ contains the cached modules that were previously built. python always ignore the cache when: they are directly loaded via CLI (it recompiles the module). when the module is a binary. to reduce the compiled size use: -O to remove assert statements -OO to remove asserts and __doc__ opt- to optimize the binary .pyc are only faster for loading not executing Packages collection of modules inside the package, when importing, python searchs in sys.path for the names. To find the submodules inside your package, each submodule must have a __init__.py file. when loading submodules with import python tries to find the name as a declarion/statement from the module, if itās not find it tries to load as a submodule. In case itās not found, it will raise and ImportError. when using import * it only import the names defined for that package, not every submodule name. you can use relative imports within the submodules to navigate quickly between code. you can also use āpathā to check which directory python search for the submodules. Any module that has a __path__ is a package. Regular Packages directories with __init__.py. Namespace Packages split a pacakge between multiple locations on disk. cannot contain __init__.py files. __path__ is read-only. at runtime you can use sys.path to discover them. __init__.py can be empty but can also run initialization code. when a module is imported, the __init__.py is executed. define a package. Import Protocol it has two parts when both are implement itās called an importer. finder and loader can be the same object. finders it determines if a module can be found. return a module spec with all information needed for loading it. canāt point to whatever location, not requering to be in the local machine. can be a meta_path finder, which operates at the beggining of the importing proccess, and path_entry finder, which responsible for finding and loading modules and packages located via a string path entry. sys.path_importer_cache maintains a cache of finders objects. loaders donāt need to check for sys.modules, import will check it before. module execution. Overall Execution pipeline (Default pipeline as I understood) you use import it uses under the hood __import__() search the module at cache sys.modules if not found, run the meta hooks run the finder iteratively if no meta_path worked, it iterates over sys.path and sys.path_hooks trying to see if any of the paths can be handled check if .pyc file is up-to-date, when importing python files if not, it regenerates the file and save the new hash run loader returning a module object binds the module object into a name provided via import References https://www.grumpymetalguy.com/programming/python_importlib/ https://docs.python.org/3/library/importlib.html https://docs.python.org/3/reference/simple_stmts.html#import https://github.com/python/cpython/blob/3.14/Lib/importlib/init.py https://docs.python.org/3/glossary.html#term-importer https://docs.python.org/3/glossary.html#term-loader https://docs.python.org/3/glossary.html#term-module-spec https://realpython.com/ref/stdlib/importlib/ https://discuss.python.org/t/usage-of-all-in-init-py/17936/5 https://discuss.python.org/t/usage-of-pythonpath/18086/7 https://bic-berkeley.github.io/psych-214-fall-2016/using_pythonpath.html https://github.com/stas00/the-art-of-debugging https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html https://nodejs.org/api/modules.html https://nodejs.org/api/esm.html https://tc39.es/ecma262/#sec-modules https://docs.python.org/3/tutorial/modules.html https://docs.python.org/3/glossary.html#term-namespace-package https://docs.python.org/3/reference/datamodel.html#module.path https://docs.python.org/3/reference/import.html https://docs.python.org/3/library/sys.html#sys.modules https://docs.python.org/3/library/sys.html#sys.meta_path https://peps.python.org/pep-0302/ https://docs.python.org/3/library/sys.html#sys.path_importer_cache https://docs.python.org/3/glossary.html#term-portion https://micropython-stubber.readthedocs.io/en/main/50_frozen_stubs.html#frozen-modules https://github.com/python/cpython/blob/main/Python/frozen.c https://wiki.python.org/moin/Freeze https://docs.python-guide.org/shipping/freezing/ https://docs.python.org/3/library/sys_path_init.html https://docs.python.org/3/tutorial/classes.html#tut-scopes https://docs.python.org/3/library/compileall.html#module-compileall https://peps.python.org/pep-3147/ https://peps.python.org/pep-0420/ https://packaging.python.org/en/latest/guides/packaging-namespace-packages/ https://realpython.com/python-namespace-package/ https://docs.python.org/3/library/importlib.html#importlib.machinery.PathFinder.find_spec https://stackoverflow.com/questions/41990169/how-to-use-sys-path-hooks-for-customized-loading-of-modules https://stackoverflow.com/questions/31882967/why-are-pyc-files-created-on-import https://peps.python.org/pep-3147/#python-behavior https://medium.com/@utkarshshukla.author/what-is-a-pyc-file-visualizing-pythons-bytecode-generation-fcce8e6da679 https://peps.python.org/pep-0451/ https://github.com/python/cpython/blob/main/Lib/importlib/_bootstrap.py https://github.com/python/cpython/blob/main/Lib/importlib/_bootstrap_external.py https://github.com/python/cpython/blob/main/Lib/importlib/abc.py https://github.com/python/cpython/blob/main/Lib/importlib/_abc.py https://www.reddit.com/r/Python/comments/untwoc/syspath_hooks_is_fun_for_everyone_cfgimp_a_misuse/ https://docs.python.org/3/glossary.html#term-path-entry-finder https://docs.python.org/3/glossary.html#term-path-entry-hook https://snarky.ca/writing-a-zip-file-importer-the-path-hook-part-1/ https://rahul.gopinath.org/post/2018/09/07/python-importer/ https://docs.ploomber.io/en/latest/api/_modules/root/ploomber.SourceLoader.html
Moving my website from NextJS to HUGO
So, itās been a long time since I first created my blog using NextJs and MongoDB. The previous setup was kind a mess. You can still check it on my github 966949eb6e321c5f8478d40fa07550b41351401f. This old version was relying deeply on Nextjs server components, mdx plugin and the amazing api capabilities. Wich was nice, and gave me a freedom I wouldnāt have in other environments, however it was so complicated to create new posts. ...
UV TLS issue
Recently, Iāve been working on a python project that required me to use the qiskit-ibm-runtime package to do some quantum stuff. So, the first thing I did was run: uv add python-dotenv qiskit-ibm-runtime then I created a simple snippet to test it: import os from dotenv import load_dotenv from qiskit_ibm_runtime import QiskitRuntimeService if __name__ == "__main__": load_dotenv() QiskitRuntimeService.save_account(channel="ibm_quantum_platform", token=os.getenv("IBM_KEY"), instance=os.getenv("CRN"), overwrite=True, set_as_default=True) ā service = QiskitRuntimeService() print(service.least_busy(filters= lambda b : not b.simulator and b.num_qubits >= 9)) and ran the script with: ...