Skip to content

Instantly share code, notes, and snippets.

View jamesseanwright's full-sized avatar
🤔

James Wright jamesseanwright

🤔
View GitHub Profile
FROM amazon/aws-lambda-nodejs:14
ARG handler
COPY ./package.json ./package-lock.json /var/task/
COPY ./common /var/task/common
COPY ./${handler} /var/task/handler
WORKDIR /var/task
RUN ["npm", "i", "--production"]
[
{
"date": "2021-05-21T20:09:15.000Z",
"value": 3
},
{
"date": "2021-05-21T20:04:40.000Z",
"value": 3
},
{
$ curl -XGET \
-H "Content-Type: application/json" \
"http://$API_HOST/events?deviceID=8f188304-e7b3-4a16-a243-b9470468478a&eventType=temp_celcius&date=$(date -u +%F)"
{
"message": "Created event"
}
$ curl -XPOST "http://$API_HOST/events" -H "Content-Type: application/json" -d '
{
"date": "'$(date -u +%FT%TZ)'",
"deviceID": "8f188304-e7b3-4a16-a243-b9470468478a",
"eventType": "temp_celcius",
"value": 3
}'
@jamesseanwright
jamesseanwright / unhandled.js
Created October 24, 2020 08:40
Unhandled rejections in Node.js 12
'use strict';
const microtasks = () => new Promise(res => {
setImmediate(res);
});
(async () => {
try {
const retrieve = Promise.reject(new Error('No'));
await microtasks();
@jamesseanwright
jamesseanwright / ts-mapped-types-minus.ts
Created September 7, 2020 09:59
Using the minus operator in TS mapped types
interface Person {
readonly name: string;
age?: number;
}
type WellFormedMutable<T> = {
-readonly[K in keyof T]-?: T[K];
};
const p: WellFormedMutable<Person> = {
@jamesseanwright
jamesseanwright / reno-auth-hof.ts
Created September 4, 2020 11:13
Authentication in Reno with a higher-order route handler
import {
RouteHandler,
AugmentedRequest,
textResponse,
createRouter,
createRouteMap,
} from "https://deno.land/x/[email protected]/reno/mod.ts";
import { Status } from "https://deno.land/[email protected]/http/mod.ts";
@jamesseanwright
jamesseanwright / variadic-kinds.ts
Last active June 18, 2020 10:38
Example of variadic kinds in TypeScript, landing in version 4.0
const concat = <...TInput, ...TItems>(
input: ...TInput,
...appendees: ...TItems,
): [...TInput, ...TItems] => [...input, ...appendees];
const x = concat([1, 2], '3', { no: 4 }); // [1, 2, '3', { no: 4 }]
typeof x; // [number, number, string, { no: number }]
@jamesseanwright
jamesseanwright / ts-mapped-types.ts
Created April 24, 2020 16:22
Creating TypeScript object types with mapped types
type LogLevel =
| 'debug'
| 'info'
| 'warning'
| 'error';
type Logger = {
[Level in LogLevel]: (...args: unknown[]) => void;
};