Skip to content

Instantly share code, notes, and snippets.

View hew's full-sized avatar

Matt hew

View GitHub Profile
@davidkpiano
davidkpiano / reducer-with-effects.js
Last active August 20, 2021 18:58
An idea for actor-model-based effects with reducers
import {
useReducerWithEffects,
// hand-wavey, but meant to be used by React to create something
// external will produce async values sent to components
createEffect
} from 'react';
function fetchUserEffect(id, parentRef) {
const controller = new AbortController();
const signal = controller.signal;
@damianrr
damianrr / amplify-function-graphql-cognito.js
Last active March 6, 2020 22:42
How to query/mutate AppSync's GraphQL from within Amplify's lambda functions by login into Cognito user pool and reusing Authorization token.
const R = require('ramda');
const aws = require("aws-sdk");
const { GraphQLClient } = require("graphql-request");
aws.config.update({
region: process.env.REGION
});
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({
apiVersion: "2016-04-18"
});
@undefobj
undefobj / index.js
Last active August 17, 2022 18:28
Calling AppSync from Lambda
const https = require('https');
const AWS = require("aws-sdk");
const urlParse = require("url").URL;
const appsyncUrl = process.env.API_BACKENDGRAPHQL_GRAPHQLAPIENDPOINTOUTPUT;
const region = process.env.REGION;
const endpoint = new urlParse(appsyncUrl).hostname.toString();
const graphqlQuery = require('./query.js').mutation;
const apiKey = process.env.API_KEY;
exports.handler = async (event) => {
let all = Js.Promise.all;
let resolve = Js.Promise.resolve;
let reject = Js.Promise.reject;
let andThen =
(p: Js.Promise.t('a), fn: 'a => Js.Promise.t('b)): Js.Promise.t('b) =>
p->Js.Promise.then_(fn, _);
@mhallin
mhallin / App.re
Created August 6, 2018 11:45
Async import pattern
PageModule.fetchModule("./MyComponent")
|> Js.Promise.then_(m => send(SetRootElement(m())));
const invalidMatchSignal = new Error();
function makeProxyThrower(input) {
return new Proxy(input, {
get(target, prop, receiver) {
if (prop in target) {
const result = Reflect.get(target, prop, receiver);
if (typeof result === "object" && result !== null) {
return makeProxyThrower(result);
@busypeoples
busypeoples / FormExample.re
Created April 23, 2018 00:20
Form Example in ReasonML
type validation('a) =
| NotEmpty
| Custom('a);
type t = string;
let validate = (rule, value, values) =>
switch (rule) {
| NotEmpty => String.length(value) > 0
| Custom(fn) => fn(value, values)
@Zerim
Zerim / SignupForm.re
Last active February 19, 2018 23:25
A simple SignupForm written in ReasonML
/* `action` and `state` types must be defined before the `let component` statement for type inference to work */
type action =
| UpdateEmail string
| UpdatePassword string;
type state = {
email: string,
password: string
};
@lilactown
lilactown / promises.re
Last active August 20, 2022 07:56
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
module.exports = {
use: [
'autoprefixer',
'postcss-import',
'postcss-url',
'postcss-browser-reporter',
'postcss-reporter'
],
input: 'index.css',
output: 'dist/bundle.css',