ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.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
davic has quit [Ping timeout: 240 seconds]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
davic has joined #crystal-lang
<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.
hemite has quit [Ping timeout: 265 seconds]
hemite has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> well shit
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dba4a8b9c39821509b520d0]
Nazral has joined #crystal-lang
<Nazral> Hi
<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
<Nazral> thank you!
<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
<Nazral> it works thank you !
<FromGitter> <Blacksmoke16> np πŸ‘
<Nazral> (didn't need the sleep because I have my user input loop preventing the main fiber from terminating)
<FromGitter> <watzon> Oh he made a PR to Crystal? I'll check it out
<FromGitter> <Blacksmoke16> otherwise, hoping to finish that up this weekend? idt it will be too hard to implement
<FromGitter> <watzon> Ok that's not bad. So I'd just have to include every value in my lookup table directly into the Discriminator
<FromGitter> <watzon> If this works it's going to make me so happy
<FromGitter> <Blacksmoke16> gl
<FromGitter> <Blacksmoke16> wonder if you could use a macro to add the mapping?
<FromGitter> <Blacksmoke16> i doubt it tho
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 264 seconds]
<FromGitter> <watzon> Hmm I'm having trouble making it work with `@type`
<FromGitter> <watzon> @asterite should this work? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dba57a114d55a3785a7fc33]
ma__ has joined #crystal-lang
<FromGitter> <watzon> It works if I change the `@type` to `tdtype` so it matches the name of the property, but it's not working with a different key
<FromGitter> <watzon> Got it working with some modifications
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> I didn't know this was a problem, but apparently you can't have a property in a Serializable class have a type that's abstract
<FromGitter> <watzon> https://carc.in/#/r/7x6d
_whitelogger has joined #crystal-lang
bougyman has quit [Ping timeout: 246 seconds]
bougyman has joined #crystal-lang
fyber has quit [Quit: The Lounge - https://thelounge.github.io]
ht_ has joined #crystal-lang
absolutejam2 has joined #crystal-lang
ht_ has quit [Quit: ht_]
absolutejam2 has quit [Ping timeout: 245 seconds]
<FromGitter> <didactic-drunk> How do you get the bytesize of an Int variable?
_whitelogger has joined #crystal-lang
ma__ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ma__ has joined #crystal-lang
ma__ has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <naqvis> Either use SizeOf (https://crystal-lang.org/api/0.31.1/Crystal/Macros/SizeOf.html) macro, or you can hardcode that like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dbaab0d9825bd6bacfd941f]
<FromGitter> <naqvis> above snippet from `byte_format.cr#L133`
<FromGitter> <didactic-drunk> ```sizeof(typeof(var))``` works. ```sizeof(var)``` doesn't.
<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`
<repo> what's any.raw?
<repo> hmm
<repo> not sure how that would help
mamantoha has joined #crystal-lang
<FromGitter> <Blacksmoke16> naw it doesnt
<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
<repo> i'd be super happy if there'd be a way
<FromGitter> <Blacksmoke16> could try out https://github.com/crystal-lang/crystal/pull/8406
<FromGitter> <Blacksmoke16> otherwise my serialization shard uses JSON::Any, will be adding that feature this weekend as well
<repo> oooh awesome!!
<repo> this pr!
<repo> i've been wanting to do this for so long!!
<FromGitter> <Blacksmoke16> granted its an RFC atm, no promise it'll get merged
<FromGitter> <Blacksmoke16> so dont get too invested atm :P
<FromGitter> <j8r> repo you can serialize from an union
mamantoha has quit [Ping timeout: 268 seconds]
<repo> j8r: i know but it requires the object to have different keys for each subtype
<repo> the major drawback with discriminators though is that you loose streaming capability
<repo> *lose
<repo> you need to load the whole object into memory before you can decide what you want to deserialize it as
<repo> actually i'm curious how it currently works for unions
<repo> does it just try each type in the union until it finds one that doesn't raise?
<FromGitter> <j8r> or repo, you can also directly use JSON::Parser
<repo> yeah
<repo> but the type of the column is JSON::Any unfortunately so i have to work with that
<FromGitter> <Blacksmoke16> repo: yes
<repo> mhm
<repo> but how does that work with streaming data?
<FromGitter> <Blacksmoke16> :shrug:
<repo> if type A raises while halfway parsing through the object, how is B getting the chance to start from the beginning? what's read is read.
<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> <ImAHopelessDev_gitlab> array.shuffle = πŸ’—
<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> <asterite> I think ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dbafa203d669b28a00d9ac6]
<FromGitter> <asterite> You also have `Channel#receive?`
<FromGitter> <Blacksmoke16> would be super helpful to get some docs on those methods
<FromGitter> <asterite> no built-in timeout for now, you have to spawn, sleep, then send over a channel, and use `select` on two channels
<FromGitter> <bararchy> @asterite I think `Channel#receive?` is blocking
<FromGitter> <asterite> https://crystal-lang.org/api/0.31.1/Channel.html#receive?-instance-method :-)
<FromGitter> <asterite> Oh, you are right
<FromGitter> <asterite> Yeah, concurrency is not yet documented because it's being worked on
<FromGitter> <bararchy> `Otherwise, this method blocks until a value is sent to the channel.`
<FromGitter> <asterite> but it's all very similar to Go, so if you have doubts you can search in Go
<FromGitter> <asterite> at least the way `select` works
<FromGitter> <ilanusse> Hey guys! How's it going?
<FromGitter> <Blacksmoke16> o/
<FromGitter> <ilanusse> How's Windows compatibility going?
<FromGitter> <kinxer> @ImAHopelessDev_gitlab Are you trying to get a new array from `Array#shuffle` or shuffle an existing array in-place?
<FromGitter> <bajro17> is this example of radix tree
<FromGitter> <bajro17> ?
<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.
absolutejam2 has joined #crystal-lang
ht__ has joined #crystal-lang
alexherbo20 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 268 seconds]
<FromGitter> <j8r> @bararchy beware, this commit will be on the next release https://github.com/crystal-lang/crystal/commit/1254fd2fc87c5ea65f68bf06d9e75d5a49ee95ce
<FromGitter> <j8r> But I can't get `non_blocking_select` working when recompiling the compiler in master
absolutejam2 has quit [Ping timeout: 240 seconds]
sagax has quit [Quit: Konversation terminated!]
sagax has joined #crystal-lang
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
alexherbo20 has quit [Ping timeout: 265 seconds]
<FromGitter> <bararchy> @j8r thanks for the headsup :)
hightower3 has joined #crystal-lang
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
MasterdonX has quit [Ping timeout: 240 seconds]
MasterdonX has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 2.5: Β‘Chau!]
<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`
<hightower3> some example maybe?
<FromGitter> <tenebrousedge> well, you could scroll back to the last time you asked, but here's (https://stackoverflow.com/questions/45237446/recursive-proc-in-crystal) a relevant SO
<hightower3> tenebrousedge ah sorry I meant we just said that procs could do it, I didn't remember example given, thanks
<hightower3> aah this is fabulous, thanks
rohitpaulk has quit [Ping timeout: 265 seconds]
<FromGitter> <watzon> @Blacksmoke16 let me know whenever CrSerializer supports JSON like that. I'll probably switch over to using it.
<FromGitter> <Blacksmoke16> πŸ‘ will do
<FromGitter> <Blacksmoke16> maybe this weekend? at least an experimental version you can try is what im hoping for
<FromGitter> <DRVTiny> Hello4All! ⏎ How to read 4 bytes from Slice(UInt8) to UInt32? ⏎ Or from IO to UInt32
<FromGitter> <Blacksmoke16> bytes that represent a number or?
<FromGitter> <DRVTiny> Yes, bytes that represent a number (little-endian)
<FromGitter> <Blacksmoke16> would that help?
<FromGitter> <Blacksmoke16> something like `IO::ByteFormat::LittleEndian.decode(UInt32, bytes)`
<FromGitter> <DRVTiny> @Blacksmoke16 ⏎ Thank you, it works!! :) ⏎ ⏎ ```IO::ByteFormat::LittleEndian.decode(UInt16, "abc".to_slice[0,2]) ⏎ => 25185``` [https://gitter.im/crystal-lang/crystal?at=5dbb376b2a6494729c742402]
<FromGitter> <Blacksmoke16> or from an `IO`, `io.read_bytes(UInt32, IO::ByteFormat::LittleEndian)`
<FromGitter> <Blacksmoke16> πŸ‘
<hightower3> I'm gonna have some questions about this same topic in a couple days
<hightower3> (bytes)
<FromGitter> <Blacksmoke16> `01101111 01101011`
<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?
absolutejam2 has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> https://i.redd.it/m2t98ir2nwv31.jpg LOL
Raimondi has joined #crystal-lang
<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
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dbb4a90a03ae1584f442b4d]
<FromGitter> <Blacksmoke16> something like that
<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?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7xgb
<FromGitter> <Blacksmoke16> if you yield it requires the block
<hightower3> yes, right, but there's no way to check
<FromGitter> <Blacksmoke16> no because its a compile time error
<FromGitter> <Blacksmoke16> there is https://crystal-lang.org/api/master/Crystal/Macros/Def.html#accepts_block?:BoolLiteral-instance-method
<FromGitter> <Blacksmoke16> but that in macro land
<FromGitter> <Blacksmoke16> and isnt exactly the same thing
<hightower3> right, right, understandable
<hightower3> great, thanks
<FromGitter> <Fryguy> Ruby's weird in that any method accepts a block even if it doesn't use it or declare it
<FromGitter> <Fryguy> Crystal, since it's statically typed, needs to check that this extra "parameter" is coming in, so you use overloading
<FromGitter> <ImAHopelessDev_gitlab> https://play.crystal-lang.org/#/r/7xgw is it possible to create a tuple literal using an alias?
<FromGitter> <tenebrousedge> I don't think so. Why not use a struct though?
<FromGitter> <ImAHopelessDev_gitlab> i forgot too in the beginning, so everything is now memorized by index
ht__ has quit [Quit: ht__]
<FromGitter> <ImAHopelessDev_gitlab> nvm, i don't think this is a good idea
<FromGitter> <Blacksmoke16> \cc @veelenga https://github.com/veelenga/awesome-crystal/pull/453 and anyone who i mented in the PR
duane has quit [Ping timeout: 268 seconds]
absolutejam2 has quit [Read error: Connection reset by peer]
absolutejam2 has joined #crystal-lang
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
<FromGitter> <wontruefree> just a little reminder we are having our remote meetup next week
<FromGitter> <wontruefree> chicagocrystal.org/events/bbhsjryzpbkb/
<FromGitter> <wontruefree> I mean if you are in Chicago please join us
<FromGitter> <Blacksmoke16> i think that link is broken @wontruefree
<FromGitter> <christopherzimmerman> Are there any other meetups that go on? Like is there a list somewhere?
<FromGitter> <christopherzimmerman> I think I’ve only seen any info for the Chicago one