Skip to content

Instantly share code, notes, and snippets.

type Middleware<In, Out> = <T extends In>(req: Request, res: Response, state: T) => Promise<T & Out>;
export const fooMiddleware: Middleware<{}, { foo: string }> = async (req, res, state) => {
return { ...state, foo: "foo" };
};
export const barMiddleware: Middleware<{}, { bar: string }> = async (req, res, state) => {
return { ...state, bar: "bar" };
};
@aselbie
aselbie / useRecentRestaurants.ts
Created November 9, 2018 00:55
Buffet Custom Hooks Example
import { Context, useMemo } from 'react';
import { BaseRestaurant, NormalizedRestaurant, RestaurantDTO } from './ScopeSelector.types';
import { UserConsumer, State as UserContextState } from '@buffet/user-service';
import { RestaurantConsumer, State as RestaurantContextState } from '@buffet/restaurant-service';
import { normalizeRestaurant } from './RestaurantMapper';
export const LOCAL_STORAGE_KEY = 'gc.UserRecentRestaurants';
export const MAX_RECENT_RESTAURANTS = 5;
export interface RestaurantsByUserId {
@aselbie
aselbie / cloneElement.js
Created August 31, 2017 18:05
Function as Child compared to cloneElement
class MyComponent extends React.Component {
render() {
return (
<div>
{React.cloneElement(React.Children.only(this.props.children), {
name: 'Scuba Steve',
})}
</div>
);
}
type Status = 'fetching' | 'init' | 'failure' | 'success';
type CustomMessageSource = {
language: string, // the language from the custom message where this message spec is translated from
version: number, // the version from the custom message where this message spec is translated from
message: string, // the message from the custom message where this message spec is translated from. Not used for now
}

Keybase proof

I hereby claim:

  • I am aselbie on github.
  • I am aselbie (https://keybase.io/aselbie) on keybase.
  • I have a public key whose fingerprint is AA95 D439 A002 51A6 E1EA 3596 C7BF 9F64 6726 3176

To claim this, I am signing this object:

var quicksort = function(A) {
var swap = function(a, b) {
var temp = A[a];
A[a] = A[b];
A[b] = temp;
}
var partition = function(left, right) {
var pivotIndex = Math.floor((left + right) / 2);