Skip to content

Instantly share code, notes, and snippets.

@webpapaya
webpapaya / property-based-testing.ts
Created January 16, 2021 14:01
Start of diamond heart kata using property based testing (Code Retreat 2021-01-16)
import {
allOf,
assertThat,
describe,
equalTo,
everyItem,
greaterThanOrEqualTo,
hasProperty, hasSize,
lessThanOrEqualTo
} from 'hamjest';
<!doctype html>
<html>
<head>
<title>FHS-Modules</title>
</head>
<body>
<a href="/test1">First Link</a>
<a href="/test2">Second Link</a>
<section id="content">
let questions = null;
async function getQuestion() {
questions = await getQuestions()
return questions[Math.random() * questions.length - 1]
}
function answerQuestion(question, answer) {
questions.find((currentQuestion) => currentQuestion.question === question.question)
// ^^^^^^^
// if answer question is called before getQuestion is called you'll run into
@webpapaya
webpapaya / calculator_closure.js
Created November 11, 2020 16:30
code from lecture Frontend Development (2020-11-05)
function calculator() {
let value = 0
return function (difference) {
value += difference
console.log(value)
}
}
const calulator1 = calculator()
@webpapaya
webpapaya / convert_promise_to_async_await.js
Created November 11, 2020 16:27
code from Frontend Development lecture (2020-11-11)
const callbackFetch = (url, callback) => {
// ....
}
const promiseFetch = (url) => {
return new Promise((resolve, reject) => {
callbackFetch(url, (result) => {
if (result.error) { reject(result) }
else { resolve(result) }
})
  • You're building an issue tracking system
  • Build a component which displays the names of assignees
    • eg. <Assignees assignees={['Mike', 'Sepp', 'David']} />
    • build a simple ul
  • WITH more than 3 assigness,
    • only display 3 assignees
    • display a show more button
  • WHEN the show more button was clicked
    • display all assignees
  • a show less button is displayed instead of a show more button
import { AnyAction } from 'redux'
import { ThunkAction, ThunkDispatch } from 'redux-thunk'
import { rootReducer } from '.'
import createHTTPInstance from '../utils/create-http-connection'
export type ExternalDependencies = {
http: ReturnType<typeof createHTTPInstance>
}
export type AppState = ReturnType<typeof rootReducer>
const SignInForm = ({ onSubmit }) => {
const [formState, setFormState] = useState({ username: '', password: '' })
const handleChange = (evt) => {
setFormState({ ...formState, [evt.target.name]: evt.target.value })
}
return (
<form onSubmit={() => onSubmit(formState)}>
// @ts-ignore
import {assertThat, equalTo} from 'hamjest';
type CellState = 'alive' | 'dead'
type EventType = CellState | 'nextGeneration'
type Event<Type> = {
state: Type
}
import React, { useState } from 'react';
const Button = ({ children, variant = 'button' }) => {
return (
<button style={{ background: variant === 'button' ? 'blue' : 'green'}}>
{ children }
</button>
)
};