2020-12-31

New machine

8 years after the previous one, I bought a new computer and available hardware has changed quite a lot!

I bought an Asus PN50 with an AMD Ryzen 4800U, which is probably 30 or 40 times smaller than my previous machine but more powerful while using a lot less power...

Asus PN50 next to a credit card for size reference

I fit it with 32GB ram (with a second slot free to go to 64 later) and WD BLACK SN750 1TB NVME SSD and performance is really impressive for such a small machine with low power consumption (building an x86_64 Linux kernel with defconfig takes 2m35s). 

Writing to a file is far from the announced 3000MB/s Sequential Write Performance but still crazy high compared to what I was used to:

$ dd bs=16M count=512 if=/dev/zero of=test oflag=sync
512+0 records in
512+0 records out
8589934592 bytes (8.6 GB, 8.0 GiB) copied, 11.4705 s, 749 MB/s

It also gives me accessible USB-A, USB-C and micro SD ports which is very convenient for example to write images to USB sticks or SD cards.

2020-12-10

Playing with Chrome extensions

After a few days trying to book a Visa appointment with TLS Contact which had 0 availability and the consulate telling me to just often refresh, I decided to write a Chrome extension to check when they add them and notify me in case I would be around.

In the past I had done that with scripts after saving the cookies/tokens but this time I decided to try doing it in the browser. 

Pros:

  • I just need to login in a tab and let it there. It keeps refreshing so the session remains valid, but if it expired I would just need to login again.
  • I get to learn extensions APIs
Cons:
  • I will not be notified while not in front of my computer, however they seem to be manually adding the appointments so only during working hours
The first part was to create a content script to be run in the context of the page each time I visit a page matching the given URL. This is achieved by adding this to the manifest.json:

"content_scripts": [
  {
    "matches": ["https://*.tlscontact.com/*/myapp.php*"],
    "js": ["contentScript.js"]
  }
],

In that script I made it reload the page every 10 minutes (as the data is directly in the response from the PHP script) and when the page is loaded to parse it to find available appointments. I then used the storage API to preserve that list between reloads and compare to know if there are new appointments.

I used the sync API, meaning it is shared between my browsers, just because I can.

chrome.storage.sync.get('available', function(result) {
  var av = result['available'] || {};
  // Diff, log changes and notify of new ones
  chrome.storage.sync.set({available: available}, function() {});
});

The next interesting part is the notifications, as user scripts are very restricted and can not use the notification API. What I had to do was to add a background script, which has more power, by adding this to the manifest.json:

"background": {
  "scripts": ["background.js"],
  "persistent": false
},

Now when the content script wants to notify of a new appointment, it sends a message:

chrome.runtime.sendMessage({Appointment: a}, function(response) {});

In the background script, I listen to those messages and create notifications:

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    chrome.notifications.create(request.Appointment, {
      type: 'basic',
      title: 'New appointment available!',
      message: request.Appointment
    }, function(notificationId) {});
    sendResponse({response: ""});
  }
);

And that's it! It turned out to be much simpler than expected, and we booked an appointment the next day.


2020-12-02

Enlarging an AWS NVMe root disk

There are plenty of documentations/questions about enlarging partitions but I had a problem before reaching that stage as the kernel does not seem to notice that the size of the disk changes (and I did not want to reboot).

AWS documentation says it should work Linux kernel 4.2 or later but this does not work for me with 5.7.19. It also suggests hdparm -z but that fails as the disk is busy.

After a bit of digging I found the right sysfs entry:

# echo 1 > /sys/block/nvme0n1/device/rescan_controller

Now the kernel notices:

[472580.761678] nvme0n1: detected capacity change from 107374182400 to 214748364800

And everything else works as expected:

# growpart /dev/nvme0n1 1
CHANGED: partition=1 start=206848 old: size=209508319 end=209715167 new: size=419223519 end=419430367
# resize2fs /dev/nvme0n1p1
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/nvme0n1p1 is now 52402939 (4k) blocks long.