Skip to content

Instantly share code, notes, and snippets.

View MichielDeMey's full-sized avatar
Always available for a coffee

Michiel De Mey MichielDeMey

Always available for a coffee
View GitHub Profile
@MichielDeMey
MichielDeMey / machine.js
Last active March 11, 2021 13:34
Generated by XState Viz: https://xstate.js.org/viz
const mockPoll = () => {
return new Promise((resolve, reject) => {
console.log('Polling...')
setTimeout(() => {
console.log('Done polling')
return resolve([{
id: 'foo',
name: 'Foo'
}, {
id: 'bar',
@MichielDeMey
MichielDeMey / machine.js
Last active March 5, 2021 16:34
Generated by XState Viz: https://xstate.js.org/viz
const mockPoll = () => {
return new Promise((resolve, reject) => {
console.log('Polling...')
setTimeout(() => {
console.log('Done polling')
return resolve([{
id: 'foo',
name: 'Foo'
}, {
id: 'bar',
const dialTimeout = 7000;
const answerTimeout = 7000;
const externalActions = {
notify: () => {
window.alert('Notified care circle');
}
}
const dialActor = (timeout = 5000) => {
@MichielDeMey
MichielDeMey / machine.js
Last active October 31, 2019 09:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@MichielDeMey
MichielDeMey / machine.js
Last active September 24, 2019 14:07
Generated by XState Viz: https://xstate.js.org/viz
const guards = {
maxAttemptsReached: (ctx, event, { cond }) => {
return ctx[cond.actor].attempts >= cond.numAttempts && !ctx[cond.actor].success
},
maxAttempsCurrentCarerReached: (ctx, event, { cond }) => {
return ctx.carers[ctx.currentCarerIndex].attempts >= cond.numAttempts && !ctx.carers[ctx.currentCarerIndex].success
},
additionalAttemptsMainCarerReached: (ctx, event, { cond }) => {
return ctx.mainCarer.additionalAttempts >= cond.numAttempts
},
@MichielDeMey
MichielDeMey / transform_json_streaming.js
Created July 31, 2017 07:28
Transform a JSON array using streams
const fs = require('fs')
const transfuse = require('transfuse')
const stationsStream = fs.createReadStream('./stations.json')
const geoJSONStream = fs.createWriteStream('./stations.geojson', { autoClose: false })
const stationTransformer = transfuse((doc, map) => {
if (doc.lng > 180.0 || doc.lng < -180.0 ||
doc.lat > 90.0 || doc.lat < -90.0) {
console.log('malformed location', doc.naam)
@MichielDeMey
MichielDeMey / keybase.md
Last active June 15, 2016 10:57
keybase

Keybase proof

I hereby claim:

  • I am michieldemey on github.
  • I am michieldemey (https://keybase.io/michieldemey) on keybase.
  • I have a public key ASAMVzuGgsiMNwwR7VsjFMrfzylMnJB4xyLk0Lgl0TfhrAo

To claim this, I am signing this object:

@MichielDeMey
MichielDeMey / Rails CORS workaround
Created November 21, 2012 15:24
Rails CORS workaround
# before_filter :authenticate_admin_user!
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'