Saturday 2 January 2021

Some JavaScript Beauties 2021

Lately I've come across some pretty interesting JavaScript projects, fragments of code... whatever

This article comparing Deno with Node is a great read, but there's something that particularly caught my eye, this code:


// http-server.ts 
import { serve } from "https://deno.land/std/http/server.ts"; 

for await (const req of serve({ port: 8000 })) {
    req.respond({ body: "Hi from Deno!\n" }); 
} 

I was used to see Web Servers implemented as event emitters. You provide a callback/handler to the server.run and each time a request is received your callback is invoked, so requests are pushed to you. This Deno server takes a quite different approach, it's implemented as an asynchronous pull stream (asyn iterator). Your code asynchonously iterates over a stream of web requests. I don't say that one approach is better than the other, I just think that it's really "fresh" and interesting.

Trying to get a basic glimpse of Machine Learning I came across tensorflow.js. I particularly liked this demo.

Those demos use pretrained models, so obviously you are not running the traning algorithms in the browser, but anyway I became curious as to whether it would be possible to run code into the GPU from browser side javascript. This curiosity is due to the fact that GPUs are important in training models cause they are very good for data parallelism, and basically model training involves running the same matrix calculations on huge datasets. And yes, we have GPU.JS! The magic that allows browser JavaScript to get access to the GPU lies in WebGL.

I've known about processing-js since a long while, and I've recently found that there is a related project p5.js that takes the functionality beyond the canvas, allowing to interact also with html5 elements. One more thing added to my list of "play with it once you find some time...".

No comments:

Post a Comment