#elixir-lang - 09 April 2019
« Back 1 day Forward 1 day »
[08:33:25] mrus: it seems pretty much impossible to find Elixir "Hello World" examples where there's no pre-built long-running module (e.g. Cowboy/Plug) involved. Nobody seems to care to build a bare "Print Hello World 10 times on the screen" example that follows the Application/GenServer design principles.
[08:47:37] lpil: There's no need for one unless you have a task in mind. Could you give more of an example of what you want to do?
[08:48:12] lpil: nicholasruunu: It's best not to make a GenServer sleep with Process.sleep/1 as it stops the GenServer responding to messages (including system ones). Instead use Process.send_after
[08:49:58] mrus: lpil: well, no specific task in mind, I just noticed that all example really just rely on some other module to do all the ground work, but there don't seem to be a lot of examples describing how the heavy lifting can be done manually in case one would want to implement something totally different than yet another Phoenix site or some API project.
[08:50:50] lpil: The problem is largely that the way these tools are used will be very different depending on what you want to achieve, and generally it's best to avoid them and write synchronous code until you have a good reason to do otherwise.
[08:51:11] lpil: If you want to learn about them in the abstract I would recommend the book Learn You Some Erlang https://learnyousomeerlang.com
[08:53:59] mrus: lpil: so, let me put it different. Let's assume you're new to Elixir and you ran `mix new myapp --sup` and now you'd like the app to print Hello World on the screen.
[08:58:06] mrus: well, alright, then I guess my expectations are misaligned here. I would have expected "myapp.ex" to contain an example GenServer that's already connected to application.ex.
[08:59:17] lpil: That would almost always be deleted as most applications don't need a top level genserver
[09:00:28] lpil: mdbm: Huh, it should return a list of strings where each is a codepoint. There's some detail for getting them as ints here -> https://hexdocs.pm/elixir/String.html#module-integer-codepoints
[09:16:39] mdbm: lpil, I would like to know what are the bytes of this: "ç" and I just can't. In IEx even if I have utf8 configured in ConEmu, it shows byte 0
[09:17:11] mdbm: lpil, I get the decimal codepoint 231 thanks to your doc, but I think it's two bytes then
[09:17:53] lpil: If you want to see the bytes try appending a null byte to make it invalid, then the repl will print it in bitstring format
[09:21:25] mdbm: lpil, but I'm confused now, the decimal codepoint for "ç" is 231, which is less than 255, so why are there two bytes 195 and 167?
[09:25:13] mdbm: lpil, I guess it's because UTF-8 reserves the first bit of each byte to know the number of bytes a character occupies
[09:40:54] mdbm: lpil, it's easy. You got ASCII encoding which is a 7 bit encoding. Doesn't include characters such as à, é, è, ç, ö and so on. So people invented 8-bit encodings to use that wasted bit, most famous: iso-8859-1 and windows-1252. But not enough for other languages such as Chinese. So then Unicode was invented which defines the codepoint for each character, then you have UTF-8, UTF-16, etc. which are multi-byte encodings
[09:43:19] mdbm: thank you, I meant variable length encoding* (e.g. minimum 1 or more bytes for UTF-8, minimum 2 or more bytes for UTF-16)
[09:45:41] mdbm: note that Unicode is not an encoding, it is the table that maps a character with a codepoint. Then you have UTF-8, UTF-16, etc. which are the encodings using Unicode codepoints to translate those codepoints into bytes.
[09:50:25] rawtaz: lpil: i agree with mdbm - it's easy. and especially if you just go the simple route - make sure everything is utf8, then it will all Just Work[tm]
[09:50:55] rawtaz: every single time ive worked out problems with encoding in systems it's come down to some piece not using utf8. when everything uses utf8, it just works
[09:51:07] rawtaz: at least for my use cases, i guess some exotic languages could see other types of issues
[09:51:26] rawtaz: btw, Joel Spolsky made a nice article about Unicode many years ago, if you want to read up on it
[16:20:09] shmink: Is there a way when in iex and you do an ecto query you don't see the debug information outputed?
[16:22:15] dysfun: you can either set the minimum logging level for the application or ecto's log level
[16:56:39] mrus: What's the proper way to implement a GenServer that is able to retrieve messages (`receive do ..`) and process them?
[16:58:47] mrus: dysfun: so, simply return the desired state from init() and then have handle_info retrieve it as soon as some other process posts something to the GenServer's inbox?
[17:08:12] dysfun: genserver handles the message loop. handle_info is called for messages that weren't sent through genserver
[17:09:48] mrus: cool, just tested it, works. Thank you! I'm just wondering... I see the init() output a couple of times now. And every time init starts with an empty state.
[17:13:26] mrus: Could it be that the code inside handle_info is silently crashing what would lead to the GenServer being restarted a couple of times?
[17:18:54] dysfun: my gut feeling is your `with` block in init has something not returning what you think
[17:20:19] mrus: it returns an array of References (`[#Reference<0.951360907.333053985.34902>, ...]`) which is fine for me.
[17:58:15] shmink: I would like to set up a docker container where it has my elixir project loaded in and ready to go. You would then go interactivley into it at command line where you would be able to run `mix test` for example.
[18:36:51] shmink: dysfun: what would my dockerfile look like? I mean I have the following so far but not sure how to wrap it up https://hastebin.com/ekoliqevar.css
[18:43:18] shmink: I'll explain my situation. I'm completing a technical exercise for a potential job oppurtunity. They let me choose to do it in any language. I done it in elixir but I don't want the possibility of them not being able to install elixir correctly or whatever so I was thinking having a container removed that potential risk. So they could just run the image and then going interactivley into it they could then just go ahead
[18:43:18] shmink: and run tests or go into iex or whatever else. So I don't think a volume would be the best for this perhaps?
[21:27:17] inoas: is ecto conventioned around plural or singular only btw? as for table names, foreign keys etc?
[23:03:30] starbelly: josevalim: You should give a talk on when it's a good thing to side step ecto and just go for SQL :)
[23:22:57] starbelly: Feel free to ask me about it... it really has to do with extremes... i.e., using your tool vs fighting it... it's no fault of ecto, but a human problem really. But I think until devs in general hear from the mouth of an "authority", then they will try to do everything possible to use that tool, even when it's folly.
[23:24:51] starbelly: there's a lot of examples where it's just simpler and more time efficient to use some raw sql and query/4 vs spending a LOT of time trying to conform to a pattern or perceived prescribed way of doing things. This applies to phoenix too I think... and I mean, every other tool right... but when it comes to web dev etc. this is especially true.
[23:25:52] starbelly: As stated, regretfully, until they you, or Chris Mccord, or whomever say it, and point it out... the anti-pattern of conforming to patterns etc. results in time lost and more problems created vs solved.