Time for change: Refactoring older code and shifting to Docker

#8 Week of the Year

Florian Dahlitz
Coding experiences
Published in
5 min readFeb 25, 2018

--

Proceeded learning more about Data Science - Docker as a great way to provide software for different operating systems - fine tuning of my bash scripts.

Before I start narrating my coding experiences and presenting my learning path to you, I want to prepend a very important thing.

Last week I’ve read an interesting article about morning routines with the title “7 Keys to Winning the Morning”. This article inspired me to adjust my own morning routine.

With the beginning of this week I stood up at 4:30 am in the morning, had a small run followed by a shower. After having breakfast, I started reading articles at Medium or continued my work on side-projects. At 7:00 am I usually left home to go to work. On a few days I also spent time on creative writing to clean my head.

By changing morning routine I had a better sleep and got more productive over the day. I recommend to everybody reading this to adjust their own morning routines. Enough about non-technical topics, let’s dive into more interesting stuff.

The temporary end of my Data Science studies

Over the past week I finished the Data Science Fundamentals course at CognitiveClass, which is a great resource providing learning paths for many technical topics.

It was very helpful to learn about the techniques data scientists use to handle huge amounts of data and which kinds of methodology exist. All these things let me understand the things about Deep Learning, I’ve learned before, better.

A course about the basics of R belonged to the course. I was able to refresh my R skills, which I hadn’t use for a year.

After gaining to much theoretical knowledge about data science and it’s techniques, I wanted to get some hands-on it. I decided to use my Excel-Sheet, which I’m using to track my working time, for some data analysis. So I had to clean the data, bring it into the correct form, anaylise it and finally visualise it.

It made a lot of fun to keep busy with this topic, but I’ve decided to temporary end my personal data science learning path. There are other things existing I’m currently more interested in.

Docker and its huge possibilities

One week ago I’ve completed the Docker Essentials course at IBMs developerWorks arousing my interest. Docker seemed to me the best way to provide software for many different systems without changing code.

In the past I coded a lot in C. The problem about C is, that if you have created programs using specific Windows commands or event handler, it’s hard to migrate those programs into let’s say OSX. That’s why I wanted to create an image including C-code, which I could latre run on my other computer (Windows 10 installed).

I searched the web and found some articles making use of gcc — perfect! So I wrote a sample C-program and built based on gcc an image. My problem: The image size add up to 1.6GB! That was way to big. So I’ve searched for a second time the web and after some changes my image including three small C programs was complete. The total size of the image was only 99MB and the compressed size on Docker Hub even only 38MB — far better!

Now I wanted to create something more meaningful. Two weeks ago I listened to a podcast episode about refactoring and this week I learned the basics about Docker. Combining both things I decided to first refactor an older project and then build an image out of it.

More than a year ago I’ve created a vocabulary trainer. Unfortunately it was only running under Windows and used packages, which were no longer supported. So I took the time and refactored the vocabulary trainer and built an image. Now it’s running under all operating systems, where Docker is installed. You can get it directly via Docker Hub or by the following command:

docker pull floriandahlitz/vocab-trainer

Extending my bash-scripts

As some of you might noticed, I’m a fan of automating boring tasks and routines at the computer. That’s why I created a bash-script converting Jupyter notebooks for me and putting them in the correct directory. All this I already mentioned in my last summary.

But with this week I also restarted coding in R. And in Jupyter notebooks you can not only program in Python, but also in other programming language, e.g. R.

So I’ve extended my existing bash-script to be able to specify the language I’m using via command line options. Here are the available options:

notebooks.sh         // goes into the python notebooks directory and
// runs jupyter
notebooks.sh --pdf // converts all python notebooks into
// pdf-format and moves them into a specific
// folder
notebooks.sh -r // works as the first command, but with R
// notebooks and the respective directory
notebooks.sh -r --pdf // works as the second command, but with R and
//the respective directory

All the commands are working recursively. That means, that they are not only searching in their main directory, but in all sub-directories of the main-folder, which is quite helpful. You don’t have to relinquish a good folder structure.

Here is my quite short code for this script:

Feel free to use it on your own.

Further smaller things

Besides the previous mentioned things, I started learning more about Node.js. I kept an eye on it for quite a long time, but never did something major with it. Therefore I went through the basics at w3schools. Got some ideas for possible projects enhancing my life, but let’s see if I’ll spend enough time on that.

Furthermore I dived a little deeper into network structure and protocols, but nothing severe.

Article recommendations

As already mentioned last week, I will try to finish my weekly summaries with some article recommendations I’ve read over the week and think of worth sharing.

--

--

Florian Dahlitz
Coding experiences

Student, Developer, IBMer. Member of the RealPython.com team. Coding and sports are my passion. Python | C/C++ | Java