Skip to content

Instantly share code, notes, and snippets.

View dasch's full-sized avatar
💭
LOOKING INTENTLY INTO THE VOID

Daniel Schierbeck dasch

💭
LOOKING INTENTLY INTO THE VOID
View GitHub Profile
{-| Returns a list of repeated applications of `f`.
If `f` returns `Nothing` the iteration will stop. If it returns `Just y` then
`y` will be added to the list and the iteration will continue with `f y`.
nextYear : Int -> Maybe Int
nextYear year =
if year >= 2030 then
Nothing
else
The type annotation for `leftJoin` does not match its definition.
10│ leftJoin : Stream comparable v1 -> Stream comparable v2 -> Stream comparable (v1, Maybe v2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:
Signal ( comparable, a )
-> Signal ( comparable, b )
-> Signal ( comparable, ( a, Maybe b ) )
module Stream where
import Dict exposing (Dict)
type alias Stream comparable v = Signal (comparable, v)
leftJoin : Stream comparable v1 -> Stream comparable v2 -> Stream comparable (v1, Maybe v2)
@dasch
dasch / types.elm
Last active November 25, 2015 12:29
A type system for a stream processing framework
-- A user searched or changed to a new page of search results.
type Search = { query : SearchQuery, searchId : SearchId }
-- A user clicked a search result.
type Click = { searchId : SearchId, pageId : PageId }
-- A user viewed an article.
type PageView = { pageId : PageId }
type SearchQuery = String
counts : List comparable -> List (comparable, Int)
counts items =
let
counts' items =
case items of
[] -> []
(x, nx) :: [] -> [(x, nx)]
(x, nx) :: (y, ny) :: rest ->
counts : List Int -> Dict Int Int
counts items =
List.map (\x -> Dict.singleton x 1) items
|> List.foldr (merge combine) Dict.empty
combine : Maybe Int -> Maybe Int -> Int
combine a b =
case (a, b) of
(Just a', Just b') -> a' + b'
clicks : Signal (Int, Int)
@dasch
dasch / git-pr
Created December 18, 2014 10:27
Open the GitHub compare page for a branch
#!/bin/bash
local_branch=$(git for-each-ref --format="%(refname:short)" $(git symbolic-ref HEAD))
remote_name=$(git config branch.$local_branch.remote)
remote_refspec=$(git config branch.$local_branch.merge)
remote_branch=${remote_refspec#refs/heads/}
remote_git_url=$(git config remote.origin.url)
remote_http_url=${remote_git_url#git@github.com:}
remote_http_url=${remote_http_url%.git}
github_url="https://github.com/$remote_http_url"

Keybase proof

I hereby claim:

  • I am dasch on github.
  • I am dasch (https://keybase.io/dasch) on keybase.
  • I have a public key whose fingerprint is EF11 DF25 B02F 0136 DF44 6EA9 CED4 AD42 717D 5ECC

To claim this, I am signing this object:

@dasch
dasch / curly_doc.rb
Last active December 18, 2015 00:08
Formatting Curly methods.
module CurlyDoc
def self.documentation_for_method(method)
pretty_name = CurlyInfo.curly_name(method)
description = I18n.translate(method.name, namespace: "curly.methods")
"%s - %s" % [pretty_name, description]
end
end