The reason why I've mentioned legacy code in the last post is that I've recently reopened an old project of mine (which I'll expand upon in another post), and I've immediately seen a number of Python packages that either are outdated, have undergone a number of changes, or simply I have forgotten about.
pylab, a Matplotlib plotting interface, has been replaced by pyplot.
mplot3d, used in Matplotlib to create 3D plots, now does not require to be imported explicitly.
PyQt, the Python bindings to the Qt framework, is now at version 6. Obviously this changes some of the API.
VPython, an easy-to-use 3D library that I've used quite a lot in the past, now defaults to using a Jupyter notebook rather than a standalone viewer.
I had largely forgotten about Mayavi, an interactive 3D data visualization library. I'll need to take a look at it again. A small practical note: pip install mayavi does not work with version 4.8.1; instead, use pip install https://github.com/enthought/mayavi/zipball/master.
wxPython, my favourite Python GUI toolkit, and pyqtgraph, a more specialized graphics and GUI library, still seem largely the same. I have just not used them in a while.
One thing I enjoy doing every once in a while is to dig up some old code I wrote some time ago and look at how things have changed and, most importantly, how I have changed. I see not only how different conventions and paradigms that are established nowadays would make things different (and not always for the best), but also how I now give more importance to clarity and simplicity, and at the same time how I see more possibilities and different ways to solve the same problem.
This exercise makes me appreciate more the problem of maintaining legacy code. A developer starting work on an existing project will always see:
Changes in the API
Changes in code conventions (spacing, variable names, even indentation sometimes)
Duplicated code
Complicated code
Changes in external libraries
Changes in pieces of the overall architecture
The list goes on and on. The most important thing is always to be aware that today your skill is different (hopefully higher), and your knowledge of the problem and the domain is better, than yesterday. Be grateful and happy for the experience you have gathered so far, since it's experience that brought you to appreciate this.
I am a long-time Linux user because I value not only the developer-friendliness, but the freedom of choice and customization as well. I have the impression that Microsoft is making Windows more and more annoying to users by removing this freedom. I have at least two examples for Windows 11.
Searching files on the whole Internet
Someone at Microsoft thought that expanding the file search to the whole Internet was a good idea, and there is no clear option to disable this stupid behavior. The only choice is to manually edit the registry like so:
Open HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows.
If it doesn't exist, create an Explorer key.
Create a new DWORD under Explorer, name it DisableSearchBoxSuggestions, and give it a value of 1.
I don't want Copilot. There are many reasons, but I don't like it being imposed on me. Again, the only choice (at least for the Home edition) is to do it manually with regedit.
Open HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows.
If it doesn't exist, create a WindowsCopilot key.
Create a new DWORD under WindowsCopilot, name it TurnOffWindowsCopilot, and give it a value of 1.
In the previous post I mentioned the usage of ssh-keyscan to get and store a server's public SSH key. My doubt was that it may not be a secure-enough solution.
From what I understand, ssh-keyscan is just another instance of TOFU, or trust on first use. Basically, it only automates what you do when you're prompted to verify a key fingerprint upon first connection to a server. If the known_hosts file does not continuously change, it is ok to use this.
Anyway, I have still decided to update the GitHub Action and make use of a GitHub secret to hold the public key of the server I am connecting to.
I decided to try and use a GitHub Action to copy some content onto an FTP server. At first I tried to use an existing action, but it didn't work and debugging was proving to be cumbersome. Then, I changed strategy and used an action with CLI commands instead.
Note: I would prefer using rsync but it is not an option in this case. Also, I do not have SSH access to the server – it's SFTP only.
Getting to this has been a bit difficult, so here are a few notes on the details:
scp needs to use a private SSH key, which cannot be added to GitHub as a file. I've added the key material as a GitHub secret and imported it as an environment variable. The key file is then (re)written by the action itself.
The .ssh directory has to be created manually, first of all because the host key has to be added to known_hosts (here with ssh-keyscan). If this is not done, scp fails with Host key verification failed. (Seen on StackOverflow)
The scp command needs to include the -s switch to force the SFTP protocol. This will likely change in the future, but with the current ubuntu-latest the installed OpenSSH version does not use SFTP as a default.
I am not yet 100% sure this is completely secure, so I'll keep checking. For example: is ssh-keyscan good enough, or do I need to get the key beforehand and then inject it manually into known_hosts?
Yesterday I explored a potential solution to replace text with CSS. One of the drawbacks is that it only works if the text to be replaced is at the end of the line. I set out to remove this limitation, and the fix is relatively obvious: use another pair of classes, with the first class to be used with the ::after pseudoelement.
HTML content:
<h2 class="text-replace">
<span class="before-text-data">Some </span>
<span class="text-data">data</span> and more</span>
</h2>
Since I discovered the Datalegreya font, I've started doing experiments to include it on a webpage. The main issue I have been thinking about is: if for any reason the font cannot be loaded (network issues, webfonts blocked, and so on, leading to a FOUT), is there a way to show the original, unstyled text instead of an unreadable version with ligatures? Can I show data instead of d|2a|1t|3a|2?
Although a Javascript solution wouldn't be difficult to write, I wanted a CSS-only solution – if at all possible. I've settled on something similar to this, where in a nutshell I enclose in a <span> element the original text I want to replace, then I use a pseudoelement to replace the <span> with the styled text.
It only works if the text to be replaced is at the end of the line.
The replaced text cannot be selected.
This approach does not prevent a FOUT, because the replacement will still happen as soon as the CSS is loaded. It is still useful anyway for “text mode” (for example with screen readers, or via the browser option) as it will show the original HTML content.
Today I discovered that it's possible to use cubic Bézier curves to specify the speed curve of an animation. I was not entirely satisfied with the result I was getting with the various ease functions and I was looking for something more flexible; that's when I discovered cubic-bezier.
This is an example of how to use this type of curve with animation:
Although I am not new to Bézier curves, I found the tool on https://cubic-bezier.com to be pretty useful as it's very intuitive and CSS-specific. It has a nice “Preview & compare” feature to compare the configured curve with any of the other available animation functions.
I am more and more impressed with the amount of features that modern CSS has to offer.
While I was looking for a cool font to use, I have come across Datalegreya. I really like its original look, and the idea of using ligatures and contextual alternates to add another layer to characters is really intriguing.
Datalegreya is based on Alegreya Sans SC, a beautiful sans-serif small caps font. The interesting twist is the use of character combinations such as d|2a|1t|3a|2 to overlay a line chart (or a variation of one) onto standard characters. You can try this on Font Library itself.
The basic format is as follows:
Type the character you want to style, for example d.
Add a combination of | (pipe) and a number between 0 and 3 to determine the height of the line after it crosses the character (by default it starts with 0 before the first character).
Continue until the end of the text.
There are other features including the x-axis and y-axis legend, a min/max value indicator, and neutral spaces, all described in the README file included with the fonts.
If you plan to use this font as a Web font, be careful as the OTF files are quite large; anyway, when converted to the WOFF2 format, their size reduces significantly. I am not sure this is a good use of the font, anyway, since the text itself is hardly readable if the font is not correctly loaded for any reason; nevertheless, I find it undoubtedly cool.
I am a fan of open-source software since forever. Lately, while looking at fonts for a website, I've again come across open-source fonts. The main reason I like them is that open licenses leave no doubt about where and how you can use a font: personal projects, commercial projects, desktop applications, websites, and so on – which are instead usually limited with commercial licenses.
Do open-source fonts have to look unprofessional? Not at all. The League of Moveable Type has a great manifesto that explains why open-sourcing fonts is a good idea, and they offer some very good-looking fonts too; in fact, I still use the very popular Raleway, and for a while I've been quite in love with the less popular, futuristic-looking Orbitron.
There are many resources where to find, try, and download open-source fonts: