RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <dscottboggs_gitlab> @fenicks I'm not sure it it'll work but I think you could actually use something roughly like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcfb61ec7bf7c36625caf5d]
zorp has joined #crystal-lang
<FromGitter> <anicholson> @dscottboggs_gitlab are those `receive?` methods non-blocking, then?
<FromGitter> <dscottboggs_gitlab> so in this way crystal's case..when functions both like go's switch-case and select-case, the difference being in what goes into the when conditions
<FromGitter> <dscottboggs_gitlab> yes they return nil if nothing is on the channel yet, a value if it is
<FromGitter> <dscottboggs_gitlab> I should double check that and maybe add some documentation to the Channel class
<FromGitter> <anicholson> is this some === sorcery like Ruby's `case` statement?
<FromGitter> <dscottboggs_gitlab> my example was wholly incomplete now that I look back on it, more like a rough sketch
<FromGitter> <fenicks> @dscottboggs_gitlab I think it could be done but I don't know about the right way to do that. ⏎ `select when` or `case when`. Is a core ticker exist ? I probably need to build my own Ticker.
<FromGitter> <dscottboggs_gitlab> Yes, I think you'll need to build a ticker which emits a truthy value
<FromGitter> <dscottboggs_gitlab> `when` blocks get executed when they receive a truthy value, nil is falsy
<FromGitter> <fenicks> Ok, thanks guys
<FromGitter> <dscottboggs_gitlab> could you let me know if you get that working?
<FromGitter> <dscottboggs_gitlab> It would make a good example for the Channel documentation
<FromGitter> <fenicks> Ok
<FromGitter> <drujensen> @dscottboggs_gitlab Yes, this would make an excellent example. Syntax looks much cleaner than Go. I love Crystal!
<FromGitter> <drujensen> could you use one channel with different responses like `:ticker` and `:done`?
<FromGitter> <drujensen> or each span needs its own channel?
<FromGitter> <drujensen> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcfc1b6bbdc0b25058cdfc7]
sevensidedmarble has quit [Ping timeout: 264 seconds]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 240 seconds]
marmotini_ has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> yes that would be one way or you could get a value from a channel like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcfd3e5069fca52a5845b60]
<FromGitter> <dscottboggs_gitlab> I think it makes more sense to have separate channels for concepts like done and ticker but it could certainly be useful to perform actions based on data passed through channels; that's mainly what they're there for.
<FromGitter> <dscottboggs_gitlab> I love fibers/channels/goroutines as a concurrency pattern
<FromGitter> <dscottboggs_gitlab> > or each spawn needs its own channel? ⏎ ⏎ I think that is the best idea yes.
<FromGitter> <m-o-e> hmm, is there a way to get a property by name? as in: instance.get_property("foobar")
marmotini_ has quit [Ping timeout: 264 seconds]
<FromGitter> <fenicks> @dscottboggs_gitlab @Blacksmoke16 @anicholson @drujensen , a simple example for my use case: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcfdc6b1c100a4f29d45470]
<FromGitter> <fenicks> @dscottboggs_gitlab @Blacksmoke16 @anicholson @drujensen , a more complete: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcfdcbc82893a2f3b2de22c]
<FromGitter> <proyb6> How do I receive raw HTTP contents or request from user in byte, I want to see if I can bypass the HTTP context.request and middleware.
akaiiro has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> here's a question of preference
<FromGitter> <Blacksmoke16> to justify my thinking
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <Blacksmoke16> @proyb6 you could maybe use https://crystal-lang.org/api/0.26.1/HTTP/Client/Response.html#body_io%3F%3AIO%3F-instance-method
<FromGitter> <Blacksmoke16> then use https://crystal-lang.org/api/0.26.1/IO.html#peek%3ABytes%3F-instance-method
<FromGitter> <proyb6> @Blacksmoke16 Hmm, I’m unsure how to get body_io? Any difference to TCP socket api?
<FromGitter> <Blacksmoke16> you should just have to call`body_io` instead of `body` on your `HTTP::Response`
<FromGitter> <Blacksmoke16> oh wait, you want request
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.26.1/HTTP/Request.html#body%3AIO%3F-instance-method calling `.body` on an `HTTP::Request` should return nil or an IO
<FromGitter> <proyb6> Noted, I thought about Actix-raw could raw requests to bypass overhead, will be awesome how efficient we can do in Crystal as well
<FromGitter> <proyb6> will try tonight!
zorp has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> hm
<FromGitter> <jeff-hykin> How unrealistic is it to compile crystal to c? (or wasm)
<FromGitter> <dscottboggs_gitlab> @fenicks I wasn't aware of the select top-level method. where did you find that?
<FromGitter> <dscottboggs_gitlab> @jeff-hykin pretty unrealistic actually from what I understand
<FromGitter> <anicholson> @jeff-hykin wasm probably more likely than C, but yeah, it's hard
<FromGitter> <dscottboggs_gitlab> Go recently managed to get a working WASM port, which they "hadn't yet optimized for size" that was over 2MB
<FromGitter> <dscottboggs_gitlab> which is kinda pointless
<FromGitter> <dscottboggs_gitlab> the point is that you have to statically link the whole crystal stdlib which is going to be huge.
<FromGitter> <dscottboggs_gitlab> plus several other libraries
<FromGitter> <jeff-hykin> Thanks @dscottboggs_gitlab and @anicholson , I was what was afraid that was the case.
<FromGitter> <dscottboggs_gitlab> although
<FromGitter> <dscottboggs_gitlab> if size isn't a concern it is feasible
<FromGitter> <dscottboggs_gitlab> it would take a lot of work though
<FromGitter> <anicholson> step 0 (for wasm) would be a WASM version of the GC
<FromGitter> <dscottboggs_gitlab> I'm pretty sure I read that compiling the actual code wasn't a huge problem because LLVM can compile to WASM
<FromGitter> <jeff-hykin> I dont know a ton about converting to webassembly, but if crystal ever gets there i was going to be looking into making api bindings for browser environments
<FromGitter> <anicholson> yeah, it's the C libraries the stdlib relies on, like `libevent`, the GC, etc.
<FromGitter> <anicholson> they're the work
<FromGitter> <proyb6> @Blacksmoke16 I assume the body_io is applicable for HTTP server as well?
<FromGitter> <jeff-hykin> really? @anicholson I though c could be compled to wasm
<FromGitter> <anicholson> it can
<FromGitter> <anicholson> I guess it's a question of linking
<FromGitter> <anicholson> don't get me wrong, I'd love it to happen
<FromGitter> <jeff-hykin> Ah okay. Do you think theres any opportunity for a generic way for crystsl to call wasm-ified c libaries? Or is it pretty much going to need a custom call to each tool in the stl
<FromGitter> <anicholson> not sure, @jeff-hykin . I'm speaking from intuition & first principles rather than Actual Knowledge ;)
marmotini_ has joined #crystal-lang
<FromGitter> <anicholson> I guess there's a difference between the Crystal compiler toolchain and the programs it produces
<FromGitter> <jeff-hykin> haha okay 👍 thanks for the insight though
<FromGitter> <anicholson> theoretically there's nothing stopping someone from compiling every C lib needed by the Crystal stdlib to WASM. If you could do that, and wire the linking together properly a la `emscripten`, then it's feasible for a purely-Crystal program to be compiled to WASM via LLVM too.
<FromGitter> <anicholson> and even more hypothetically, if you solved that problem, then it's no different to C libs in userland Crystal programs. You'd need to have access to the C source though
rohitpaulk has joined #crystal-lang
* FromGitter * anicholson goes off to attempt to compile `libevent` to WASM
<FromGitter> <jeff-hykin> Haha 👌 i'll check back here in a month. Maybe convince one of the devs at mozilla to help out. Cross compatible Crystal would be pretty nice, and replacing javascript with crystal would be incredible even with no relative performance benefits.
<FromGitter> <anicholson> well, `libevent` compiled to WASM okay with a tweak
marmotini_ has quit [Ping timeout: 240 seconds]
<FromGitter> <anicholson> `bdwgc` not so much
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <bew> @fenicks did you manage to use `select`?
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
Flipez has quit [Quit: The Lounge - https://thelounge.github.io]
Flipez has joined #crystal-lang
Raimondii has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter> <fenicks> @bew Yes `select` works as I was expected
rohitpaulk has joined #crystal-lang
<FromGitter> <mettuaditya> can anyone suggest how to implement graphs in crystal
<FromGitter> <mettuaditya> like for DFS and BFS
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <yxhuvud> Uh, you basically only need a way to find neighbours of the current choice to search like that.
<FromGitter> <m-o-e> migrating the brain from ruby to crystal is funny. i almost always reach for a macro first, and then realize a different, less obtuse way to do it.
<FromGitter> <m-o-e> loving the way json/yaml mapping works
<FromGitter> <bararchy> @m-o-e What are yyou migrating?
<FromGitter> <m-o-e> @bararchy my brain! (it was just a general remark about the process of learning crystal ;))
<FromGitter> <bararchy> Ohhh ok lol
<FromGitter> <m-o-e> it's very pleasant. i think the only thing i'm really missing so far is a way to access props by name.
<FromGitter> <alehander42> whatever your usecase is for that, it's probably possible to simulate it with compile time metaprogramming
<FromGitter> <m-o-e> i assume you're referring to macros? yes, those are possible, but sadly tend to become ugly. a basic use-case that i've run into a few times now is: mapping a yaml/json-hash and then iterating over the top-level keys.
<FromGitter> <bararchy> @m-o-e we created some recursive logic to iterate over a whole JSON which is outputted via JSON.parse and extract key-value. then you you are able to change each one and re-build it with the different data inside
<FromGitter> <m-o-e> barisbalic: yes, that sounds similar to my current approach: parse, an inject a root-node, then apply mapping to the result
<FromGitter> <m-o-e> but that isn't very pretty, and requires to parse the input twice
<FromGitter> <m-o-e> i think life would be easier there if #mapping wouldn't only add getters/setters, but also a generic get_property()
<FromGitter> <m-o-e> (but i'm still new to crystal, maybe this wouldn't be idiomatic or create problems in ways that i don't grasp yet)
<FromGitter> <bew> Yes probably
<FromGitter> <bew> Btw the json/yaml (de) serialization don't necessarily use the mapping macros anymore, checkout `JSON::Serializer` in the docs
<jokke> not sure if i've asked this before but is it possible to define macro methods without having to recompile crystal?
<jokke> i'm having real trouble to keep things readable when writing more complex macros
<FromGitter> <bew> Not possible
<jokke> dang :/
<FromGitter> <bew> You could call other macros though, but keep in mind that the code must be valid
<FromGitter> <bew> For each macros
<FromGitter> <Istanful> Hi! In my application I want to import JSON in one format and output JSON in another. I find that the `JSON.mapping` macro is useful, however I can't find a nice way to output with another mapping than the original. ⏎ ⏎ Given that I have `{ "cake": "nom" }` and want to output it as `{ "Cake":"nom" }` it would be nice if I could do something like `Downcased.from_json("{ "cake": "nom"
<FromGitter> ... }").to_json(Upcased::JSON_MAPPING)`. Is something similar to this possible?
<FromGitter> <bajro17> I have problem with connection to database
<FromGitter> <bajro17> where to put password
<z64> @Istanful not entirely clear what your use case is, but you have one or two options. the first is to define `#to_json(builder)` and write the serialization yourself. another, is if you don't actually need the lower-cased input (just the Cased output) is you can use the `key` option in JSON.mapping https://carc.in/#/r/5bjf
zorp has joined #crystal-lang
<z64> that said - there isn't a high level control for that kind of thing
<z64> a tangent, but also take a look into JSON::Serializable - you might find it more powerful for certain use cases https://carc.in/#/r/5bjk
<FromGitter> <bajro17> I find solution
<z64> @bajro17 typically you specify a connection URI to something like `DB.connect` or `DB.open`; the format of it depends on the database you are using, but in postgres for example it is `postgresql://user:secret@localhost
<FromGitter> <hello2dj> I am a newbie , When i need inherit a class or include a module?
<FromGitter> <hello2dj> thank you
<FromGitter> <Istanful> @FromIRC Thing is I don't want to define a custom builder. Coming from ruby land that seems excess since I already know all the getters. :)
<FromGitter> <j8r> @hello2dj to DRY (don't repeat yourself)
<FromGitter> <Istanful> @z64 Thing is I don't want to define a custom builder. Coming from ruby land that seems excess since I already know all the getters. :)
<z64> @Istanful the problem is the JSON.mapping / JSON::Serializable does not expose any means to control how the *keys* are written, only the *values*. its not a semantic it recognizes (case insensitive keys)
<z64> you can maybe write a custom macro though for a basic object..
<FromGitter> <Istanful> @z64 Yeah the macro is the one solution I could come up with. Though that feels overkill I think
<FromGitter> <Istanful> @z64 I will go for the `to_json(builder)` solution I think. Thanks for the help!
<FromGitter> <hello2dj> thank you so much, but what the difference between inherit class and include module?
<z64> @hello2dj well mechanically for one, inheritance will add *both* class *and* instance methods (`Foo.bar` and `foo.bar`) to your type. beyond that, i know this is for ruby, but all of the semantics / practices described in this answer apply well to crystal: https://stackoverflow.com/questions/1282864/ruby-inheritance-vs-mixins
<z64> (woops, forgot to finish: `include SomeModule` will just add instance methods `foo.bar`)
<z64> there's more details and examples of both in the language reference in case you haven't seen it yet: https://crystal-lang.org/docs/syntax_and_semantics/inheritance.html https://crystal-lang.org/docs/syntax_and_semantics/modules.html
<FromGitter> <hello2dj> thank you
<FromGitter> <Blacksmoke16> @Istanful check out https://github.com/Blacksmoke16/CrSerializer
<FromGitter> <Blacksmoke16> in process of refactoring it but it should be just what you want
<FromGitter> <Blacksmoke16> ``` @[CrSerializer::Json::Options(serialized_name: "Cake")] ⏎ property cake : String?``` [https://gitter.im/crystal-lang/crystal?at=5bd076db64cfc273f91a3f29]
<FromGitter> <Blacksmoke16> ```c = Cake.deserialize("{ "cake": "nom" }")```
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> I'm working on a new configuration/object notation: `con` (Cretin Object Notation) written in Crystal, of course ⏎ What do you think of this type of syntax - any suggestions? ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5bd07a10c08b8b3067664a2e]
<FromGitter> <j8r> the delimiters for each token are either ` ' ', '\n', '\t', '\r'`
<FromGitter> <Prutheus> I am using jennifer.cr …. I have a Relational Object called Search. A user has_many searches. Now I want to modify a search by that: ⏎ ⏎ ` ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5bd07a86ae7be94016ab55df]
<FromGitter> <Blacksmoke16> do ⏎ ⏎ ```search.save ⏎ pp search``` ⏎ ⏎ Then you can see if there is an error or something on the model [https://gitter.im/crystal-lang/crystal?at=5bd07aa8c08b8b3067664e92]
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter> <Prutheus> `#<Search:0x10f7abe00 id: 1, user_id: 2, active: false, interval: 1000, running: false, next_run: 2018-10-24 00:27:45.941000000 +02:00 Local, name: "Gaming PC | Intel i7 5GHz OC | 32GB Corsair RAM | NVidia GTX 1070 Founders Ed.", platform: "EBAY-DE", options: {"keywords" => "Gaming PC Intel i7 5GHz OC 32GB Corsair RAM NVidia GTX 1070 Founders Ed", "excludes" => "", "buying_formats" => "All", "condition" =>
<FromGitter> ... "Any", "seller_score_cmp" => ">=", "seller_score_val" => 1_i64, "min_seller_percent" => "0.00", "categories" => ""}, created_at: 2018-10-24 00:27:45.941000000 +02:00 Local, updated_at: 2018-10-24 00:27:45.941000000 +02:00 Local>` ⏎ ⏎ no errors …. :(
<FromGitter> <bew> @j8r looks nice, is `bool` a keyword? Or just a key name?
<FromGitter> <j8r> that's the key
<FromGitter> <j8r> like yaml, all the keys are as is
<FromGitter> <bew> Oh cool
<FromGitter> <j8r> I'm taking a lot from JSON::PullParser, but I think it'll be more efficient because I don't use case/when with symbols
<FromGitter> <Prutheus> @Blacksmoke16 any other idea?
<FromGitter> <j8r> It returns directly the value, instead of a class `Token`
<FromGitter> <Blacksmoke16> @Prutheus try doing `pp search.errors` after trying to save it
<FromGitter> <Prutheus> returns `#<Jennifer::Model::Errors:0x107ab6e80 @messages={}>`
<FromGitter> <Blacksmoke16> welp
<FromGitter> <Prutheus> Hm?
<FromGitter> <Blacksmoke16> anything in db logs?
<FromGitter> <j8r> @bew WDYT (quickly) of https://carc.in/#/r/5bm9 ? A very early draft
<FromGitter> <Prutheus> @Blacksmoke16 I can’t see logs in pgAdmin4 :(
<FromGitter> <Prutheus> @Blacksmoke16 why can’t i save modifications on that relational item of the user-model?
<FromGitter> <Blacksmoke16> dunno mate, i dont use jennifer so not sure what to do next if the errors are empty and its not saving
<FromGitter> <Blacksmoke16> i guess make sure its not failing some FK or not null db constraint?
<FromGitter> <Prutheus> is it possible that it may be locked?
<FromGitter> <Blacksmoke16> :shrug: maybe?
<FromGitter> <Prutheus> oh man how can i fix my problem now? ….
<FromGitter> <Prutheus> ` ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ ` ... [https://gitter.im/crystal-lang/crystal?at=5bd080bcc08b8b306766779c]
<FromGitter> <Prutheus> it does a transaction but dont write to db … why?
marmotini_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> not sure
<FromGitter> <Prutheus> I need to solve that fast, the server i am working on are changed to jennifer and down cause i can’t modify my data … please help me
<FromGitter> <Blacksmoke16> try doing `search.save!` and see what the exception is
<FromGitter> <Prutheus> it rescues on the line `search.save!` with `Object is invalid: []`
<FromGitter> <Blacksmoke16> least you got a clue now
<FromGitter> <Prutheus> no really, i do not understand. but for sure, the validation fails
thews has joined #crystal-lang
<FromGitter> <bew> @j8r I'd suggest to remove the FromString version, and only keep one from IO, you can make a IO::Memory from a String object
<FromGitter> <Prutheus> @Blacksmoke16 `search.valid?` returns `true` btw ...
<FromGitter> <Prutheus> so where is the problem??? ….. :(
<FromGitter> <Blacksmoke16> beats me
<FromGitter> <j8r> @bew yes, but I guess there is a performance penality?
<FromGitter> <Prutheus> @Blacksmoke16 i need to solve that o.O ;(
<FromGitter> <Blacksmoke16> i dont know what you want me to do
<FromGitter> <Prutheus> we need to find out where the problem is
<FromGitter> <Blacksmoke16> better get on it then, how would i know :p
<FromGitter> <Blacksmoke16> maybe look up the jennifer docs?
<FromGitter> <bew> @j8r no penalty, the io memory will directly use the string's buffer, it won't re-allocate a buffer
<FromGitter> <j8r> Ok that's great I'll do this then, thanks :)
<FromGitter> <j8r> For heredocs, I'm thinking about ``` ⏎ key |some ⏎ ⏎ ```multi``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5bd086dbc7bf7c3662622624]
<FromGitter> <dscottboggs_gitlab> > I'm working on a new configuration/object notation: `con` (Cretin Object Notation) ⏎ ⏎ ...why?
<FromGitter> <j8r> https://carc.in/#/r/5bmv
<FromGitter> <j8r> I'll rather use the second one with `<`` >`
<FromGitter> <j8r> another option is using quotes
sz0 has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I'm not being sarcastic. what is the benefit of that over JSON, YAML, or TOML?
<FromGitter> <j8r> This is even simpler than JSON, and more readable than JSON (and even YAML IMHO)
<FromGitter> <dscottboggs_gitlab> computationally simpler you mean?
<FromGitter> <j8r> Maybe, haven't tested - I think it will be very close. Simpler for the user to read and write
<FromGitter> <j8r> like YAML, but YAML is sometimes hard to follow when there are deep key/values
<FromGitter> <dscottboggs_gitlab> So I'm confused about the delimiters in your Hash. everything else is separated by spaces or newlines or tabs, but that appears to have only a multi-line syntax
<FromGitter> <dscottboggs_gitlab> how would it know what ⏎ `hash { key "value" other "value" }` meant?
<FromGitter> <dscottboggs_gitlab> also are unquoted strings supposed to be special-case strings or are they like symbols?
<FromGitter> <j8r> that's only key/value
<FromGitter> <j8r> keys aren't quoted, strings are quotes
<FromGitter> <dscottboggs_gitlab> so no delimiter chars allowed in keys then?
<FromGitter> <j8r> you can escape them
<FromGitter> <dscottboggs_gitlab> hm
<FromGitter> <j8r> I general, having spaces and special symbols in keys are rare, and not recommended. But you can still do
<FromGitter> <dscottboggs_gitlab> fair
<FromGitter> <j8r> The same for the in line Hash you have put as example. You can do, the parser won't complain, but in general better to do it in multi line 😄
<FromGitter> <dscottboggs_gitlab> true
<FromGitter> <dscottboggs_gitlab> just wondering about how the notation itself worked
<FromGitter> <Prutheus> if someone can help: https://github.com/imdrasil/jennifer.cr/issues/175
<FromGitter> <j8r> Thanks to ask @dscottboggs_gitlab , this feedbacks contribute to the docs I'm writing :)
<FromGitter> <dscottboggs_gitlab> do libevent-* build dependencies need to be the specific version listed here (https://github.com/crystal-lang/crystal/wiki/All-required-libraries) or can it be a newer version?
<FromGitter> <r00ster91> When I use `STDIN.raw` and for example suddenly "hello" is coming from somewhere to STDIN, how do I just read the "hello" and then go on? ⏎ I don't want to use `gets` because it requires a delimiter but I don't know if the string will even contain the delimiter. I also don't want to use any method that requires me to say the bytesize of the string (like `read_string`) because I don't know that either. And I
<FromGitter> ... tried `gets_to_end` doesn't do anything and just hangs the program. ⏎ ⏎ Can I do this somehow? I'm pretty much searching for a string version of `read_char` which just reads what currently arrived to STDIN and then goes on [https://gitter.im/crystal-lang/crystal?at=5bd08ec06e5a401c2dc2f0cf]
<FromGitter> <j8r> It should work for any new 2.x versions AFAIK @dscottboggs_gitlab
<FromGitter> <dscottboggs_gitlab> I've got two versions of libgc on my system, when I run `whereis libgc` I get the right version though, do you think crystal/llvm is still grabbing the wrong one?
<FromGitter> <dscottboggs_gitlab> just trying to figure get crystal to compile
<FromGitter> <j8r> I don't know, what's the error?
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd08f64ab17df2631e32ef2]
<FromGitter> <dscottboggs_gitlab> oh whoops
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter> <dscottboggs_gitlab> nope I uninstalled the distro version of libgc so it's not that...
akaiiro has joined #crystal-lang
<FromGitter> <j8r> the `-dev`?
<FromGitter> <dscottboggs_gitlab> yeah, both, and double-checked all the dependencies are installed. I guess I'll raise an issue and build in docker on 16.04 for now unless you have a better suggestion
DTZUZU has quit [Read error: Connection reset by peer]
return0xe has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
<FromGitter> <j8r> yes, on my side I only build the compiler in an Alpine Docker container :)
Creatornator has joined #crystal-lang
<FromGitter> <bew> @r00ster91 how do you know there is `hello` coming and not `h` `e` `l` `l` `o` ?
non-aristotelian has joined #crystal-lang
<FromGitter> <r00ster91> I'm just pretty sure that I'm getting it in one string instead of multiple chars
<FromGitter> <bew> this doesn't make sense, there is no concept of strings when you're reading it
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <r00ster91> ooh.. so everything comes in single chars. that's good to know
rohitpaulk has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/CrSerializer ⏎ changed the syntax to be be easier to customize/expand
<FromGitter> <Blacksmoke16> for example: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd0a8b7c7bf7c366263313e]
<FromGitter> <Blacksmoke16> would have to use master branch for now in your `shards.yml` few other things i want to do before doing another release
<FromGitter> <dscottboggs_gitlab> @j8r would you mind sharing your Dockerfile? I've got a weird problem with mine
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd0ac5fc7bf7c3662634a81]
<FromGitter> <enra4> i get this weird error when trying to run crystal on another account than root ⏎ `` ⏎ host@arnesify:~$ crystal ⏎ Failed to raise an exception: END_OF_STACK ⏎ [0x7f8aadd1b746] ??? ... [https://gitter.im/crystal-lang/crystal?at=5bd0ac7b82893a2f3b3340f9]
<FromGitter> <enra4> this is `0.26.1` didnt happen on the last version of crystal i was on, which i think was `0.25.?`
<FromGitter> <dscottboggs_gitlab> you have to be *root* to run crystal??
<FromGitter> <dscottboggs_gitlab> that's weird
<FromGitter> <enra4> i also think its very weird lol
<FromGitter> <dscottboggs_gitlab> what's the output of `ls -la $(which crystal)`?
<FromGitter> <enra4> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd0ad3fef4afc4f28c640e4]
<FromGitter> <dscottboggs_gitlab> huh.
<FromGitter> <dscottboggs_gitlab> I definitely think you should raise an issue for that
<FromGitter> <enra4> okay, thanks for trying to help :)
<oprypin> enra4, the first thing i would suspect is that something is wrong with your env
<oprypin> you can use the command `env` to see the env
<oprypin> it would be interesting to see but i'm not entirely sure that it's safe for you to share it directly
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <enra4> what part specifically would be interesting to see?
silmanduin has joined #crystal-lang
<FromGitter> <enra4> its close to identical with env for root
<oprypin> it's really hard to say what could be interesting
<FromGitter> <enra4> so it turns out
<FromGitter> <enra4> i had some screen on host running a program from the older version of crystal
<FromGitter> <enra4> now that i quit the program things work fine
<FromGitter> <enra4> still dont think this should happen?
<FromGitter> <enra4> also tried making a new account, and crystal wouldnt run there either
<oprypin> wait what
<oprypin> maybe your computer is out of memory
<oprypin> regarding env: here's how you may try to rule out this option. `env -i HOME="$HOME" PATH="$PATH" LC_ALL=C crystal build example.cr`
<FromGitter> <enra4> i mean things work now
<FromGitter> <enra4> and my computer was not out of memory
<oprypin> i dont see how a crystal-compiled program could affect crystal
<FromGitter> <enra4> me neither
<oprypin> or was it running under `crystal run`?
<FromGitter> <enra4> well
<FromGitter> <enra4> i had run crystal ./app.cr
<oprypin> that's crystal run
<FromGitter> <enra4> right
<z64> @enra4 / oprypin this sounds like https://github.com/crystal-lang/crystal/issues/6965 (maybe not, but made me think..)
<FromGitter> <enra4> huh i didnt spot that issue
<FromGitter> <enra4> looks similar
<oprypin> good find
<FromGitter> <enra4> though, im fairly sure that in my case, nothing is restricted access on
<FromGitter> <enra4> im not working with a container
<FromGitter> <j8r> Wow @dscottboggs_gitlab , no need to have suck complicated Dockerfile! https://store.docker.com/community/images/jrei/crystal-alpine
<z64> note the last comment, rx14 marked it as a duplicate of another general issue that isn't specific to containers
<FromGitter> <enra4> i see now, thanks!
<FromGitter> <dscottboggs_gitlab> @j8r thank you
<FromGitter> <fusillicode_twitter> Hi guys, sorry for the bother but why can't I find the duplicates of a list of strings in this way? `(list_of_strings - list_of_strings.uniq).uniq`
Creatornator has joined #crystal-lang
<FromGitter> <fusillicode_twitter> I actually get an empty array as a results 🤔
* FromGitter * dscottboggs_gitlab sighs heavily
<FromGitter> <fusillicode_twitter> ?
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd0b78bc7bf7c366263a50e]
<FromGitter> <dscottboggs_gitlab> sorry @fusillicode_twitter I wasn't referencing your issue haah
<FromGitter> <vladfaust> I've got some issue regarding to sockets. I have this code: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ What the actual heck? [https://gitter.im/crystal-lang/crystal?at=5bd0b7c0271506518d641949]
<FromGitter> <straight-shoota> @fusillicode_twitter Because you're removing all items of `list_of_strings`. All occurences of the items in `list_of_strings.uniq` will be removed.
<FromGitter> <fusillicode_twitter> mmm
<FromGitter> <straight-shoota> What exactly do you expect?
<FromGitter> <fusillicode_twitter> uhm actually just the duplicates values 🤔
<z64> they expected `["a", "a"] - ["a"]` to remove a single occurence of `"a"` :p
<FromGitter> <fusillicode_twitter> wait
<FromGitter> <fusillicode_twitter> uhm
<FromGitter> <straight-shoota> @vladfaust `sleep 0` maybe?
<FromGitter> <vladfaust> Yep, did the job, @straight-shoota. Big thanks!
silmanduin has quit [Quit: WeeChat 2.2]
<FromGitter> <vladfaust> Isn't that a bug, btw?
<FromGitter> <fusillicode_twitter> ok now I get it...
<FromGitter> <fusillicode_twitter> ...oh gosh I'm such a douche
<FromGitter> <fusillicode_twitter> sorry guys for my silly questions... :(
<FromGitter> <straight-shoota> It looks weird because reading from a socket should also interrupt the fiber. It certainly looks weird
<FromGitter> <straight-shoota> but I don't know any context
<FromGitter> <dscottboggs_gitlab> @fusillicode_twitter don't be so hard on yourself
<FromGitter> <dscottboggs_gitlab> it was a good question
<FromGitter> <vladfaust> @straight-shoota, more context: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd0ba416e5a401c2dc43a1f]
<FromGitter> <vladfaust> changing/removing timeout doesn't change things
<FromGitter> <vladfaust> Huh, that's a small context, I guess. I'm halting a docker process with Tarantool DB instance exposing to 3001 in the near terminal tab, and crystal process just hangs
<FromGitter> <vladfaust> Adding `sleep 0` does raise on the halt
<FromGitter> <straight-shoota> I'd guess that `read_fully?` does short-curcuit somehow so you're effectively in a tight loop
<FromGitter> <vladfaust> Should it be replaced with something?
<FromGitter> <vladfaust> Sorry, afk 20 mins
zorp_ has joined #crystal-lang
marmotini has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tilpner_ has joined #crystal-lang
dostoyev1ky has joined #crystal-lang
marmotini_ has quit [*.net *.split]
zorp has quit [*.net *.split]
Flipez has quit [*.net *.split]
johndescs has quit [*.net *.split]
tilpner has quit [*.net *.split]
pabs has quit [*.net *.split]
dostoyevsky has quit [*.net *.split]
rohitpaulk has joined #crystal-lang
commavir has quit [*.net *.split]
tilpner_ is now known as tilpner
johndescs has joined #crystal-lang
Creatornator has joined #crystal-lang
Flipez has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
<FromGitter> <vladfaust> Uh, okay
<FromGitter> <vladfaust> So, adding `sleep 0` is the best and the most performant way to read exactly 5 bytes from the socket, right?
<oprypin> lol what
Jenz has joined #crystal-lang
<oprypin> after a long investigation, i see nothing wrong with the code and i see no reason why it would require sleep 0
<oprypin> read_fully calls read which should be blocking
<oprypin> if read is somehow not blocking, then yes, this is a problem
<oprypin> vladfaust, no, you know what the problem is? if `read_fully?` returns `nil` once, it will always return `nil` in all subsequent calls
<oprypin> and instantly, too
<oprypin> not sure what this `@open` is supposed to mean but the right way to write this would be while @socket.read_fully?(slice)
<oprypin> cc @straight-shoota
<FromGitter> <straight-shoota> Okay. I wasn't sure if subsequent calls would short-circuit
<FromGitter> <vladfaust> The socket can be closed manually (`my_conn.close`), so `@open` is required
<oprypin> for a socket, `read` instantly returns 0 if and only if the socket is closed, and so `read_fully` also instantly returns. causing a busyloop
<oprypin> you can certainly write `while @open && read_fully`
<FromGitter> <vladfaust> I wasn't aware of the concept of busyloops and short-circuit
<oprypin> but it's possible that @open is not necessary
<FromGitter> <vladfaust> Is there a way to *wait* without blocking unless 5 bytes are read?
<oprypin> read_fully does that
<FromGitter> <vladfaust> read_fully differs from read_fully?, right
<oprypin> def read_fully(slice : Bytes)
<oprypin> read_fully?(slice) || raise(EOFError.new)
<oprypin> i'm just treating them as the same thing
<FromGitter> <vladfaust> Hm. Is there a way to wait without blocking unless 5 bytes are read and do not raise a error?
<oprypin> "wait" and "blocking" are interchangeable in my current vocabulary
<FromGitter> <vladfaust> Yep, makes sense
<FromGitter> <vladfaust> Okay, is there a way to wait for 5 bytes read without errors and minumum impact on performance, i.e. allowing other fibers to run?
<oprypin> `read_fully?` waits until it has read 5 bytes. for the case of socket, it returns `nil` (instantly) if and only if the socket is closed
<FromGitter> <vladfaust> And if it's not closed but there are no 5 bytes of data (its empty), what's then?
<oprypin> then it blocks because it uses `read` which blocks
<oprypin> `read_fully?` in a loop works well but you must not loop on it after it has returned `nil` for the first time because THAT'S the busyloop
<FromGitter> <vladfaust> Aaaaah
<oprypin> and by "blocks" i mean "waits" , and other fibers work well
<FromGitter> <vladfaust> Now I understand
<FromGitter> <vladfaust> Wow. Thank you so much for the explaination, @oprypin
<FromGitter> <vladfaust> Really, appreciate that :)
<oprypin> i learned something too. i didn't know that `read_fully` exists so I would have basically reimplemented it myself if I needed this functionality
<FromGitter> <fusillicode_twitter> @dscottboggs_gitlab you're too kind 😅
<FromGitter> <vladfaust> You know what, I think the question is still here. Why `puts` or `sleep` leads to a error raise?
<FromGitter> <vladfaust> Why not putting or sleeping forever if `read_fully?` just returns `nil`?
<FromGitter> <vladfaust> ```code paste, see link``` ⏎ ⏎ I think because connection timeout actually has time to trigger in this case, right? [https://gitter.im/crystal-lang/crystal?at=5bd0cbd9271506518d64a2e6]
<FromGitter> <vladfaust> And when busylooping, it has no time to check for a timeout?
<oprypin> i'd like to see a complete program
<oprypin> but i'll be afk for a while
<FromGitter> <straight-shoota> > And when busylooping, it has no time to check for a timeout? ⏎ ⏎ exactly
<FromGitter> <vladfaust> @oprypin, it would take time because it's third party DB. @straight-shoota seems to confirm my guess
<FromGitter> <vladfaust> Okay, I'm glad we've figured that out :) Thanks again, guys
<FromGitter> <straight-shoota> Crystal's scheduler is cooperative, that means a fiber must explicitly yield control. If it's in a tight loop, there is no way for a different fiber to jump in. And the exception is obviously raised in a different fiber.
<Jenz> I love how crystal does its fibers :D
<jokke> is there any specific reason why to_json(JSON::Builder) isn't defined for enumerable?
<jokke> uh sorry
<jokke> makes sense
<Jenz> A default Enumerable#to_json would make some sense IMO
<jokke> nah
<jokke> Hash is also enumerable
<jokke> and yields key-value-pairs
<Jenz> Yeah, true
dostoyev1ky is now known as dostoyevsky
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Jenz has quit [Quit: 'Night']
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<jokke> i have a question about crystal-db. in the .from_rs method in the db mapping an array is returned. i see how this seems necessary because the result set has to be closed. Would the following however also work: return an iterator over the result set which closes the result set in its finalize method?
<jokke> this would delay closing it until the gc strikes but maybe that's not a problem?
<jokke> always creating an array for results will consume a lot of unnecessary memory for large result sets and also iterate twice over the results (first to create the array and later to iterate over it in the application)
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
marmotini has quit [Remote host closed the connection]
Creatornator has joined #crystal-lang
zorp_ has quit [Ping timeout: 244 seconds]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5btg shouldn't the type of `t` in this be only `Int32` since there was a nil check in super?
<FromGitter> <Blacksmoke16> nvm, because the return in there is prob getting passed down to the sub method
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang