Skip to content

Instantly share code, notes, and snippets.

Michael Martin-Smucker mlms13

Block or report user

Report or block mlms13

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mlms13
mlms13 / Overlapping.re
Created Apr 9, 2019
Different approaches to representing elements pulled out from the natural flow (menus, tooltips, etc)
View Overlapping.re
let onClick = _ => send(ToggleMenu);
// The following is how elm-ui does it (translated to JSX)
// Pros:
// - Relatively easy to understand
// - `Button` is any normal component
// - It's obvious that the container element can have all of the normal
// layout props and decoration attributes
//
// Cons:
@mlms13
mlms13 / DoFuture.re
Created Apr 9, 2019
I don't know anything about PPXs, and I'm not even quite a do-notation pro, but I'd really like something like this in Reason
View DoFuture.re
[%do Future]
do {
user <- getUser("some_user_id")
orders = user.orders
firstOrderId <- orders |> List.head |> Future.fromOption
order <- getOrder(firstOrderId)
pure(user.firstName ++ " ordered a " ++ order.productName)
};
Future.(
@mlms13
mlms13 / BooleanRuleEngine.re
Created Mar 28, 2019
Evaluate rules using other rules?
View BooleanRuleEngine.re
// I'm not entirely sure what this thing is. It feels powerful and expressive
// and like you can compose things. Not sure what it would be useful for, though.
// Maybe you could make a UI to build arbitrarily complex predicate functions
// for filtering collections of data?
module RuleEngine = {
type t('a) =
| Rule('a)
| Not(t('a))
| And(t('a), t('a))
View Calendario.re
[@bs.module "react-native-calendario"]
external calendar: ReasonReact.reactClass = "default";
type dateRange = {
startDate: Js.Date.t,
endDate: option(Js.Date.t),
};
let dateRangeFromJS = range => {
startDate: range##startDate,
View geolocation-flow.md

Current behavior

onfocus: send UpdateLocationSuggesion

UpdateLocationSuggesion

  • if we already have geolocation: send UpdateLocationSuggesions
  • if we don't: send GetLocation

UpdateLocationSuggesions

  • if mobile and empty input and LocationSuccess:
@mlms13
mlms13 / TFirstTLast.re
Created Feb 24, 2019
t-first and t-last approach when working with nested data structures in Reason
View TFirstTLast.re
/**
* t-first and t-last examples when working with `Future.t(Result.t('a, 'e))`
**/
// `Future` and `Result` are both t-last
getJSON("some/url")
|> Future.map(Result.flatMap(decodeUser))
|> Future.map(Result.mapWithDefault(DataFailed, v => ShowData(v)))
|> Future.tap(send);
@mlms13
mlms13 / elm-game-loop.md
Created Feb 21, 2019
Like TEA, but for a game loop?
View elm-game-loop.md

The Elm Architecture, specialized for games.

Key points:

  • Instead of reacting to events, application state is updated on regular intervals
    • The engine collects all input events (keys up/down, mouse movement, button clicks, possibly joysticks, game pads)
    • User of this library specifies how to translate diffs in input events to game actions
  • Instead of a single "update" function, there are several specialized functions
    • physics update
      • given a current state (which should include things like position and velocity) and a time delta, provide a new state
@mlms13
mlms13 / ChangelogBuilder.re
Last active Feb 15, 2019
Categorize Git Commits
View ChangelogBuilder.re
module Git = {
type commitish = Sha(string);
type commit = {
title: string,
descriptiong: string,
author: string,
date: Date.t
};
@mlms13
mlms13 / PromiseState.re
Created Feb 12, 2019
Dealing with async changes to state in ReasonReact
View PromiseState.re
type state = {products: RemoteData.t(array(Product.t), string)};
type action =
| FetchProducts
| SetProducts(RemoteData.t(array(Product.t), string));
let component = ReasonReact.reducerComponent(__MODULE__);
let make = _children => {
...component,
initialState: () => {products: NotAsked},
View App.re
let render = ({ state }) => {
let { viewport, page } = state;
let { width, height } = viewport;
let content =
switch (page) {
| Overview => <Welcome />
| ShowUsers(users) => <UserTable users />
| NewUser(userForm) => <AddUser user=userForm />
};
You can’t perform that action at this time.