Code Kata: Translate a decimal text to roman

A code kata is a an exercise of coding where the objective is to use simple requirements to train the coding and testing skills.You can use it to train brainstorming and analysis within the team as well.

The subjacent idea is to use the martial arts concept of kata to coding, where repetition leads to perfection.

A few tips:

  • Try to fit the analysis, coding and testing within a small range of time, like 2 hours or less.
  • Remember if it takes too long or demands a big effort, there will be no motivation to repeat it in another session.
  • Most of the exercises exist to train the TDD methodology.
  • You can find several exercises in the internet for your use, or just invent one yourself.

Translate a decimal text to roman

Imagine you have a text, or a list of texts, such as the one below, with words and numbers.
(or just write a text with words and numbers):

You want to replace all the decimal numbers with roman numbers

That said, there is also considerable cause for optimism among those who support OER. The awareness and adoption levels may be low, but they also show steady year-to-year improvements. For example, the open-licensed textbook adoption rate of 9% for 2016-17 represents a substantial increase over the rate of 5% for 2015-16. Likewise, awareness of both Creative Commons licensing and OER itself has increased each year.
OER also addresses a key concern of many faculty: the cost of materials. A majority of faculty classify cost as “Very important” for their selection of required course materials. Faculty report that their required textbooks have an average price of $97, and only 22% say that they are “Very satisfied” with that cost. It is therefore not surprising that most faculty report that not all of their students buy all the required texts for their class, with only a third saying that 90% or more of their students have purchased the required textbook.

Have a nice session!

Notes

If you implement this kata and you publish it in the internet, be kind a refer to this article. 😃

The text used in the exercise was extracted from a text file I have found in the internet. There is no special meaning to consider.

Book review: A brief history of the paradox by Roy Sorensen

The oldest recorded paradox is from Anaximander: “Does each thing have an origin?”
He answers no: there is an infinite being that sustains everything else but which is not grounded in any other thing. This answer tries to run away from the infinite loop created by the question, since everything that exists was created by a consequence of something before.
The past can be a challenge to explain, what about the future?
Does each thing end?, and now we are on the same challenge. If it ends, what happens next?

The book, starts with the first recorded paradox and continues through time and areas of knowledge, such as philosophy, science,etc, and you start to see how some paradoxes are just old paradoxes in other areas.

What I like about this book, it is not a catalog of paradoxes. For each paradox there is a history behind it, sometimes as a consequence of other paradoxes, and the author writes it very well.

You can find, in 24 chapters, near 400 pages, discussions such as:

  • Pythagoras’s Search for the Common Denominator
  • Socrates: The Paradox of Inquiry
  • Aquinas: Can God Have a Biography?
  • Kant and the Antinomy of Pure Reason
  • Russell’s Set
  • Ockham and the Insuolubilia
  • And the usual suspects such as the negative paradoxes and similares.

I love paradoxes, since they are the “living” proof that, limits exist in our thinking and science. They are the obstacles in our progress for a better understanding of the universe in every area. And as every obstacle, they exist to show our errors and works as an opportunity for us to be better.

There are several books about paradoxes, many of them work as a catalog. But this one, is not about specific paradoxes, but about the Paradox, and its history in different areas such as philosophy, science, religion and others.
I always love a good history, and when it is about paradoxes, that’s a plus.

You can find the book here:
(https://www.amazon.com/Brief-History-Paradox-Philosophy-Labyrinths/dp/0195179862/)

Book Review: Intuition Pumps from Daniel C. Dennett

Intuition pumps, and other tools for thinking, from Daniel C. Dennett is what the title says, a set of small chapters/tools, usually 2 to 4-5 pages to make you think, and so, gaining a new tool for your mental process.

The book has several sets of these intuition pumps, I will highlight these:

  • General Thinking Tools
  • Tools about meaning or content
  • Tools for thinking about evolution
  • Tools for thinking about consciousness
  • Tools for thinking about free will

This book has around 70 of these tools, as the author calls them. If you read one every day, you can read it in 2-3 months.
Since each tool fits in just a few pages, this is the kind of book you read when you just want a nugget of wisdom, at home, in a train or you just need to kill a few minutes and you don’t know what to choose to read. You will never go wrong about improving your thinking skills!

Of course, the first chapter is about making mistakes, the subject most discussed everywhere about success.
But other subjects such as: Occam’s Razor, where the author explains its origin from an older rule of thumb lex parsimaniae, or the law of parsimony, meaning in simple terms Do not multiply entities beyond necessity

The murder in Trafalgar Square is a very interesting discussion about how an event is perceived using different senses, however everyone understands it to be the same thing. Imagine a person gets shot in Trafalgar Square, one does it, another sees it, another receives the news by hearing and imagine it. If all these persons come together they can talk about it to some degree, although only one of them really experienced it. What is reality?

Or, if someone implants you a lie in your brain without you know about it, how much time do you think it will take for your brain to discover it, since there are no experiences registered in your brain that explains that lie! Is really impressions, memories or experiências?
I really loved this one.

I liked this book, since it challenges the perception we have about the reality around us and within ourselves. Every time I finish one of the intuition pumps my mind keeps thinking about it for while, which means it has found value in the reading.

The book accomplishes what proposes to achieve, just Intuition Pumps, and other tools for thinking

You can find it in amazon Here

(https://www.amazon.com/Intuition-Pumps-Other-Tools-Thinking/dp/0393348784)

Jupyter notebook – Execute with parameters using CLI

executet-params-jupyter-notebook.md

Jupyter notebook – Execute from Command Line with parameters

The best way to execute a jupyter notebook with parameters is to use Papermill

  1. install: pip install papermill
  2. create a cell at the start of your jupyter notebook and add the tag: parameters
  3. add your variables to that cell
  1. and execute the command

papermill my-jupyter-notebook.ipynb my-output-notebook.ipynb -p project_key data-science-proj-key -p date '2021-08-01'

  • --p – the variable name and the value to be injected

More details here: papermill@github

Jupyter Notebook – Execute from Command Line

executet-jupyter-notebook.md

Jupyter notebook – Execute from Command Line

A typical command to execute a jupyter notebook from command line:

jupyter nbconvert --to notebook --execute mynotebook.ipynb --output output-name

  • --to notebook – the output format
  • --execute – the name of the notebook to be executed
  • --output – an optional name for the generated file

One question sometimes asked is if it is possible to pass parameters to a jupyter notebook.

  • Yes, it is possible, but you need help from papermill. See my next posts for more details.

Jupyter notebook – export to html

Jupyter notebook – Export to HTML

A typical command to export a jupyter notebook to html:

jupyter nbconvert my-notebook.ipynb --to html --no-input --no-prompt --output my-notebook-html

  • --to html – the output format
  • --no-input – without the python code
  • --no-prompt – remove the prompts from the output
  • --output – an optional name for the html generated file

How to extract an attribute from gradle.properties using bash

In some projects the version is written in the gradle.properties file using the attribute:
version=1.0.0-SNAPSHOT

I usually use this version as the version to be tagged in the Sonar server, for code analysis. This way, it is easier to have metrics more accurate when checking the new code against the previous release.

How to get the version. Alue using bash:
cat gradle.properties | “ˆ\sversion\s=“ | cut -d’=‘ -f2

And for the definition
version=1.0.0-SNAPSHOT

you should see
1.0.0-SNAPSHOT

How to get or display the project version from maven

When I am doing quality analysis on projects, one of the things I like to use is the real version of the project in Sonar.

How to extract it from maven projects?

mvn -q -Dexec.executable=echo -Dexec.args=‘${project.version}’ --non-recursive exec:exec

If your pom.xml has something like

You should see:
1.0.0-SNAPSHOT

How many unit tests?

There are several advantages in developing unit tests:

  • finds bugs early
  • You trust your code
  • Makes your code simpler, because you probably refactor it to make the tests easier to develop
  • It documents your code. The name of each unit test almost describes the feature
  • You will be more confident to change the existing code
  • It documents your code
  • The unit tests when running they are debugging your code
  • It makes it easier to troubleshoot production issues. You can reduce the scope of the analysis
  • It reduces costs. Code with fewer bugs reduces the costs of troubleshooting later
  • They execute faster than the other tests. You can use them as a rapid verification of the quality of our code.

Looking at all these advantages, we surely start to think we should develop as many unit tests as possible.
But the truth is, you should develop just enough unit tests.

How many unit tests are enough?

Let’s first analyse the consequences of developing unit tests:

  • Every unit test increases the coupling between your production code and the unit test. Meaning, every time you change the production code, you need to update one or several unit tests.
  • Developing unit tests takes time, not only developing but maintaining them too
  • It is very easy to start testing code that doesn’t need testing, such as the use of external frameworks. I see this a lot!
  • The unit tests, test the algorithm, not the functionality. You will prefer to use that time to develop integration tests, they cover more code with just only a few tests. Be aware they require some preparation, though (a future post)
  • Can create a lot of coupling if you use have to use a high quantity of mocks

Looking at all these advantages and disadvantages, I usually advise:

  • target a coverage around 70%, more than this starts to create a high couple between the code and the tests
  • Use an approach of risk-based testing, meaning
    • choose to test the branch in your method or unit that covers the most important functionality
    • cover the code that cannot fail because it brings costs to the company
  • Develop them at the same time as you develop the method, otherwise, the code will become complicated to test. Use a TDD-ish approach.