Skip to content

Instantly share code, notes, and snippets.

View vivmaha's full-sized avatar

V Maharajh vivmaha

View GitHub Profile
import { GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
import stableStringify from "fast-json-stable-stringify";
import forge from "node-forge";
import { createS3Client } from "./client-aws";
import { streamToString } from "./stream-ultils";
function get128BitHash(input: string): string {
const messageDigest = forge.md.md5.create();
messageDigest.update(input);
return messageDigest.digest().toHex();
import pMap from "p-map";
import { invokeLambdaAsync, invokeLambdaSync } from "./lambda-utils-aws";
export const mapReduce = async <TItem, TMap, TReduce>(options: {
items: TItem[];
map: {
functionName: string;
getPayloadForItem: (item: TItem) => TMap;
concurrency: number;
};
// Example usage of https://gist.github.com/vivmaha/f34fdea72d0f1fa0467a671b5ec7321e
render(
(
<BrowserRouter>
<div>
<ScrollToTop />
<Route exact path="/" component={Home} />
<Route path="/article/:id" component={Article} />
<Route path="/series/:id" component={ArticleSet} />
import * as React from "react";
import { RouteComponentProps, withRouter } from "react-router";
// Scroll restoration based on https://reacttraining.com/react-router/web/guides/scroll-restoration.
export var ScrollToTop = withRouter(
class ScrollToTopWithoutRouter extends React.Component<RouteComponentProps<any>, void> {
componentDidUpdate(prevProps: Readonly<RouteComponentProps<any>>) {
if (this.props.location !== prevProps.location) {
window.scrollTo(0, 0)
}