This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule HeaderReader do | |
| def read(conn) do | |
| {:ok,headers} = Agent.start_link(fn -> %{} end) | |
| init_line = :gen_tcp.recv(conn, 0) | |
| do_read(headers, conn, :gen_tcp.recv(conn, 0)) | |
| end | |
| defp do_read(headers, conn, {:ok, "\r\n"}) do | |
| IO.inspect Agent.get headers, fn state -> state end | |
| :gen_tcp.close conn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class List(T) | |
| class Node(T) | |
| property :value | |
| property :next | |
| def initialize(@value : T, @next : List::Node(T) | List::EmptyNode) | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def s(l, start, stop, accuracy = 1000000) | |
| range = stop - start | |
| dx = range / accuracy.to_f | |
| sum = 0 | |
| accuracy.times do | |
| sum += 0.5 * (l.(start) + l.(start + dx)) * dx | |
| start += dx | |
| stop += dx | |
| end | |
| sum |
NewerOlder