Skip to content

Instantly share code, notes, and snippets.

Corey Haines coreyhaines

Block or report user

Report or block coreyhaines

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
@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
}
@coreyhaines
coreyhaines / Flow.elm
Created Oct 13, 2016
General workflow-management
View Flow.elm
module Flow exposing (Flow(..), map, withDefault, mapDefault, view, update)
import Html
import Irn
type Flow state
= NotRunning
| Running state
@coreyhaines
coreyhaines / Animation.elm
Last active Jun 19, 2017
Animation support library
View Animation.elm
module Animation exposing (..)
import Task
import Process
import Time exposing (Time, millisecond)
type Animation state
= Setup state
| Animate state
View gist:8943a6d6204ec4843304a889b365e6f0
function directory_to_titlebar {
local pwd_length=42 # The maximum length we want (seems to fit nicely
# in a default length Terminal title bar).
# Get the current working directory. We'll format it in $dir.
local dir="$PWD"
# Substitute a leading path that's in $HOME for "~"
if [[ "$HOME" == ${dir:0:${#HOME}} ]] ; then
dir="~${dir:${#HOME}}"
fi
You can’t perform that action at this time.