Skip to content

Instantly share code, notes, and snippets.

View mikaelvesavuori's full-sized avatar

Mikael Vesavuori mikaelvesavuori

View GitHub Profile
@mikaelvesavuori
mikaelvesavuori / notes.tdd-by-example.md
Created July 23, 2023 08:26
Book notes - "Test-Driven Development by Example" (Kent Beck)

Book notes - "Test-Driven Development by Example" (Kent Beck)

Red/green/refactor:

  • Red: Write a test that does not work, maybe does not even compile
  • Green: Make the test work quickly, be OK with any "sins" this might entail
  • Refactor: Eliminate duplication and "sins"

Social effects of writing tests:

@mikaelvesavuori
mikaelvesavuori / static-factory.ts
Created July 23, 2023 08:08
Factory through static convenience method.
class Thing {
constructor() {
console.log('Done!');
}
static create() {
console.log('Ding!');
return new Thing();
}
}
@mikaelvesavuori
mikaelvesavuori / template.lens.json
Created July 23, 2023 08:03
AWS Well-Architected Lens template.
{
"schemaVersion": "2021-11-01",
"name": "Replace with lens name",
"description": "Replace with your description",
"pillars": [
{
"id": "pillar_id_1",
"name": "Pillar 1",
"questions": [
{
@mikaelvesavuori
mikaelvesavuori / metaprogramming.ts
Created July 14, 2023 12:55
Metaprogramming example.
const data = {
age: 37,
firstName: 'Same',
lastName: 'Person',
something: 123
};
function reflection(obj: Record<string, any>) {
Reflect.deleteProperty(obj, 'something');
console.log(obj);
@mikaelvesavuori
mikaelvesavuori / decorators.ts
Created July 14, 2023 12:54
TypeScript 5.0 decorators.
class DecoratorDemo {
@log
public do() {
console.log('BLIP');
}
}
const d = new DecoratorDemo();
d.do();
@mikaelvesavuori
mikaelvesavuori / serverless.yml
Created July 11, 2023 11:05
Lambda code signing using Serverless Framework.
# See: https://alsmola.medium.com/github-actions-signing-lambda-code-5b7444299b
# See: https://blog.awsfundamentals.com/serverless-framework-resource-extensions
service: code-signing-demo
provider:
name: aws
runtime: nodejs18.x
architecture: arm64
stage: ${opt:stage, 'prod'}
@mikaelvesavuori
mikaelvesavuori / create-csv-files-from-excel-multi-value-fields.ts
Last active July 1, 2023 17:56
Create individual CSV files from multi-value fields in Excel file.
import fs from 'fs';
import readXlsxFile from 'read-excel-file/node';
import { Cell, Row } from 'read-excel-file/types';
const config = {
inputFile: './file.xlsx',
headers: 'ID,Period,Team',
multiResponseHeaders: {
something:
'Some header'
@mikaelvesavuori
mikaelvesavuori / browser-import-maps-demo.html
Created June 30, 2023 06:34
Demo of browser-native JavaScript import maps, as adapted from https://web.dev/import-maps-in-all-modern-browsers/
<!DOCTYPE HTML>
<head>
<title>
Browser import maps demo
</title>
<style>
h1 {
font-family: sans-serif;
}
@mikaelvesavuori
mikaelvesavuori / authenticate.ts
Last active June 21, 2023 15:06
Example of an AWS Lambda authorizer function that runs authentication and authorization on a request. Some parts are made up or missing here. Adapted and simplified from production code, using Auth0 and GitHub as the identity provider.
import jwt from 'jsonwebtoken';
import jwksClient from 'jwks-rsa';
import { MikroLog } from 'mikrolog';
const logger = MikroLog.start();
const keyClient: any = (jwksUri: string) =>
jwksClient({
cache: true,
cacheMaxAge: 86400000,
@mikaelvesavuori
mikaelvesavuori / auth0-login-example.ts
Last active June 21, 2023 15:07
Auth0 login example as a set of functions that can be run in a typical front end application. The `checkAuthState()` function is run on load.
import { Auth0Client, createAuth0Client } from '@auth0/auth0-spa-js';
const authConfig = {
"domain": "MY_SITE.eu.auth0.com",
"clientId": "SOME_STRING",
"cacheLocation": "localstorage",
"useRefreshTokens": true
}
/**