🏋️♂️
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
# config.exs | |
config :my_app, | |
http_adapter: HTTPoison | |
# test.exs | |
config :my_app, | |
http_adapter: Http.Mock |
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 Http.Behaviour do | |
@typep url :: binary() | |
@typep body :: {:form, [{atom(), any()}]} | |
@typep headers :: [{atom, binary}] | [{binary, binary}] | %{binary => binary} | |
@typep options :: Keyword.t() | |
@callback post(url, body, headers, options) :: {:ok, map()} | {:error, binary() | map()} | |
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 derive_key(%Private{chain_code: chain_code} = private_key, index) | |
when normal?(index) do | |
chain_code | |
|> compressed_hmac_sha512(private_key, index) | |
|> private_derivation(private_key) | |
end | |
def derive_key(%Private{key: key, chain_code: chain_code} = private_key, index) | |
when hardened?(index) do | |
chain_code |
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 Pathlist do | |
@mersenne_prime 2_147_483_647 | |
def to_list(<<"m/", path::binary>>), do: {:private, to_list(path)} | |
def to_list(<<"M/", path::binary>>), do: {:public, to_list(path)} | |
def to_list(path) do | |
path | |
|> String.split("/") | |
|> Enum.map(&cast_to_integer/1) |
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
<<fingerprint::binary-4, _rest::binary>> = | |
pub_key | |
|> compress() | |
|> hash_160() |
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
@mersenne_prime 2_147_483_647 | |
defguardp hardened?(index) when index > @mersenne_prime | |
defguardp normal?(index) when index <= @mersenne_prime and index > -1 |
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 Task2 do | |
@doc """ | |
Problem: | |
We would like to check what users are actively using one of our web applications and, if so, ask for their opinion. | |
Each user enters the application and navigates between pages. | |
For each user, we log whenever he or she opens main page or any other page. | |
Whenever he or she open a page for the first time or after a break of at least 30 minutes, | |
we count it as a new session. We will ask the user for his or her opinion | |
only when for the last three days he or she used the application each day |
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 Task1 do | |
@doc """ | |
A function that receives two sequences: A and B of integers and returns one sequence C. | |
Sequence C should contain all elements from sequence A (maintaining the order) except those, | |
that are present in sequence B p times, where p is a prime number. | |
Example: | |
A=[2,3,9,2,5,1,3,7,10] | |
B=[2,1,3,4,3,10,6,6,1,7,10,10,10] | |
C=[2,9,2,5,7,10] |
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 compress(<<0x04::8, x_coordinate::256, y_coordinate::256>>) do | |
y_coordinate | |
|> rem(2) | |
|> compress(x_coordinate) | |
end | |
def compress(0, x_coordinate), do: <<0x02::8, x_coordinate::256>> | |
def compress(1, x_coordinate), do: <<0x03::8, x_coordinate::256>> |
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
<< | |
version_number::binary, | |
0::8, # depth | |
0::32, # fingerprint | |
0::32, # key index | |
chain_code::binary, | |
key::binary | |
>> |