Skip to content

Instantly share code, notes, and snippets.

View galenweber's full-sized avatar

Galen Weber galenweber

  • New York Federal Reserve
  • New York City
View GitHub Profile

Have a data modeling question I'd be interested in your take on (if you have time):

One of the entities in our database is the Case (as in, legal case). We send a Case to a lawyer, and they can indicate if they are interested in talking to the case or not (we call this "precleared").

Then the lawyer reaches out to the client, and the lawyer can decide if they want to represent the Case or not. (we refer to this as "referred" (or not))

Then the lawyer sends a retainer agreement to the client, and the client signs that agreement (or not). (we refer to this as the Case is "retained" (or not))

If a Case is rejected at any stage, we want to capture why the Case was rejected.

@galenweber
galenweber / trigger-circle.js
Last active November 13, 2018 19:25
Simple Google Cloud Function to trigger a Circle job when called
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
const https = require('https');
exports.triggerCircle = (req, res) => {
server.get('/*', (req, res) => {
const component = router(req.url);
const prismicFetch = component.PRISMIC_FETCH_REQUEST
? component.PRISMIC_FETCH_REQUEST()
: (() => Promise.resolve());
prismicFetch(res.locals.ctx)
.then((document) => {
const element = React.createElement(component, { document });
const page = renderToString(element);
server.get('/*', (req, res) => {
const component = router(req.url);
const prismicFetch = component.PRISMIC_FETCH_REQUEST();
prismicFetch(res.locals.ctx)
.then((document) => {
const element = React.createElement(component, { document });
const page = renderToString(element);
// inject React page (as a string) into an HTML template
const html = template(page);
@galenweber
galenweber / Terms.tsx
Created July 10, 2018 00:28
Terms React page component
export default class Terms extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
}
static PRISMIC_FETCH_REQUEST() {
return (ctx: any) => ctx.api.getByUID(
// page type
'page',
// uid
@galenweber
galenweber / server-with-basic-prismic.ts
Last active July 10, 2018 00:21
Request handler that fetches content from prismic
server.get('/*', (req, res) => {
const component = router(req.url);
res.locals.ctx.api.getByUID('page', 'my-content')
.then((document) => {
const element = React.createElement(component, { document });
const page = renderToString(element);
// inject React page (as a string) into an HTML template
const html = template(page);
@galenweber
galenweber / middleware.ts
Last active June 29, 2018 01:59
Middleware to inject Prismic "context" into every request
import express from 'express';
import Prismic from 'prismic-javascript';
import PrismicDOM from 'prismic-dom';
// Middleware to inject prismic context
const injectContext: express.RequestHandler = function (req, res, next) {
res.locals.ctx = {
endpoint: process.env.PRISMIC_URL,
};
@galenweber
galenweber / server.ts
Last active July 7, 2018 01:11
Primary logic of express server for SSR React application
server.get('/*', (req, res) => {
const component = router(req.url);
const element = React.createElement(component);
const page = renderToString(element);
// inject React page (as a string) into an HTML template
const html = template(page);
res.send(html);
});
@galenweber
galenweber / html.ts
Last active February 18, 2018 19:03
HTML function for React TypeScript SSR
const html = ({ body }: { body: string }) => `
<!DOCTYPE html>
<html>
<head>
</head>
<body style="margin:0">
<div id="app">${body}</div>
</body>
<script src="js/client.js" defer></script>
</html>
@galenweber
galenweber / index.ts
Created February 18, 2018 19:00
Express server rendering React for React TypeScript SSR
import React from 'react';
import express from 'express';
import { renderToString } from 'react-dom/server';
import Counter from '../containers/Counter';
import html from '../html';
const port = 3000;
const server = express();
server.use(express.static('dist'));