Find all fitting files and run the fixer-script in parallel over it.
( find . -name "CMakeLists.txt" ; find . -name "*.cmake" ; find . -name "*.h" ; find . -name "*.cpp" ) | parallel --bar ../removeTrailing.sh
After playing for a while with sed and awk and not being able to get a fitting solution, I decided to create my own as python-script. It squashes all consecutive double-whitespace-lines (and adds one to the end if missing).
(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
The first month of 2019 already passed. And we passed it with flying colors!
But let’s have a look at 2018 – a year full of challenges and success: I’ve worked full-time, organized and participated in advanced courses for Python and in Requirements Engineering (officially: IREB Requirements Engineering Foundation Level-approved) and pursued a new employment as software engineer.
And I wrote some software in my spare-time, as you can see in the graph for the public github-repositories. The gaps in the commits can be explained with the birth of my daughter and the time where I acquired the new job and moved nearly 900 km across the country. Yay! Nice personal projects were and are Cullendula and the Daily Coding Challenges, which I solve mostly with fully Unit-tested Python (3).
More new, hands-on knowledge was gained in the area of CMake and Qt-charts.
Well – 2018 was great. Let me make 2019 greater! 💪
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.
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
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("\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 the position of the last brace.
# possible improvement: in case of some malformed mpc: skip ..
lastPos = -1
position = 1
with open(filename, "r") as file: #has implicit close - which is nice
for line in file:
lastPos = position
position += 1
# 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)
wasSuccessful = addMacroToFile(full_path, newStatement)
if wasSuccessful == "success":
print(" modified :)")
# prevent recursion into those subdirs with meta-data
if '.svn' in dirnames:
if '.git' in dirnames:
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)
I am currently traveling back from my very first paid educational leave. Proper selection, arrangement and preparation lead to some awesome impressions: about the capabilities of Python and about the city of Detmold.
Daniel Warner lead us – an assembly of five inquisitive men in the age-range from 30 to 60 – along the details and
specialties of that programming language. I learned much, in detail:
- basic structures; list comprehension
- classes; objects; overrides; imports; representation; init-method
- dictionaries for caching results (memoisation)
- decorators (nice for for printing, caching and thread-safety)
- descriptors, properties and slots, kwargs
- (multi-)inheritance and its quirks
- recursive functions; functional programming
- threads, synchronisation, atomic access
I put all the exercises (full script with my own annotations) into a Git-repository right from the beginning and published it: https://github.com/marcelpetrick/Python_FortgeschrittenenSeminar/.
Which also makes a nice view of the github-history 🙂
Python was chosen by me by intent: I see and plan for ways to use it with artifical intelligence (TensorFlow-binding ..); microcontroller-programming (ESP can run MicroPython) and for the Raspberry (currently the tumblr-upload-script for the catcam is also Python); for daily data-manipulation-tasks which are currently done more or less on Bash or AutoIt or Batch – and then: write it once, run it both on Linux and Win).
This was a great choice! And I want to thank my wife for supporting these stays absent from home and my plan to achieve the wanted education 🙂 And I got a small certificate – but that’s just icing on the cake.
My plan as first real exercise is to re-implement the “find all islands in the given map”-programming challenge. This will be fun. Getting to know some specialties and what properties/slots mean in Python-context (compared to the Qt-ones) was nice. And the decorators are a really powerful way to add special functionality to methods without bloating them and without blocking the view to the busines logic.
Some weeks ago I’ve replaced the case of the ‘catcam’. A Raspberry Pi 3 which was running for 1.5 years without interruption with the nice script & python-upload triggered by a cronjob. And now the device freezes. Still running, but neither accessible via SSH nor VNC (of course, if SSH is not working ..).
I left the case open; removed the camera; upgraded kernel and Raspbian: nothing helped.
My last guess is that the camera stopped working. But to be sure I want to let the RPi3 long-time with temperature-logging. So … we need a simple program:
temp = os.popen("vcgencmd measure_temp").readline()
print(time.ctime() + " ## " + measure_temp())
executed like this, because else the output is buffered up to 4 or 8 kByte:
$ stdbuf -oL python temperature.py > worstLoggingEver.txt
and the content of the textfile is something like:
Tue Mar 6 22:52:59 2018 ## 51.5'C
Tue Mar 6 22:53:00 2018 ## 52.1'C
I am currently trying to enhance my skills by learning Python. I made a choice between Ruby and Python after I was quite frustrated sometimes while writing the contactSheet-script. Bash is missing some general debug-abilities (or I don’t know them ;)) and the way to control the code-/data-flow was quite limited from my POV. I came from high level-strong typed-precomiled C++ and then hit bash ..
It is quite amusing to guide the hero(ine). I finished already 22 levels.
For in detailed explainations I stick to: “Learn Python the hard way“