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
<FromGitter> <Blacksmoke16> this blog is paying off, kinda realized i dont have a way to set a dynamic header from a route action...
<FromGitter> <Blacksmoke16> to set a JWT token header
<FromGitter> <Blacksmoke16> can either require each action has a `context` param and pass it in, or maybe do some fancy `set_header` macro
<FromGitter> <Blacksmoke16> opinions?
<FromGitter> <Blacksmoke16> im leaning towards the former
<FromGitter> <Blacksmoke16> Would be more flexible
<FromGitter> <Blacksmoke16> No, I have a better idea
laaron- has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bms :thinking:
<FromGitter> <Blacksmoke16> ` get_response.headers.add "Foo", "Bar"` added a class method that is accessible in all controllers, to get request/response
<FromGitter> <Blacksmoke16> so its there if you need it but not in the way if you dont
g- has quit [Quit: Lost terminal]
g- has joined #crystal-lang
sagax has joined #crystal-lang
rohitpaulk has joined #crystal-lang
jemc has quit [Ping timeout: 250 seconds]
jemc has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> what does `private def` at the top-level do? Does it make it file-scoped?
jemc has quit [Ping timeout: 246 seconds]
<FromGitter> <dscottboggs_gitlab> `wrong number of arguments for macro 'page_not_found' (given 0, expected 0)` ooof
<FromGitter> <dscottboggs_gitlab> lol
<FromGitter> <dscottboggs_gitlab> #7465
<DeBot> https://github.com/crystal-lang/crystal/issues/7465 (The error given when trying to send a macro as a proc could be more helpful)
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
devil_tux has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <j8r> Send macro as a proc?!
<FromGitter> <j8r> Remember macro are expanded before compilation
<FromGitter> <j8r> If proc there is, it can only be done inside the macro world
<devil_tux> what does `wrap` keyword does?
<devil_tux> s/does/do
hightower2 has joined #crystal-lang
ashirase has quit [Ping timeout: 250 seconds]
<FromGitter> <dscottboggs_gitlab> @j8r I realize it didn't work, and I figured it probably wouldn't, the (kinda funny) issue is the `given 0, expected 0` error message
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron- has joined #crystal-lang
ashirase has joined #crystal-lang
<FromGitter> <Sija> @devil_tux there's no such thing as `wrap` keyword (or method for that matter)
<FromGitter> <Sija> where did you get it from?
fanta7531 has joined #crystal-lang
<devil_tux> jeez what I was looking at .. o.o also searched github repo
<FromGitter> <vladfaust> I can't find the name of a blockchain company which started to work with Manas this year. Could you help me?
<FromGitter> <luislavena> @vladfaust sushichain: https://blog.sushichain.io/Welcome-to-the-blog/
<FromGitter> <vladfaust> Nope, the another one. There was a blog post
<FromGitter> <luislavena> Ah, right, I think is this one? https://medium.com/manas-tech/bringing-back-to-life-5-000-year-old-30a27c442b65
<FromGitter> <vladfaust> Yeah, Sikoba. Thanks, @luislavena
fanta7531 is now known as fanta7531|away
fanta7531|away has quit [Quit: fanta7531|away]
jemc has joined #crystal-lang
jemc has quit [Client Quit]
<mps> I found reason for failed build of the crystal 0.27.2 on Alpine. Build fails with libxml2 2.9.9 version. with previous libxml2 version i.e. 2.9.8, crystal can be built and pass tests with some small tweaks
<mps> so, my question is, what is the libxml2 version with which 0.27.2 is build for other distributions, if anyone can tell me
<FromGitter> <straight-shoota> @j83 That's wrong. The compiler binary is actually built and linked on alpine 3.8. But the compiler itself doesn't use libxml2, so it's not linked.
<FromGitter> <j8r> oh ok
<FromGitter> <j8r> so it uses the libxml2 of the host
<FromGitter> <j8r> @straight-shoota but why there is a from debian at the start?
<FromGitter> <j8r> this Dockerfile is a bit messy :/
<FromGitter> <straight-shoota> Yes, definitely
<FromGitter> <straight-shoota> It first cross-compiles the compiler from debian (gnu) to alpine (musl) and links it statically on alpine. This boostrapped compiler is then used to compile the actual binary and it's also linked on alpine.
<FromGitter> <j8r> got it, thanks
<FromGitter> <straight-shoota> Resolving #7196 should help to reduce the complexity at least a little bit
<DeBot> https://github.com/crystal-lang/crystal/issues/7196 (Default target triple baked into compiler fails on musl)
<FromGitter> <straight-shoota> mps, the compiler itself doesn't use libxml, but the stdlib specs. On CI they run in the crystal-lang/crystal docker image https://github.com/crystal-lang/distribution-scripts/blob/master/docker/Dockerfile That's a debian xenial and uses the default libxml2-dev package which seems to be 2.9.3
<FromGitter> <dscottboggs_gitlab> xenial is not a debian version itโ€™s ubuntu 16.04 but close enough
<FromGitter> <straight-shoota> Oh, right. I mistyped.
<FromGitter> <dscottboggs_gitlab> Nbd I just didnโ€™t want someone to get confused because they couldnโ€™t find debian xenial haha
<mps> straight-shoota: your post explains a lot to me
<mps> I waste some time trying to understand that
<mps> building (compiling, testing and building static version of compiler) on Alpine 3.8 worked without problem and on the v3.9 before libxml2 is upgraded
<FromGitter> <straight-shoota> what exactly is the error message with libxml2 2.9.9?
<mps> after libxml2 upgrade it fails in check (make spec)
<mps> straight-shoota: right now I don't have it saved, but something about sigfault
<mps> I will upgrade libxml2 again and run build and will save build log
<FromGitter> <straight-shoota> okay ๐Ÿ‘
<FromGitter> <straight-shoota> Just open an issue about that
<mps> on github? I don't have account there
<mps> I will post results to some of paste services
<jokke> hm is it by design that i can't require code from below src/
<jokke> i have stuff in db/ that needs compiling
<jokke> if i try requiring files there i get an error that the file wouldn't exists
<jokke> -s
<FromGitter> <straight-shoota> mps, allright, then post it here
<mps> ok, will do
<FromGitter> <straight-shoota> jokke, what's the require expression?
<jokke> require "../../db/template_migrations/*"
<FromGitter> <straight-shoota> And the file path?
<jokke> src/here-ems-backend/template_migrations.cr
<FromGitter> <straight-shoota> then there's one `..` too much
<jokke> hm why?
<jokke> one .. would be in src/
<FromGitter> <straight-shoota> and the file you want to require is in src/db/template_migrations
<FromGitter> <straight-shoota> ?
g- has quit [Quit: Lost terminal]
<jokke> no
<jokke> it's in db/template_migrations
<jokke> so outside of src
<FromGitter> <straight-shoota> Oh okay, you said it was below src
<FromGitter> <straight-shoota> By default, only src is in the path
<jokke> ah
<jokke> that'd explain it
<FromGitter> <straight-shoota> You can add `./db` (or `.`) to `CRYSTAL_PATH` to make this directory available, but I think it's a good convention to keep all code in src
<jokke> it's a good security feature though
<jokke> yeah definitely but these are database migrations
<FromGitter> <straight-shoota> Hm, yeah
<FromGitter> <straight-shoota> Have you looked at how frameworks like amber and lucky do this?
<FromGitter> <straight-shoota> Well, probably they don't include the migrations into the binary and just run them on the fly
<FromGitter> <straight-shoota> But I can see there's a use case for embedding them into a single binary.
<FromGitter> <straight-shoota> So why not put them in src/db/ instead of db/ ?
<FromGitter> <Sija> IIRC that's a convention inherited from (at least) Rails
<FromGitter> <Sija> which btw makes sense, since migrations are not code *per se*, they are coded transformations
<FromGitter> <Sija> so they could be written down in many formats, not necessarily code even though they usually are
<FromGitter> <Sija> you don't keep specs or benchmarks under src/ as well, same story here I guess
wmoxam has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> does it make sense to have a shared library with migrations?
<FromGitter> <j8r> a `.so` I mean
<FromGitter> <Sija> I dunno, seems pretty weird
<Yxhuvud> it could make sense if the app share a db with another app, but that isn't very common
<Yxhuvud> aka avoid it if you can
wmoxam has joined #crystal-lang
Dreamer3 has joined #crystal-lang
<devil_tux> is there literal to alias_method? aka an alias to specific method, can `previous_def` be used like that
<devil_tux> currently I can create new `def` and call previous method
<FromGitter> <Sija> @devil_tux nope, there is not, quite intentionally because Crystal tries to discourage aliases
<devil_tux> shame :<
<FromGitter> <Sija> `previous_def` has nothing to do with aliases though, it's used to call the previous impl *of the same method* inside the override
<devil_tux> yeah, figured that out.. not sure why is it described as an rubys `alias_method` tho
<FromGitter> <Sija> you can easily do it with macros if u need to
<FromGitter> <Sija> where's that?
<FromGitter> <Sija> you'd need to ask @r00ster91 about it since he's the original author as it seems
<FromGitter> <jwoertink> I have some code using `Time.now.to_s("%Y-%m-%d %H:%M:%S %:z")` and `Time.parse_utc(current_time, "%Y-%m-%d %H:%M:%S %:z")`. Is there any Time constant that already specifies this format? or maybe a shortcut method to handle this? I saw some things like the iso_8601 and rfc something, but I'm not sure which to use?
<FromGitter> <Sija> IMO this comparison should be removed since it's highly confusing
hightower2 has quit [Ping timeout: 245 seconds]
<FromGitter> <Sija> @jwoertink IIRC there's none but @straight-shoota will know for sure
<FromGitter> <jwoertink> I like how rails has `Time.now.to_s(:db)`. It would be sweet to have that as well as doing `Time.parse(time, :db)` or even `Time::Format::DB` or whatever
<FromGitter> <Sija> last time I've checked `Time::Format` is missing some commonly used format(s), but in any case you can define it yrself for sure
<FromGitter> <jwoertink> Yeah. I'll probably end up just defining it myself. Think I should open an issue to discuss? Or would this fall under the "just do it yourself" category? lol
<FromGitter> <Sija> I'm pretty sure that it would end up in this category but you can open an issue anyway ;)
<FromGitter> <Sija> Some kind of a neat API to access commonly used formats (with ability of extension) would be a nice thing to have... I'd give it a ๐Ÿ‘ for sure
fanta7531 has joined #crystal-lang
<FromGitter> <mixflame> hey guys, I'm back
<FromGitter> <mixflame> :D
<FromGitter> <jwoertink> Welcome back
Dreamer3 has quit [Quit: Computer has gone to sleep.]
<FromGitter> <kingsleyh> Evening
<FromGitter> <mixflame> Evening (morning here)
<FromGitter> <mixflame> Thanks :D
fanta7531 has quit [Quit: fanta7531]
<FromGitter> <girng> https://play.crystal-lang.org/#/r/6bso anyone know why going from the number `42` to `43` modifies `p.health` to a negative number?
<FromGitter> <kinxer> @girng It's because you're using an `i8`
<FromGitter> <girng> i also feel like i'm using f32 too much. is it worth it to jus use the regular float64? i was just thinking of using float32 because less space, but that's negligible right
<FromGitter> <girng> that way, i don't need to do "f32" everywhere, really ajnnoying
<FromGitter> <kinxer> You're multiplying `level` by 3. `42 * 3` is `126`, which barely fits in the range of an 8-bit integer. When you change it to `43`, that product becomes `129`, which overflows back down to `-127`. You then add `10.0`, getting `-117.0`
<FromGitter> <kinxer> This is what you want, right? https://play.crystal-lang.org/#/r/6bsr
<FromGitter> <kinxer> You have to convert `level` before multiplying it.
<FromGitter> <girng> ohhhh i see
<FromGitter> <girng> thanks for explanation, got it now
Jenz has joined #crystal-lang
<FromGitter> <girng> so when messing with floats, the moral of this problem is. always make sure the end results have matching types?
<Jenz> Is there a way to check if string contains only unique chars better than `string.chars.uniq == string.chars`?
<FromGitter> <girng> in this case, the left and right side both need to be float32s
<oprypin> Jenz, u make a set of chars
<oprypin> .size == string.size
<Jenz> string.chars.to_set.size == string.size ?
<oprypin> assuming `to_set` is a thing, yes
<oprypin> wait no
<Jenz> I think it is
<Jenz> But that wouldn't work
<oprypin> string.chars.to_set.size == string.chars.size
<oprypin> and save the intermediate value
<Jenz> Alright, thanks, looks smart, though I dunno how to_set is better than using .uniq
<Jenz> Thanks again oprypin, I really appreciate your help and all you've done for the crystal community
<Jenz> And everyone else :D
<oprypin> yay
<Jenz> So many nice Crystal people
<oprypin> Jenz, `uniq` needs to keep the order and a set doesn't
<oprypin> though hopefully it also uses a set under the hood (otherwise it's n^2 complexity)
<FromGitter> <j8r> Why set won't keep the order? It's based on Hash
<FromGitter> <j8r> @girng that's why I said better to use integers...
<FromGitter> <j8r> When you got thousands of player, it may affect perf to have floats operations and casting everywhere
<Jenz> Hashes are amazing
<Jenz> ...
<Jenz> Though I don't really get 'em
<Jenz> I should read more
<Jenz> (On them)
<Jenz> s/more/anything/
<Jenz> I'm sad how rarely I manage to find places I can use Sets
<FromGitter> <drum445> Does anyone know how to get days between two dates correctly?
<FromGitter> <drum445> actually, is there a way to set the time location to use app wide, this new change with locations is causing a lot of issues?
<FromGitter> <drum445> `Time::Location.local = Time::Location.load("UTC")` โŽ if anyone needs
Dreamer3 has joined #crystal-lang
devil_tux has quit [Read error: Connection reset by peer]
Jenz has quit [Quit: leaving]
<mps> straight-shoota: sorry, had a visitors. here is result of 'abuild check' (make spec) http://tpaste.us/ErXO
<mps> crystal 0.27.2 with libxml2 2.9.9, llvm5
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 remember when I was trying to create a type union using a macro? Look what I just found in the Kemal source code! โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6f1f25a7d733509da4baa8]
<FromGitter> <Blacksmoke16> ayy
<FromGitter> <Blacksmoke16> nice one
<FromGitter> <dscottboggs_gitlab> indeed!
devil_tux has joined #crystal-lang
<FromGitter> <Blacksmoke16> i found another bug with athena/granite last night :(
<FromGitter> <dscottboggs_gitlab> oh, no
<FromGitter> <dscottboggs_gitlab> what happened
<FromGitter> <Blacksmoke16> `in lib/CrSerializer/src/CrSerializer/json/to_json.cr:15: no overload matches 'Granite::Base#to_json' with types JSON::Builder, Array(String), Array(String)`
<FromGitter> <Blacksmoke16> works fine when i only have 1 model defined, else i get that that wont compile
<FromGitter> <Blacksmoke16> yet i can call it manually and serializes just fine
<FromGitter> <dscottboggs_gitlab> oh, I feel like this is kinda related to an issue I've been running into
return0e_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> havent dug into it much yet tho
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <dscottboggs_gitlab> If you try to serialize a type union that can also resolve to an abstract class, you run into weird errors
<FromGitter> <Blacksmoke16> i think it has to do with the type being a union of the two models
<FromGitter> <dscottboggs_gitlab> I haven't been able to create a consistent minimal example but there have been a few times where I've run into issues where that happened.
return0e has quit [Ping timeout: 255 seconds]
<FromGitter> <dscottboggs_gitlab> I think I'll take another stab at a minimal example now...
<FromGitter> <dscottboggs_gitlab> take a look at the issues surrounding promotion of Unions to a common type, there might be something going on there @Blacksmoke16
<FromGitter> <Blacksmoke16> yea, based on the error its defaulting to its base type
<FromGitter> <Blacksmoke16> ill poke you if i find out anything
<FromGitter> <dscottboggs_gitlab> yeah that's similar to the issue I've been running into with `instantiating allocate` and other not-helpful errors. haha
<FromGitter> <Blacksmoke16> because like both should easily be able to have that method called on them
<FromGitter> <Blacksmoke16> im defining it on `Object` like standard serialization stuff
<FromGitter> <Blacksmoke16> :shrug: ill figure it out
<FromGitter> <dscottboggs_gitlab> my workaround most recently was to replace the abstract base class with an alias, but that won't work for you
<FromGitter> <dscottboggs_gitlab> OH!
<FromGitter> <dscottboggs_gitlab> So, {{type}}::Serializable is a module, which defines `self.new` on an included class, right?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> also gets carried over to subclasses
<FromGitter> <dscottboggs_gitlab> I think what's happening, is if you define that on an abstract class, it might try to actually instantiate the abstract class, on line 119 there
<FromGitter> <Blacksmoke16> but its not abstract
<FromGitter> <Blacksmoke16> and im calling `to_json` so shouldnt be related?
<FromGitter> <dscottboggs_gitlab> but if I were right, there would be a rescue on that allocate that would be obfuscating the error there too
<FromGitter> <dscottboggs_gitlab> ๐Ÿ’ญ
<FromGitter> <Blacksmoke16> :shrug: see if you can reproduce it :P
<FromGitter> <Blacksmoke16> but i have a WIP draft of the athena + granite blog/tutorial post i been working on if you wanted to see it
<FromGitter> <Blacksmoke16> get some early feedback
<FromGitter> <dscottboggs_gitlab> sure
<FromGitter> <dscottboggs_gitlab> I got it! https://carc.in/#/r/6bw1
<FromGitter> <Blacksmoke16> oh that error
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> your's seems to be a reduction, so least we know it has something to do with the serializable stuff now?
<FromGitter> <dscottboggs_gitlab> yeah, I hope this helps find the root of the problem
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/6996 is also annoying :(
<FromGitter> <dscottboggs_gitlab> oof, yeah that's really similar
<FromGitter> <Blacksmoke16> aye
<FromGitter> <Blacksmoke16> afk a bit, driving home
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab yea union is getting borked i think
<FromGitter> <Blacksmoke16> type of the response when there are two models is `Granite::Base`
<FromGitter> <dscottboggs_gitlab> yeah I remember seeing an issue where they were talking about doing that to conserve memory I think
<FromGitter> <Blacksmoke16> while its the actual article while there is just one
<FromGitter> <Blacksmoke16> well thats totally broken
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bx5
<FromGitter> <dscottboggs_gitlab> yeah kinda. Like I said I had to work around it by removing the base class, but you don't have that option
<FromGitter> <Blacksmoke16> looks like compiler doesnt know included types when returning from a proc?
<FromGitter> <dscottboggs_gitlab> oooof
<FromGitter> <dscottboggs_gitlab> that's a really concise example
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bx7 vs where it works fine when there is just the one type
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bx8 looks like its also related to the serializeable stuff?
<FromGitter> <Blacksmoke16> otherwise that should fail to
<FromGitter> <dscottboggs_gitlab> oh, interesting!
<FromGitter> <dscottboggs_gitlab> just tried cross-compiling and got this error: โŽ โŽ ```cc: error: /usr/share/crystal/src/ext/libcrystal.a: No such file or directory``` [https://gitter.im/crystal-lang/crystal?at=5c6f39c8c4da4a11f59470cc]
<FromGitter> <dscottboggs_gitlab> I can't just copy that file over, can I?
<FromGitter> <Blacksmoke16> whoa
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bxe
<FromGitter> <Blacksmoke16> making `Base` abstract fixes it
<FromGitter> <dscottboggs_gitlab> what in the hell?
<FromGitter> <Blacksmoke16> making an issue now
<FromGitter> <dscottboggs_gitlab> yeah, haha
<devil_tux> is smth like property a, b : String? possible
<FromGitter> <dscottboggs_gitlab> pretty sure if you declare `@a : String` and `@b : String` separately then you can do `property a, b` afterwards
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bxm
<FromGitter> <Blacksmoke16> kinda
<FromGitter> <Blacksmoke16> but have to type hint both properties