Posts

Showing posts with the label JavaScript

Converting callbacks to promises quick and easy

It’s easier to work with Promises (or Async/await) compared to callbacks. This is especially true when you work in Node-based environments. Unfortunately, most Node APIs are written with callbacks. Today I want to show you how to convert callbacks to promises. Before you read this article, it helps to know what a  promise  is. Converting Node-styled callbacks to promises Callbacks from Node’s API have the same pattern. They’re passed into functions as the final argument. Here’s an example with  fs.readFile . const fs = require ( 'fs' ) fs . readFile ( filePath , options , callback ) Also, each callback contains at least two arguments. The first argument must be an error object. fs . readFile ( 'some-file' , ( err , data ) => { if ( err ) { // Handle error } else { // Do something with data } } ) If you encounter a callback of this pattern, you can convert it into a promise with Node’s  util.promisify . const fs = require ( '...

Hand Tracking in the Browser using Tensorflow.js and 3 lines of code.

Image
Handtrack.js library allows you track a user’s hand (bounding box) from an image in any orientation, in 3 lines of code. Here’s an example interface built using Handtrack.js to track hands from webcam feed. Try the  demo here. A while ago, I was really blown away by results from an experiment using  TensorFlow  object detection api to  track hands  in an image. I made the  trained model and source code available , and since then it has been used to prototype some rather interesting usecases ( a tool to help kids spell , extensions to  predict sign language ,  hand ping pong , etc). However, while many individuals wanted to experiment with the trained model, a large number still had  issues  setting up Tensorflow (installation, TF version issues, exporting graphs, etc). Luckily, Tensorflow.js addresses several of these installations/distribution issues, as it is optimized to run in the standardized environment of browsers. To...

Popular posts from this blog

How to download a file using command prompt (cmd) Windows?

The future of Artificial Intelligence: 6 ways it will impact everyday life

Angular 9 - User Registration and Login Example & Tutorial