Skip to content

Instantly share code, notes, and snippets.

View ObsidianCat's full-sized avatar

Lula Leus ObsidianCat

View GitHub Profile
@ObsidianCat
ObsidianCat / type-script-basics.ts
Last active December 6, 2019 17:21
Examples of type script basics types and their use
//inferance bottom up
// the compiler know function result type, baesed on it`s arguments
let userId = (a: string, b: number): string =>a+b;
//*******************************
//Union type (variable can be any of these types)
let thing: string | number | string[];
// Alias
type thing = string | number | string[];
const { getRandomWordSync, getRandomWord } = require("word-maker");
const fs = require("fs");
console.log("It works!");
// YOUR CODE HERE
//Additional functions
//asynchronous in loop
function delayedRandom(){
const random = Math.random();
return new Promise(resolve => setTimeout(()=>resolve(random), 100));
}
async function* generateDelayedRandoms(){
let num;
num = await delayedRandom()
yield 'One ' + num;
// Object destructuring
//Object
const response = {
status: 200,
data: {
user: {
name: 'Rachel',
title: 'Editor in Chief'
},
@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
// ./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;
// ./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/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');
{
"sub": "00un7nfq2aTE0HOAl356",
"name": "Lula Leus",
"locale": "en-US",
"email": "[email protected]",
"preferred_username": "lulaleus",
"given_name": "Lula",
"family_name": "Leus",
"zoneinfo": "America/Los_Angeles",
"updated_at": 1559047283,
@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
})