Total Lunar Eclipse (Super Blue Blood Moon), January 31, 2018

Yesterday sister sent me a request over an e-mail if I could print some document for her. Of course I wanted to grant her wish immediately only to find out after first page being printed, a black cartridge was out. Since it was only 6 pm and the nearest shop that sells cartridges was still open for an hour, I decided to take a walk. It was a nice weather outside, low temperatures (7 °C) felt refreshing, and after a few steps I glanced up in the sky. I noticed bright clouds and at first thought they are just high enough for sun still reaching them. But after some distance, when house rooftops cleared from my view, I saw the reason. It was a full moon, slightly bigger than usual and brighter.

Till than I knew nothing about the phenomena which is quite unusual for me since I spent a lot of time behind computer due to my profession. So I should’ve been able to spot the news by then on news portal and social media. It turned out this was a total lunar eclipse, also know as a full blue blood moon. This means:

  • super: full or new moon that is more or less closest to the shortest distance between Moon and Earth,
  • blue: has nothing to do with the colour. Refers to second full moon in a month or 3rd or 4th in a season.
  • blood: due to its reddish colour. It happens because sunlight reflects from Earth and its atmosphere filters and scatters green and violet lights on spectrum more than red.

Avtomatska rokometna lestvica (WordPress plugin)

Last weekend I developed for an acquintance a WordPress plugin which I’ve titled “Avtomatska rokometna lestvica” (translates to “Automatic handball league table” from Slovene). He’s a contributor to an official website of RK Trimo Trebnje, my local handball club and asked me if it’s possible to have a functionality which replaces the manual work of reading a website with statistics for a league table, selecting only a handful of columns and saving it to a blogpost. I had a lot of experiences with web scraping so I was immediately sure it can be done.

Without knowing where the scraped data will be displayed, I coded plugin’s option page using WordPress’s Settings API (and utilizing my library which simplifies creating option’s page). It’s just a textarea which accepts CSV-like data where each league table is represented in one line and one line contains a selection name and URL to its stats.

I have also coded a logic which actually scrapes the necessary data – table of team position, team name and team points and makes new table which is than saved into the database. For reading and constructing HTML tables I’ve used PHP’s DOMDocument. I’ve enjoyed working with this class.

Web-scraping is done periodically at midnight using wp-cron. They way wp-cron works is it launches when first user visits the site after the time it’s set to repeat.

Now comes the part where I learned how it’s going to be displayed. More than one league table needed to be shown (for selections like members, cadets, juniors,…), they were grouped in tabs. Inputs where they are edited were present on certain WordPress page using cusom fields. The problem for me was I had no idea where this fields are stored in the database. So the content from web-scraping process can be saved there.

I fixed this problem quite elegantly, I must say. I saved the content into wp_options table under a key {$package}_{$selection} and for displaying it I’ve coded a shortcode which queries wp_options for the key {$package}_{$selection} and returns HTML stored under that key – selection is specified as an argument to shortcode.

My experiences using Anko library (Android Kotlin)

I’ve been using Anko library from the start of my Kotlin journey and my experiences with it are mostly positive.

According to its Github readme page, Anko is

...a Kotlin library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.

Anko consists of several parts:

- Anko Commons: a lightweight library full of helpers for intents, dialogs, logging and so on;
- Anko Layouts: a fast and type-safe way to write dynamic Android layouts;
- Anko SQLite: a query DSL and parser collection for Android SQLite;
- Anko Coroutines: utilities based on the kotlinx.coroutines library.

It provides basic guide for getting started.

Where I find Anko the most valuable is when dealing with SQLite and creating dialogs.

  • When dealing with SQLite, you don’t need to worry about closing the database after querying it, concurrent access, creating cursors.
  • Dialogs simplifies Android development so much because it eliminates all boilerplate associated with connecting dialog fragment to activity and dialog-activity communication with after user interacted with the dialog.

I don’t like its layouts component though. Because:

  • it encourage mixing logic with presentation,
  • it doesn’t work so nicely with complex layouts,
  • it has no layout preview.

But because pros of using the library out-weights the cons, I’m willing to rate my experience with the library positively. I haven’t refrained from using its layouts component, just limited its usage to simple use cases.

One-liner for serving static files in Go explained

Whenever I want to set up a server for serving static files in Go, which is not often, I always have to spend some time to figure out the following one-liner.

http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("./images"))))

What confuses me probably the most here is all three strings being practically the same.

So in this post I will explain what this does for my future-self so he won’t have to google about it and will have it explained here in a way he’ll like it. 🙂

For this particular example (where one-liner above applies) let’s say we are storing images in ./images folder on a server and accessing them from outside of the server with <server's domain>/images/article2.jpeg

  • We shouldn’t set up a file server at root endpoint if our server accepts other endpoints.
  • http.FileServer(http.Dir("./images"))) exposes folder ./images as a handler.
  • http.StripPrefix is used because images are stored in ./images` folder and not in it’s subfolder images (we want ./images/article2.jpeg not ./images/images/article2.jpeg). It strips prefix from request’s URL.

A friendly reminder

Serving static files is more efficient using dedicated web server (Nginx, Apache,..). This approach also aids to better security of your application.

Gut and Psychology Syndrome (GAPS)

In last year I kinda became obsessed with healthy foods. I decided to eliminate sugar (not counting fruit) and processed food and instead incorporate more healing foods into my diet. Examples include green tea, kefir, bone broths and other other inflammatory food.

I also became acquainted with so-called healing diets, namely Specific-Carbohydrate diet (SCD diet) and Gut and Psychology (GAPS) diet. I’ve studied them both but haven’t practiced them. Also for a SCD diet I think it’s a way too restrictive. But what’s great about both diets are the fact they are backed by books, written by authors of diets (SCD diet has Breaking the Vicious Cycle by Elaine Gottschall, GAPS diet has Gut and Psychology Syndrome by Natasha Campbell-McBride). I read both of them. Each of them was very informative.

I’ve enjoyed reading Gut and Psychology Syndrome because it has chapters which describe how human gut works (beneficial, opportunistic flora), how it’s state influences our immune system, what harms it. That’s what interests me very much in general. But other chapters (about genetics, vaccination) deserves attention too because we live in a world where it’s lifestyle (diet rich in sugar and processed food, medicine) does tremendous damage to our body and next generations and are responsible for diseases, which weren’t so widespread till the 20th century. The author, Natasha Campbell-McBride, the doctor and a mother of a recovered autistic child thanks to her GAPS diet, writes in thought-provoking style from time to time which also makes for an entertaining read.

The GAPS diet is explained in her book and that’s what I was looking too when borrowing the book from hometown library. It’s premise is to heal a disease by healing the gut. I intend to incorporate additional food to my diet from it.

I definitely recommend the book to parents who have children (whether they have health problems or not) and people who wants to lead a more normal life with less or free of digestive problems and better immunity.