Posts

Building collections: Immutable Clojure vs mutable OOP

In traditional OOP, if you have some collection A and based on the elements of A you need to build another collection B, a common approach is instantiating B as an empty collection, iterating over A and at each iteration appending a new element to B. When working with Clojure I had to invite a new way of thinking about this sort of task. To demonstrate the two approaches, I've thrown up equivalent solutions to the same task in both PHP and Clojure. The task defines a map whose keys are years and values are structures which contain 2 integers (liabilities and equity). The goal is to calculate assets (the sum of liabilities and equity) of each year and just put them in another structure: an array in PHP and a list in Clojure. The original structure, of course, needs to remain intact. The following is the version in PHP which loops through one structure and mutates another. Now, the interesting part. In Clojure, as data structure are immutable you cannot instantiate an empty s...

Preserving test cases when removing the tested classes

In my - most likely - final days of PHP development, I thought about writing something related to PHP. I had this topic on my todo list for some time. It is about testing. It is a strategy, actually 2 of them, that I often used to cover my arse when refactoring code. I have talked about it verbally but, in my opinion, writing information down is always a good thing. The whole idea is described in  https://github.com/varfrog/testing-topic . The content below is a copy-paste of the README from Github. Scenario There is a class  \App\Example1\Formatter  with a single public method  format(string) . This method receives a string, reverses the sequence if its words, and in the resulting set of words appends an increasing natural number to each word. For example: Input Output a b c c1 b2 a3 foo bar baz baz1 bar2 foo3 This method is unit-tested, see  \App\Example1\Tests\Unit\FormatterTest . It tests that the method correctly transforms the text as in the table above: #...

Proper thickness of gymnastics rings to learn the false grip

Image
I am training to do a proper muscle-up on gymnastics rings. A muscle-up has 3 components: a false grip ( https://www.google.com/search?q=false%20grip ) a pull-up a dip I do have the strength to do pull-ups and dips on rings separately. However, in a muscle-up you join two movements together - you transition from a pull-up to a dip. For the transition to be possible you have to hold the rings with a false grip, as it shortens the distance from your chest to the rings. For quite some time I was having big trouble with the false grip. I could not support my full body weight with a false grip, not to mention pulling myself up. It hurt the spot that touched the ring, at the hand joint area. Pushing through pain is an idiotic approach to exercise, and I did not want an injury. I did some research on the web and decided to try rings with a greater diameter. The rings I was having trouble with were  28 mm  in diameter, and they were made of plastic. I bought new wooden ones with a dia...

Database Deadlocks

Image
I have had to explain database deadlocks several times and I had this old code project to produce a database deadlock and I had the following scheme for explanation: However it was a bit too little or too confusing to get the idea through sometimes, so I retired the project and recreated a new one on the newest Symfony. It runs on Docker and produces a deadlock by running just one command. It’s on Github:  https://github.com/varfrog/deadlock-symfony . The main point is that a deadlock happens when the same records are being locked by different processes in a different sequence. More on this in the README of the project.

Cyberghost Vpn on Arch Linux

  CyberGhost has apps or shell scripts for various Linux distros but not for Arch Linux, at least not at the time of writing this. However, it is very easy to configure it for Arch. Here’s what I did. Steps Logged into  https://my.cyberghostvpn.com/,  “My Download Apps” -> “Other Apps” -> “Routers and other devices” -> “Configure New Device”. Make the selections, for my setup I’ve selected “Open VPN” as the protocol. Download the OpenVPN configuration files. Extract the archive, mv the files to  /etc/openvpn/client . chmod 600 /etc/openvpn/client/* chown openvpn:network /etc/openvpn/client/* Create an auth file that stores the login credentials for this VPN connection /etc/openvpn/client/login.conf with the username on the 1st line and the password on the 2nd line. Change  auth-user-pass  in cyberghost.conf to  auth-user-pass login.conf . sudo systemctl start openvpn-client@cyberghost sudo systemctl enable openvpn-client@cyberghost Check the I...

Dual booting Arch Linux and Ubuntu on separate SSDs

Image
  Issues I have Arch Linux on one SSD disk and I installed Ubuntu on a new SSD disk. Upon system restart it booted automatically with the GRUB configuration that Ubuntu had installed, not the GRUB configuration that I had for my Arch Linux - BIOS/EFI prioritized the disk Ubuntu is on (issue A, see below). Also this GRUB configuration had an os-prober-generated grub.cfg “menuentry” to boot into my Arch Linux installation (issue B), which unsurprisingly did not work. Disk setup I chose identical setup for both of the SSD’s - and thus an EFI partition in the 2 of them. [root@arch-pc grub.d]# fdisk -l Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors Disk model: ADATA SP580 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: A1ADEEAF-4A37-4807-9C99-6F4B2AAB79D8 Device Start End Sectors Size Type /dev/sda1 2048 534527...