Skip to content

Instantly share code, notes, and snippets.

View wende's full-sized avatar

Krzysztof Wende wende

  • Neon Tree Solutions Ltd.
  • Gdańsk, Poland
View GitHub Profile
module SingletonIncrementer exposing (..)
import Platform exposing (Task(..))
import Task
cast :
(a -> msg)
-> (a -> state -> state)
-> Task Never ()
module GlobalCounter exposing (..)
type alias Model = Int
type Msg
= Increment
| Decrement
| Reset
| GetState Pid
main =
test "Sum of lists" do
assert Hello.sum([]) == 0
assert Hello.sum([2]) == 2
assert Hello.sum([1, 2, 3, -1, -2, -3]) == 0
end
@wende
wende / fizbuzz.ex
Last active May 31, 2017 16:50
Elmchemy article #3
defmodule FizzBuzz do
use Elmchemy
import XList, only: [{:'range', 0},{:'map', 0}]
@doc """
Fizzes the buzzes and buzzfizzes the fizz out of buzz
iex> import FizzBuzz
iex> fizzbuzz.(1).(7)
@wende
wende / fizbuzz.elm
Last active May 31, 2017 16:50
Elmchemy article #2
module FizzBuzz exposing (fizzbuzz)
import List exposing (map, range)
{-| Fizzes the buzzes and buzzfizzes the fizz out of buzz
fizzbuzz 1 7 == "1 2 Fizz 4 Buzz Fizz 7"
-}
fizzbuzz : Int -> Int -> String
fizzbuzz from to =
@wende
wende / elixir_tuple_case.ex
Last active May 23, 2017 18:21
Elmchemy article #1
def example do
item = {10, 2, {20, 30, []}}
case item do
{10, 2, {20, 30}, []} -> :ok
end
end
example()
## -> ** (CaseClauseError) no case clause matching: {10, 2, {20, 30, []}}
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@wende
wende / test.js
Last active August 23, 2016 23:19
[action.type, matchedKey, "_"].reduce( (acc, a) =>
acc || handlers.hasOwnProperty(a) && handlers[a](state, action)
, null) || state
module GameOfLife where
import [Enum, Access]
neighbours(x,y, state) ->
[{nx, ny} || nx <- -1..1, ny <- -1..1]
|> reduce(0, ({nx, ny}, acc) -> (state[x + nx][y + ny] || 0) + acc)
alive(1, n) -> if n in 2..3, do: 1, else: 0
alive(0, n) -> if n == 3, do: 1, else: 0
@spec chunk(t, pos_integer, pos_integer, t | nil) :: [list]
def chunk(enumerable, count, step, leftover \\ nil)
when is_integer(count) and count > 0 and is_integer(step) and step > 0 do
limit = :erlang.max(count, step)
{acc, {buffer, i}} =
reduce(enumerable, {[], {[], 0}}, R.chunk(count, step, limit))
if is_nil(leftover) || i == 0 do
:lists.reverse(acc)