Skip to content

Instantly share code, notes, and snippets.

View szemate's full-sized avatar

Máté Szendrő szemate

  • London / Budapest
View GitHub Profile
@szemate
szemate / token-auth.md
Last active March 17, 2022 17:57
Stateful Token Authentication

Stateful Token Authentication

  1. Create a tokens table in the database with two columns:
    • token text field, primary key
    • user_id foreign key to the users table
  2. In the POST /login request handler, after checking the user name and the password, generate a new token. It can be done using the uuid Node module (https://github.com/uuidjs/uuid). The token will look something like 1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed.
  3. Insert the new token into the tokens table.
@szemate
szemate / testResultGradingSolution.js
Created October 17, 2021 12:13
JS test result grading exercise - solution
/*
TEST RESULT GRADING
We are writing a program for teachers that helps them grade test results. The
program receives the test results as an array of objects; each object contains
the name of a student and their test score (see below).
*/
const results = [
{ student: "Gytha Wheatley", score: 44 },
{ student: "Alishia Thorpe", score: 83 },
{ student: "Zack Vernon", score: 59 },
@szemate
szemate / storeAccountingSolution.js
Last active October 17, 2021 12:15
JS store accounting exercise - solution
/*
STORE ACCOUNTING
We are writing a program module for an online shop that processes purchases.
The program receives the sold items as an array of objects; each object
contains the name of the item, its price and its category (see below).
*/
const items = [
{ product: "Premier Housewives Stainless Steel Toolset", price: 19.97, category: "homeware" },
{ product: "iChinchin Women's Long Sleeve T Shirt", price: 15.99, category: "clothing" },
{ product: "U-Design Toothbrush Holder Set", price: 10.55, category: "homeware" },
@szemate
szemate / fetch-exercise.md
Last active November 9, 2021 13:03
Fetch exercise

Fetch exercise

Create a dictionary page that shows word definitions from the Free Dictionary API. The API documentation can be found at https://dictionaryapi.dev/.

  1. Open the developer tools in your browser and try the API with different words. Figure out how to get a definition from the returned JSON object.
  2. Check what the response is when no definition is found.
  3. Copy-paste index.html and script.js below into VSCode and open index.html with live server.
  4. Complete script.js to show the first definition of the word from the input field when the user clicks the submit button. Don't forget to handle the case when no definition is found.
  5. Stretch goal: include all definitions of the word and the example sentences.
@szemate
szemate / api-exercise.md
Last active October 30, 2021 07:40
API exercise

API Exercise

We will discover the Chuck Norris Jokes API. The documentation can be found at https://api.chucknorris.io/.

  1. Read the "Usage" section and try each endpoint in the browser.
  2. Retrieve a random Chuck Norris fact related to movies. You will need to combine the data from two endpoints.
@szemate
szemate / feature-branch-exercise.md
Last active February 19, 2022 14:29
Git feature branch exercise

Feature branching exercise

The trainee who shares the screen

  1. Fork https://github.com/szemate/git-branching-demo
  2. Add the other trainees in the breakout room as collaborators (to the forked repository)

Everyone in the breakout room

  1. Confirm yourself as a collaborator
@szemate
szemate / word-score.md
Last active March 17, 2022 17:56
Scrabble Word Scores Exercise

Scrabble Word Scores Exercise

In this word game points are awarded based on the length of the word and the letters used. The user has to create a word from the letters in their hand. Their hand consists of 7 letters.

Could you create a function which returns the correct scores for the words played? The input is a list of words, and the output is an object where the keys are the words played and the values are the word points.

@szemate
szemate / package-lock-conflicts.md
Last active April 15, 2025 03:08
How to resolve package-lock.json conflicts

How to resolve package-lock.json conflicts

It is not possible to resolve conflicts of package-lock.json in GitHub's merge tool and you need to do a manual merge.

  1. Update the master branch with the latest changes:
    git checkout master
    git pull
    
  2. Merge your feature branch into master:
@szemate
szemate / pizza-generator.md
Last active October 15, 2022 05:23
Pizza Generator

Pizza Generator

A pizza place offers the following toppings:

  • ham
  • salami
  • mushroom
  • spinach
  • artichoke
@szemate
szemate / html-converter.md
Last active September 15, 2022 12:34
HTML converter exercise

HTML to Plain Text Converter

Create a script that takes the name of a HTML file as a command line argument, and prints its visible content as plain text to standard output (to the terminal).

  • Only the body contents should be printed.
  • All HTML tags and indentation should be removed.
  • Contents of block elements (<p>, <h#>, <div>) should be divided by empty lines.
  • Line breaks (<br />) should be respeced.
  • Only <br /> elements should be treated as line breaks, new line characters should not.