Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create/publish an Elixir package on Hex.pm #95

Closed
6 tasks done
nelsonic opened this issue Nov 1, 2018 · 14 comments
Closed
6 tasks done

How to create/publish an Elixir package on Hex.pm #95

nelsonic opened this issue Nov 1, 2018 · 14 comments
Assignees
Labels
awaiting-review An issue or pull request that needs to be reviewed enhancement New feature or enhancement of existing functionality epic A feature idea that is large enough to require a sprint (5 days) or more and has smaller sub-issues. help wanted If you can help make progress with this issue, please comment! question A question needs to be answered before progress can be made on this issue starter A beginner-friendly issue that is a good starting point for a new person T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Nov 1, 2018

We don't have a beginner-friendly write-up for creating Hex.pm packages; we need a concise guide.

GOTO: /code-reuse-hexpm.md

Todo: Done!

Consolidate these:

How to Use the Package Locally Before Publishing it to hex.pm

@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! question A question needs to be answered before progress can be made on this issue T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies starter A beginner-friendly issue that is a good starting point for a new person labels Nov 1, 2018
@nelsonic
Copy link
Member Author

Create a Mix Project and Run Elixir Code

https://pragmaticstudio.com/tutorials/create-elixir-mix-project-and-run-code

This is a good intro to using mix new and running the code. 👍

@nelsonic
Copy link
Member Author

Decided I didn't need to introduce the complexity at this stage. 😕
Wrote my own recursive function to test all properties in quotes.json

Meanwhile I've found a way of testing Quotes.random() using the Brithday Paradox! 😉
https://betterexplained.com/articles/understanding-the-birthday-paradox/
image

@nelsonic
Copy link
Member Author

Lovely docs for free!:
quotes-docs

@nelsonic
Copy link
Member Author

@nelsonic
Copy link
Member Author

nelsonic commented Oct 17, 2019

TIL: how to pass a function as a parameter in Elixir:

https://stackoverflow.com/questions/22562192/how-do-you-pass-a-function-as-a-parameter-in-elixir

Use &Module.function/arity to pass it, and .(…) to call it.

For example:

def my_hof(f) # "hof" = higher order function (in case you're wondering...)
    f.([1, 2, 3], &(&1 * 2))
end

my_hof(&Enum.map/2)

in my example I modified the code from:

  # This recursive function calls Quotes.random until a quote is repeated
  def get_random_quote_until_collision(random_quotes_list) do
    random_quote = Quotes.random()
    if Enum.member?(random_quotes_list, random_quote) do
      random_quotes_list
    else
      get_random_quote_until_collision([random_quote | random_quotes_list])
    end
  end

  test "Quotes.random returns a random quote" do
    # execute Quotes.random and accumulate until a collision occurs
    random_quotes_list = get_random_quote_until_collision([])
    # this is the birthday paradox at work! ;-)
    # IO.inspect Enum.count(random_quotes_list)
    assert Enum.count(random_quotes_list) < 200
  end

To:

  # This recursive function calls func (argument) until a quote is repeated
  def get_quotes_until_collision(random_quotes_list, func) do
    random_quote = func.()
    if Enum.member?(random_quotes_list, random_quote) do
      random_quotes_list
    else
      get_quotes_until_collision([random_quote | random_quotes_list], func)
    end
  end

  test "Quotes.random returns a random quote" do
    # execute Quotes.random and accumulate until a collision occurs
    random_quotes_list = get_quotes_until_collision([], &Quotes.random/0)
    # this is the birthday paradox at work! ;-)
    # IO.inspect Enum.count(random_quotes_list)
    assert Enum.count(random_quotes_list) < 200
  end

@nelsonic
Copy link
Member Author

I've written 5k words in https://github.com/dwyl/learn-elixir/blob/code-reuse-publishing-to-hexpm-issue%2395/code-reuse-hexpm.md and https://github.com/dwyl/quotes and I feel it's close to being finished ... but I need to work on something else for a bit ...

#brb

@nelsonic nelsonic added the epic A feature idea that is large enough to require a sprint (5 days) or more and has smaller sub-issues. label Nov 30, 2019
nelsonic added a commit that referenced this issue Apr 12, 2022
@nelsonic
Copy link
Member Author

Used the quotes package in https://github.com/dwyl/phoenix-content-negotiation-tutorial so I think we can consider this tutorial complete. Assigning the PR to @SimonLab #146 🙏

@nelsonic nelsonic added the awaiting-review An issue or pull request that needs to be reviewed label Apr 12, 2022
SimonLab added a commit that referenced this issue Jun 22, 2022
…e#95

Code reuse publishing to hexpm issue #95
@nelsonic
Copy link
Member Author

GOTO: /code-reuse-hexpm.md

LuchoTurtle added a commit that referenced this issue Oct 17, 2022
…e#95

PR: Code Reuse Publishing to Hex.pm issue #95 & 183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review An issue or pull request that needs to be reviewed enhancement New feature or enhancement of existing functionality epic A feature idea that is large enough to require a sprint (5 days) or more and has smaller sub-issues. help wanted If you can help make progress with this issue, please comment! question A question needs to be answered before progress can be made on this issue starter A beginner-friendly issue that is a good starting point for a new person T4h Time Estimate 4 Hours technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
None yet
Development

No branches or pull requests

2 participants