Skip to content

Instantly share code, notes, and snippets.

View cobalamin's full-sized avatar
👾

Simon Welker cobalamin

👾
View GitHub Profile
@cobalamin
cobalamin / RidiculousFizzBuzz.hs
Last active May 23, 2016 18:42
Yet Another Unnecessary FizzBuzz in Haskell
module RidiculousFizzBuzz where
divBy :: Int -> Int -> Bool
divBy d x = x `mod` d == 0
fizzIt :: Int -> (Int, Bool, Bool)
fizzIt = (,,) <$> id <*> divBy 3 <*> divBy 5
fizzString :: (Int, Bool, Bool) -> String
fizzString (x, False, False) = show x
@cobalamin
cobalamin / fit80CharsInBody.js
Created May 25, 2016 19:59
Simple JS to make the content of a website wrap at about 80 chars per line. Mainly useful on wide monitors, for websites without any styling
(function fit80CharsInBody() {
var p = document.createElement('p');
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
p.textContent = chars;
var s = p.style;
s.position = 'absolute';
s.visibility = 'hidden';
s.width = s.height = 'auto';
s.whiteSpace = 'nowrap';
@cobalamin
cobalamin / CrashYoTab.js
Created June 3, 2016 17:35
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// after 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 milliseconds, print 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 times
for(i=0;i<1e308;i++){setTimeout(console.log.bind(console,1e
@cobalamin
cobalamin / FocusTree.elm
Last active July 15, 2016 22:51
An Elm module that defines an Tree type and a zipper-like structure for it. HistoryTree.elm re-exposes this as a simple API.
module FocusTree exposing (FocusTree, Tree, Index, init, goUp, goDown, insertAndFocus, unfocus, getCurrentValue)
import Array exposing (Array)
import Maybe exposing (andThen)
type Tree a
= Empty
| Node a (Array (Tree a))
@cobalamin
cobalamin / MonoidMaximum.hs
Created July 18, 2016 09:34
A monoidal safe maximum function in Haskell
module MonoidMaximum where
safeMaximum :: (Ord a, Monoid a) => [a] -> a
safeMaximum [] = mempty
safeMaximum [x] = x
safeMaximum (x:xs) = max x (safeMaximum xs)
@cobalamin
cobalamin / LinkedCounter.elm
Last active July 25, 2016 11:08
Three synced Elm counter apps
port module LinkedCounter exposing ( .. )
import Html exposing (Html, Attribute, button, div, text)
import Html.Attributes exposing (style)
import Html.App as App
import Html.Events exposing (onClick)
-- MODEL
@cobalamin
cobalamin / ChildAges.elm
Last active July 26, 2016 07:46 — forked from pfitz/ChildAges.elm
Add more beutifil
module ChildAges exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import Html.App
import String
import Array
@cobalamin
cobalamin / HaskellVsElm.md
Last active April 2, 2022 09:19
Elm (0.17) syntax and functionality differences for Haskell programmers
  • Types are declared with : and not ::, and the consing operator conversely is :: instead of :
  • No where clauses, only let/in
  • The standard style is different, check http://elm-lang.org/docs/style-guide for reference
  • Multiline strings are a thing with """
  • Haskell's data corresponds to type in Elm, and also, Haskell's type corresponds to Elm's type alias
  • ($) is (<|), but you don't use it all that much – Elm people like the flipped operator (|>) which lets you build something that reads like a pipeline
  • Related: Backticks will likely die soon in favour of functions that have an argument order that lends itself to pipelining with (|>)
  • Also, (.) is (<<), and a flipped version (>>) exists, but I don't see it used that much either
  • (&gt;&gt;=) is not an available operator and would not be polymorphic (no typeclasses, see below), and is instead commonly named SomeType.andThen – e.g. Maybe.andThen : Maybe a -&gt; (a -&gt; Maybe b) -&gt; Maybe b
@cobalamin
cobalamin / DictSelect.elm
Last active July 28, 2016 20:23
Selecting a set of keys from an existing Dict to make a new one. Fails silently if key doesn't exist in old dict.
module DictSelect exposing (..)
import Dict exposing (Dict)
import Set
select : List comparable -> Dict comparable v -> Dict comparable v
select keys dict =
List.foldr (putIfIn dict) Dict.empty keys
@cobalamin
cobalamin / BorkingElm.elm
Created August 1, 2016 16:55
Borking Elm
module BorkingElm exposing (..)
undefined : a
undefined = undefined
str : String
str = "hello" ++ undefined
num : Int
num = 1 + undefined