Skip to content

Instantly share code, notes, and snippets.

View ObsidianCat's full-sized avatar

Lula Leus ObsidianCat

View GitHub Profile
@ObsidianCat
ObsidianCat / algo-binary-tree-traversion.js
Created May 30, 2020 10:26
Building and traversing of binary tree
// Node definition
function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
// Assemle a tree
const left = new TreeNode(2)
const right = new TreeNode(2)
const rightRight = new TreeNode(3)
@ObsidianCat
ObsidianCat / algo-roman-numbers.js
Created May 19, 2020 17:21
2 algorithms - Conversion of roman number to integer and integer to roman number
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
let result = 0
const conversion = {
"I": 1,
"V": 5,
"X": 10,
@ObsidianCat
ObsidianCat / algo-number-to-digits-conversions.js
Last active May 12, 2020 20:13
Can be used as foundation for algo questions which ask to split number into digits and manipulate it in some way afterward
// Can be used as foundation for algo questions which ask to split number into digits and manipulate it in some way afterward
function numberToSumOfDigits(num) {
let totalSum = 0;
while(num > 0){
const digit = num %10
num = Math.floor(num/10);
totalSum += digit
}
return totalSum
@ObsidianCat
ObsidianCat / algo-build-linked-list-from-array
Last active May 8, 2020 10:55
Accept array, convert it into linked list and return list head
function ListNode(val){
this.val = val;
this.next = null;
}
function createList(arr){
let result = arr.map((item, index, arr)=>{
const node = new ListNode(item)
return node
})
{
"sub": "00un7nfq2aTE0HOAl356",
"name": "Lula Leus",
"locale": "en-US",
"email": "example@example.com",
"preferred_username": "lulaleus",
"given_name": "Lula",
"family_name": "Leus",
"zoneinfo": "America/Los_Angeles",
"updated_at": 1559047283,
// ./cypress/integration/recipes-page.test.js
describe('Recipes page', () => {
before(() => {
cy.loadRecipesPage();
// Save selector as shortcuts, usefull if they will be used repetitively
cy.get('[data-cy=recipes-vegan-toggle] input').as('toggle');
cy.get('[data-cy=recipes-vegan-toggle] label').as('toggleLabel');
cy.get('[data-cy=recipe-card]').as('recipeCards');
// ./cypress/support/commands.js
Cypress.Commands.add('loadRecipesPage', () => {
// One command can call another, just like plain functions
cy.mockOktaLoggedState();
// When UI requests recipes, Cypress, not the actual server, will return response
cy.route('GET', '/api/recipes', 'fixture:recipes.json').as('recipes');
// I can do manipulation on a fixture before serving it
// ./cypress/support/commands.js
Cypress.Commands.add('mockOktaLoggedState', () => {
// Set cookies
cy.setCookie('okta-oauth-nonce', 'value of this cookie copied from the browser');
cy.setCookie('okta-oauth-state', 'value of this cookie copied from the browser');
// To avoid token expiration, we create a new timestamp every time
const oneDayFromNow = Date.now() + 1000 * 60 * 60 * 24;
@ObsidianCat
ObsidianCat / enzyme-two-components.spec.js
Last active December 6, 2019 17:22
Very minimalistic enzyme test of two components
import React from 'react';
import { mount } from 'enzyme';
import ParentComponent from './ParentComponent';
import ChildComponent from './ChildComponent';
describe('Parent component', () => {
it('adds and removes child component from the DOM', async () => {
const wrapper = mount(<ParentComponent />);
//Find button in Parent component
// Object destructuring
//Object
const response = {
status: 200,
data: {
user: {
name: 'Rachel',
title: 'Editor in Chief'
},