Skip to content

Instantly share code, notes, and snippets.

View jesuarva's full-sized avatar
💭
Ars longa vita brevis

Jean jesuarva

💭
Ars longa vita brevis
View GitHub Profile
@jesuarva
jesuarva / SketchSystems.spec
Last active March 22, 2020 11:09
My Awesome Sketch
My Awesome Sketch
loggedOut
authSuccess -> loggedIn
loggedIn
logOut -> loggedOut
@jesuarva
jesuarva / machine.js
Last active February 13, 2020 13:27
Generated by XState Viz: https://xstate.js.org/viz
function resolveOrReject(shouldResolve, resolve, reject, data) {
if (false) shouldResolve ? resolve(data) : reject(Error("🐞💩"));
}
["validateForm"].forEach(functionName =>
eval(`${functionName} = function (a, b) { return a + b; };`)
);
const formMachine = Machine({
id: 'FormMachine',
@jesuarva
jesuarva / machine.js
Last active February 14, 2020 10:26
Generated by XState Viz: https://xstate.js.org/viz
function resolveOrReject(shouldResolve, resolve, reject, data) {
if (false) shouldResolve ? resolve(data) : reject(Error("🐞💩"));
}
['configFileTemplates', "loadTemplate", "loadCurrentConfig", "getTenantList", "validateForm"].forEach(functionName =>
eval(`${functionName} = function (a, b) { return a + b; };`)
);
const formMachine = Machine({
id: 'FormMachine',
@jesuarva
jesuarva / machine.js
Last active January 24, 2020 09:13
Generated by XState Viz: https://xstate.js.org/viz
function resolveOrReject(shouldResolve, resolve, reject, data) {
if (false) shouldResolve ? resolve(data) : reject(Error("🐞💩"));
}
function getBaseConfigDetails() {
return new Promise((resolve, reject) => {
resolveOrReject(true, resolve, reject, {
tenant: "SCB_SINGAPORE_CBP",
kiosk_version: 2.2,
dev_environment: "development"
@jesuarva
jesuarva / maxPathLength.js
Last active December 10, 2018 09:39
Given a binary tree, find the longest posible path. O(n) -> only one 'depth first search' like loop.
'use extrict';
class Node {
constructor(value, left, right) {
this.value = value;
this.left = left; // A reference to another Node object
this.right = right; // A reference to another Node object
this.leftPathLengtth = 0; // The longest path on the left side of the Node
this.rightPathLengtth = 0; // The longest path on the right side of the Node
this.getMaxPathLength = this.getMaxPathLength.bind(this);
@jesuarva
jesuarva / sudokuValidator.py
Created September 27, 2018 09:54
Validates a sudoku grid.
def grid3x3(i):
if i in range(0, 3):
return 1
if i in range(3, 6):
return 2
if i in range(6, 9):
return 3
def validateSudoku(grid):
@jesuarva
jesuarva / is_permutation_palindrome.py
Last active July 26, 2018 15:47
String has a permutation that is a palindrome? - Python
'''Write a function that, given a string, determines whether any permutation
of that string is a palindrome.
Examples:
"civic" should return True
"ivicc" should return True
"civil" should return False
"livci" should return False
@jesuarva
jesuarva / binarySort.js
Created July 12, 2018 15:26
Given an array comprised of 0s and 1s, write a function in linear time that will sort the array.
function binarySort(arr) {
let control = '';
arr.forEach((digit, index, arr) => {
!control && arr[index] == 1 && (control = index);
if (control && arr[index] == 0) {
arr.splice(index, 1);
arr.splice(control, 0, 0);
control++;
@jesuarva
jesuarva / cycledLinkedList.js
Last active July 11, 2018 16:01
Check if the a Linked List contains cycle.
/*
Create a function that returns true if a linked list contains a cycle, or false if it terminates
Usually we assume that a linked list will end with a null next pointer, for example:
A -> B -> C -> D -> E -> null
A 'cycle' in a linked list is when traversing the list would result in visiting the same nodes over and over
This is caused by pointing a node in the list to another node that already appeared earlier in the list. Example:
@jesuarva
jesuarva / reverseSinglyLinkedLists.js
Created July 10, 2018 15:40
Reverse a Single Linked List
/*
Write a function that will take the head of a singly-linked list, and reverse it,
such that the head is now the tail, and the node that head pointed to now points to the old head (the new tail).
*/
function reverseSinglyLinkedLists(node) {
let currentNode = node;
let nextNode = currentNode.next;
const toInvert = [];
while (nextNode) {