Skip to content

Instantly share code, notes, and snippets.

Jonas Adler jadlr

  • Berlin, Germany
Block or report user

Report or block jadlr

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
View bataille_royale.ex
defmodule BatailleRoyale do
@cards 0..7 |> Enum.to_list |> List.duplicate(4) |> List.flatten
def times(n) do
results =
1..n
|> Enum.map(fn _ -> play() end)
|> Enum.map(fn {_, _, moves} -> moves end)
@jadlr
jadlr / Max.scala
Created May 10, 2017
Slowly relearning Scala syntax
View Max.scala
import java.util.NoSuchElementException
import cats._
import cats.implicits._
import scala.annotation.tailrec
object Max extends App {
def maximum[A : Order](list: List[A]): A = list match {
@jadlr
jadlr / pushbutton_handle_events.ex
Created Dec 9, 2016
`gen_statem` example rewritten in elixir using only handle_event functions
View pushbutton_handle_events.ex
defmodule PushButtonHandleEvents do
@behaviour :gen_statem
@name :pushbutton_statem
# Client API
def start do
:gen_statem.start({:local,@name}, __MODULE__, [], [])
end
View pushbutton.ex
defmodule PushButton do
@behaviour :gen_statem
@name :pushbutton_statem
# Client API
def start do
:gen_statem.start({:local,@name}, __MODULE__, [], [])
end
@jadlr
jadlr / Repdigit.hs
Created Jul 19, 2016
Repdigit sequence calculation in haskell
View Repdigit.hs
module Repdigit where
-- https://oeis.org/A010785
repdigit :: Integer -> Integer
repdigit n = (n - 9 * floor ((fromInteger n - 1) / 9)) * (10 ^ floor ((fromInteger n + 8) / 9) - 1) `quot` 9
repdigits :: [Integer]
repdigits = go 0
where go n = repdigit n : go (n + 1)
@jadlr
jadlr / FizzBuzz.hs
Last active Apr 6, 2016
fizzbuzz in haskell
View FizzBuzz.hs
{-# LANGUAGE ParallelListComp #-}
module FizzBuzz where
-- https://en.wikipedia.org/wiki/Fizz_buzz
fizzBuzz :: [String]
fizzBuzz = take 100 $ go 1
where go n
| n `mod` 15 == 0 = "fizzbuzz" : go (n + 1)
View LeftPad.hs
module LeftPad where
leftPad :: Int -> Char -> String -> String
leftPad n c x
| n > length x = leftPad n c (c : x)
| otherwise = x
@jadlr
jadlr / RateLimiter.scala
Created Feb 29, 2016
Reusable rate limiter for akka streams
View RateLimiter.scala
import akka.stream.FlowShape
import akka.stream.scaladsl.{Flow, GraphDSL, Source, Zip}
import scala.concurrent.duration.FiniteDuration
object RateLimiter {
private def rateLimiter[A](rate: FiniteDuration) = {
case object Tick
@jadlr
jadlr / ListPermutations.hs
Last active Feb 22, 2016
Permutations of a certain length of a list in haskell (v2)
View ListPermutations.hs
module ListPermutations where
listPermutations :: [a] -> Integer -> [[a]]
listPermutations _ 0 = [[]]
listPermutations [] _ = []
listPermutations (x:xs) n = fmap (x:) (listPermutations xs (n - 1)) ++ listPermutations xs n
@jadlr
jadlr / ListPermutations.ex
Last active Feb 22, 2016
Permutations of a certain length of a list in elixir (v2)
View ListPermutations.ex
defmodule ListPermutations do
def list_permutations(_, 0), do: [[]]
def list_permutations([], _), do: []
def list_permutations([h|t], n), do: Enum.map(list_permutations(t, n-1), fn(l) -> [h|l] end) ++ list_permutations(t, n)
end
You can’t perform that action at this time.