Skip to content

Instantly share code, notes, and snippets.

View johnhaley81's full-sized avatar

John Haley johnhaley81

View GitHub Profile
@johnhaley81
johnhaley81 / Decode_Result_Custom_test.re
Created November 26, 2018 21:44
Possible addition to tests for printing out custom errors
/* Snip */
test("Enum failure can be mapped to string", () => {
let message =
switch (Color.decode(jsonInvalidStr)) {
| Belt.Result.Ok(result) => result->Belt.Result.Ok
| Belt.Result.Error(parseError) =>
Decode_ParseError.toDebugString(
x =>
switch (x) {
| `InvalidColor => (_json => "Invalid color")
@johnhaley81
johnhaley81 / Reselect.re
Created March 6, 2019 18:50
Reason bindings vs TypeScript types
type selector('state, 'result) = 'state => 'result;
[@bs.module "reselect"]
external createSelector1:
('state => 'a, 'a => 'result) => selector('state, 'result) =
"createSelector";
[@bs.module "reselect"]
external createSelector2:
('state => 'a, 'state => 'b, ('a, 'b) => 'result) =>
open Relude.Globals;
module ParseError = Decode.ParseError;
module Decode = {
let isValidDate: 'a => bool = [%raw
{|
function isValidDate(date) {
return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date);
}
@johnhaley81
johnhaley81 / EnvVars.re
Last active December 19, 2019 20:08
Some reasonml bindings for graphile worker
open Relude.Globals;
[@bs.module "dotenv"] external getEnvVars: unit => unit = "config";
let getEnvVars = () =>
getEnvVars()
|> (() => Node.Process.process##env)
|> (Js.Dict.map((. x) => x |> Json.Encode.string) >> Json.Encode.dict);
open Relude.Globals; // I usually do this in bsconfig
type user = {
firstName: string,
lastName: string,
};
type error =
| AlreadyLoggedIn;
type context = {
[Error - 5:11:15 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
at Object.dispose (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:26597:25)
at Object.dispose (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:14916:35)
at LanguageClient.handleConnectionClosed (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:17151:42)
at LanguageClient.handleConnectionClosed (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:34239:15)
at closeHandler (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:17138:18)
at CallbackList.invoke (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:7965:39)
at Emitter.fire (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:8024:36)
at closeHandler (/Users/john/.vscode/extensions/ocamllabs.ocaml-platform-0.9.0/dist/index.js:25933:26)