#elixir-lang - 20 May 2019
« Back 1 day Forward 1 day »
[09:57:45] serafeim: i see from the docs that the plug Conn struct has a "private" attribute that "is reserver for library use": https://hexdocs.pm/plug/Plug.Conn.html#module-private-fields
[09:58:18] serafeim: is that a problem? can I use this for my controller ? I want to extract the :phoenix_action field from it: pry(27)> conn.private[:phoenix_action]
[10:10:45] serafeim: yes i'm aware of assign i use it in other places i can't understand how it can be used to fullfill my requirement :)
[10:16:27] serafeim: dysfun well I want to create a plug that will retrieve the current method (:index, :show, :new, :create etc) and authorize (or not) depending on that
[10:18:53] serafeim: also i'd like to ask, is it possible to match on multiple keywords on a function ? i.e I have a def foo(:index) and def foo(:create) ... I want both of these to do the same. i.e can I do something like def foo(:index OR :create) do ?
[10:22:48] serafeim: of course a possible solution would be to do something like def foo(:index), do: foo2_index_or_create() and def foo(:create), do: foo2_index_or_create() ... and move the common functionality to the foo2_index_or_create() function. but this is not ideal for me
[10:30:02] dysfun: i don't know where phoenix stores its routing information, i haven't needed to play with it
[10:34:24] serafeim: dysfun no problem i'll then use the con.private field as it seems to be working fine
[10:52:10] serafeim: josevalim thank you. so i'll have multiple plugs depending on the action_name; yes that can also work
[13:19:37] serafeim: is there a quick way to output a string containining newlines to <br />s in an eex template ?
[13:21:35] serafeim: i guess i can replace \n with <br /> and mark it as safe, however i don't want to allow any other html elems (only brs)
[13:40:38] dysfun: escaping the html directly, *then* replacing newlines with <br />, *then* marking it safe?
[13:41:03] micmus: serafeim: is this what you're looking for? https://hexdocs.pm/phoenix_html/Phoenix.HTML.Format.html#text_to_html/2
[15:16:16] nickjj: when it comes to best practices, if you have a route where you expect an ID to be present and there's only 1 id being passed, do you use :id or :foo_id where foo is the schema name?
[16:37:27] dsimon: hey all, i was wondering about some of the behavior of Streams, specifically about when i can rely on reading a stream to be side-effect-free
[16:37:37] dsimon: e.g. check out this Gist: https://gist.github.com/robmckinnon/7d1a74e979c15e78a812913673f7f8fd#file-elixir_stream-sh
[16:38:22] dsimon: using Enum.at(0) to read from a Stream based on a simple list or from File.stream! seems to have no side effects
[16:39:02] dsimon: but reading from a stream based on IO.stream(:stdio) does seem to permanently advance the "stream source"
[16:39:58] dsimon: I don't see much documentation about this except a warning in a couple spots that "an IO stream has side effects and every time you go over the stream you may get different results"
[16:40:29] dsimon: but can i rely on this always happening (or not happening) in the same circumstances?
[16:41:09] dsimon: or should i always use something like https://github.com/tallakt/stream_split just to be safe, if i want to be able to read from a stream and rely on subsequent reads of the same stream returning the same data?
[17:10:04] nickjj: josevalim, do you think in phoenix 2.0+ you will rethink making schema_id the new default?
[17:20:31] nickjj: also when you say default, do you mean the generated code, or is there some functionality that works with :id without you having to pass in an argument to some function (i don't know which one off hand)?
[17:39:26] starbelly: Hmm, trying to understand why an UUID isn't casted in an embedded schema... that is to say, I can pass any string in for the binary id field and the changeset is always valid
[17:40:04] starbelly: of course, I can just validate the field myself, but want to be sure something is not being missed overall
[17:49:02] starbelly: Ahh n/m I see what the fix is... must be `belongs_to(:foo, Foo, type: Ecto.UUID)` vs `field(:foo_id, type: :binary_id)`
[17:52:25] nickjj: josevalim, realistically what type of migration process are we talking about? is it all user land code?
[17:52:37] nickjj: going into your router.ex, replacing id with schema_id and adjusting all controller params for that too?
[17:53:33] nickjj: but on the phoenix side of things, there's nothing that would have worked with :id but wouldn't have worked with :schema_id?
[17:54:00] nickjj: aka. on a new project now, argument can be made for schema_id without making things "worse" from a phoenix usability standpoint
[18:39:50] nickjj: does anyone want to help me take a shot at setting up a form that needs to validate things from 2 different schemas and also deals with a transaction? i've been able to hack together a bunch of other things but i can't find a single example of what i'm trying to do online, and i don't know enough about complex phoenix/ecto relations to pull this off alone
[18:40:30] nickjj: this isn't for a paid gig (it's a side project, which i plan to open source) but it might take like 30 minutes for someone experienced to come up with a solution, i'm actually willing to pay someone to help if need be
[18:41:08] nickjj: i wrote up a workflow of what i'm trying to do at https://gist.github.com/nickjj/e31a467f863374228be212dc0475755c
[18:50:08] josevalim: perhaps have a schema meant to model the form and then internally you convert it to the proper schemas?
[18:50:36] josevalim: nickjj: there is an eaxmple here: http://blog.plataformatec.com.br/2016/05/ectos-insert_all-and-schemaless-queries/
[18:52:14] starbelly: I posed this question on erlanger slack... it's dead there right now... Anyone have resources on building a register based VM ala the BEAM in C?
[18:58:54] starbelly: josevalim: I do have that book marked, but I suppose the angle I'm coming from... I've never even built a VM, so I suppose I'm looking for some thing of a tutorial in that regard.
[18:59:29] starbelly: that and the beambook ofc... and I could always just rip apart the BEAM... but wanted to try a different approach then my normal M.O.
[19:02:02] starbelly: Hmm to note the goal is build a simple VM that only does a few things the BEAM is capable of and by no means do a full implementation. This is in order to gain a better understanding of VMs and the BEAM, so then I can move on to making more contributions in that area and moving a stepping stone for learning project #2. Implement my own erlang :)
[19:02:53] nickjj: josevalim, thanks. the schemas are mappers seems interesting but there's still a lot of unknowns, i'll see what i can do tho
[19:03:09] mahmudov: http://beam-wisdoms.clau.se/en/latest/ where can i find details of latest news?
[19:32:36] micmus: starbelly: I think this is a decent resource http://www.craftinginterpreters.com/ - it builds a stack-based VM instead of a register-based one, but the differences between them aren't that huge and stack-based VMs are simpler (you don't need the whole register allocator shebang), so it might be a better learning tool