function formatBytes(bytes) {
if (0 === bytes)
return '0 Bytes';
const sizes = [
'Bytes',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
],
s = Math.floor(Math.log(bytes) / Math.log(1024)),
size = bytes / Math.pow(1024, s);
return `${size.toFixed(2)} ${sizes[s]}`
}
Smart Doorbell Client, Server and Hardware Applications
I delivered an Angular JavaScript front-end for an Access-Control System with Facial-Recognition, refactored the API and entire Python back-end over the IoT device, built the Desktop setup application and even contributed to the Hardware development !
Wireless Raspberry Pi Bridge
A little while ago, I wrote some setup script and web application for a wireless Raspberry Pi bridge.
This package wirelessly connects a Raspberry Pi to available WiFi networks and bridges the connection to an access point.
You will need a Raspberry Pi 3 and an extra WiFi adapter.
More details on the GitHub repository.
JavaScript API Client Class: Queue, Fetch and Cache
An ES6 class to queue API requests, fetch results and cache for performances. See the script on gist.github.com.
How to Use
I’m glad you’re asking. Let’s take the Movie Database for instance.
import API from './api';
const theMovieDB = new API('https://api.themoviedb.org/3', {
api_key: 'YOUR-API-KEY'
}, 1000 / 4);
We instanciate the API to request with an api_key
parameter, and set the rate limit to 4 requests per second.
const topRatedRequest = theMovieDB
.get(`movie/top_rated`, {}, 12 * 60 * 60);
Then we queue a GET request and set it to cache for twelve hours.
topRatedRequest.done(data => console.log('Top Rated Movies', data.results));
When response is available, we log the results.
topRatedRequest.cancel();
But we could also cancel this request.