RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
Kixune has quit [Quit: Kixune]
DTZUZO has quit [Ping timeout: 252 seconds]
<FromGitter> <paulcsmith> @TheOnlyArtz hop on to https://gitter.im/luckyframework/Lobby if you have any questions about lucky. Lots more people there that can help. But yeah I’d say most of the frameworks all have comparable performance. It’s probably not even worth making it into the equation. But yeah Lucky is fast. In release mode with a simple page it will send an html page in a couple hundred microseconds
<FromGitter> <paulcsmith> Happy to help more in the Lucky room. I don’t follow this one as closely so I might miss it. Or ping me. I created it so can hopefully help answer your questions about it
_whitelogger has joined #crystal-lang
DmitryBochkarev_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
OvermindDL1 has quit [Ping timeout: 264 seconds]
fanta7531 has joined #crystal-lang
sagax has quit [Ping timeout: 268 seconds]
sagax has joined #crystal-lang
<jokke> hey!
<jokke> any idea why i get this error? https://carc.in/#/r/6qc1
<jokke> i don't understand how it could be Nil
<jokke> hm maybe this isn't going to work anyway
<jokke> because i'm overwriting the new class method defined by JSON::Serializable
fanta7531 has quit [Quit: fanta7531]
go|dfish has quit [Quit: SIGQUIT]
<FromGitter> <straight-shoota> jokke, just put `include JSON::Serializable` in the `included` hook
<FromGitter> <straight-shoota> https://carc.in/#/r/6qc4
<jokke> ah sweet!
ashirase has quit [Ping timeout: 252 seconds]
ashirase has joined #crystal-lang
<FromGitter> <vladfaust> Hello, little help here, please. What's the most efficient way to turn single `UInt8` into hexstring?
<FromGitter> <r00ster91> `20_u8.to_s(16)`?
<FromGitter> <dscottboggs_gitlab> if `to_s base: 16` isn't the most efficient, then it should be?
<FromGitter> <vladfaust> Thanks, that was not obvious for me :)
<FromGitter> <dscottboggs_gitlab> hehe I was gonna say if you find a faster way to let us know :p
<FromGitter> <vladfaust> It's 55M/s on my machine, should be enough :)
<FromGitter> <vladfaust> Is there a set of rules determining which string building to use -- interpolation or concatenation -- and when chars are better than strings? I.e. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb5a30fb34ccd69e7c8799c]
<FromGitter> <vladfaust> Sometimes interpolation is faster. What does it depend on?
<FromGitter> <r00ster91> there's also #4964
<DeBot> https://github.com/crystal-lang/crystal/issues/4964 (Concatenating a few strings is faster than interpolation)
<FromGitter> <dscottboggs_gitlab> i think since strings are sequences of chars (despite the whole char != UInt8 issue), a char would be more efficient to use if possible.
<FromGitter> <vladfaust> According to the issue, the rule is using concatenation if the amount of "inner" strings is 1-2
<jokke> vladfaust: i think for longer strings it's most efficient to use String::Builder
<jokke> since it just uses IO::Memory
<jokke> afair
<jokke> but i've made it a habit to use it everywhere
<jokke> except if it's something really trivial
<jokke> but i never use { foo, bar }.join('.') or something
<FromGitter> <cserb> There is also this: https://github.com/icyleaf/fast-crystal#string
<FromGitter> <cserb> But not sure how accurate this is
<FromGitter> <vladfaust> Nice point about IO::Memory, thanks, @jokke
<jokke> cserb: it's also missing String.build
<FromGitter> <j8r> there is an unsafe optimization when concatenating string/char to a string https://github.com/crystal-lang/crystal/blob/master/src/string.cr#L2502
<FromGitter> <vladfaust> Hex thing from Andrey Konovod -- https://carc.in/#/r/6qcd
<jokke> not sure how representative this is though because the "hello " + WORLD might be optimized into "hello " + "world" into "hello world" on compile time
fanta1 has joined #crystal-lang
fanta1 has quit [Quit: fanta1]
Vexatos has quit [Read error: Connection reset by peer]
Vexatos has joined #crystal-lang
fanta1 has joined #crystal-lang
_whitelogger has joined #crystal-lang
DmitryBochkarev has joined #crystal-lang
DmitryBochkarev_ has quit [Ping timeout: 250 seconds]
DmitryBochkarev has quit [Ping timeout: 246 seconds]
DmitryBochkarev has joined #crystal-lang
fanta1 has quit [Quit: fanta1]
gangstacat has quit [Ping timeout: 268 seconds]
lucasb has joined #crystal-lang
gangstacat has joined #crystal-lang
<wuehlmaus> i am not even able to ``shards install'' hedron at all :-(
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> hedron? is that that one OS from that company in London that deals with scalability?
<FromGitter> <j8r> no, thats https://github.com/hedron-crystal/hedron
<FromGitter> <Blacksmoke16> ah i was thinking of `Hadean`
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/athena/releases/tag/v0.5.0 Athena 0.5.0 is now released. Brings some CLI updates, support for CORS, and some bug fixes.
<FromGitter> <Blacksmoke16> ill update the blog post/demo app this week/weekend
DmitryBochkarev_ has joined #crystal-lang
DmitryBochkarev has quit [Ping timeout: 246 seconds]
DmitryBochkarev has joined #crystal-lang
DmitryBochkarev_ has quit [Ping timeout: 268 seconds]
DTZUZU has joined #crystal-lang
DmitryBochkarev has quit [Remote host closed the connection]
DmitryBochkarev has joined #crystal-lang
rohitpaulk has joined #crystal-lang
DmitryBochkarev has quit [Ping timeout: 246 seconds]
DmitryBochkarev has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
DmitryBochkarev has quit [Ping timeout: 255 seconds]
<FromGitter> <TristanBomb> Hello! Is there any way to make something like this work, where `draw` is defined on `Drawable` but not `Entity`? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb614721cd0b8307d21a323]
<FromGitter> <Blacksmoke16> im assuming `Drawable` inherits `Entity`?
<FromGitter> <Blacksmoke16> why not just just do
<FromGitter> <TristanBomb> `Drawable` is a module, in this case.
<FromGitter> <Blacksmoke16> ```def tryDraw(entity : Drawable) ⏎ entity.draw ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5cb6154097dcb371d8c2986f]
<FromGitter> <TristanBomb> The function is being called on a list of entities, some of which are Drawable, some of which are not; of course, we could check whether the entity `is_a? Drawable` before calling the function rather than in the function, but there's going to be many subsystems similar to `Drawable`, so explicitly adding all of those checks will get rather tedious.
<FromGitter> <tenebrousedge> Is it necessary to define a method for this? It's not reasonable to do `entity.try &.draw` in the parent context?
<FromGitter> <TristanBomb> Let me give that a shot.
<FromGitter> <Blacksmoke16> could also try like `entity.responds_to? :tryDraw`
<FromGitter> <Blacksmoke16> is there some other method that would happen if they are not `Drawable`
<FromGitter> <Blacksmoke16> if so could do like
<FromGitter> <Blacksmoke16> ```case entity ⏎ when Drawable then .draw ⏎ when Colorable then .color ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5cb6167a1cd0b8307d21b8c8]
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <TristanBomb> The correct behavior for objects that are not `Drawable` is to simply do nothing. The way the program is structured, there is a list of entities and a number of subsystems designed to handle specific categories of entity (so there might be a `DrawableSystem` and a `ColorableSystem`). To advance the program logic, each subsystem tries to run its specific `apply` code to each entity, so long as that entity is
<FromGitter> ... the correct type. So every `Drawable` entity gets passed into `DrawableSystem.apply`, each `Colorable` entity gets passed into `ColorableSystem.apply`, and so on.
<FromGitter> <TristanBomb> It's possible I'm going about this entirely the wrong way, though
<FromGitter> <shreeve> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb616f92e2caa1aa66b5617]
<FromGitter> <shreeve> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb617214b4cb471d9089b47]
<FromGitter> <shreeve> wondering why I get those errors... this code worked in a crystal 0.25-ish... do I need more type hinting in later Crystals???
<FromGitter> <Blacksmoke16> is there more to the error @shreeve ?
<FromGitter> <shreeve> that's it...
<FromGitter> <Blacksmoke16> @TristanBomb `responds_to? :drawTest` prob be way to go then, give that a shot
<FromGitter> <shreeve> seems like it can't find code with the right signature?
<FromGitter> <Blacksmoke16> is possible there was a breaking change with Kemal since then
<FromGitter> <Blacksmoke16> maybe check the changelog
<FromGitter> <shreeve> proxy is my own method though...
<FromGitter> <shreeve> ah... maybe headers has a different type?
<FromGitter> <shreeve> @Blacksmoke16 - i'll check that now... is there a way for me to see (when compiling) what type it *is* so I can find out more?
<FromGitter> <shreeve> it'd be nice to see what type it's looking to match
<FromGitter> <TristanBomb> `typeof()`, IIRC
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> but not at compile time
<FromGitter> <shreeve> checking kemal source... but, is there a way for the compiler to show what type it is looking for?
<FromGitter> <shreeve> it knows that it cannot find a match, but it would probably be easy for the compiler to say what it was looking for (but failed to find)
<FromGitter> <shreeve> assuming the types are correct, is this "otherwise okay"? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb618b21cd0b8307d21ccf6]
<FromGitter> <shreeve> I don't need to specify anything like "optional" or something simple like that, right>
<FromGitter> <shreeve> ?
<FromGitter> <Blacksmoke16> what if you do like
<FromGitter> <Blacksmoke16> `def proxy(xxxx, &block)`
<FromGitter> <shreeve> ok, i'll try that right now
<FromGitter> <Blacksmoke16> you dont have any type restrictions on it anyway so it shouldnt matter
<FromGitter> <Blacksmoke16> is `type` a string in your case?
<FromGitter> <shreeve> adding &block didn't do anything... checking kemal types to make sure that headers is an HTTP::Headers type (I gotta believe it is)
<FromGitter> <shreeve> it's "open"
<FromGitter> <Blacksmoke16> ah right, `&block` just makes it more clear your method takes a block
<FromGitter> <shreeve> is it the 'body' argument that is causing the confusion?
<FromGitter> <Blacksmoke16> no, just that i just never saw a method that takes a block without the `&block` param
<FromGitter> <shreeve> actually, I see this when I mess with some of the calls to proxy: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb61bb98790b0307eb043e0]
<FromGitter> <shreeve> i'll add "&block" and will keep trying...
<FromGitter> <shreeve> @Blacksmoke16 - should all my code that passes a block be defined using method_name(..., &block) ??
<FromGitter> <Blacksmoke16> its a good practice imo
<FromGitter> <shreeve> ok
<FromGitter> <Blacksmoke16> can also then type guard your blocks
<FromGitter> <Blacksmoke16> like `proxy(xxx, &block : String -> String)`
<FromGitter> <shreeve> what if block is optional? foo(..., &block = nil)????
<FromGitter> <shreeve> ah, I see...
<FromGitter> <shreeve> thanks
<FromGitter> <TristanBomb> Seems like `is_a?` only works on compile-time constants. So I can't do something like `if entity.is_a? subsystem.class::INPUT_TYPE`.
<FromGitter> <Blacksmoke16> maybe try to use an `enum`
<FromGitter> <Blacksmoke16> er nvm
<FromGitter> <shreeve> @Blacksmoke16 - the error message `'proxy' is not expected to be invoked with a block, but a block was given` seems to imply that I really should add the "&block" when defining the method, maybe more than just best practice
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6qgd it isnt required tho
<FromGitter> <Blacksmoke16> compiler sees `yield` and knows it takes a block
<FromGitter> <Blacksmoke16> afaik there isnt a concept of optional block?
<FromGitter> <shreeve> I agree with you... I've never *had* to add "..., &block)" before when defining methods... That error message (which doesn't always show up) is a bit gruff though.
<FromGitter> <Blacksmoke16> maybe thats the issue
<FromGitter> <shreeve> i think it's mainly due to a change in the HTTP::Client.post(...) args?
<FromGitter> <shreeve> This used to work (almost a year ago): `yield HTTP::Client.post(UPSTREAM, headers, body).body`
<FromGitter> <shreeve> but, I think (based on those signatures) that I can't call it like this anymore... I probably need to use `.post(UPSTREAM, headers: headers, body: body)`
<FromGitter> <Blacksmoke16> i could go with that
<FromGitter> <Blacksmoke16> no, the third from the top should match
<FromGitter> <shreeve> I need to pass the response's "body" to the block, I think that one passes the "response" object directly...
<FromGitter> <shreeve> `def self.post(url : String | URI, headers : HTTP::Headers? = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response`
<FromGitter> <shreeve> in this method, do I have to call it with (url: "foo", headers: ..., body: "...") or is ("foo", headers: ... , body: "...") okay?
<FromGitter> <shreeve> I mean does it know that the first arg is `url` or do I have to say `url: "..."`?
<FromGitter> <Blacksmoke16> yea but you were doing `yield HTTP::Client.post(UPSTREAM, headers, body).body` i.e. do the request and return the body param to the block
<FromGitter> <kinxer> @TristanBomb `Drawable` inherits from `Entity`, right? Is there any reason not to define an empty `Entity#draw` method?
olbat[m] has joined #crystal-lang
<FromGitter> <Blacksmoke16> see if you can narrow down what causes the issue to happen
<FromGitter> <Blacksmoke16> i.e. try like `yield "FOO"` and if it still happens you know it doesnt have anything to do with the `.post`
<FromGitter> <shreeve> ok, thanks will try...
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <shreeve> @Blacksmoke16 - it's weird... if I have a real error in the code, like trying to use a variable as an integer when it can be a string, then the compiler will error out and show me several errors. But, when I fix that one error... it'll compile just fine. It's almost like there are a set of "warnings" that aren't bad enough to "error out" when compiling. But, if I do have a bad error, then it'll show it to me,
<FromGitter> ... along with all the other things that would otherwise only be considered a warning. Does this match your experience?
<FromGitter> <Blacksmoke16> ive came across https://github.com/crystal-lang/crystal/issues/7083 before
<FromGitter> <Blacksmoke16> where its deff a compiler bug since the trace just kinda stops
<FromGitter> <Blacksmoke16> but doesnt look like the same error format as you have
<FromGitter> <Blacksmoke16> do you have your code in a repo somewhere?
<FromGitter> <shreeve> i can put it there, one sec
<FromGitter> <shreeve> @Blacksmoke16 - sent an invite
<FromGitter> <Blacksmoke16> and you just doing `crystal src/bam.cr`?
<FromGitter> <shreeve> crystal build src/bam.cr
<FromGitter> <Blacksmoke16> rgr
<FromGitter> <Blacksmoke16> lol worked fine :S
<FromGitter> <shreeve> this project is a crystal based ws<->http proxy, similar to grip
<FromGitter> <shreeve> classic!
<FromGitter> <Blacksmoke16> here is what i would do
<FromGitter> <Blacksmoke16> you on linux?
<FromGitter> <shreeve> mac, but yeah, have linux box too
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> `rm -rf ./lib/ ~/.cache/crystal ~/.cache/shards shard.lock && shards install && crystal build src/bam.cr`
<FromGitter> <shreeve> ok
<FromGitter> <Blacksmoke16> and should be good
<FromGitter> <shreeve> great -- thanks!
<FromGitter> <Blacksmoke16> it work?
<FromGitter> <shreeve> it works great
<FromGitter> <shreeve> !!
<FromGitter> <Blacksmoke16> nice
<FromGitter> <shreeve> THANK YOU!
<FromGitter> <Blacksmoke16> must have just been some cached shard or something
<FromGitter> <shreeve> those compile messages were all pretty much red herrings?
<FromGitter> <Blacksmoke16> well it was prob running latest crystal against some older version of kemal
<FromGitter> <Blacksmoke16> would be my guess
<FromGitter> <shreeve> ok
<FromGitter> <elorest> In a few hours my company will be demoing our hydrogen electric vehicles at Nikola World 2019. The trucks and off road vehicles are running crystal/amber for their infortainment system and instrument cluster which will be part of the demo. https://nikolamotor.com/
<FromGitter> <elorest> Live stream will be accessible though the site
<FromGitter> <Blacksmoke16> hopefully they dont end up like the hindenburg :P
<FromGitter> <Blacksmoke16> pretty cool dude, congrats
<FromGitter> <shreeve> awesome!!!
<FromGitter> <vladfaust> Wow
<FromGitter> <elorest> @Blacksmoke16 Hindenburg didn't burn because of Hydrogen. Mostly it was the wax canvas. Hydrogen is less dangerous than gasoline but still flamable. It has a huge advantage though in an accident because in the case of a leak it rises so fast that the flame is almost always higher than the vehicle.
<FromGitter> <Blacksmoke16> it probably didnt help tho
<FromGitter> <kinxer> @elorest I learned something today. Cool.
<FromGitter> <Blacksmoke16> im a fan of hydrogen, just need a way that as convenient/easy to fuel up as electricity at your house or one of thousands of gas stations
<FromGitter> <elorest> @Blacksmoke16 True. However the given the circumstances the hindenburg would still have burned even even with helium. Almost everyone got off alive and those who didn't died jumping.
<FromGitter> <Blacksmoke16> deff going to be a good source of energy in the future
<FromGitter> <elorest> > im a fan of hydrogen, just need a way that is as convenient/easy to fuel up as electricity at your house or one of thousands of gas stations ⏎ ⏎ We're working on that too.
<FromGitter> <elorest> Mostly stations.
<FromGitter> <Blacksmoke16> also would really help when we figure out space travel, given its much easier to find in space than on earth
<FromGitter> <elorest> Yeah. Methane is also really ubundant in space. As solar becomes cheaper and cheaper it's pretty inexpensive to make H2 out of water. When fuel cells combine it back together it turns back into water again anyway.
<FromGitter> <elorest> Pretty much any hydrogen that leaks though just drifts off into space. So eventually maybe that could become an issue.
<FromGitter> <elorest> We use up all the worlds water by turning it to H2 and releasing it...
<FromGitter> <elorest> Doesn't seem like an issue for a long time though.
<FromGitter> <Blacksmoke16> ill prob be dead by then ha
<FromGitter> <Blacksmoke16> *not my problem*
<FromGitter> <Blacksmoke16> by the time the poles melt there will be plenty of more water to use
<FromGitter> <Blacksmoke16> ha
<FromGitter> <shreeve> is working with JSON as hard as it seems in Crystal? just want to create a basic hash and convert it back to JSON...
<FromGitter> <Blacksmoke16> ```require "json" ⏎ ⏎ puts {"foo" => "bar"}.to_json``` [https://gitter.im/crystal-lang/crystal?at=5cb6342d1cd0b8307d2299d8]
<FromGitter> <Blacksmoke16> ?
<FromGitter> <shreeve> ```info = {} of String => JSON::Any ⏎ info["one"] = ["does this work?"]``` [https://gitter.im/crystal-lang/crystal?at=5cb634378790b0307eb0ed15]
<FromGitter> <shreeve> `no overload matches 'Hash(String, JSON::Any)#[]=' with types String, Array(String) ⏎ `
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6qh0
<FromGitter> <Blacksmoke16> yea thats not the same
<FromGitter> <Blacksmoke16> that would be
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cb634775b3f941aa54123ad]
<FromGitter> <elorest> Json isn't that hard.
<FromGitter> <Blacksmoke16> you only deal with `JSON::Any` when you do a `JSON.parse(json_str)`
<FromGitter> <shreeve> What if keys and values are pretty much anything?
<FromGitter> <shreeve> info["two"] = 99
<FromGitter> <shreeve> do I need to specify every possibly type that a value can be?
<FromGitter> <Blacksmoke16> yes, but this example here is more dealing with typing of a hash not json
<FromGitter> <shreeve> ok cool... thx
<FromGitter> <Blacksmoke16> ofc since if you declare `info` as type `Hash(String, Int32)` it wont let you do like `info["str"] = "foo"`
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <tenebrousedge> So, it looks like `Hash#merge` creates a new object, but it doesn't seem to copy any `@block` properties. Is that right?
<FromGitter> <Blacksmoke16> got an example?
<FromGitter> <tenebrousedge> https://play.crystal-lang.org/#/r/6qhf
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> and you do know you're setting `proc` as the default, which gets returned since `["q"]` doesnt exist?
<FromGitter> <Blacksmoke16> so the proc isnt actually a member of the hash
<FromGitter> <Blacksmoke16> so yea i guess it doesnt copy the default value
<FromGitter> <tenebrousedge> is this an oversight, or intentional behavior?
<FromGitter> <Blacksmoke16> im not sure
<FromGitter> <Blacksmoke16> maybe make an issue on the forums/github and get some feedback?
<FromGitter> <tenebrousedge> It might be fixed in master
<FromGitter> <tenebrousedge> you're right, I tested the wrong thing just now
<FromGitter> <tenebrousedge> well, I'll file an issue
<FromGitter> <tenebrousedge> it would be nice if Hash implemented `#default_block=`, too
<FromGitter> <Blacksmoke16> arguable on that one
RX14 has quit [Quit: Fuck this shit, I'm out!]
RX14 has joined #crystal-lang
lucasb has quit [Quit: Connection closed for inactivity]