Skip to content

Instantly share code, notes, and snippets.

View hanford's full-sized avatar
🌝

Jack Hanford hanford

🌝
View GitHub Profile
@litewarp
litewarp / ClientComponent.tsx
Last active March 23, 2023 21:04
Relay Nextjs13
'use client'
import {graphql} from 'react-relay'
import graphqlQuery, {
AllSecuritiesPageQuery
} from '~/__generated__/AllSecuritiesPageQuery.graphql'
import {createRelayHydrator} from '~/lib/relay/create-relay-hydrator'
export const {useHydratedPreloadedQuery, Hydrator} =
createRelayHydrator<AllSecuritiesPageQuery>(graphqlQuery)
// This proxy is only used for e2e
const proxy = require('express-http-proxy');
const express = require('express');
// const { parse } = require('url');
// const dev = process.env.NODE_ENV !== 'production';
// const handle = app.getRequestHandler();
const port = parseInt(process.env.PORT || 5900, 10);
@sciyoshi
sciyoshi / esbuild-relay.js
Created February 19, 2021 16:34
Esbuild plugin for compiling relay queries
import { promises } from "fs";
import crypto from "crypto";
import path from "path";
import { print, parse } from "graphql";
const plugin = {
name: "relay",
setup: build => {
build.onLoad({ filter: /\.tsx$/, namespace: "" }, async args => {
let contents = await promises.readFile(args.path, "utf8");
@threepointone
threepointone / iframe.tsx
Created December 8, 2020 00:16
An iframe loader powered by Suspense
import { Suspense, useLayoutEffect, useRef, useState } from 'react';
type IFrameProps = React.ComponentPropsWithRef<'iframe'> & {
fallback?: JSX.Element;
};
export function IFrame(props: IFrameProps) {
const { fallback, ...rest } = props;
return (
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
@stinger
stinger / CombineFetcher.swift
Last active January 28, 2023 18:07
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
@antmdvs
antmdvs / ReactHooks.code-snippets
Last active November 7, 2018 17:51
Snippets for React's *EXPERIMENTAL* `useState()` hook -- See https://reactjs.org/hooks
{
"useState()": {
"prefix": "us",
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"body": [
"const [${1}, set${1/(.*)/${1:/capitalize}/}] = useState($2);",
"$0"
],
"description": "React: useState()"
},
type state = {
count: int,
};
type action =
| Add
| Subtract;
module Counter = {
let component = ReasonReact.reducerComponent("Counter")
@sibelius
sibelius / MutationUtils.js
Created March 19, 2018 10:20
Helper methods for Relay Modern updater
// @flow
import { ConnectionHandler } from 'relay-runtime';
import { isObject, isArray } from 'lodash/fp';
export function listRecordRemoveUpdater({ parentId, itemId, parentFieldName, store }) {
const parentProxy = store.get(parentId);
const items = parentProxy.getLinkedRecords(parentFieldName);
parentProxy.setLinkedRecords(items.filter(record => record._dataID !== itemId), parentFieldName);
}
@hanford
hanford / service.js
Last active February 9, 2018 20:06
import Service, { Router } from '@eaze/service'
import { auth, isAdmin } from '@eaze/middleware'
class Acacia extends Service {
static router () {
return (
<Router>
<Get route='/products' handler={(req, res) => res.send(200)} />
<Post route='/products/create' middleware={[ isAdmin ]} handler={(req, res) => res.send(200)} />
<Patch route='/products/:id' middleware={[ isAdmin ]} handler={(req, res) => res.send(200)} />