new section: page for “TIL – today I learned”
TIL or real post? Questions over questions.
Sometimes some newly acquired enlightenment is too “small” or my new knowledge is just the start for the future journey. Or just some news.
Then I think that a full fledged post is a bit “breaking a butterfly on a wheel”. Therefore I introduced the page: TIL – today I learned.
*tadaa*
Linux Mint 17.3: upgrade CMake
Ok, cmake 2.8 was installed – I need 3.0. At least. For C++11 features.
The good old Ubuntu-forum helped. This is the condensed version:
|
1 2 3 4 |
sudo apt-get install software-properties-common sudo add-apt-repository ppa:george-edison55/cmake-3.x sudo apt-get update sudo apt-get upgrade |
Patterns, idioms, whatchamacallit?
Had first an interesting discussion if you can call the “patterns” we use patterns. Or if there are no “patterns” in software-development, just “idioms”. Of course, quite academical question.
But it reminded me to remove the dust & spider-webs from my own knowledge and refresh it a bit. What’s better than doing it with some C++17 – support?
The other book was just referenced in some software architecture-book. Interesting collection of anecdotes. I can confirm half of the given examples as “seen in real life and projects” ..
First pull-request on github, yay!
Searched for a usable NTP-library, which assorts well with Qt and stumbled over qntp. While fiddling around I noticed in their source some opportunities to improve the code. So I cloned the repo, did them and created my very first pull-request for open-source 🙂
(Side-note: currently mostly Python-code is pushed due to the daily coding-challenge. But C++/Qt is still my carthorse.)

keep the catcam up to date
Logging in to the raspberry(ies) to update them on a regular basis takes time and effort. Both are currently dear.
Also: while the catcam is taking pictures, you can’t update the rpi-binaries.
So I made this nice script, which first suspends the catcam-operation while renaming the script from the cronjob, then does all updates, reverts the renaming and then reboots the MCU.
|
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/env bash # author: Marcel Petrick (mail@marcelpetrick.it) mv /home/pi/Desktop/webcam/regulargif.sh /home/pi/Desktop/webcam/regulargif.sh1 sudo rpi-update sudo apt-fast update && sudo apt-fast dist-upgrade -y sudo apt-get autoclean sudo apt-get autoremove mv /home/pi/Desktop/webcam/regulargif.sh1 /home/pi/Desktop/webcam/regulargif.sh sudo reboot |
Make it executeable via ‘sudo chmod +X updateCatcam.sh’ and also add it as cronjob (once a day).
rsync: get all files from the camera’s sd-card .. without interruption
|
1 |
rsync -avzr --progress /media/tanteedith/4C26-6BEF/DCIM/ /home/tanteedith/digikamArchive/ |
Of course, you need the same source- and target-directory 😉
Using this, because Nautilus (or how that horrible explorer is called) is prone to auto-unmounting the card while transfer due to heavy load ..
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
I can use the quote from Benjamin Franklin or the straight-forward one from my professor “You learn programming by programming.”. So, for gaining further knowledge about Python and how to use it, I subscribed to the mailing-list @ dailycodingproblem.com and try to solve every day a new problem. Most of them seem easily doable, because – at least – I know algorithms and have developed software for some ~years~ decades. But then hypocrisy hits reality and I realize that my Python-skills are virtually non-existant 🙂 So I do a lot of look-ups at stackoverflow, the internet and the manuals for python-standard-libraries. And this is fine, totally fine. Because this way I learn (it the hard way).
Results are committed at: https://github.com/marcelpetrick/pythonCollection/tree/master/dailyCodingTask
And – which I am really happy about – I tend to write proper unit-tests BEFORE I start implementing the real functionality!
dailycodingproblem.com always adds some example-data and the expected result. This is already the first test.
ESP32: first hands on MAX7219 and WiFi
For an investment of 80-90 minutes time I am quite happy about the result and amazed what sohisticated capabilites are offered at some really easily accessible level.
What has been achieved so far?
* setting up a working Arduino Studio 1.8.5-environment with ESP32-toolchain on a Win7-laptop (not my favorite, but Linux-PC was blocked)
* setting proper options to the IDE to make the examples compile and upload via serial to the board; learn how to use the integrated serial-monitor
* finding the proper PIN-setup for the MAX7219-LED-display (just one module – for now) and setting up the library
* playing around with the WiFi-functionality (scanning for networks)
* putting both tasks (network scan and led-output) together and running into the first “I need threads”-pit
[Video was taken at an early stage: a static string is displayed.]
Of course, THIS is nothing, just the very first tiny baby-step. Everyone is able to achieve this, because almost no creativity needs to be invested.
But: configuring all the necessary tools was already a pain in the ass. Of course, just read the manual(s) [..]
But this is not a “unwrap and press start”-toy, so the learning-curve was steeper than expected.
But I did it. And I look forward. Especially to put some threaded application on the MCU, because – why just run one thread, when you can have two? 😉
[The MAX7219 and the ESP32-dev-board from MakerHawk hours before the first test run. Battery pack not included.]
MPC: adding additional DEFINES
Some weeks ago I noticed how the qDebug()-output could be enriched, so that in bigger solutions with a lot of different “unknown” components a reported error could be immediately pinned. And you save writing always __FILE__ and __LINE__. Referres to this post.
But the problem was that with the mpc-buildsystem it was unknown to me how to force it to put this DEFINE into the vcxproj-files.
It can be done via the “macros”-statement!
So I worked on my Python-skills and wrote a short script which iterates the given path recursively and fixes all mpc-files by checking for the position of the line with the last closingbrace “}” and then it adds before that position the line. Of course, the experts know several thousand ways to improve that script – but I am currently happy with it. It works, it is debug-able (.sh, I look at you!) and I will use the skeleton also for some other tasks.
It can be found (like most Python-snippets) at: https://github.com/marcelpetrick/pythonCollection
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import fileinput import sys import os #------------------------------------------ def addMacroToFile(filename, newStatement): #print("called addMacroToFile:", filename, determinePositionOfLastBrace(filename)) returnValue = "fail" posLastBrace = determinePositionOfLastBrace(filename) posCurrentLine = 1 for line in fileinput.input(filename, inplace=True): # add additional line in case of matching last brace if posCurrentLine == posLastBrace: sys.stdout.write(newStatement) sys.stdout.write("\n") # newline, else it would be put just before the brace returnValue = "success" sys.stdout.write(line) # prints without additional newline (on windows) posCurrentLine += 1 return returnValue #------------------------------------------ # return the position of the last brace. # possible improvement: in case of some malformed mpc: skip .. def determinePositionOfLastBrace(filename): lastPos = -1 position = 1 with open(filename, "r") as file: #has implicit close - which is nice for line in file: if line.__contains__("}"): lastPos = position position += 1 return lastPos # ------------------------------------------ # find all mpb/mpc files def fixAllFilesRecursively(path, suffix, newStatement): for dirname, dirnames, filenames in os.walk(path): for filename in filenames: full_path = os.path.join(dirname, filename) if full_path.endswith(suffix): print(full_path) wasSuccessful = addMacroToFile(full_path, newStatement) if wasSuccessful == "success": print(" modified :)") # prevent recursion into those subdirs with meta-data if '.svn' in dirnames: dirnames.remove('.svn') if '.git' in dirnames: dirnames.remove('.git') #------------------------------------------ #------------------------------------------ path = "D:\Repo_INS_RADARNX" suffix = "mpc" newStatement = " macros += QT_MESSAGELOGCONTEXT" # TODO possible improvement: prevent double application of the added macro .. fixAllFilesRecursively(path, suffix, newStatement) |
Preventing the crash of the performance-profiler from Visual Studio (2013-2017) due to Meltdown-/Spectre-patches
I needed some analytical help from Visual Studio (due to the fact that MTuner and AQTimer could not work properly with our suite). So, I build my solution, fire up the “Performance Profiling” in VS2015 and *zump* computer reboots.
Discussions and investigations led to the thesis that some Windows-patches are the culprit, because they prevent that previously used hooks are usable.
So, setting those two lines in an admin-enabled cmd.exe (plus reboot) lead to alleviation:
|
1 2 |
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 3 /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f |
