#elixir-lang - 16 May 2019
« Back 1 day Forward 1 day »
[00:38:58] nageV: wow, OTP 22.0 is a beast!! my program runs 2x faster now (went from 9min 50sec for processing a 21GB file down to just 4min 33sec now) just by upgrading :O
[05:33:58] Schmuserkadser: When i want to store form Informations in a Connection instead of Changeset, do i need to create an Empty Connection Struct? As josevalim said it doesn't make any sense to set the own Connection.
[06:15:41] Schmuserkadser: When i want to store form Informations in a Connection instead of Changeset, do i need to create an Empty Connection Struct? As josevalim said it doesn't make any sense to set the own Connection.
[11:26:25] nickjj: if i wanted to match on a controller function where a specific form field has a non-empty string then using `when byte_size(myfield)` is the way to go right?
[11:39:27] nickjj: my plan was to have 2 functions , one match for myfield (when it's filled out) and another when myfield is empty (in which case, no guard clause)
[11:40:21] nickjj: in this case it's coming from a form field params, wouldn't it always be a string at this point?
[11:41:46] nickjj: do you know of any references in the docs that compares things like using byte_size(foo) > 0 vs a != ""
[11:42:45] dysfun: unless the compiler is smart enough to rewrite the former to the latter these days
[11:44:08] nickjj: i guess in this case, is it a style preference to use guards vs clauses? i just googled an alternative solution
[11:44:46] nickjj: for example, in this case the person just matches on myfield's argument being empty or not empty https://stackoverflow.com/a/47099430 (instead of a guard)
[11:46:45] dysfun: well, i might choose one in the case where i didn't want to match the empty case and i just wanted to let it fall off the match and crash
[11:46:48] nickjj: the guard seemed kind of nice on paper because it means i wouldn't have to modify the "other" non-empty case (which i consider the success case)
[11:47:19] nickjj: because this is a controller function that detects whether or not a honeypot field is submit (basically preventing the form from doing its normal thing if a bot filled it out)
[11:47:36] dysfun: but the point is which comes out cleaner and easier to understand in a given situation
[11:48:58] nickjj: in the clause case, does the ordering matter? for instance, does the empty clause fn need to be written first?
[11:52:33] nickjj: thank you, after seeing both written out, i'm with you in that i prefer the clause -- at least for sure in this use case
[11:54:29] nickjj: in both cases i didn't even have to modify the "other" case either, because in that case the form param doesn't exist at all
[12:10:11] scj: hello, I'm experimenting with the demo app for phoenix liveview, but I can't figure out what message I need to send to be able to change the location from IEx
[16:34:51] edwinbalani: I have a case where some elements in a map are required if the value of another element is 200 (for success)
[16:36:12] edwinbalani: It would be clearer to read if I could define a 'common' map of the elements that are required in both, and then Map.merge(common_elements, unique_elements) to form each typespec
[17:17:13] ankhers: Then in the documentation for your struct, you can say that keys a, b and c are required, while x, y and z are optional.
[17:24:45] edwinbalani: In reality, the API shouldn't be too complex for this application; the messy bit is the responses fed into it from a remote server
[17:25:26] ankhers: Or if you want to not make a struct, you can just say in the documentation that the function(s) they accepted keys in the map or keyword list.
[17:26:10] ankhers: You can just say in the documentation of the function which keys are accepted and how they interact.
[17:28:03] ankhers: Basically it comes down to a documentation thing, and not really a typespec thing. You can still create a type around a map though if it helps.
[20:35:41] benwilson512: chrismccord: if I have live view A and inside I live_render B, should connected?(socket) in B return true when A does?
[20:37:18] chrismccord: on WS connct, the parent will be connected? True, and a shell for the child will be rendered
[20:37:42] chrismccord: so on WS connect, parent child flow happens in serial, not all at once, if that makes sense
[20:38:21] benwilson512: sure, but I'm trying to understand a situation where the child doesn't mount in a connected way until the parent does a change > 1 min after the initial connection
[20:38:50] benwilson512: the scenario is: I want a tiny live view that you pass a DateTime value to, and it shows "time ago in words" with respect to that value, updating every second
[20:39:43] benwilson512: what I was experiencing is that it wouldn't start its timer until the container it was in did some sort of change
[20:40:31] benwilson512: some of my issues were caused by not realizing that <%= Timex.from_now(@some_fixed_time) %> would never re-render cause the assign there doesn't change
[22:27:49] benwilson512: chrismccord: yeah that works great. is this a bad idea in general by the way? Initially I thought this would be important so that I wasn't re-rendering the whole main page but it seems like you already optimize rendering enough that that doesn't happen
[22:29:30] chrismccord: benwilson512 : we don't yet optimize collections, so in this case data wise it's the most efficient. The caveat being you require a process per "ago" view
[22:30:10] chrismccord: so lots of extra processes and timers. Depending on scale, may be totally fine. I would use send_after rather than :timer.send_interval
[22:33:26] benwilson512: chrismccord: speaking of scale, we're running ~100 subscriptions per user on the index page
[22:34:03] benwilson512: it's really the same subscription but on 100 topics, that's basically the same thing
[22:43:41] benwilson512: blurg, Timex's time ago in words function uses `now()` as a side cause _deep_ in the code
[22:52:34] benwilson512: chrismccord: what I'd really like to do is <%= Timex.from_now(@now, point_in_time) %>` and then just update `@now` on whatever timer I want
[22:52:59] benwilson512: doing it in the child is actually super obnoxious because each thing renders at slightly different moments
[22:53:54] benwilson512: but best I can tell there isn't a way to do Timex.time_difference_in_words(t1, t2) because `Timex.from_now` calls `now()` at the formatter level
[22:54:20] benwilson512: https://github.com/bitwalker/timex/blob/3.5.0/lib/format/datetime/formatters/relative.ex#L62
[22:54:35] benwilson512: ah but there is https://github.com/bitwalker/timex/blob/3.5.0/lib/format/datetime/formatters/relative.ex#L83
[23:00:19] nageV: what's the best way to force a deep copy of a data structure that contains sub-binaries / refc binaries on shared heap? I'm thinking of doing this: mydata |> :erlang.term_to_binary |> :erlang.binary_to_term
[23:01:02] nageV: I want to essentially disconnect my data structure from the shared heap (so that the refc binaries can be garbage collected) before I send it off to another process for further processing
[23:02:48] nageV: (this is inside a Flow where millions of such data structures need to be "disconnected" in this way)
[23:03:19] benwilson512: nageV: you may be better off just calling :erlang.garbage_collect on your process after you send off the binaries
[23:04:14] nageV: benwilson512: thanks, but wouldn't the sent-off data structures still contain sub-binaries/refc-binaries which still occupy space on the shared heap?
[23:05:02] benwilson512: yes, but running garbage collect would ensure that your intermediary process wasn't holding on to any references itself
[23:05:18] benwilson512: IE you still get the efficiency of not needing to copy the binary when it's sent to the other process
[23:05:42] benwilson512: which can lead to the binary leaks you're presumably doing all of this to avoid
[23:08:39] nageV: oh! exactly: i have a many-partitioned Flow that these data structures pass through, and the memory usage (VmHWM: max RSS level) is basically being multiplied as data flows through each partition