<FromGitter>
<watzon> Ok well I've been hammering at this for hours and can't figure out a good way to make it work. I don't know enough about JSON parsing in Crystal to parse things manually. I did manage to build my own code generator though so that I can create the classes based on Telegram's schema.
alexherbo2 has quit [Ping timeout: 264 seconds]
dwdv_ has quit [Ping timeout: 240 seconds]
<FromGitter>
<asterite> I also agree about puts, print and not having println, but we inherited that from Ruby (which seems to have inherited it from C) and maybe now it's a bit too late. Plus puts is conveniently short and what you usually use.
<FromGitter>
<Blacksmoke16> i think i need a mutex somewhere
<FromGitter>
<Blacksmoke16> o/
<Nazral>
I've just started using crystal for an utility at work, and it works well. Now I'd like to add a server loop (not much more complicated than the basic HTTP::Server example) running on the side
<Nazral>
I'm not sure how to have both running in parallel
<FromGitter>
<Blacksmoke16> docker usually works well?
<FromGitter>
<Blacksmoke16> one container for the one, one for the other?
<Nazral>
No no
<Nazral>
I mean in one program
<Nazral>
like if I wanted to do an IRC client, I'd need to have a loop listening to the servers, and one to the user input
<FromGitter>
<Blacksmoke16> specifically the one that `require "socket"`
<Nazral>
I guess putting a HTTP::Server instead of the socket should work similarly, by putting the `server.listen` in the fiber ?
<FromGitter>
<Blacksmoke16> could do something with a fiber, then call `sleep`, which would cause the main fiber to block and allow the server to run indefinitely. is that what you were looking to do?
<Nazral>
yes, I think so
<FromGitter>
<watzon> @Blacksmoke16 how long do you think I'd have to wait for CrSerializer to be able to handle structures like we were discussing earlier? I've been hammering at this all day and haven't made any progress :/
<FromGitter>
<Blacksmoke16> could try the PR @asterite made
<FromGitter>
<didactic-drunk> That's what confused me.
sorcus has joined #crystal-lang
dwdv_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
<FromGitter>
<Blacksmoke16> size is based on the type not the instance
<FromGitter>
<Blacksmoke16> specific value*
mjblack has joined #crystal-lang
<FromGitter>
<didactic-drunk> I expected it to work at least as easily as c. For some reason it doesn't. The error message ```Error: expecting token 'CONST', not 'i'``` could be improved.
<FromGitter>
<ImAHopelessDev_gitlab> good morning!!
absolutejam2 has joined #crystal-lang
<repo>
hey!
<repo>
is it somehow easily possible to initialize a JSON::Serializable with a JSON::Any?
<repo>
(without having to do from_json(any.to_json)
<repo>
)
<FromGitter>
<Blacksmoke16> whats the use case?
<FromGitter>
<j8r> strange question
<repo>
yeah sorry :D
<FromGitter>
<j8r> why there is a JSON::Any in the first place?
<repo>
i have a json column in a postgres table
<FromGitter>
<Blacksmoke16> what if you do `from_json any.raw`
<FromGitter>
<j8r> Better to directly use JSON::Serializable
<repo>
currently i'm basically going through the json any structure "by hand" by doing stuff like `any["value"].as_a.map do { |another_any| OtherClass.from_json(another_any) }` and so on
<FromGitter>
<j8r> repo: isn't it possible to use Serializable in the first place?
sagax has joined #crystal-lang
<repo>
maybe, but i doubt it. the data stored in the column is polymorphic and is dependent on the value of a related record
<FromGitter>
<Blacksmoke16> it reads_raw so its using the raw string at that point
<repo>
ah
<repo>
yeah
<repo>
so basically the same drawback as with the descriminator approach
<repo>
i mean, it's nitpicking. i think json parsing isn't a memory issue.
<repo>
but being able to pull parse is a neat thing
<FromGitter>
<Blacksmoke16> it has its uses
<FromGitter>
<Blacksmoke16> but idk how you would do it if you need to know the data before seeing what to serialize
<FromGitter>
<Blacksmoke16> like the descriminator
<repo>
yeah there's no way
<repo>
well
<FromGitter>
<Blacksmoke16> would have to keep some way to rewind
<repo>
the only way is for the descriminator to be outside of the object about to be parsed
<repo>
no
<repo>
not even that would help
<repo>
you could do a shitty implementation of having to provide the type as the first element of an array of which the second element is the polymorphic object
<repo>
but then i think json is not the right tool
<repo>
anyway thanks for the insights!
absolutejam2 has quit [Ping timeout: 264 seconds]
duane has joined #crystal-lang
<FromGitter>
<greenbigfrog> I think I might've gotten github to ratelimit me thanks to having too many shards and shard update;ing
<FromGitter>
<kinxer> Oh, wow. How many shards?
<FromGitter>
<greenbigfrog> not that many, but around 3x ~15 across various projects. Should use `--local` more often I guess ;)
<repo>
oh lol :D
<repo>
that's hilarios
<repo>
*hilarious
<FromGitter>
<greenbigfrog> thank good VPNs are a thing
<FromGitter>
<greenbigfrog> I still don't understand why `shards update` will update `shard.lock`, but not `lib/` unless I first remove the folder...
<erdnaxeli>
the doc says it should update /lib :s
<FromGitter>
<kinxer> It should update `/lib`.
<FromGitter>
<kinxer> That's been my experience with `shards update`.
<FromGitter>
<greenbigfrog> Yeah. I know. Sometimes it's just not working for me, but I haven't been able to really reproduce/debug it
<FromGitter>
<bararchy> What's the current syntax for `select`?
<FromGitter>
<bararchy> (in regards to channels)
<FromGitter>
<bararchy> and does it support somekind of built-in timeout ?
<FromGitter>
<bararchy> Maybe even better, is there a way to receive without blocking? or check if there is something waiting in the channel without receiving
<FromGitter>
<kinxer> @bajro17 I don't think so. That tree uses a `<` comparison for placement, suggesting that it's actually a binary search tree. A radix tree would store multiple strings (or use them as keys?) using the substrings for comparison.
<hightower3>
Hey couple days ago we said that Procs can re-invoke itself? How would I do this? e.g. ->( el : Something) { do_something; el.children.each { |c| __re-invoke self with el=c?__ }
<FromGitter>
<watzon> We really do need some documentation for async stuff. There is far too little of it.
<FromGitter>
<tenebrousedge> you need to declare the proc as `uninitialized`
<FromGitter>
<ImAHopelessDev_gitlab> @kinxer just shuffling local array in-place. to re-roll item mods. example, i need to select 3 values from an array and they must be unique. i can do array.shuffle[0..2] to get them. shuffle is amazing
<FromGitter>
<Blacksmoke16> just an FYI `#shuffle` returns a new array
<FromGitter>
<Blacksmoke16> could use `#shuffle!` to shuffle the contents inplace
<FromGitter>
<Blacksmoke16> @asterite couldn't you make it define the `type` property for you?
<FromGitter>
<Blacksmoke16> like have the macro define a `getter type : String` by default or something?
<hightower3>
Hey if I want a function to accept either a block, &block, or proc, do I need to provision for each of those manually or there is a way to somehow catch-all?
<FromGitter>
<Blacksmoke16> could always not define a type restriction
<FromGitter>
<Blacksmoke16> otherwise would prob need an overload for each
<hightower3>
right but I'd still need two versions, one with no explicit arg and calling yield, and one with one arg, which can be a block or proc, right?
<FromGitter>
<Blacksmoke16> right yea
<FromGitter>
<Blacksmoke16> well you can capture the block and pass that to the other overload
<FromGitter>
<Blacksmoke16> so no need to yield?
<hightower3>
oooh, indeed, if I have &block it captures the {block}. Interesting, I thought it didn't. Thanks
<FromGitter>
<Blacksmoke16> np
<hightower3>
also while we're on this subject, do I see/remember it right that Ruby had #block_given? , and that crystal doesn't?
<FromGitter>
<Blacksmoke16> whats that do?
<hightower3>
tells you if block was passed to the function or not. I just checked, right, ruby has it, crystal doesn't
<hightower3>
f() {} -> block_given? #=> true
<FromGitter>
<Blacksmoke16> i dont think so as it would have to be separate methods?