21. Nov 2020 |

Let the Spotify play your favourite songs by 30 seconds

Inspired by this article and the economic situation for musicians I wrote this little script. This lets Spotify to play your favourite artists on rotation and automatically presses “next” after every 33 (+ littlebit of random) seconds. 30 seconds is the minimum amount of time a song must be listened to before Spotify registers a single “play”.

Loading the song also takes little bit of time so you can not maximize the play count by making the loop take exactly 30 seconds long.

function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min) + min);
}

function doSomething() {
    var button = document.querySelector('[aria-label="Next"]');
    button.click();
}

(function loop() {
    var rand = getRandomInt(33000, 37000);
    console.log(rand);
    setTimeout(function() {
        doSomething();
        loop();
    }, rand);
}());

If you are using Spotify in your browser the press ctrl+shift+k or just F12, open console tab, paste this code there and press enter. This code does nothing but pressing the button with title attribute “Next” after every 33-37 seconds (random between these times).

Example of how it works in browser.

It is one option to support your favourite artists 🙂

12. Oct 2020 |

Entity–relationship diagram (ERD scheme) for family tree database

I have seen this question asked many times and most of the times poorly answered.

Entity–relationship diagram for family tree database. N means ‘nullable’ in this syntax.

I think it could be done like this. The left one has two tables – person and pairing. Person table is for entities and the other table for relationships between persons. The green one has both in one table and it is basically recursion hierarchy between Persons.

I don’t know if this solution is correct or not. Neither know I which one is better 🙂

Lines on the right ERD explained:

  • Each mother_id can be mother to zero-to-many person_id’s
  • Each father_id can be father to zero-to-many person_id’s
  • Each person_id can have 0-to-1 father id (zero if I don’t know the father) and 0-to-1 mother id. Person can not have more than one biological father and mother.

NB! You can not add relationships between Persons before you have created the Person you need. Therefore I suggest to leave everything nullable where it makes sense.

Please come back later. If I have time I will share SQL query for setting up MySQL database with sample data and maybe some simple php interface.

10. Oct 2020 |

MySQL autoincrement PK growing quickly

Primary key (PK) is skipping values for some reason. This was an issue I spent time solving until I discovered that auto increment column increases after insertion error occurs. To avoid duplicates on this website I set rule on MySQL side that if three colums match then don’t insert (give insertion error and continue). This way I had hundreds of insertion errors every hour and therefore PK was growing rapidly.

19. Sep 2020 |

mysqli ja täpitähed

Kulutasin eile öösel paar tundi, et täpitähtede liikumine andmebaasi ja andmebaasist tagasi ühel kodulehel korda saada. Hetke lahendus on selline nagu pildil. See set_charset("utf8") oli puudu. Aga enna ma muidugi toimetasin kõvasti charseti kallal ja tegin andmebaasi uuesti ja kõike muud 😀

Muidu virinat ka. Tore, et WordPress ja Blogspot genereerivad erineva struktuuriga RSSi ja et blogijad omakorda suudavad seda RSSi kerge vaevaga purustada.

1. Nov 2019 |

How to remember

When I do coding tasks for school I find really cool solutions and wonderful workarounds from time to time. I wonder how should I remember all this. How should I archive and structure all this knowledge. Should it be like learning a language where I should prepare learing cards (for vocabulary) to remember basic things by heart. Like what goes where when I need to append something to a list.

 

7. Oct 2019 |

It is EU Code Week 5-20 October 2019

EU Code Week is a grassroots initiative which aims to bring coding and digital literacy to everybody in a fun and engaging way.

The last part of this EU Code Week aim is somewhat non-relatable. Because I just debugged my WP store like 6 hours (to make stock syncs faster) on Saturday and at the moment struggling with entry-level Python tasks for school. So, I can say this period of “fun and engaging” is very short in the learning curve 🙂 In my previous profession in the pharmaceutical industry it was called misleading communication and it was not allowed.

Or, I may be doing something wrong.