Skip to content

Instantly share code, notes, and snippets.

stateDiagram-v2

[*] --> OrderDataPackage: click
OrderDataPackage --> OrderError
OrderDataPackage --> OrderSuccess
OrderError --> [*]
OrderSuccess --> PollDelay

PollDelay --> DataExportStatus
import * as winston from "winston";
import path from "path";
import DailyRotateFile from "winston-daily-rotate-file";
const { json, timestamp, combine } = winston.format;
const { Console } = winston.transports;
export default function CreateLogger(appName: string, nodeEnv: string, logFolder: string): winston.Logger {
const dailyRotateFile: DailyRotateFile = new DailyRotateFile({
filename: path.join(logFolder, `ui-${appName}-%DATE%.log`),
datePattern: "YYYY-MM-DD-HH",
module.exports = {
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
],
"rules": {
"indent": [
export default function smoothScrollTop(): Promise<null> {
let lastScrollTop = Infinity;
return new Promise((resolve) => {
const smoothScrollTopImpl = () => {
const top = document.documentElement.scrollTop || document.body.scrollTop;
if (top > 0 && lastScrollTop > top) {
lastScrollTop = top;
window.requestAnimationFrame(smoothScrollTopImpl);
window.scrollTo(0, top - (top / 8));
} else {
@objectfoo
objectfoo / long-list.tsx
Created May 2, 2021 01:47
batch load a long list
import * as React from "react";
import * as faker from "faker";
function batch(count: number = 10): Faker.Card[] {
// return [faker.helpers.createCard()];
return [
faker.helpers.createCard(),
faker.helpers.createCard(),
faker.helpers.createCard(),
@objectfoo
objectfoo / site-nav.tsx
Last active January 12, 2021 01:48
Greedy nav
import * as React from "react";
import Box from "@material-ui/core/Box";
import Button from "@material-ui/core/Button";
import Toolbar from "@material-ui/core/Toolbar";
import Menu from "@material-ui/core/Menu";
import MenuItem from "@material-ui/core/MenuItem";
import createStyles from "@material-ui/core/styles/createStyles";
import makeStyles from "@material-ui/core/styles/makeStyles";
import { Theme } from "@material-ui/core";
import clsx from "clsx";
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = function (env, argv) {
const isProduction = argv.mode === "production"
const plugins = [];
plugins.push(
new MiniCssExtractPlugin({
@objectfoo
objectfoo / parse-url.js
Created June 11, 2019 23:54
deslash and switch protocol using url-parse
var urlParse = require('url-parse');
var testurl = 'http://www.book.com//one/asdf//#123?a=12';
var parsed = urlParse(testurl.replace(/([^:]\/)\/+/g, '$1'), {});
parsed.set('protocol', 'https:');

The auth server is distinct from the key-cloak api gateway.

An express server's middleware will need access to some key-cloak services. These services would include the current bearer token and an async function fetchApiToken.

This could be implemented as middleware, including a middleware at the top of your stack could init this manager, including fetching the initial token. It would need to have some way to set the credentials that will be used to get the token from the auth server. It would provide the getToken and fetchApiToken functions on the req.app.locals[some-key] property. The key should be configurable, or maybe just over-rideable.

IDEA: instead of a getToken function we could be more like aws4.sign(options, credentials), as shown in got docs, where options is an object with headers and presumably headers.Authentication. The function mutates the headers object directly :(

Getting the intial key should be required for a successful ecv check.

process.on('uncaughtException', (e) => {
console.log('XXXX UNCAUGHT EXCEPTION XXXX');
});
process.on('unhandledRejection', (e) => {
console.log('XXXX UNHANDLED REJECTION XXXX');
});
const newError = (name = 'GenericError', message = 'error messaage') => {
const e = new Error(message);