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 / 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 / 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 / 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 / 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 / sql-week2-exercise.md
Last active January 29, 2022 15:29
SQL Week 2 Exercise

Node with Postgres Exercise

This exercise requires a working Postgres DB server with the homework database from https://github.com/CodeYourFuture/SQL-Coursework-Week1/tree/main/2-classes-db.

  1. Initialise a new Node/Express web server.
  2. Set up a connection pool to the homework database with node-posgtres.
  3. Create a GET /spends endpoint that returns the list of all spends as a JSON array of objects. Each object should contain the date, description and amount properties.
  4. Create a GET /suppliers endpoint that returns the list of the names of all suppliers as a JSON array of strings. Make sure the response is an array of strings and not an array of objects!
  5. Extend the GET /spends endpont to return a more compete list of spends. Each object should contain the expense_area, expense_type, supplier, date, description and amount properties. The objects should not include any IDs, that is, the tables should be joined together.
@szemate
szemate / node-week1-exercises.md
Last active July 22, 2022 11:03
Node Week1 exercises

Node Week 1 Exercises

Exercise 1

  1. Extract the contents of the zip file into a new directory and open the folder in VSCode.
  2. Initialise a new Node app in the directory. The entry point should be the existing server.js.
  3. Install Express.
  4. Create an Express app in server.js that listens on port 3000.
  5. Create a new request in Postman to make sure that the server is working.
@szemate
szemate / storeAccounting.js
Last active September 22, 2022 13:39
JS store accounting exercise
/*
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).
1. Print the names and the number (the count) of all sold homeware accessories.
2. Print the total revenue (the sum of the prices of all sold items).
3. Print the average price of the items. Make sure that the price is rounded to 2 decimal points.
@szemate
szemate / testResultGrading.js
Last active October 16, 2021 08:48
JS test result grading exercise
/*
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).
1. Print the names and the number (the count) of the students who passed the test (had at least 40 points).
2. Print the average score.
3. Print the name of the student who had the highest score.
@szemate
szemate / destructuring.js
Last active February 9, 2025 00:26
Destructuring exercises
/**
Exercise 1
Rewrite the code below to use array destructuring instead of assigning each value to a variable.
*/
{
console.log("EXERCISE 1");
let item = ["Egg", 0.25, 12];
@szemate
szemate / http-exercise.md
Last active March 21, 2021 07:29
HTTP exercise

HTTP request-response exercise

1. GET request

Open the Network tab in the browser's Developer Tools, copy-paste http://httpbin.org/get?org=CodeYourFuture&class=ldn7 into the browser's address bar and inspect the following:

  • Request URL: identify the scheme, the host, the endpoint and the query string
  • Request Method
  • Status Code: look it up at https://httpstatuses.com/
  • Request Headers: find the content type