Month: August 2018

Learning Python design patterns Second Edition, book review

learning_python_design_patterns_se-Book_Cover

Published on: 15.08.2018

Number of pages: 141
Written by: Chetan Giridhar
Publish by: PACKT Publishing

Conclusion
This is the first book that I have read regarding software design patterns in Python language, for me it is useful as the code implementation reference.

Review

Book explains and implements some(singleton, factory, facade, proxy, observer, command, template method, MVC, state design) software design patterns in Python language.

It also gives the general overview of design patterns and antipatterns.

What I do not like is that book first does an explanation of code and then shows the code that has been already explained.

For me, it is better first to see the code and then to read the explanation of it.

The best approach for explaining code so far I have seen in Fluent Python.

In that book, the first code is shown and then it is explained.

And the best part, in Fluent Python, not the whole code is explained but just concepts that you have not seen in the book before.

My experience with learning software design patterns from books is generally unsuccessful.

I learn things when I need to use them, so generally only when I had the unmaintainable code and when I wanted to make it more manageable I usually end up reinventing some pattern.

Then I was able to understand some design patterns, from standpoint of why to use it (what is the benefit).

But I do recommend reading books about design patterns, even if you do not understand it completely because probably you will remember it when you need it in practice and then you can open it, read it and implement it.

Believe me, it is easier than reinventing patterns from scratch.

I think that book would be better is first there was code written without design patterns because than the reader could see what kind of mess it is and how hard is it to maintain it.

But that kind of book would probably be even 3-5 time longer.

How to backup personal GitHub repositories

Published on: 01.08.2018

I will show how to do a backup of your GitHub repositories with python-github-backup

Why to bother with a backup of GitHub

I can already see that there will be comments regarding why to do the backup of GitHub.

  • “It is a waste of time.”
  • “GitHub internally already have backups.” (I hope so)
  • “They will not lose your code” (But maybe I will)
  • “They will not go overnight out of business.”

Response to all those comments is:
You will not be worst off if you have your own backup.

If forever reason (GitHub go under, all repositories deleted by accident, alien attack) GitHub is not available anymore, I have my own backup of code that I have written.

Paid solution

If you are looking for a paid solution, BackHub looks like a good solution.
I have no experience with BackHub, nor am I in any way associated with it.

Free solution

After researching all available options I have decided to go with python-github-backup because it had more stars and contributors on GitHub than other projects.

I have used the number of stars and contributors on GitHub as the assumption that python-github-backup is more in use than other solutions so there are more people who will continue to support it in future.

In order to access your GitHub personal data, you need to have a personal access token.

After that, you can install it with pip/pipenv:
(I have installed it in separate virtualenv)

pipenv install github-backup
or
pip install github-backup

Run it with:
/full/path/github_backup/venv/bin/github-backup sasa-buklijas -t your_personal_access_token -o /full/path/github_backup --all

This command will backup all your GitHub information to /full/path/github_backup directory.

It would be tiresome to run this command every day, so I have automated it on my online hosting.

Crontab

My usecase:
15 00 * * * /full/path/github_backup/venv/bin/github-backup sasa-buklijas -t your_personal_access_token -o /full/path/github_backup --all > /full/path/github_backup/last_log.txt

> /full/path/github_backup/last_log.txt is used to have an output of the last backup command.
>> can be used to have outputs of all backup commands, but I have found that having just last one is enough.

Conclusion

“You will not be worse off if you have your own backup.”

Do you have backups of your own personal GitHub repositories, if you have, what do you use for backup?