View machine.js
const splitA = { | |
id: 'splitA', | |
initial: 'qualifStep', | |
states: { | |
qualifStep: { | |
on: { | |
NEXT: 'emailStep' | |
}, | |
}, |
View geojson-to-networksettings.js
// 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] |
View intervalAsync.js
/* | |
`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(), { |
View seasoning.js
/* | |
`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' }) |
View ES6-promise-resolveAll.js
/* | |
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 => { |
View ES6-request-json.js
/* | |
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); |
View AWS Serverless Architecture notes.txt
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? |
View validCandidate.js
function validCandidate(languages) { | |
let validCandidate = false | |
let languageRegex = /script$/ | |
if(Array.isArray(languages)) { | |
validCandidate = !!languages.filter( (language)=> languageRegex.test(language) ).length | |
} else if (typeof languages == 'string') { | |
validCandidate = languageRegex.test(languages) | |
} | |
return validCandidate | |
} |
NewerOlder