Skip to content

Instantly share code, notes, and snippets.


Alex Girard grabcode

View GitHub Profile
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
// 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]
grabcode / intervalAsync.js
Created Jul 26, 2017
Utility function to cope with `interval` executing asynchronous call.
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.
// real life usage, used in a redux thunk
interval(() => bodymap.get(), {
grabcode / seasoning.js
Created Jul 24, 2017
Is winter coming? `seasoning.js` adds season awareness to your programs.
View seasoning.js
`seasoning.js` adds season awareness to your programs. Help finding out what season it is.
// Get the season using the user's browser location (NOTE: it requires the user's authorisation)
// Get the season using the user's geoip
seasoning.getSeason({ locationProvider: 'ipinfo' })
grabcode / ES6-promise-resolveAll.js
Last active Jul 5, 2017
resolveAll is concurrently running promises until they all either resolve or reject. Free to customise how to handle failure.
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
.then(resolved => console.log('List of my resolved promises result'))
.catch(errors => {
grabcode / ES6-request-json.js
Last active Jul 5, 2017
ES6 fetch syntactic sugar: handling common fetch usage with json content type, same headers, and stringified body
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.
View AWS Serverless Architecture notes.txt
Using native nodejs packages?
How to figure out the amount of memory needed?
How does my lambda consume external APIs?
When a lambda fails, does it retry itself?
View cookie-recipe.html
grabcode / validCandidate.js
Last active Apr 12, 2016
validCandidate function
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