Skip to content

Instantly share code, notes, and snippets.

@mrmurphy
mrmurphy / Handler.re
Created August 7, 2018 17:04
Type Safe Reason Express Handlers
/* Prom is a library that provides
<$> (map)
and
>>= (bind, or flatMap)
for promises.
*/
open Prom;
/*
A Handler is a more functional and type-safe way of dealing with composable "middleware" in the express chain.
type queryBuilder;
type t = (. string) => queryBuilder;
type querySql('options) = {
.
"method": string,
"options": 'options,
"bindings": array(string),
"sql": string,
Verifying my Blockstack ID is secured with the address 18Fj9tXaLucYW57miX6oteLJaN8AHcgDkq https://explorer.blockstack.org/address/18Fj9tXaLucYW57miX6oteLJaN8AHcgDkq

dayone.me

  • Log in to dayone.me
  • Log in to dayone.me with apple auth
  • Forgot password?
  • Create account
  • Link Apple ID
  • Unlink Apple ID
  • Change Password
  • Change Email Address
  • Add email address (apple only accounts)
module Model.Lenses exposing (..)
-- other imports omitted
import Monocle.Optional as MO
import RemoteData
entryInList : String -> MO.Optional (List Entry) Entry
entryInList id =
{ getOption = List.Extra.find (\entry -> entry.id == id)
@mrmurphy
mrmurphy / Select.elm
Last active September 19, 2016 17:55
A bug in the select
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App exposing (beginnerProgram)
type alias Model =
{ showSelect : Bool
, selectVal : Maybe String
@mrmurphy
mrmurphy / Main.elm
Created June 20, 2016 12:46
Decoding Ints
import Html exposing (text)
import Json.Decode exposing (Decoder, decodeString, list, int)
-- Define a "recipe" (decoder)
-- Execute the recipe (decoder)
-- Result x a = Err x | Ok a
num = "4"
nums = "[1,3,5,6,7]"
@mrmurphy
mrmurphy / prepend.bash
Created May 27, 2016 16:45
Insert a line at the beginning of files matching search pattern
# Requires siver-searcher to be installed
FILES=$(ag "<search term here, can be regex>" -l --js)
for i in $FILES; do
echo -e "<stuff to prepend here>\n$(cat $i)" > $i
done
module Inversions (countInversions, mergeAndCount) where
import List.Extra exposing (splitAt)
import List exposing (length, sort, foldl, concat, head)
import Maybe.Extra exposing (isNothing, map2)
mergeAndCount : List Int -> List Int -> ( List Int, Int )
mergeAndCount left right =
let