This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Text-based snake game</title> | |
<style> | |
#board { | |
border: 3px solid; | |
float: left; | |
font-size: 24px; | |
line-height: 1.5ex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const splitA = { | |
id: 'splitA', | |
initial: 'qualifStep', | |
states: { | |
qualifStep: { | |
on: { | |
NEXT: 'emailStep' | |
}, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Geojson | |
// Produced by | |
// 1. Google My Map / Export to KMZ | |
// 2. Convert KMZ to GeoJSON (using https://mygeodata.cloud/converter/kmz-to-geojson) | |
// 3. Utilise any helpers below to produce the `output` and, through the console, run copy(JSON.stringify(output)) | |
// Util: polygonToAllowedArea | |
// Convert a polygon in a Network.settings.AllowedArea ([]{latitude: number, longitude: number}) | |
// Entry: Array[Longitude: number, Latitude: number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
`setInterval` triggers a function every X secs. | |
It's not satifying when you deal with asynchronous functions, such as API calls. | |
It is indeed possible that the response comes right before the next scheduled call, or even after, defeating the purpose of intervals. | |
The `interval` function below aims at solving this issue. | |
Usage: | |
// real life usage, used in a redux thunk | |
interval(() => bodymap.get(), { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
`seasoning.js` adds season awareness to your programs. Help finding out what season it is. | |
Usage: | |
// Get the season using the user's browser location (NOTE: it requires the user's authorisation) | |
seasoning.getSeason() | |
.then(console.log); | |
// Get the season using the user's geoip | |
seasoning.getSeason({ locationProvider: 'ipinfo' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2017, still not using Promises? You missed the memo. | |
Promise.all lets you run a serie (iteratable list) of promises but will reject as soon as one reject. | |
Sometimes though, you want to try resolving all of them, and then address the rejected ones. I call that "gracefully fail". | |
Usage (promises is an array of promise): | |
// Using the default error handler | |
resolveAll(promises) | |
.then(resolved => console.log('List of my resolved promises result')) | |
.catch(errors => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
fetch is awesome, there's no question about it. | |
But aren't you tired of: | |
- Writing your `res => res.json()` handler | |
- Having to stringify your body | |
- Signin your request with the same headers (```{'Content-Type': json, Authorization: 'JWT ...'}```) | |
- Inconsistently handling the response status code and not reject promise when relevant. | |
Usage: | |
request('http://yourawesome.api.com').then(console.log).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using native nodejs packages? | |
https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/ | |
How to figure out the amount of memory needed? | |
https://github.com/berezovskyi/lambda-test | |
How does my lambda consume external APIs? | |
https://aws.amazon.com/blogs/aws/aws-ip-ranges-json/ | |
When a lambda fails, does it retry itself? |
NewerOlder