How to subtract dates in Node.js

Need to subtract dates in Node.js? No problem, let’s use Java for that. After installing GraalVM using SDKMAN: $ sdk install java 20.0.1-graal as well as installing GraalVM’s Node.js runtime using gu1: $ gu install nodejs we can now perform some black magic: // index.js // "Import" LocalDate & ChronoUnit from ☕️ const LocalDate = Java.type("java.time.LocalDate"); const ChronoUnit = Java.type("java.time.temporal.ChronoUnit"); const firstDate = LocalDate.of(2023, 7, 20); const secondDate = LocalDate.of(2023, 8, 4); console....

July 20, 2023 · 1 min · Abdelrahman Abdelhafez

The Sierpiński triangle

Recently I’ve watched a video showing how to draw an approximation of the Sierpiński triangle on paper using the following steps1: Plot three points to form an equilateral triangle Randomly select any point inside the triangle and consider that your current position Randomly select any of the triangle’s vertices Move half the distance from your current position to the selected vertex Plot the current position Go to step 3 I found it absolutely fascinating, and at the same time I was extremely skeptical....

January 1, 2023 · 3 min · Abdelrahman Abdelhafez

Logic programming in JavaScript

Have you ever contemplated the possibility of having your computer solve your problems for you, without you having to tell it how? If your answer is a frantic “yes!”, you’re in luck: this is a thing, and this thing is called logic programming. We start writing our logic pragram by declaring the facts that we know. Let’s consider a typical, red-haired, magical family: % main.pl % Facts father(arthur, ron). % Arthur is a father of Ron father(arthur, ginny)....

May 30, 2022 · 3 min · Abdelrahman Abdelhafez