Skip to content

Instantly share code, notes, and snippets.

View asamurai's full-sized avatar
:octocat:
Learning

Artem Verhun asamurai

:octocat:
Learning
View GitHub Profile
@asamurai
asamurai / machine.js
Last active August 3, 2023 12:07
Generated by XState Viz: https://xstate.js.org/viz
const GAP_WALK_TASK_STATE_MACHINE_ID = "gapWalkTask"
const createGapWalkMachine = taskContext =>
Machine(
{
strict: true,
id: GAP_WALK_TASK_STATE_MACHINE_ID,
initial: 'toDo',
context: {
import { useEffect, useState } from 'react';
import { Keyboard } from 'react-native';
export const useBackHandler = () => {
const [isOpen, setOpen] = useState(false);
useEffect(() => {
const keyBoardShowListener = Keyboard.addListener('keyboardDidShow', () => setOpen(true));
const keyBoardHideListener = Keyboard.addListener('keyboardDidHide', () => setOpen(false));
return () => {
keyBoardShowListener.remove();
provider "fastly" {
api_key = "${var.fastly_apikey}"
}
resource "fastly_service_v1" "iot_main" {
name = "IoT main service ${var.environment_tag}"
domain {
name = "${var.fastly_domain}"
}
import findShortestWay, { Matrix } from './algorithm';
/**
* To test this algorithm for finding the shortest way
* from the client location to target server location
* we can show abstractly pull of servers as an undirected graph.
*
* As undirected graph we can use simple randomly filled grid or matrix.
*
* Matrix cell filled with "1" means as unavailable server
export type MatrixLocation = Array<number>;
export type Matrix = Array<Array<number>>;
/**
* This function describes possible algorithm to find
* the shortest way from client to server
*
* @param serverMatrix - matrix of available servers
* @param client - initial client location
* @param server - target server location