david

david

Avatarex - Generate unique, reproducible avatars from hashed strings

Avatarex is an elixir package for generating unique, reproducible Avatars from hashed strings.
The package is inspired by Robohash

Hey everyone! I’ve been working on a personal project and was in want of some unique placeholder avatars for my users. I really love the Robohash python lib, but wanted something a bit for “functional”. So here’s what I put together this weekend.


Current Avatar sets include Birdy and Kitty avatars created using images created
by David Revoy and used under CC-BY-4.0.

You can create your own avatar sets, see the AvatarexSet docs for more details.

Images are generated using @kip’s Image elixir package.

Note: The package is currently under development but is up on hex.

Cheers

Most Liked

Eiji

Eiji

Looks like there is a bug in this line:

it should be:

:avatarex |> :code.priv_dir() |> Path.join(~w[sets kitty])

Same patch should be applied to the birdy

Unfortunately current macro code does not allow it and I was in need to use it like:

defmodule Kitty do                               
  use AvatarexSet,
    dir: "deps/avatarex/priv/sets/kitty",
    keys: [:body, :eye, :fur, :mouth, :accessory]
end

which cannot be used in prod environment static paths are not guaranteed to work in all environments and therefore you should support: :code.priv_dir/1.

Similarly the macro does not allows to use a sigil for keys i.e.:

defmodule Kitty do                                                  
  use AvatarexSet,                                                  
    dir: "deps/avatarex/priv/sets/kitty",                                 
    keys: ~w[body eye fur mouth accessory]a
end
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:sigil_w, [delimiter: "[", line: 5], [{:<<>>, [line: 5], ["body eye fur mouth accessory"]}, 'a']} of type Tuple. This protocol is implemented for the following type(s): Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream
    (elixir 1.14.4) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.14.4) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.14.4) lib/enum.ex:4307: Enum.reduce/3
    (avatarex 0.1.0) expanding macro: AvatarexSet.__using__/1

The other problem is priv/renders. Once again there should be a :code.priv_dir/1 call. To support priv directory for current project you should use otp_app and pass this option to said function. Your documentation does not mentions to create such a directory which would not work in app generated using mix new task. I would recommend to create it automatically using File.mkdir_p with combination to :code.priv_dir/1 call mentioned above.

Also why do you use AvatarexSet instead of Avatarex.Set? It’s like reserving 2 namespaces for just one package and therefore it’s not seen as a good practice.

david

david

Updated with all your suggestions.

Eiji

Eiji

Already better, but you have still a lot to learn. I reserved some time, deeply investigated your code and created an example pull request with project rewrite proposal to show what code you would be able to write in future. :rocket:

If you do not understand something feel free to ask questions in this thread. :dark_sunglasses:

Have a nice day! :smiling_imp:

Eiji

Eiji

I have dropped some more comments in your latest 3 commits. You still doing the same mistake i.e. you are thinking from author perspective and not from someone who would use the library. Therefore for example default values for optional options are more confusing than helpful even if they work excellent in avatarex itself. You are just used to write project and not hex dependency. Hope my comments helped.

david

david

Thanks for the comments, they are excellent and appreciated. Yep, I’ve been definitely wrapping my head around some of the meta programming side of things and how they differ from solely project based. Particularly around the conventions for where to put things, how to spec & test, and working with AST at compile time.

Where Next?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement