Skip to content

Instantly share code, notes, and snippets.

Avatar

Dario Gieselaar dgieselaar

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am dgieselaar on github.
  • I am dgieselaar (https://keybase.io/dgieselaar) on keybase.
  • I have a public key ASCPrwb8INtoj797_8G_vcIMIT_LVzzkrGQHYbDIndb3Pgo

To claim this, I am signing this object:

View create_route_typed.ts
import t from 'io-ts';
import { Request } from 'hapi';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'fp-ts/lib/function';
interface Params {
path?: t.HasProps;
query?: t.HasProps;
View create_route.ts
import t from 'io-ts';
import { Request } from 'hapi';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { isLeft } from 'fp-ts/lib/Either';
interface Params {
path?: t.HasProps;
query?: t.HasProps;
body?: t.Any;
}
View route-with-codec.ts
const route = createRoute({
url: '/api/metrics/:type',
method: 'GET',
params: {
path: t.type({
type: t.string
}),
query: t.type({
start: t.string,
end: t.string
View decode.ts
import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import codec from './codec.ts';
const input = {
title: 'Title of this article',
content: 'Content of this article',
options: {
private: true
}
View codec.ts
import * as t from 'io-ts';
/*
This codec represents the following TypeScript type:
{
title: string,
content: string,
options: {
private?: boolean
}
View fetch.ts
const response = await fetch({
url: `http://localhost:5601/api/metrics/cpu`,
query: {
start: new Date().getTime() - 1000 * 60 * 60,
end: new Date().getTime() - 1000 * 60 * 60
},
method: 'GET'
});
View route.ts
server.route({
url: '/api/metrics/:type',
method: 'GET',
handler: ( request ) => {
const { type } = request.params;
const { start, end } = request.query;
return getMetrics({ type, start, end });
}
});
View findDupes.js
const fs = require('fs');
const path = require('path');
const { uniq, groupBy, pickBy } = require('lodash');
const beautifiedJsFile = fs.readFileSync(path.join(__dirname, './build.js'), 'utf-8');
const nodeModulesRegex = /"(.*?\/node_modules\/.*?)"/;
const findNodeModules = ( str ) => {
const lines = str.split('\n');
View SplitCssByMediaPlugin.js
const RawSource = require('webpack-sources').RawSource;
class SplitCssByMediaPlugin {
apply(compiler) {
// wait until compilation becomes available
compiler.hooks.compilation.tap(
'SplitByCssMediaPlugin',
(compilation) => {
// hook into additionalAssets phase
compilation.hooks.additionalAssets.tap(