RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.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> <dscottboggs_gitlab> which is the preferred way of writing this type: `Int32 | String | Nil`, `Int32 | String?`, or `(Int32 | String)?`?
<FromGitter> <Blacksmoke16> i like middle one best
<FromGitter> <Blacksmoke16> last one isnt proper syntax i think
<FromGitter> <dscottboggs_gitlab> really? I was questioning if that one would even work haha. I've been going with the first one to be safe
<FromGitter> <Blacksmoke16> first and 2nd mean the same thing
<FromGitter> <dscottboggs_gitlab> πŸ‘
<FromGitter> <Blacksmoke16> can declare it as an alias without Nil, then add the `?` to make it nilable when you need/want
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5coz
<FromGitter> <dscottboggs_gitlab> true.
<FromGitter> <fenicks> @j8r Ok thanks, I'm waiting my new device. For now I only have a Raspberry Pi2 which is armhf.
<FromGitter> <dscottboggs_gitlab> is there any way to define a JSON::Field on a def as opposed to an instance variable?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5cp0
<FromGitter> <dscottboggs_gitlab> I'm just gonna have to do a `#to_json(JSON::Builder) for this one`
<FromGitter> <Blacksmoke16> ah, not as far as i know, its based on the property, you could build out your own `to_json` method tho
<FromGitter> <dscottboggs_gitlab> yeah
<FromGitter> <Blacksmoke16> what you trying to do?
<FromGitter> <Blacksmoke16> change the key only on to_json?
<FromGitter> <dscottboggs_gitlab> it has some silly data structures
<FromGitter> <dscottboggs_gitlab> like instead of a list there are values stored in the keys of objects mapped to empty objects.
<FromGitter> <dscottboggs_gitlab> so I need to define custom builder functions for those
<FromGitter> <dscottboggs_gitlab> not to mention this one ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd3b2771c100a4f29ed33f1]
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/CrSerializer check this out, could use `serialized_name` to change the key of that property on `to_json` only
<FromGitter> <dscottboggs_gitlab> huh. I could do that.
<FromGitter> <Blacksmoke16> is still a WIP but am looking for some feedback/ideas etc
<FromGitter> <Blacksmoke16> should be pretty solid atm, on the serialization side of things
<FromGitter> <Blacksmoke16> just be sure to use master branch
zorp_ has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I don't see the feature you were talking about?
<FromGitter> <Blacksmoke16> yea sorry docs are a WIP as well :P
<FromGitter> <Blacksmoke16> would be like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd3b39082893a2f3b46d07a]
<FromGitter> <Blacksmoke16> im pretty sure using a method like `serialized_name: get_key` would work too
<FromGitter> <dscottboggs_gitlab> ooh boy. no that's getting too obscure. Don't try to be fancy, just be straightforward, I always say. I'll just do a builder method. thanks for the suggestion though.
<FromGitter> <Blacksmoke16> as you wish :p
<FromGitter> <Blacksmoke16> would be easier to understand than a custom to_json method imo, esp if you have a lot of fields, keeping that up to date/editing it was a pita for me
<FromGitter> <Blacksmoke16> is what inspired this :p
* FromGitter * dscottboggs_gitlab shrugs
notdaniel has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <bajro17> can someone please help me this 2 work together https://play.crystal-lang.org/#/r/5cpk
<FromGitter> <bajro17> @rishavs maybe you will be interested its router with parameters I want make work
<FromGitter> <Blacksmoke16> hmm specs are failing on travis but pass on local computer
<FromGitter> <Blacksmoke16> wait what, if i run the one spec on its own it fails, but passes when doing `crystal spec`
zorp_ has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> ill see if i can reproduce in a smaller project tomorrow, night
<FromGitter> <proyb6> @bajro17 which are the two in the playground? One thing for sure about the performance with H2load (Http1.1), I’m baffled that Rust and Go fasthttp routers are 2 times faster in throughput
_whitelogger has joined #crystal-lang
<FromGitter> <alex-lairan> Hi everyone ! ⏎ ⏎ I have files with extentions `js.ecr` and I want to uglify it. ⏎ ⏎ Do you know any shards for this? :) [https://gitter.im/crystal-lang/crystal?at=5bd41b45ae7be94016c2fe6c]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
Jenz has joined #crystal-lang
<FromGitter> <j8r> @fenicks I compile statically on x86 for aarch64 through docker/qemu
Jenz has quit [Ping timeout: 246 seconds]
<FromGitter> <vladfaust> Is there a way to do binary search in Crystal Array?
<FromGitter> <vladfaust> Thanks
<FromGitter> <fenicks> @j8r Nice really useful. I you have a link for the setup, I'm interested in.
DTZUZO has quit [Ping timeout: 246 seconds]
<Yxhuvud> proyb6: are the go and rust variants perhaps using more than one cpu?
<FromGitter> <j8r> @fenicks I've a custom project to do it https://github.com/DFabric/apps-static ⏎ To adapt it to your need, you have to rename https://github.com/DFabric/apps-static/blob/master/source/dppm-static and the files inside, and you should be good.
_whitelogger has joined #crystal-lang
<FromGitter> <zoorod> hi all
<FromGitter> <zoorod> first time here
<FromGitter> <zoorod> have some issues related to reading the code and print the output
<FromGitter> <zoorod> is there another way then using "puts" to get output in terminal ?
<FromGitter> <zoorod> 1) except
<jhass> there's print
<FromGitter> <zoorod> hmm
<FromGitter> <Blacksmoke16> `pp`
<FromGitter> <Blacksmoke16> can also define a logger like `logger = Logger.new STDOUT`
<FromGitter> <Blacksmoke16> then `logger.info "my message"`
<FromGitter> <zoorod> for example if I want to inspect some variables here https://github.com/jeromegn/slang/blob/master/src/slang/parser.cr
<FromGitter> <zoorod> how do I get the output in terminal ?
<FromGitter> <zoorod> then i try I brake the code
<FromGitter> <zoorod> 1) when
<jhass> what do you try, what error do you get?
<FromGitter> <Blacksmoke16> if you're using that shard in a project you could go into your `lib/slang` folder and add like `pp my_var` and it should get printed when using it in your app
<FromGitter> <Blacksmoke16> ofc would only be temp as changes would be reverted if you updated the shard or changed computers etc
<FromGitter> <melonlub> Hi, I am using https://github.com/meew0/discordcr (a library for connecting to discord api). It works fine on linux but when I am trying it on WSL, it doesn't work and raise a 400 exception. Any idea what might be the cause?
<jhass> what's the full error message?
<FromGitter> <zoorod> If I use "puts or print"
<FromGitter> <zoorod> undefined local variable or method 'hi
<jhass> gist the whole file with your changes
<FromGitter> <melonlub> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd47a103844923661a84626]
<FromGitter> <Blacksmoke16> @zoorod well it has to be an actual variable, like could do `pp node` after this statement https://github.com/jeromegn/slang/blob/master/src/slang/parser.cr#L45
<jhass> @melonlub and you're sure you run the exact same code on both?
<FromGitter> <melonlub> yes
<FromGitter> <melonlub> I also tried the example in the repo
<jhass> well then I'd try to put wireshark or mitmproxy in between and look for differences
<FromGitter> <zoorod> sorry for my slow reply, logger.info "hi" brake the code but gives :
<FromGitter> <zoorod> undefined local variable or method 'logger' ⏎ ⏎ ``` logger.info "hi"``` [https://gitter.im/crystal-lang/crystal?at=5bd47ac7271506518d7bd213]
<jhass> zoord: let's stick to your first approach
<jhass> what's the error there?
<FromGitter> <zoorod> using puts ?
<jhass> yes
<FromGitter> <zoorod> sorry, have some difficulties to understand , lets say I want to get the "str" value on line 14 in the file . How should I do that ?
<jhass> "puts str" on line 15
<jhass> but it's just an IO::Memory, so pretty boring
<FromGitter> <zoorod> that return nothing
<jhass> how do you run it?
<jhass> note that regularly it runs as a run macro: https://github.com/jeromegn/slang/blob/master/src/slang/macros.cr
<FromGitter> <zoorod> ah, maybe that is the problem
<jhass> so you'd find the output in the generated code
<jhass> but you can just crystal run the process.cr file directly and give it the template as an argument
<FromGitter> <Blacksmoke16> here's a question. My specs fail on CI https://travis-ci.org/Blacksmoke16/CrSerializer/builds/446986861?utm_source=github_status&utm_medium=notification but if i run `crystal spec` locally it passes. But if i run some spec files on their own it fails with same error as CI did
<FromGitter> <zoorod> I have no experience using macros , I will play around a bit and be back later
<FromGitter> <zoorod> thanks
<jhass> @Blacksmoke16 I guess your specs or project depend on filesystem order to load dependencies before dependents, so make sure you require dependencies explicitly before you need them
<FromGitter> <Blacksmoke16> pretty sure i am?
<FromGitter> <Blacksmoke16> only happens when the `@assertions` array in that example is empty
<FromGitter> <Blacksmoke16> so is like using the base type of the class, which is abstract
<FromGitter> <Blacksmoke16> ill see if i can replicate it
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5cul
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5cuo but this one (where im pre filling the `assertions` array in the `Validator` class runs fine
<FromGitter> <Blacksmoke16> updated links, bit easier to understand
return0e has quit [Ping timeout: 252 seconds]
return0e_ has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5cvp simplest i could get it, if you remove the `(ActualValueType)` generic on `MyAssertion` class it works
<FromGitter> <fenicks> @j8r Excellent your work on https://github.com/DFabric/apps-static. I'll try it in a few hours
<FromGitter> <bajro17> how to in function put 2 blocks
<FromGitter> <bajro17> I have &action : HTTP::Server::Context->Nil when I try add another block it write expect ) instead of ,
dabedoc has joined #crystal-lang
<dabedoc> hello
<FromGitter> <melonlub> I was wondering which IDE do you guys se?
<FromGitter> <Blacksmoke16> sublime text for crystal plugin for the most part
<FromGitter> <melonlub> I wish there was an intelli j plugin. I am so spoiled by it.
<FromGitter> <Blacksmoke16> there is
<FromGitter> <Blacksmoke16> only really does highlighting atm iirc
<FromGitter> <melonlub> yeah I know. I installed it lol.
<FromGitter> <Blacksmoke16> :p
<FromGitter> <vlazar> @S-YOU Sorry to bother you, but do you know what happened to h2o.cr results on TFB? I can't find them for latest runs :(
<FromGitter> <Blacksmoke16> i figured it out, apparently unused generics cause it
<FromGitter> <Blacksmoke16> i made an issue for it https://github.com/crystal-lang/crystal/issues/6996
return0e_ has quit [Ping timeout: 246 seconds]
return0e has joined #crystal-lang
sevensidedmarble has quit [Remote host closed the connection]
<FromGitter> <vlazar> never mind S-YOU just found your new PR with a fix
RX14 has joined #crystal-lang
dabedoc has quit [Ping timeout: 256 seconds]
<FromGitter> <ljuti> Thought I found a bug/new corner case in hash implementation, but I was just using it wrong :)
<FromGitter> <ljuti> Error messages could’ve been a bit more helpful, though. I’m sure I won’t be the only one to try to use it the wrong way and not realize it right away.
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Client Quit]
rohitpaulk has joined #crystal-lang
<FromGitter> <jwoertink> @ljuti How were you using it?
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter> <rishavs> I am struggling a lot with desrializing json coming from my server request. ⏎ I am trying; ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5bd4c690271506518d7dc0bc]
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> try `req2 = Req.from_json(ctx.request.body.gets_to_end)`
<FromGitter> <Blacksmoke16> currently you're passing it the string `"ctx.request.body.gets_to_end"`
<FromGitter> <Blacksmoke16> @rishavs
<FromGitter> <Blacksmoke16> or something like that, want to pass the json string to `from_json`
zorp_ has joined #crystal-lang
<FromGitter> <j8r> @rishavs you can also try JSON::Serializable
<FromGitter> <rishavs> yeah, but i thought If i can do the former, I can do the latter. I believe that serializable depends on mapping anyway
<FromGitter> <rishavs> i am now getting `#<JSON::ParseException:unexpected token 'EOF' at 1:1>`
<FromGitter> <Blacksmoke16> what if you just do `ctx.request.body`
<FromGitter> <Blacksmoke16> which should just return the body of the request as a string
<FromGitter> <rishavs> getting the same error. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd4cdc3ab17df2631fe5736]
<FromGitter> <Blacksmoke16> is this using kemal or something?
<FromGitter> <rishavs> plain crystal
<FromGitter> <rishavs> i am on a masochistic journey on using vanilla cr for my server
<FromGitter> <Blacksmoke16> hm, what does the request look like?
<FromGitter> <rishavs> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd4cedd069fca52a5a44842]
<FromGitter> <Blacksmoke16> so its pretty clear that the `from_json` is failing because the body contains an EOF value
<FromGitter> <Blacksmoke16> are you able to do like `pp ctx.request.body`?
<FromGitter> <Blacksmoke16> to confirm what the payload looks like
<FromGitter> <rishavs> `"{\"email\":\"foot@mail.com\",\"password\":\"pass\",\"nickname\":\"Axe \"}"`
<FromGitter> <Blacksmoke16> well thats deff json
<FromGitter> <Blacksmoke16> if thats what `ctx.request.body.gets_to_end` returns then im unsure why `from_json` wouldnt like that
<FromGitter> <dscottboggs_gitlab> how to define a macro variable or make a variable accessible from a macro?
<FromGitter> <rishavs> looks like i will have to stick to json.parse :(
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd4d1b3ef4afc4f28e05347]
<FromGitter> <Blacksmoke16> that works fine for me
<FromGitter> <j8r> @rishavs no serializable is new, mapping may be deprecated in the future
<FromGitter> <j8r> because the future of named tuples as we know them is uncertain...
<FromGitter> <jwoertink> strange, it works for me using that
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd4d1efc08b8b3067820704]
<FromGitter> <Blacksmoke16> that would work, issue is its coming from an http request
<FromGitter> <Blacksmoke16> which is erroring on reading the body for some reason in his case
<FromGitter> <dscottboggs_gitlab> > the future of named tuples as we know them is uncertain... ⏎ ⏎ why's that? I saw some discussion on an old PR about possibly removing symbols. Is that something that's being worked on?
<FromGitter> <jwoertink> There's always talk of removing something. Until the language is 1.0 just assume that could be the case with anything
<FromGitter> <dscottboggs_gitlab> I don't have a problem with it, symbols seem like a great way to introduce bugs
<FromGitter> <dscottboggs_gitlab> even a global enum for your project would be better than a global enum for the whole language
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <dscottboggs_gitlab> although I couldn't think of a concrete example where an enum collsion would create a bug so maybe I'm just being cautious for nothing, but my instincts say it's a little fishy
<FromGitter> <Blacksmoke16> symbols are not enums
<FromGitter> <dscottboggs_gitlab> idk I'm just rambling, hoping someone has any clue how to iterate over the same tuple in two separate macros
<FromGitter> <dscottboggs_gitlab> I mean it's basically a single global enum - readable names for efficient integer values
<FromGitter> <Blacksmoke16> make it a constance and reference that?
<FromGitter> <dscottboggs_gitlab> oh! really??
<FromGitter> <Blacksmoke16> maybe?
<FromGitter> <Blacksmoke16> would have to give some example for what you're trying to do
<oprypin> yeah, macros can work with constants
<FromGitter> <dscottboggs_gitlab> that definitely did it, thanks @Blacksmoke16
<FromGitter> <rishavs> thanks for the help guys. i will sleep over this issue. hopefully tomorrow will be easier :)
<FromGitter> <Blacksmoke16> np
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` ⏎ ⏎ is there any way to move that to a compile time error? [https://gitter.im/crystal-lang/crystal?at=5bd4d8cec08b8b30678235ab]
<FromGitter> <Blacksmoke16> is that a custom overload of `[]`?
<FromGitter> <Blacksmoke16> if you're trying to do like `have at least one key to index, but ability or provide others` you could do like
<FromGitter> <dscottboggs_gitlab> yeah for a hash-like class
<FromGitter> <dscottboggs_gitlab> that's what I'm trying to do yes
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5d1b
<FromGitter> <dscottboggs_gitlab> eh, close enough
<FromGitter> <dscottboggs_gitlab> thanks
<FromGitter> <Blacksmoke16> got a more complete example?
<FromGitter> <dscottboggs_gitlab> I can post the class as it is right now, just a sec
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5d1e
<FromGitter> <Blacksmoke16> couldnt you just do like ` (keys : Array(String))`
<FromGitter> <dscottboggs_gitlab> I guess so... I usually use splats. wouldn't that mean you'd have to put like `val[["key1", "key2"]]` and still have the problem of checking for empty at runtime?
<FromGitter> <dscottboggs_gitlab> yeah, I like this ⏎ ⏎ ```def []?(key: String, *keys : String) ⏎ all_keys = {key} + keys``` [https://gitter.im/crystal-lang/crystal?at=5bd4ddb182893a2f3b4dcf93]
<FromGitter> <Blacksmoke16> πŸ‘
zorp_ has quit [Ping timeout: 245 seconds]
Raimondi has quit [Quit: WeeChat 2.2: Β‘Chau!]
DTZUZO has joined #crystal-lang
Raimondi has joined #crystal-lang
thews has quit [Ping timeout: 240 seconds]
thews has joined #crystal-lang
<FromGitter> <vladfaust> `JSON::Serializable` leads to an error when included into a custom `Exception` because it tries to parse super-type in the end as I understand: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ See https://carc.in/#/r/5d22 ... [https://gitter.im/crystal-lang/crystal?at=5bd4f802271506518d7ed93c]
<FromGitter> <vladfaust> Replacing with `JSON.mapping` works
<FromGitter> <m-o-e> ^ can someone help with this fairly basic question? i think i'm probably missing a standard crystal macro or idiom there
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5d2w