Skip to content

Instantly share code, notes, and snippets.

Avatar

Corey Haines coreyhaines

View GitHub Profile
@coreyhaines
coreyhaines / peano.pl
Last active Apr 19, 2020
Peano's Axioms in Prolog
View peano.pl
% Peano's Axioms
:- module(peano, [
is_zero/1,
is_natural/1,
equal/2,
add/3,
subtract/3,
multiply/3,
divide/3
]).
@coreyhaines
coreyhaines / peano.pl
Created Apr 19, 2020
Peano's Axioms in Prolog
View peano.pl
% Peano's Axioms
:- module(peano, [
is_zero/1,
is_natural/1,
equal/2,
pred/2
]).
/** Peano's Axioms
*
@coreyhaines
coreyhaines / maybe.ts
Last active Jun 19, 2019
Simple Maybe<T> approximation in typescript
View maybe.ts
type Maybe<T> = T | undefined;
function maybeMap<T, U>(mv: Maybe<T>, f: (v:T) => U) : Maybe<U> {
if(mv !== undefined) {
return f(mv);
}else{
return undefined;
}
}
function maybeBind<T, U>(mv: Maybe<T>, f: (v:T) => Maybe<U>) : Maybe<U> {
if(mv !== undefined) {
@coreyhaines
coreyhaines / Foldit.exs
Last active Apr 4, 2018
Convert a list of paths to a tree
View Foldit.exs
defmodule FolditTest do
use ExUnit.Case
doctest Foldit
def to_keyword([], keyword), do: keyword
def to_keyword([val], keyword) do
Keyword.update(keyword, nil, [val], fn existing -> [val | existing] end)
end
@coreyhaines
coreyhaines / Id.elm
Last active Jul 8, 2017
The Id type I like
View Id.elm
type Id
= Id Int
idIs : Id -> { a | id : Id } -> Bool
idIs thisId =
idFieldIs .id thisId
idFieldIs : (a -> Id) -> Id -> a -> Bool
View UserAlert.elm
module Shared.UserAlert exposing (UserAlert, Msg, show, startShowAlertAnimation, startHideAlertAnimation, default, update, view)
import Helpers exposing (classes)
import Shared.Animation as Animation
import Html exposing (Html, div, span, text)
import Html.Attributes exposing (class)
import Task
type UserAlert
View Editable.elm
module Editable exposing (..)
type Editable ofType
= NotEditing { value : ofType }
| Editing { originalValue : ofType, buffer : ofType }
value : Editable ofType -> ofType
value editable =
@coreyhaines
coreyhaines / Elm.rake
Created Dec 9, 2016
Rake task to compile/copy elm
View Elm.rake
namespace :elm do
Apps = [ "WorkspaceMain", "ManageSubscribersMain", "NotebookMain", "ResponsesMain" ]
JsFileName = "irn_elm.js"
JsOutputDir = "app/assets/javascripts"
desc "Updates packages, compiles the Elm code and copies it to #{JsOutputDir}"
task :compile_and_copy => [:package_install, :make, :copy] do
puts "Updated Packages, Compiled and copied Elm code to #{JsOutputDir}"
end
@coreyhaines
coreyhaines / Api.Error.elm
Last active Dec 9, 2016
Elm Form Builder for Hearken
View Api.Error.elm
-- support stuff for remote stuff
type alias ErrorMessages =
Dict.Dict String (List String)
type alias ApiError =
{ message : String
, errors : ErrorMessages
, explanation : Maybe String
}