Simple SQL tips

Nothing ground breaking, but hey, simplicity and basics are the most important. Reader Rules Don’t run select * queries without filters You might not know how big the table you are querying is. Therefore, in order not to negatively impact the performance of the whole system, limit the amount of the query. Instead of 1 select * from myTable; use 1 select * from myTable limit 10; Writer Rules Use transactions Even simple & tested queries might have unintentional side-effects. ...

April 20, 2024 Â· 2 min Â· 231 words

How to do a null check

Checking for null is important in programming to avoid potential runtime errors, prevent crashes, and ensure the reliability and robustness of your code. In C#, we can check for null in few different ways, depending on the context. So far I have been using following methods: Using the equality operator 1 2 3 4 5 6 7 object obj = null; if (obj == null) { // if null, do something } Using the is keyword 1 2 3 4 5 6 7 object obj = null; if (obj is null) { // if null, do something } Using the ReferenceEquals() method 1 2 3 4 5 6 7 object obj = null; if (ReferenceEquals(obj, null)) { // if null, do something } Using the != opeartor 1 2 3 4 5 6 7 object obj = null; if (obj != null) { // object is not null } Using the null-conditional operator ?. 1 2 3 var text = null; int? length = text?.Length; // length will be null, if text is null Using the null-coalescing operator ?? 1 2 3 var text = null; var result = text ?? "default non-null value"; // if text is null, use the default value

March 11, 2024 Â· 1 min Â· 203 words

Update PIP Packages

I am trying to implement inifinite scroll functionality to some of my blog pages and at the same time decided to do some maintanance work for my blog, which includes upgrading the packages I am using. I have found a lot of ways, but really simple one is to use an external library called pip-review. First install the lilbrary: pip install pip-review{.single} To upgrade packages manually run: pip-review --local --interactive{.single} To upgrade all packages automatically run: ...

March 10, 2024 Â· 1 min Â· 79 words

Access Modifiers

I have recently started learning C# language, which, compared to python, is a lot more verbose and structured. C# syntax is influenced by C and C++ languages. Part of CS50 Introduction to Computer Science course used C language, so having seen the syntax before helps a lot. However, working mostly with Python, there is a lot of difference. As I like to do, I will try to summarize key points as it helps me to learn and understand the language more. ...

February 25, 2024 Â· 3 min Â· 486 words

Inspecting temporary pop-up

I needed a selector for a temporary pop-up, but it was impossible to get it in time as it would disappear quickly. Found a small trick using browser devtools. Open console Run the following javascript: setTimeout(() => { debugger; }, 5000){.single} Click the element that calls the pop-up Browser will enter debugger mode in 5 seconds (you can adjust), freeze the page and you can inspect the pop-up.

November 25, 2023 Â· 1 min Â· 68 words

PyTest - Parametrizing Test Functions

One of key features of PyTest is the ability to create parametrized tests, meaning running test cases with various input values without having to write separate test cases. Main goal of my most recent Django project is to develop better understanding of testing principles and tools. I have already built few Django applications, however never really focused on testing my own code - I was just happy the app “worked”. Knowing what and how to test is a skill in itself. It is quite a challenge. One can write hundreds of test cases which are not really covering the essential functionalities, or they repeat. Just as most of the things, it comes with a practice. However, I understand the long-term value of writing and having effective tests. ...

October 6, 2023 Â· 2 min Â· 417 words

Dump & Restore PostgreSQL database in a Docker

I was updating my blog and needed to use the same database which I currently have in production. Since my blog is fully dockerized, managing the state of the application between production & development environment is a lot easier. For this purpose, I have researched and learned two handy commands, one to export the database and the other one to import the database. Export (dump) with pg_dump{.single}: 1 docker exec -i container_name /bin/bash -c “PGPASSWORD=actual_password pg_dump —username actual_username database_name” > /path/of/export/export.sql Import (restore) with psql{.single}: 1 docker exec -i container_name /bin/bash -c “PGPASSWORD=actual_password psql —username actual_username database_name” > /path/of/export/export.sql I have noticed successful import even with errors (default PostgreSQL behaviour), because I already had some migrations (in my Django app). Therefore I would recommend first resetting the whole DB and then importing the database. If you want to overwrite this default behaviour and stop upon error, add -set ON_ERROR_STOP=on{.single} to your command. ...

September 13, 2023 Â· 1 min Â· 152 words

Django Password Validators

By default Django comes with an advanced password validator, meaning user must enter password with a minimum length of 8 characters, some special sign, number. For production environment this is very important, however for development environment a simpler password would do and it wouldn’t take so much time. Today I have learned how to turn the advaced password protection off (remember to remove this line for production). Add the following line to your settings.py file: ...

August 31, 2023 Â· 1 min Â· 79 words

yield vs return

As I’m currently using and learning PyTest framework in my QA Automation project, I have noticed that a lot of functions decorated with @pytest.fixture() decorator use the yield keyword instead of the return keyword. I was not sure about the exact difference between these two statements, therefore I have decided to research it a bit more. return vs yield statement Both yield and return are keywords in Python and both are used in a function to pass values from one function to another in a program. ...

August 8, 2023 Â· 2 min Â· 346 words

Page Object Model

To improve my automation skills, I am working on a QA Automation project where I have to solve various Test Cases that test many aspects of the web-application. I have started this project with the main goal of developing better understanding of Page Object Model, Selenium and PyTest. For the bigger projects it is very important to correctly design and structure the project itself. Very popular design pattern for this purpose is called Page Object Model. This way, I would like to sum-up some of the things I have learned about POM so far. ...

August 7, 2023 Â· 4 min Â· 786 words