Skip to content

Instantly share code, notes, and snippets.

Avatar

Corey Haines coreyhaines

View GitHub Profile
View show script class
def foo
p self
end
p self
foo
@coreyhaines
coreyhaines / peano.pl
Last active April 19, 2020 20:31
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 April 19, 2020 19:55
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 June 19, 2019 19:16
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 April 4, 2018 20:53
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 July 8, 2017 18:49
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
@coreyhaines
coreyhaines / UserAlert.elm
Created January 27, 2017 22:18
User Alerts
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
@coreyhaines
coreyhaines / Editable.elm
Last active August 25, 2022 05:11
type Editable
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 December 9, 2016 18:24
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 December 9, 2016 21:25
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
}