Skip to content

Instantly share code, notes, and snippets.

View mikahimself's full-sized avatar

Mika Laihanen mikahimself

View GitHub Profile
@mikahimself
mikahimself / typescript-generics.md
Last active March 23, 2022 06:24
Working with lists and dictionaries with the help of TypeScript generics

Converting lists to dictionaries

TypeScript generics come in handy when you have similar lists that you need to convert to dictionaries. Consider the following lists:

const idList = [
  { id: "0001", firstName: "Levi", lastName: "Ackerman" },
  { id: "0002", firstName: "Mikasa", lastName: "Ackerman" },
  { id: "0003", firstName: "Eren", lastName: "Yeager" },
  { id: "0004", firstName: "Armin", lastName: "Arlert" },
@mikahimself
mikahimself / fem-javascript-testing-practices-and-principles.md
Last active March 10, 2022 06:40
Notes from Javascript Testing Practices and Principles course on FrontendMasters.com

Javascript Testing Practices and Principles

Material available on GitHub.

Introduction

Creating a very simple assertion library

You can create a simple assertion library by creating a function that returns an object that holds a method. This lets us use the expect(result).toBe(expectedResult) structure. However, this solution will only run the first item, and it also hides the exact location of any errors that pop up.

@mikahimself
mikahimself / api-design-in-node-js-v3.md
Last active September 21, 2022 06:11
Notes from API Design in Node.js from Frontend Masters

API Design in Node.js

Introduction

REST

Most popular API design pattern; definition rather blurry. The REST (Representational State Transfer) pattern defines:

  • Database connections
  • Route paths
@mikahimself
mikahimself / fem-deep-javascript-foundations-v3.md
Last active March 7, 2024 15:06
Notes from Deep JavaScript Foundations v3

Deep JavaScript Foundations v3

Types

Primitive types

In JavaScript, everything is NOT an object. ECMAScript language types are:

  • Undefined
  • Boolean
  • String
@mikahimself
mikahimself / composing-webpack-configurations.md
Last active April 9, 2021 07:46
Example of creating a composed webpack configuration using Webpack 5

Composing Webpack configurations

Handling multiple Webpack configurations for development, production, and maybe for reviews can be a chore, especially if the configuration files are made up of mostly shared content, and changes in one place have to be copied into the other configuration files.

One way to make life simpler is to compose the configuration file to be used from a base configuration file and a specialized configuration file, and then merge them together using webpack-merge.

The idea behind this is explored in much more detail in Sean Larkin's Webpack 4 Fundamentals course at FrontendMasters.com.

Base configuration file

webpack related scripts in package.json

So, why are there a bunch of commands available to use without paths within package.json? Well, because npm creates inside node_modules a folder called .bin that stores a whole bunch of binary executables. These are then available within the scope of package.json.

piping/composing commands

You can easily pipe commands in package.json:

  "webpack": "webpack"
 "dev": "npm run webpack -- --mode development"