30. Dec 2020 |

1/100 – js

Found #100DaysOfCode challenge on Tekkie‘s Twitter where he is currently learning Rust. I will try. Today is the first day.

Started with M. Kalmos JS course from 2018 🙂 I will try to do it as much as possible before it vanishes. Then it will turn into Distributed Systems (js and dotnet course).

I wanted to rebuild this in JS with some improved functionality but stuck into async-await and promises issue 😀 Classic. Need to continue tomorrow. At least I have something to do for an hour.

Update: It was simpler. For some (esthetic?) reason I executed the script before DOM was build. Rookie mistake.

15. Dec 2020 |

NETSDK1005 – update dotnet aspnet-codegenerator

If you are getting this error NETSDK1005 when trying to scaffold the webpages that says “Assets file [..] doesn’t have a target for ‘net50′” then please check if you have updated dotnet aspnet-codegenerator. Documentation is behind this link.

I got stuck to this for some time before figuring it out. I had updated dotnet SDK and runtime but not aspnet-codegenerator (which I was not aware of).

Though, now I am running into another issue – “A file matching the name Create.cshtml was not found” 🙂 I have not yet figured out any solutions. But I see people running into it quite everywhere.

Update: I discussed it with the teacher and TAs and got to the conclusion that this is some kind on Linux specific aspnet-codegenerator issue. As it is used mainly for intoductory/demo purposes at this point then I simply proceed without demo content as there is no actual need for this.

Few useful commands for myself as a footnote:

dotnet --info

dotnet tool list -g (List your dotnet tools, useful)

Updates
dotnet tool update --global dotnet-ef (EF update to the latest, link)
dotnet tool update -g dotnet-aspnet-codegenerator (Update codegenerator, link)

5. Dec 2020 |

C# – cannot resolve symbol ‘UseIdentityColumns’

Getting build errors in DAL after InitialMigrate due to missing nuget package.

If you get such an error from Rider after initial migration dotnet ef migrations add InitialMigration --project DAL --startup-project WebApp that cannot resolve symbol ‘UseIdentityColumns’ then please check that you have nuget package Microsoft.EntityFrameworkCore.SqlServer v5.0.0 installed in DAL (data access layer) class library. I had it missing and could not figure out for some time and Stack Overflow did not have any threads available for it at this point.

I use C# 9, dotnet 5.0 and Rider EAP 2020.3 at the moment. If you use any of the earlier versions of dotnet or C# then please pay attention to getting the correct version of the package.

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.