An awesome entry to better code: The gilded rose kata

For some reason, I was told an interesting github repo, The Gilded Rose Kata. It really grasps my attention. The code's behavior is correct, but both code quality and code style are terrible. The author of the repo made it so bad on purpose. So it is the best material to teach newbies how to refactor.

From the Readme file of the repo, I learnt some new tools, one is the text based approval test. I actually know that concept before many years ago, but never practiced it. I just found it is easy to setup and easy to run. It tests your code from a new angle. I believe it could belong to a kind of greybox test. You need to know the code to test, but you don't know too much like other unit test methods.

I have done the refactoring, and my result has been put on Github.com

  1. first approach is on the main branch https://github.com/shukebeta/GildedRose-Refactoring-Kata/tree/main/csharpcore

  2. a better approach is on the other branch https://github.com/shukebeta/GildedRose-Refactoring-Kata/tree/simple-factory-pattern-approch

Here are some good links, and I would update it timely.

Writing good tests for the gilded rose kata
Principles for agile test automation
The gilded rose refactoring kata
How to refactor gildedrose refactoring kata with simple factory pattern and strategy pattern

Git Tips: Remove tracking branches no longer on remote

My colleage Joe asked me tonight, "how to remove those branches that no longer exist on remote?"

In short, you have two options

  1. run git remote prune origin at times
  2. run git config --global fetch.prune true command to config your git to delete those branches every time when you run git fetch

I prefer the second option, how about you?

Reference

Fix swagger stuck on extend an API: How to configure Swashbuckle to ignore property on model

Referenced

I found the root cause is that the JSON generated by swagger is too large: Swagger outputs over 18000 lines for that API! Further research told me that two property fields contribute about 17000 lines. So how to configure swagger to ignore these two properties is the key. After googling a while, I found VeganHunter's answer in this thread Reference is the simplest.

Solution for .NET Core 3.1 and .NET Standard 2.1:

Use JsonIgnore from System.Text.Json.Serialization namespace.

( JsonIgnore from Newtonsoft.Json will NOT work )

public class Test
{
    [System.Text.Json.Serialization.JsonIgnore]
    public int HiddenProperty { get; set; }
    public int VisibleProperty { get; set; }
}

Hope it could also help someone else. 😀

"Wind River" is a great movie

I watched the movie yesterday morning on my own. It's a moving movie, and it's great! The reason to choose this movie is this tweet. I always have the interest in the Indian people in America. They are kind of our Asian's relatives, aren't they?

Three things made me love this movie.

  • The plot, no preachment, just a story.
  • The hunter, he is a great father!
  • The mountains and the snow everywhere.

Indian people deserve a better treatment.

Solved: XPS 15 on Pop OS 20.04 gui got stuck after updating firmware

Previously, I have updated the firmware several times, so when I saw there's a new update, I clicked the "Update" button without too much thoughts. Yes, I got trouble this time. I got a black screen while the system is not dead. I can log into the system by pressing Alt+Ctrl+F2, no gui, but I can do something to fix it. It is good enough. I searched on my cellphone to try find something. And the following article helped me.

System76 login-loop-pop

In my case, I guess that the root cause could be the nvidia driver, so I followed the [Reinstall NVIDIA Driver] section in that article and it did save my life.

# remove current driver
sudo apt purge ~nnvidia
sudo apt autoremove
sudo apt clean
# reinstall it
sudo apt update
sudo apt full-upgrade
sudo apt install system76-driver-nvidia

In case someone else got trapped into the same situation, I wrote my solution here and hope it helps.