Skip to content

Instantly share code, notes, and snippets.

@sesteva
sesteva / machine.js
Last active June 11, 2020 14:43
Generated by XState Viz: https://xstate.js.org/viz
const gameMachine = Machine(
{
id: "pyramid",
initial: "play",
context: {
bet: 25,
levels: 3,
currentLevel: 1,
pyramid: {
// 0 => losing element
@sesteva
sesteva / quick_sort.js
Created April 30, 2020 22:09 — forked from pedrombafonso/quick_sort.js
Quick sort Sorts JSON complex type arrays by property
function partition ( list, prop, begin, end, pivot ) {
var piv = list[pivot];
swap (list, pivot, end-1 );
var store = begin;
var ix;
for ( ix = begin; ix < end - 1; ++ix ) {
if ( list[ix][prop] <= piv[prop] ) {
swap (list, store, ix );
++store;
}
@sesteva
sesteva / machine.js
Last active April 7, 2020 22:25
Generated by XState Viz: https://xstate.js.org/viz
const queueMachine = Machine({
id: 'queue',
initial: '',
context: {
queue: []
}
})
const calendarMachine = Machine({
id: 'calendar',
@sesteva
sesteva / machine.js
Last active February 20, 2020 14:31
Generated by XState Viz: https://xstate.js.org/viz
const results = [
{
"category":"Entertainment: Video Games",
"type":"multiple",
"difficulty":"easy",
"question":"Which game did &quot;Sonic The Hedgehog&quot; make his first appearance in?",
"correct_answer":"Rad Mobile",
"incorrect_answers":[
"Sonic The Hedgehog",
"Super Mario 64",
@sesteva
sesteva / machine.js
Last active February 19, 2020 18:04
Generated by XState Viz: https://xstate.js.org/viz
const results = [
{
"category":"Entertainment: Video Games",
"type":"multiple",
"difficulty":"easy",
"question":"Which game did &quot;Sonic The Hedgehog&quot; make his first appearance in?",
"correct_answer":"Rad Mobile",
"incorrect_answers":[
"Sonic The Hedgehog",
"Super Mario 64",
@sesteva
sesteva / machine.js
Created January 8, 2020 13:29
Generated by XState Viz: https://xstate.js.org/viz
const CART_EVENT = {
ADD: "ADD",
REMOVE: "REMOVE",
UPDATE_QTY: "UPDATE_QTY",
SAVE_FOR_LATER: "SAVE_FOR_LATER"
};
const SAVE_FOR_LATER_EVENT = {
ADD_TO_LIST: "ADD_TO_LIST",
UNSAVE: "UNSAVE",
MOVE_TO_CART: "MOVE_TO_CART"
@sesteva
sesteva / machine.js
Last active December 18, 2019 14:43
Generated by XState Viz: https://xstate.js.org/viz
const cartActions = {
addProduct: assign((ctx, evt)=> ({
cart:{
...ctx.cart,
count: ctx.cart.count + 1,
products: [...ctx.cart.products, evt.payload]
}
})),
addSaveForLater: assign((ctx, evt)=>({
@sesteva
sesteva / machine.js
Last active December 12, 2019 23:24
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sesteva
sesteva / machine.js
Created December 2, 2019 21:40
Generated by XState Viz: https://xstate.js.org/viz
const context = {
password: ""
};
const passwordMachine = Machine(
{
initial: "idle",
context,
states: {
idle: {
@sesteva
sesteva / machine.js
Last active February 10, 2020 16:00
Generated by XState Viz: https://xstate.js.org/viz
const buttonMachine = Machine(
{
id: "submitButtonWithTransitions",
initial: "disabled",
states: {
active: {
on: {
HOVER: "hovered",
PRESS: "pressed",
CLICK: "clicked",