Skip to content

Instantly share code, notes, and snippets.

View kgoggin's full-sized avatar

Kyle Goggin kgoggin

View GitHub Profile
@kgoggin
kgoggin / captureFixtureData.ts
Created October 20, 2022 17:55
Capture Fixture Data
import { useCallback } from 'react';
import { isEqual } from 'lodash';
interface UseCaptureFixtureDataConfig {
localStorageKey: string;
equalityCheck?: typeof isEqual;
}
const cache = new Map<string, unknown[]>();
@kgoggin
kgoggin / ReducerWithEffects.re
Created May 18, 2021 19:52
Reducer With Side Effects
module ReducerWithEffects = {
type actionWrapper('state, 'action) =
| Update('state)
| SideEffect(('action => unit) => unit)
| UpdateWithSideEffect('state, ('action => unit) => unit)
| NoUpdate;
type stateWrapper('state, 'action) = {
state: 'state,
effect: option(('action => unit) => unit),
@kgoggin
kgoggin / README.md
Created June 11, 2019 16:48
Prisma Client Promise Weridness

The prisma client has what it calls a "fluent" API, which allows you to chain requests for sub-types but work with them all as if they were a promise (docs). Example:

const organization = await prisma.schedule({id: "foo"{}).organization();

All of the examples in the documentation demonstrate using async/await syntax when working with the client. Inspecting what gets returned from a call to the client shows then and catch properties, like a normal promise, as well as the other fields exposed as functions (which is what allows the fluent API).

The Problem

@kgoggin
kgoggin / ApolloCache.re
Last active April 27, 2020 08:45
Custom react-apollo ReasonML bindings
open ApolloTypes;
type js_read_query_options = {
.
"query": queryString,
"variables": Js.undefined(Js.Json.t),
};
type js_write_query_options = {
.
let verifyGraphQLType = (~typeName, json) =>
switch (json->Js.Json.decodeObject) {
| None =>
Js.log({j|Unable to decode $typeName object|j});
raise(Not_found);
| Some(root) =>
switch (root->Js.Dict.get("__typeName")) {
| None =>
Js.log("Provided object is not a GraphQL object");
raise(Not_found);
type stateDef('event, 'state) = {
on: 'event => option('state),
onEnter: option('event => unit),
onExit: option('event => unit),
};
module type Machine = {
/* type event; */
type state;
let initial: state;
@kgoggin
kgoggin / SketchSystems.spec
Last active July 27, 2018 14:54
WelcomeScreen
WelcomeScreen
newAccount -> ValidatePhoneNumber
signIn -> SignIn
searchForOrg -> SearchForOrg
SignIn
EnterPhone
usePW -> EnterUNPW
continue -> SendCode
back -> WelcomeScreen
SendCode
@kgoggin
kgoggin / RecursiveGQLTypes.re
Created April 10, 2018 13:19
This gist shows how you could go about defining ReasonML types based on a GraphQL schema that reference each other, as well as a recursive decoder function used to parse a JSON response into the correct type.
/* Use Reason's ability to define recursive types with the `and` keyword */
type movie = {
id: option(string),
name: option(string),
rating: option(Js.null(string)),
runTime: option(Js.null(int)),
actors: option(list(actor)),
}
and actor = {
id: option(string),
@kgoggin
kgoggin / component.re
Created January 15, 2018 19:06
Reason Routing
let getRouteComponent: ReasonReact.Router.url => ReasonReact.reactElement =
(url) =>
switch (MainRoutes.match(url)) {
| Home(_url) => <Page message="Home" />
| Admin(route) => <AdminRoot route />
| NotFound(_url) => <Page message="404" />
};
@kgoggin
kgoggin / CalSync
Last active August 29, 2015 14:02
One-way sync two calendars within OS X Calendar app. In this case, used to move events from an Exchange account to an iCloud account.
property today : current date
property bfCal : "*NAME OF SOURCE CALENDAR*"
property iCal : "*NAME OF DESTINATION CALENDAR*"
-- used for Growl notification
property allNotifications : {}
tell application "Calendar" to launch
tell application "Calendar" to reload calendars
-- wait for reload to happen