6. Feb 2022 |

Eestiblogid.eu – my hobby project

To improve my coding skills in a safe environment I should start working more on the hobby project eestiblogid.eu. I currently has ~150 weekly users so if I mess something up it should not be huge problem 🙂

Currently it is just 2 small services which I call Reader and Writer.

Reader is a small independent PHP application which basically reads the given list of XML files (RSS feeds) every hour and checks if there is anything new. If there is something new then entry is made to the database. Rules for detecting “new” are very primitive. Therefore, quite often you can see duplicate posts. Reader will probably stay as it is. I should just make the code cleaner from time to time, implement some logging etc.

Writer is also a small php application (using Twig for templating and Bootstrap for styling) to generate views for the front end and reading data from database.

There is no admin panel at the moment. I go straight to the database to edit things (remove, deactivate, delete etc).

Up next

What I would like to do now is to prepare REST endpoints for the front end. Probably it will be php backend built with Laravel or Lumen using their Eloquent ORM.

Front end should be built with React together with admin views for myself (using JWT for authentication).

I try to keep you informed of the progress under this eestiblogid.eu tag.

Update 09.03.22

It has been less than a month. I have not done anything (too busy with my internship). But, meanwhile, Lumen has become extinct (not being developed any further) and I am most probably considering GraphQL (with Lighthouse) insead of REST. So probably it is good that I have not done much.

14. Jan 2022 |

Solution: Composer dependencies require a PHP version…

Sorry. This is stupid advice here. Please don’t follow it 🙂 If your dependencies require different PHP version then change PHP version or change the dependency (to different version). Simple.

I tried to initiate new Laravel project and ran into an error. I have been using php 8.0.2 but Magento needed 7.4 so I switched to 7.4 and now I am having this issue with Composer 🙂

Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27.

PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27. in C:\Users\john\AppData\Roaming\Composer\vendor\composer\platform_check.php on line 24

How to get the value of PHP_VERSION_ID

In terminal run php -a and then var_dump(PHP_VERSION_ID);  You should see the id. To exit you can use ctrl+c.

How to solve it

Open the platform_check.php file and update the PHP_VERSION_ID to what you currently have.

Not sure if it is the best practice but it works.

8. Jan 2022 |

How to prepare for the TestDome php assessment – my mistakes and tips

3rd year IT student in search of an internship

5th semester at school is pretty much over by now. Only one small assignment to do on upcoming Tuesday Thursday. Hopefully, I will write about the semester at some point.

On Monday I am going to do PHP tests for the internship that I applied for. I am preparing for it at the moment by solving Testdome PHP exercises and PHP interview questions. If I succeed it would be a huge step for me to become a sufficient Magento developer one day.

Continue reading “How to prepare for the TestDome php assessment – my mistakes and tips”

8. Oct 2021 |

PostgreSQL create db and user

I need it quite often during development (mainly school work) that I need to create new database together with new user that can only use this specific database. Here are three simple commands that do just that.

CREATE DATABASE robert_db;
CREATE USER robert WITH ENCRYPTED PASSWORD 'x1y2z3';
GRANT ALL PRIVILEGES ON DATABASE robert_db TO robert;

In development I usually keep db name and user name the same so that I have less variables to remember.

10. Sep 2021 |

Tee endale vanast arvutist server

Kui ma oleksin teadnud, et enda serveri tegemine on nii lihtne, siis ilmselt oleksin seda teinud juba varem.

Otsides kohta, kust enda arenduse asjadeks pisike VPS võtta, jõudsin selleni, et tegin (esialgu) enda vanast riiulis seisvast Dell XPS13 läpakast Linuxi serveri. 2011 mudel, i5-2467M, 4GB RAM, 512 SSD (dual masin boot, millest osa on Win7 all). See seisab ka serverina 99% ajast ilma koormuseta.

Nüüd mõtlen, et peaks võibolla läpaka Raspberry Pi 4B‘ga asendama (komplekt läheks kuskil 145 eurot). Kui kellegi on pakkuda, siis anna märku 🙂 Update: Hetkel tundub hea mõte, et ma sellega ei kiirustanud. ARM protsessoril ei tööta Docker normaalselt (viide) nii et kui üldse, siis pigem mõni Inteliga NUC või mini-PC (nt IBMi ThinkCentre).

Mul on kodus kõige tavalisem Elisa 50/10 internet ja meeldivaks üllatuseks on kõik public IP pordid lahti. Public IP’le päringuid tehes saan enda serverile ligi. Jah, see on aeglane 😀 Kui Zone annab VPSile 1 Gbit/s sisenev ja 100 Mbit/s väljuv liiklus, siis minu puhul on need hetkel vastavalt 20x ja 10x pisemad. Aga andmebaasipäringuteks piisab küll.

Kuna mul zone.ee’s on ka mõne domeenid registreeritud, siis tegin ühele neist A-kirje ja nii ei pea ma enda IP’d meeles pidama. Kuna IP ei ole staatiline, siis IP muutumisel, piisab A-kirje uuendamisest.

Mis mul seal on

Operatsioonisüsteemina on serveris Ubuntu Desktop 18.04.5 LTS (sest juba ammu installitud). Kõik asjad, mis serveris jooksevad on Dockeri konteinerina.

Esimene asi, mille tööle püüdsin saada oli see, et IP’le päringu tehes avaneks kõige tavalisem nginx (hääldatakse nagu “engine X”) Welcome Page. Piisas sellest, kui:

  • Docker on installitud (snap install docker või snap remove docker eemaldamiseks)
  • nginxi kontener käivitada docker run --name nginx_container --rm -d -p 8080:80 nginx (viide). –rm tähendab, et kui teed docker stop containerId, siis konteiner kustutatakse ära.
  • Ruuteris teha port forward sisse tuleva public IP port 80 mappida sisemises võrgus oleva seadme (ehk siis laptopi) IP porti 80. Minu puhul oli vaja mappimine teha Elisa antud Technicolori ruuteris (kuhu server-läpakas on kaabliga ühendatud). See on kõige lihtsam setup.

Seejärel installisin (kõik eraldi dockeri konteinerid) MariaDB, phpMyAdmin (selle MariaDB külge) ja Microsoft SQL Serveri.

Millest on abi

tracert that.ee – näed, kust seadmetest su liiklus läbi läheb ja kuhu ta jõuab.

Turvalisus

Selle koha peal ma olen kõige tuhmim hetkel ja mul ei ole head ettekujutust, missugused ohud mind varitsevad.

  • Ufw (Uncomplicated Firewall) panin peale
  • Sisse saab ainult SSHga, parooliga sisselogimise keerasin kinni

Kasulikud Dockeri käsud

Dockeriga toimetamine tahab super useri õiguseid. Ehk siis sudo su.

sudo snap install docker – installib Dockeri
sudo snap remove docker – eemaldab Dockeri
sudo docker ps -a – näitab kõiki konteinereid ja nende infot
sudo docker start <containerId> – käivitab konteineri
sudo docker stop <containerId> – peatab konteineri
sudo docker rm <containerId> – kustutab konteineri

sudo docker image list – näitab arvutis olevate image’te nimekirja
sudo docker image rm <imageId> – kustutab image

Kui mingi asjaga tekib raskuseid, siis Google otsing ja Digital Oceani juhendid aitavad enamasti alati.

9. Sep 2021 |

IDEA shortcuts

ctrl+shift+F10 – execute current file
ctrl + alt + M – extracts code to method
ctrl + alt + V – introduce variable
ctrl + B – move into method and back
alt+F7 – who is using variable
ctrl+alt+T – surround…

Debugger F8 – step over
Debugger F9 – resume program

Useful

Breakpoint → add condition

6. Sep 2021 |

URL shortener (free) using only PHP8 and SQLite3

I wrote a small, easy to deploy URL shortener. As it is written in PHP and uses SQLite3 as a data storage then no installation is needed. Just drag and drop the files through FTP to your host, configure the .htaccess file and you are ready to go.

Files are available on github – github.com/robineero/php-url-shortener. There is also database already prepared and SQL script available. Feel free to modify everything according to your needs.

2. Sep 2021 |

VPS price comparison – student in search of the cheapest

My main use of VPS is that i need to keep my dev MS SQL, PostgreSQL and MariaDB servers somewhere. The cheapest Hetzner VPS has done the job though for simple CRUD tasks. But bigger appliations (like WooCommerce) the Digital Ocean’s smallest droplet tends to become slow. Therefore I would not recommend anything below Hetzner’s CPX11 2 vCPU and 4GB of RAM.

The cheapest end of VPS

Minimum requirements: 1vCPU and 2GB memory. Looking only for Linux machines.

AWS, Google Cloud, Azure and Alibaba Cloud are much more expensive and more difficult to use for this simple purpose of just hosting few Docker containers with capped (end therefore predictable) pricing.

If you need 2 vCPU then starting price at the moment is shown in the table below.

Digital Ocean $15
Hetzner CPX11 € 4.75
26. Jul 2021 |

How to declare jQuery variables

var $allParas = $("p"); – When a variable starts with a $ sign, like in the following line of code, it’s a convention that developers use to indicate when a variable is storing a jQuery collection. Which means that you don’t have to do it, but you can if you’d like.

Many developers like to prefix the names of variables that store jQuery collection objects with a $, because it makes it obvious that they can call jQuery methods on them. It’s particularly useful if your code has a mix of variables that store jQuery collections and variables that store DOM elements.

Also acceptable to use var pic = $("#picture"); variable which stores a jQuery collection object. That collection does indeed contain a reference to the selected DOM element object, but it also contains many other properties and methods.

Source: Khan Academy