Traditionally, relational databases required all tables to have a fixed data schema, i.e. a set of attributes (such as a “user” table with attributes “firstName”, “lastName” and “email”). You could change the schema by adding and removing attributes, but the available attributes were always know at a given point in time.
For many use cases, this was acceptable. However, some applications have the need to store semi-structured data: entries where the attributes are not known ahead of time.
Since 2012, PostgreSQL allows to store semi-structured data inside tables in the JSON notation:
"Title": "How to store JSON in PostgreSQL"
This allows having different sets of attributes for different rows in your table while leaving your table schema constant.
This tutorial is about how to highlight the currently active page in your navigation with Thymeleaf and Spring Boot. Highlighting the active page is a known usability pattern and should help users to find their way around your web application.
Consider this example:
In the navigation above, the navigation item “Cronjob Monitoring” is highlighted.
By using th:each, a link is generated for each navigation entry.
th:classappend is used to conditionally append a CSS class to the <a> element. The class mdl-navigation__link-active in this case simply changes the background color, but you can opt for a less subtle approach.
request.requestURI.startsWith(navItem.getLink()) evaluates to true if the specific navigation item’s URL is currently opened in the user’s web browser. For example:
This method is very powerful because as long as you add all your controller actions with the same prefix, your navigation works out of the box without having to set any variables in the controller methods.
https://www.pingmy.tech/ is currently launching as a public beta – it is a new web app which helps you monitoring your periodic background tasks (such as backups, data exports, accounting checks etc) and notifies you via email or slack when your services appear unavailable. Check it out – it is completely free.
Running regular background tasks on a network-attached storage (NAS) is an essential use case for backups, monitoring and more. With Synology DiskStations, there is an easy GUI-based approach to configure such tasks which still allows you to execute custom scripts.
First, navigate to Control Panel > Task Scheduler:
In a blue-green deployment strategy, there are always two instances of your application running in production. A reverse proxy is used to direct traffic to either the green or the blue version. You then deploy changes to your application by first updating the inactive version and then changing the load balancer config to redirect traffic to the updated instance.
In this video, I will show you how to set up a very simple version of such a blue-green deployment using just Apache, Docker and CentOS 8.
Sometimes I want to quickly save some code changes that I am not ready to commit into a real branch. For example, I might be in the middle of a long refactoring and there is a complete mess that I do not want to show up in version control history:
Git has the “stash” command which removes all uncommitted changes and saves them to a local data structure where they can be retrieve later. However, this comes at the disadvantage that stashed changes only live in your local environment – they cannot be synced to tools like GitHub or GitLab.
This is fine for small changes, but when you really need to make sure to keep your changes, there is a more permanent solution that also does not pollute your version control history.
You save your changes by committing them to a “dirty”, temporary branch (let’s call it temp_refactor:
git checkout -b temp_refactor
git add .
git commit -m "some trash commit"
Your changes are now reflected in the temp_refactor branch and can be pushed to a remote repository.
When you are ready to continue, change to the branch you actually want your changes to end up at and do the following:
git checkout feature/my_normal_feature_branch
git checkout temp_refactor -- .
All your changes are now back as unstaged changes and you can continue your work.
Zabbix is a great open source tool to monitor operating system and application metrics. You can install it on your web server and out of the box, it is able to show you fancy graphs for things like:
Disk space usage
Free swap space
In this guide, I will show you how to create a dashboard widget that displays the response time for a specific URL over time. You can use this to monitor your production website and make sure there are no performance issues. In the end, it will look like this:
Make sure that you copy the generated p12 file to the same folder where the Dockerfile is located because the “ADD” command expects a relative path as a first argument.
Adapting your application.properties
Either directly append these lines to your application.properties or add the corresponding keys as environment variables as described in this article (the keys need to be transformed to underscore-separated capitalised letters – e.g., SERVER_SSL_KEYSTORE="..."):
You need to renew your Let’s Encrypt certificate regularly. Use the certbot tool with the following parameters:
certbot-auto certonly -a standalone -d subdomain.example.org
and copy the resulting certificate to the same location used before. Then restart your Docker container and you are done – your certificate has been renewed.
Also make sure your port 80 is still free – if you have an application running on that port, stop it for a few seconds (you can restart it immediately after the invocation of certbot-auto) – otherwise the renewal process might fail.
You can verify whether the certificate works by running your application and targeting your browser to its URL with the https:// prefix – you should see the following HTTPS information:
Ignoring the semantics of HTTP methods such as GET and POST can have disastrous security repercussions. You might think that using GET methods for deleting entities is fine since you only need to pass a single identifier and do not want to set up its own HTML form for doing so. Please let me convince you of the opposite.
Before we can go into detail why this distinction matters for web application security, we need to grasp the semantics of HTTP methods.
MDN lists HTTP GET as an HTTP method that needs to be safe and idempotent. If you want to conform to their interpretation of REST principles (and I believe this to be a very good idea), you need to fulfil those two properties in all your GET methods.
Depending on your security settings, the following warning needs to be accepted by clicking “Open”:
You should then see an output similar to the following:
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
Congratulations! You have installed OpenJDK 14.
One more thing:
I’m currently working on a cool side project named pingmy.tech – it allows you to monitor the execution of regular background tasks such as backups and notifies you when they are not executed on time. Please check it out and use the invitation code BLOG20 to create an account for free: https://www.pingmy.tech
In this post, I am showing you how to use the freely available Open Weather Map API to retrieve hourly weather forecasts 48 hours into the future for a given place using Python without external packages.
Continue reading if you need an easy and flexible way to obtain weather data in your python application and you want to avoid using third-party dependencies for the task. You will use the free tier of the Open Weather Map API. The resulting weather data includes:
sunrise and sunset time
“feels like” temperature
All the above data points are returned hourly for the next 48 hours in JSON format for free.
We will use Python to query the API without using any dependencies except for the requests and json packages so you can easily adapt it to suit your particular needs. Let’s get started!