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
ur5us has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
dwdv has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> It would be cool if we have the Crystal playground be like the ponylang playground and have the option to show the LLVM IR and ASM output
<FromGitter> <watzon> I've seen some other ones that have it too
<FromGitter> <watzon> Dark mode would also be nice to have
Creatornator has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
ht_ has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_whitelogger has joined #crystal-lang
ht_ has quit [Quit: ht_]
_whitelogger has joined #crystal-lang
kotrcka has quit [Remote host closed the connection]
DTZUZO has quit [Ping timeout: 268 seconds]
<FromGitter> <bnsv> In lib/kemal/src/kemal/base_log_handler.cr:4:31 ⏎ ⏎ 4 | class Kemal::BaseLogHandler < HTTP::Handler ⏎ ⏎ ``` ^------------``` ... [https://gitter.im/crystal-lang/crystal?at=5deb74b132df1245cbfb5835]
<FromGitter> <bnsv> Hi All, what is the meaning of this error when running a kemal app, thank you. ⏎ ⏎ > In lib/kemal/src/kemal/base_log_handler.cr:4:31 ⏎ > ⏎ > 4 | class Kemal::BaseLogHandler < HTTP::Handler ... [https://gitter.im/crystal-lang/crystal?at=5deb753cb065c6433c52e15d]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
<foxxx0> good morning. when i'm spawning fibers that have interconnected channels and i want to wait for all fibers to return before i continue, how would i do that?
<foxxx0> do i need control-channel for the fiber and wait for them to send e.g. "finished" there and have blocking receive calls on the control channel?
<foxxx0> yep, that seems to work
<FromGitter> <bew> yes that's the way to go foxxx0 :)
<foxxx0> works like a charm, slowly i'm getting the hang of it
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 250 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
DTZUZO has joined #crystal-lang
dwdv has joined #crystal-lang
DTZUZO has quit [Ping timeout: 250 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
HumanG33k has quit [Ping timeout: 240 seconds]
tleydxdy has quit [Quit: killed]
olbat[m] has quit [Quit: killed]
HumanG33k has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
DTZUZO has joined #crystal-lang
Human_G33k has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
HumanG33k has quit [Ping timeout: 268 seconds]
tleydxdy has joined #crystal-lang
olbat[m] has joined #crystal-lang
beepdog has joined #crystal-lang
erdnaxeli has joined #crystal-lang
ternarysolo has joined #crystal-lang
DTZUZO has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
hightower2 has quit [Ping timeout: 276 seconds]
sagax has quit [Read error: Connection reset by peer]
duane has quit [Ping timeout: 268 seconds]
sagax has joined #crystal-lang
duane has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
duane has quit [Ping timeout: 246 seconds]
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DTZUZO has joined #crystal-lang
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <johnpyp> Is there a shorthand way to cast a type of (T | Nil) to T at runtime, because you know that an invariant has been met that allows you to bypass the nil check? I know you can do `.as(T)`, but that gets cumbersome
<FromGitter> <Blacksmoke16> `not_nil`?
<FromGitter> <Blacksmoke16> only if you know for sure it wont be nil tho
<FromGitter> <tenebrousedge> `try` also can be used
<FromGitter> <johnpyp> `not_nil` seems to be what I'm looking for, it's a bit better than the `.as(T)`. It would be cool to have an explicit NPE operator like kotlin does https://kotlinlang.org/docs/reference/null-safety.html#the--operator. Has this been considered?
<FromGitter> <Blacksmoke16> thats what `not_nil!` does tho
<FromGitter> <johnpyp> Isn't it?
<FromGitter> <Blacksmoke16> ` converts any value to a non-null type and throws an exception if the value is null`
<FromGitter> <Blacksmoke16> exactly yes
<FromGitter> <johnpyp> ah, yeah I mean it would be nice to have a shorthand syntax like what kotlin does (just for brevity), like `!!`
<FromGitter> <Blacksmoke16> :shrug: ideally you shouldnt have to use it often
<FromGitter> <Blacksmoke16> and crystal isnt a fan of aliases, which that essentially would be
<FromGitter> <johnpyp> gotcha
<FromGitter> <tenebrousedge> also `!!` is already a thing
<FromGitter> <Blacksmoke16> naw its just `!` twice
<FromGitter> <Blacksmoke16> but would cause some confusion thats for sure
<FromGitter> <tenebrousedge> but since it's the quickest way to cast to a boolean, it's presumably used in a fair amount of real code
<FromGitter> <tenebrousedge> so it's not an operator *per se*, but it's a common technique in Crystal and most other Algol derivatives, and if you used `!!` to get rid of `Nil` then you would have to find some other way to express `!!`
<FromGitter> <Blacksmoke16> Technically `!!` gets rid of `Nil` :trollface:
<FromGitter> <r00ster91> when i call a macro inside a method, is it in the macro possible to receive the name of the method that called it?
<FromGitter> <Blacksmoke16> prob can use `{{@def.name}}` within the macro
<FromGitter> <r00ster91> ah yeah forgot about that special variable
<FromGitter> <watzon> Crap, so it's not possible to decode `Bytes` into a `BigInt`?
<FromGitter> <watzon> With `IO::ByteFormat`
<FromGitter> <tenebrousedge> you can probably do `unsafe_as` to get it to an `Int` of some sort, but I don't know how `BigInt` works
<FromGitter> <watzon> Yeah I'm gonna try that, fingers crossed
<FromGitter> <Blacksmoke16> or could use the string initializer if that doesnt work
<FromGitter> <watzon> Would that give the same result?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.31.1/BigInt.html#new(str:String,base=10)-class-method
<FromGitter> <Blacksmoke16> i.e. like `BigInt.new String.new bytes` that would prob do it...
<FromGitter> <Blacksmoke16> idk if its the *best* way to do it tho
<FromGitter> <watzon> Unfortunately I don't think that will do it. The bytes represent data, not a number. So in this case I end up with an `Invalid BigInt` exception
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <bew> @watzon `IO::ByteFormat` works for normal integer/floats because their binary representation is widely known and it basically "casts" the memory region as the target type and returns that. The binary representationof Big* is not widely known as far as I know, so unless your data is a binary dump of a Big* you'll have to convert it some other way
<FromGitter> <watzon> Yeah that's what I'm figuring out
<FromGitter> <watzon> Crap
<FromGitter> <tenebrousedge> so why are you trying to treat data like a number, anyway?
<FromGitter> <bew> what is your data?
<FromGitter> <watzon> It's for encrypting a payload using RSA
<FromGitter> <watzon> The data should be 256 bytes though
<FromGitter> <watzon> So it shouldn't be too hard
<FromGitter> <watzon> cls
<FromGitter> <tenebrousedge> how are you transforming it?
<FromGitter> <bew> offtopic: yay I finished day3 of advent of code :P
<FromGitter> <tenebrousedge> @bew what's your code like?
<FromGitter> <bew> will put it on the forum once I cleaned it
<FromGitter> <watzon> It's pretty easy to get bytes from a hex string it
<FromGitter> <watzon> Yeah hexbytes
<FromGitter> <watzon> I wonder if that will work
<FromGitter> <watzon> Just have to do the reverse
<FromGitter> <tenebrousedge> usually they make these operations fairly simple when expressed in binary
<FromGitter> <watzon> Looks like this might do it https://play.crystal-lang.org/#/r/85pq
<FromGitter> <tenebrousedge> 👀
<FromGitter> <watzon> Basically I'm trying to do this https://github.com/pyrogram/pyrogram/blob/develop/pyrogram/crypto/rsa.py#L208
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <watzon> Since Crystal doesn't have good RSA support yet, and I don't feel like implementing it myself right now, this seemed like the easiest way around it
* FromGitter * tenebrousedge pokes it with a stick
<FromGitter> <Blacksmoke16> https://github.com/stakach/openssl_ext ?
<FromGitter> <watzon> Looked at that, but it's missing some things I need
<FromGitter> <watzon> And also a couple PRs that keep it from breaking haven't been merged
<FromGitter> <Blacksmoke16> :/
<Yxhuvud> bew: I keep mine at github: https://github.com/yxhuvud/aoc19
<FromGitter> <bew> here is mine, updated with day3 https://github.com/bew/adventofcode-2019
<FromGitter> <tenebrousedge> huh
Creatornator has joined #crystal-lang
<FromGitter> <bew> @tenebrousedge I'll steal your DIRECTIONS if you don't mind :P
<FromGitter> <bew> that's a good idea
<FromGitter> <tenebrousedge> please do
<FromGitter> <watzon> Well this seems to work. Idk if it's actually correct, but I guess I'll find out https://gist.github.com/0a4c282c654a8ca85bc76e90685872bd
<FromGitter> <Blacksmoke16> @knixer https://www.youtube.com/watch?v=Be_CyeFqziY
<FromGitter> <Blacksmoke16> @knixer https://www.youtube.com/watch?v=Be_CyeFqziY
<FromGitter> <Blacksmoke16> @kinxer https://www.youtube.com/watch?v=Be_CyeFqziY
<FromGitter> <watzon> https://crystal-lang.org/api/0.31.1/OpenSSL/Cipher.html should show how and where to get a list of supported ciphers
<FromGitter> <watzon> Because apparently "aes-256-ige" doesn't work
<FromGitter> <watzon> AES256 does, but I need the IGE variant 😢
<FromGitter> <mavu> advent of code day 7. I think its time for bed. ⏎ My code is producing almost the correct solutions for the tests, but the last digit is missing. ⏎ When I went looking for the problem, I noticed that my code *should NOT* be working. ⏎ I now have a solution that almost works, and that I myself, after writing it, don't understand. [https://gitter.im/crystal-lang/crystal?at=5dec241bf65fec1c8ede64f7]
<FromGitter> <mavu> > .>
<FromGitter> <tenebrousedge> that happens. Usually for me it's when I do actually fix it
<FromGitter> <bew> lol, good luck trying to sleep without thinking about it
<FromGitter> <tenebrousedge> "Yay, it works! ...Wait, what does this even do, again?"
<FromGitter> <mavu> Yes, sleep will help, even if I will keep thinking about it )
<FromGitter> <mavu> found it. Still running fiber when the program ends. have to add a Fiber.yield.
<FromGitter> <mavu> Is there a kind of "ps aux" for fibers?
<FromGitter> <watzon> Can someone that understands C a little better tell me what exactly the GET and PUT macros are doing here? And maybe the Crystal equivalent?
<FromGitter> <watzon> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dec2ec95506624598882dcc]
<FromGitter> <watzon> The first 3 are easy, but GET and PUT seem to be dealing with pointers which I'm a little more fuzzy on in C
<FromGitter> <watzon> Is GET dereferencing `p` and then calling SWAP on it?
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <christopherzimmerman> Yep, with the addition of the typecast.
<FromGitter> <bew> it doesn't really dereference p, but it re-interprets the value of p as a uint32_t (similar to a `p.unsafe_as(UInt32)` in cr)
<FromGitter> <bew> and then SWAP that
<FromGitter> <christopherzimmerman> Would it be `p.unsafe_as(Pointer(UInt32))`?
<FromGitter> <watzon> Ahhhh ok
<FromGitter> <bew> no `unsafe_as` already does the thing with pointer
<FromGitter> <christopherzimmerman> I get that unsafe as takes the pointer of whatever is being passed, but in this context, isn't GET typecasting to a uInt32 pointer, and not a uint32?
<FromGitter> <watzon> Yeah, and then PUT is setting the value of that pointer
<FromGitter> <christopherzimmerman> In crystal you probably wouldn't be passing by reference like this though.
<FromGitter> <bew> hum I may be wrong indeed, @watzon p is a pointer?
<FromGitter> <watzon> I'm not sure if p is tbh
<FromGitter> <watzon> All I know is this seems to work ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dec3466b065c6433c58121b]
<FromGitter> <bew> if so, then `*((uint32_t *)(p))` is basically dereferencing p and getting a uint32 out of it (even if p was a pointer to some other type)
<FromGitter> <bew> what are you binding?
<FromGitter> <watzon> In this case not binding, I'm trying to port some C code to pure Crystal
<FromGitter> <watzon> Some AES stuff
<FromGitter> <bew> 🙏 I'm praying for you :D
<FromGitter> <watzon> Lol I'll need it
<FromGitter> <watzon> I've definitely seen worse C code
<FromGitter> <watzon> Half of it is defining lookup tables
<FromGitter> <bew> nice, note that lookup tables are not optimzed by cr compiler, meaning that if you put them in constants, there will be some (small) time at the program launch to create those lookup tables (C does not have this overhead, as the lookup tables are embedded directly in the compiled bianry)
<FromGitter> <watzon> Hmm, even stored as StaticArrays?
<FromGitter> <bew> don't know..
<FromGitter> <watzon> I figured that StaticArrays would actually be embedded into the binary since they're known at compile tile
<FromGitter> <watzon> Either way, not a huge deal
<FromGitter> <bew> true! btw how are you creating the static arrays?
<FromGitter> <watzon> Like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dec37f09319bb5190fa8e6c]
<FromGitter> <watzon> Should they be created with a macro to be compile time?
<FromGitter> <bew> in this case it's already a macro: https://github.com/crystal-lang/crystal/blob/master/src/static_array.cr#L50-L56
<FromGitter> <watzon> Ahh nice!
<FromGitter> <bew> but as you see, there's still some time spent (very little I agree) to initialize the static array memory
<FromGitter> <watzon> Yeah I feel it's worth it at this point. Are there plans to improve on that?
<FromGitter> <bew> whereas if it was embedded in the binary, the init time would be 0..
<FromGitter> <bew> not that I know of
<FromGitter> <bew> (but I've been a bit off, so might have missed some things)