ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | 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> <christopherzimmerman> Does anyone know of any libraries that implement something like a hash, but the type of each key is handled like a tuple, where it's not a union? I thought some of the DB libraries would have it for schemas but haven't had any luck finding it
<FromGitter> <christopherzimmerman> Nevermind, I'm an idiot, it's part of the standard library
<FromGitter> <christopherzimmerman> Found it 30 seconds after asking
deavmi has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> aka a named tuple? :P
<FromGitter> <christopherzimmerman> Yep :) Not sure how I missed it
<FromGitter> <Blacksmoke16> they are immutable tho
<FromGitter> <Blacksmoke16> is a key difference
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> raz: is where i ended up
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ Im quite happy with it i think [https://gitter.im/crystal-lang/crystal?at=5ed2f78b225dc25f54b7b6f1]
rocx has quit [Read error: Connection reset by peer]
rocx has joined #crystal-lang
<FromGitter> <christopherzimmerman> Is it possible to use named tuples with generics? Something like: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed2fa0c778fad0b13388c2f]
<FromGitter> <Blacksmoke16> does that not work?
<FromGitter> <Blacksmoke16> pretty sure you could just do like `@data : T` and `T` will inferred from the type of `data` local var
_whitelogger has joined #crystal-lang
rocx has quit [Quit: 👏 developers 👏 developers 👏 developers 👏 developers 👏 developers]
rocx has joined #crystal-lang
baweaver has quit [Ping timeout: 260 seconds]
lanodan has quit [Ping timeout: 260 seconds]
csaba has quit [Ping timeout: 260 seconds]
csaba has joined #crystal-lang
lanodan has joined #crystal-lang
<FromGitter> <wontruefree> @j8r we can get https but we have not yet
<FromGitter> <wontruefree> there are a lot of things to do
_whitelogger has joined #crystal-lang
masterdonx2 has quit [Ping timeout: 246 seconds]
MasterdonX has joined #crystal-lang
<FromGitter> <emanzx> hi all
<FromGitter> <emanzx> I just install my first FreeBSD 12 and wanted to compiled my crystal code, and im getting this error.
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed350532c49c45f5ab2940f]
<FromGitter> <emanzx> here are some top error
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed350cda91f120a6cd3c49d]
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3512ea91f120a6cd3c54d]
_whitelogger has joined #crystal-lang
<raz> blacksmoke16: looks good!
kradnoel has joined #crystal-lang
sagax has quit [Ping timeout: 260 seconds]
kradnoel has quit [Remote host closed the connection]
kradnoel has joined #crystal-lang
kradnoel_ has joined #crystal-lang
kradnoel has quit [Ping timeout: 256 seconds]
zorp_ has joined #crystal-lang
kradnoel_ has quit [Remote host closed the connection]
sagax has joined #crystal-lang
tdc has joined #crystal-lang
tdc has left #crystal-lang ["Leaving"]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <naqvis> @emanzx From the error it is evident that your system is missing openssl `openssl-devel` library.
<FromGitter> <naqvis> Have it installed and then try compilation again
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
<FromGitter> <emanzx> @naqvis thank god. that settle everythings.
sagax has quit [Remote host closed the connection]
<FromGitter> <naqvis> 👍
<FromGitter> <emanzx> ok seem crystal working again.. but im having lots of dependencies problem because im using 0.32.1 and its 0.34.0 in the wild now. But I manage to solve some dependencies if it happen caused by dependencies. But this one I have lost. can anyone point me again where is wrong? or I need to fix my code?
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3937c3ffa6106f1e67547]
<FromGitter> <naqvis> what are you trying to achieve? `Hash(String, Hash(Hash(String, String), Int32))` seems strange to me
<FromGitter> <naqvis> you are having `Hash` as a key for Hash?
<FromGitter> <naqvis> `Hash` isn't a silver bullet and i'm sure your use-case can be solved via different constructs
<FromGitter> <naqvis> but its good if you can explain your use-case or what is it you are trying to achieve?
<FromGitter> <emanzx> oh.
<FromGitter> <emanzx> I have a data of domain
<FromGitter> <emanzx> let me find an example
<FromGitter> <emanzx> ok starting with the code
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed39f81b101510b202b4010]
<FromGitter> <emanzx> I do a log parsing of bind 9 RPZ log file. from there I take out information such as View, Client IP, Action, RPZ Zone and Query. So the things is there is a lot of same line and I need to count the how many time the line happen on specific time_bucket. So I took out all the same info into hash and make it as a key and the count as the value. The crystal version 0.28.0 bellow seem to accept it and ruby did
<FromGitter> ... too. So I was just following the flow as it is okay. But I know its not good but could not think of Idea to used as a key for the hash.
<FromGitter> <emanzx> here the code that referred to_json.
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3a3602280c80cbfdd6661]
<FromGitter> <naqvis> data structure you have can't be converted to valid JSON, so you are receiving that error, i mean how `Hash(String, Hash(Hash(String, String), Int32))` would be represented in JSON?
<FromGitter> <naqvis> do you have any output format, which you were targeting to store the calculated outcome?
<FromGitter> <emanzx> currently I plan to save into json line.
<FromGitter> <emanzx> let me see if I have any
<FromGitter> <emanzx> okay here are the previous version of the code I have compiled with old crystal
<FromGitter> <emanzx> {"facebook.com/a/in":{"{\"client_ip\" => \"127.0.0.1\", \"view\" => \"viu\", \"rpz_type\" => \"QNAME\", \"action\" => \"NXDOMAIN\", \"rpz_zone\" => \"facebook.com.blacklist.rpz\"}":4}}
<FromGitter> <emanzx> im getting this
_ht has joined #crystal-lang
<FromGitter> <Blacksmoke16> is that bad?
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <j8r> BTW by exprience, parsing by char is better than by line
<FromGitter> <j8r> It can sounds it is, but not that harder to do, and more flexible and efficient
<FromGitter> <j8r> I sounds like you are parsing logs?
<FromGitter> <j8r> (Nvm, you already said it)
<FromGitter> <emanzx> yup. Im parsing bind9 rpz logs.
<FromGitter> <emanzx> @Blacksmoke16 im not sure myself but the early version of crystal are able to convert and save it to JSON. but im not sure it did it.. but I can parse back the JSON and reload back the Hash(String, Hash(Hash(String, String), Int32))
<FromGitter> <Blacksmoke16> im prob not caught up on what the problem is
<FromGitter> <Blacksmoke16> convert and save what to JSON?
<FromGitter> <emanzx> here are the code I use to re read the JSON.
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3c8182c49c45f5ab3a0eb]
<FromGitter> <Blacksmoke16> whoa
<FromGitter> <emanzx> > convert and save what to JSON?
<FromGitter> <emanzx> In BindRPZCollector.cr:466:33 ⏎ ⏎ 466 | json_data = data.to_json ⏎ ⏎ ``` ^------``` ... [https://gitter.im/crystal-lang/crystal?at=5ed3c846ff7a920a7222e194]
<FromGitter> <Blacksmoke16> did you require json?
<FromGitter> <emanzx> im getting this error
<FromGitter> <emanzx> yes I already did
<FromGitter> <emanzx> you can refer the error here
<FromGitter> <Blacksmoke16> that error isnt in that code snippet tho
<FromGitter> <Blacksmoke16> if possible maybe make a simpler example that reproduces the error?
<FromGitter> <emanzx> hmm
<FromGitter> <emanzx> let see
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3ca3eff7a920a7222e74d]
<FromGitter> <Blacksmoke16> oh
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3ca5e2280c80cbfddc87a]
<FromGitter> <Blacksmoke16> well yea, you have a hash as they key of JSON
<FromGitter> <emanzx> yup
<FromGitter> <Blacksmoke16> thats not valid JSON, what should the key be?
<FromGitter> <emanzx> but it works well in early crystal
<FromGitter> <Blacksmoke16> and what did it output?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/96qt
<FromGitter> <Blacksmoke16> stringified version of the hash as a key, that seems less than ideal...
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3caf94c9b0f060d364d8e]
<FromGitter> <Blacksmoke16> how is that useful tho?
<FromGitter> <Blacksmoke16> shouldnt `1` be the key, and the value be that hash?
<FromGitter> <emanzx> hmm..
<FromGitter> <emanzx> maybe I turn that around
<FromGitter> <emanzx> let me try
<FromGitter> <emanzx> but can I have multple same key?
<FromGitter> <emanzx> I mean I can have multiple value of key
<FromGitter> <emanzx> and the value of value are different?
<FromGitter> <Blacksmoke16> prob would make more sense to have it like `Hash(String, Array(hash(String, String))`
<FromGitter> <Blacksmoke16> or really, use structs for this and not deal with hashes
<FromGitter> <emanzx> sorry Im still lacking in programming.. crystal did teach me alot.. and I learn to use hash a lot in crystal most of the time I just use single variable for each value.. haha
<FromGitter> <emanzx> structs is quite new for me
<FromGitter> <emanzx> I will check it out.
<FromGitter> <emanzx> so right now crystal are not able to convert those hashes to json?
<FromGitter> <emanzx> because in ruby its looks okay
<FromGitter> <Blacksmoke16> its easy to fix if you *really* need it, but is kinda strange to use a hash as the key of your json
<FromGitter> <Blacksmoke16> might want to rethink your data model
<FromGitter> <emanzx> hmm
<FromGitter> <emanzx> I will talk with my collegue and discuss how I can make it simple
<FromGitter> <emanzx> btw..
<FromGitter> <emanzx> if I save a string of hash to file
<FromGitter> <emanzx> how can I parse it back into crystal?
<jhass> don't :) Save JSON or YAML instead
<FromGitter> <Blacksmoke16> ^
<FromGitter> <emanzx> err
<FromGitter> <emanzx> crystal wont want me to do that..
<jhass> how so?
<FromGitter> <emanzx> I can do it in ruby and older crystal
<FromGitter> <emanzx> it throwing me error
<jhass> show what you got?
<FromGitter> <Blacksmoke16> hes trying to use a stringified version of a hash as the key to the json obj
<jhass> that's terrible but shouldn't prevent anything?
<FromGitter> <emanzx> :)
<jhass> or do you want to parse the key back into a hash?
<FromGitter> <emanzx> yup
<FromGitter> <emanzx> I need to save the hash to file in order to do that I convert it to json and save to file
<jhass> can you store it as json instead? https://carc.in/#/r/96r0
<FromGitter> <emanzx> later I re-read each line of the JSON data and construct the hash back
<jhass> I mean you really really shouldn't use mutable values as hash keys, especially not containers
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/96r2 is his problem jhass
<jhass> yeah, just premap to
<jhass> string keys
<FromGitter> <Blacksmoke16> `{log_data.to_s => 1}`would prob do it
<jhass> use json if you ever want to recover that
<FromGitter> <emanzx> oh..
<FromGitter> <emanzx> let see
<FromGitter> <Blacksmoke16> better plan would be not to use another json object as a key but :shrug:
<jhass> yes the proper solution to any of this is to throw it away and start from scratch
<jhass> if you ended with collections as hash key you just more than wrong turn on the road :P
<FromGitter> <emanzx> okay..
<FromGitter> <emanzx> how should I structure my data
<FromGitter> <Blacksmoke16> id need to know more about what the data/goal is
<jhass> ^
<FromGitter> <emanzx> I think it easier for me to share all of the code?
<FromGitter> <emanzx> if data.empty? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3d47b3ffa6106f1e72062]
<FromGitter> <Blacksmoke16> no that doesnt really help
<FromGitter> <emanzx> this is one of the reason why I use the hash as key
<FromGitter> <Blacksmoke16> so what does `log_data` represent? and what does the `1` represent?
<FromGitter> <Blacksmoke16> your parsing logs or?
<FromGitter> <emanzx> log_data represent the metadata of the log file I process..
<FromGitter> <Blacksmoke16> you*re
<jhass> is there some kind of unique value per log_data instance?
<FromGitter> <emanzx> I dont think so
<FromGitter> <emanzx> the 1 represent how many line of the same log line that have the same meta data
<FromGitter> <Blacksmoke16> can you not just make that part of the metadata?
<jhass> well, I'm sure you can find a compound key
<jhass> worst case out of all values
<jhass> build a string or deterministic hash out of such a compound key (simplest case, just join it all together)
<FromGitter> <emanzx> okay here is sample of log file
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3d5743ffa6106f1e72274]
<jhass> then use that key and assign it something like {"meta" => log_data, "count" => 1}
<FromGitter> <Blacksmoke16> whats the end goal? Like what do you do with this hash?
<jhass> I mean you came up with some definition of what "the same log entry" is already, no?
<FromGitter> <emanzx> okay If I have multiple log_data
<jhass> just reapply it to build a compound key
<FromGitter> <emanzx> how can I relate with the count?
<jhass> this can be a one way function of log_data to the key
<jhass> as long as you store the original under the key you can reconstruct it always
<FromGitter> <emanzx> would it as simple as this?
<FromGitter> <emanzx> if data.empty? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3d65489941d051a349ee1]
<FromGitter> <emanzx> if I want to add eg. count to it
<jhass> that's the exact code you posted earlier?
<FromGitter> <emanzx> for now I just search the whole hash based on the domain key and add or merge the hash
<FromGitter> <emanzx> yes
<jhass> what's @0x805e1dd68 in the original LOG?
<FromGitter> <emanzx> I think its the cookies for the DNS
<FromGitter> <emanzx> I dont need it
<FromGitter> <emanzx> > *<jhass>* https://play.crystal-lang.org/#/r/96r4 ⏎ ⏎ I think I am getting this..
<jhass> I still think there's a better way though
<FromGitter> <emanzx> okay..
<FromGitter> <emanzx> I will try to find other way
<FromGitter> <emanzx> okay now I know why I have this code in my reader module
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ed3db6df0b8a2053ac614d8]
<jhass> emanzx: some ideas: https://play.crystal-lang.org/#/r/96re
<jhass> eh, ran into the struct pitfall, fixed: ehttps://play.crystal-lang.org/#/r/96re
sagax has joined #crystal-lang
rocx has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Anyone got a way to check the % progress of a HTTP request? I'll be downloading large files and I want to write in some progress bars or output status
<FromGitter> <j8r> You can do a HEAD request at first to get the Content-Length header
<FromGitter> <j8r> then, something like bytes read count / Content-Length
<FromGitter> <Daniel-Worrall> how would I get the bytes read?
<FromGitter> <Daniel-Worrall> I don't see anything exposed on HTTP::Client
<FromGitter> <Daniel-Worrall> Ah, streaming
<jhass> yeah, you'd need to do something like IO.copy does but exposing the progress
<FromGitter> <Daniel-Worrall> yeah, no, Idk
<FromGitter> <watzon> Is there a flag that says what the target platform is? I know you can use `flag?(:linux)` etc to check if the target is linux, but what if I want to actually get the target? Any option besides `if flag?(:linux) ... elsif flag?(:windows) ...`?
<jhass> what is the target then?
<jhass> if linux is not a platform to you
<FromGitter> <watzon> No, I mean I want to return the target platform as a string value rather than just checking if the target platform is a specific value. Something like ⏎ ⏎ ```{% puts flag(:target) %} ⏎ # => linux ⏎ ⏎ {% puts flag(:arch) %} ⏎ # => x86_64``` [https://gitter.im/crystal-lang/crystal?at=5ed3f619549761730b6cf013]
<FromGitter> <watzon> Does anything like that exist?
<FromGitter> <j8r> I think you can have the target triple
rocx has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
zorp_ has quit [Ping timeout: 256 seconds]
DTZUZU has joined #crystal-lang
Mikaela has quit [Quit: Mikaela]
Mikaela has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <emanzx> > *<jhass>* eh, ran into the struct pitfall, fixed: ehttps://play.crystal-lang.org/#/r/96re ⏎ ⏎ wow. thanks so much.. I will look into that. a lot of things are new to me. thanks again
<jhass> watzon: Well, flags don't really have keys, so how would you reference them? You could parse Crystal::DESCRIPTION I guess...
<jhass> might be better to shell out to `uname` though
_ht has quit [Quit: _ht]
<FromGitter> <watzon> I was just thinking Crystal might have some way to expose the target triple seeing as those flags exist. It looks like the LLVM method just returns the default target triple, not the one the program was built with.
<jhass> yeah, no I don't think that exists in any way
<jhass> I mean it's just a little macro if else for the platforms you care about though
<oprypin> so i'm on windows and getting the compiler to crash. all information i get is `Nil assertion failed (NilAssertionError)` because stack traces are not implemented. what are my options to track this down?
<oprypin> oh shit i just had the brightest idea
<oprypin> `class Object; def not_nil!(file = __FILE__, line = __LINE__); p! file, line; previous_def(); end; end`
<jhass> Yeah let's do that
<oprypin> ah damn, the only problem is that those constructs don't work either 😂
<jhass> I think we even have some issue comment somewhere suggesting that
<jhass> (including that in the message)
<oprypin> `BUG: "!#{file}:#{line}!" at c:\code\crystal\src\nil.cr:106:10 should have been expanded (Exception)`
<oprypin> hmm? im not sure what you're pointing at; if you still think you have a solution
<oprypin> im stuck still
<jhass> nah, just talking about your idea. I think somebody somewhere suggested having that generally
<jhass> I think I had the idea at some point that you could have a kind of macro that you could call on a type instance and it would have access to its receiver AST node
<jhass> that would be helpful now, could've just redefiend not_nil! as such a macro method then
<jhass> idk, can you stick it into a debugger and let it print a backtrace for you?
<oprypin> my idea was just to try to solve the prior issue, but it didn't work
<oprypin> jhass: debugger, eh. i haven't had the best of time with that on Windows
<oprypin> maybe it's time for it again
<jhass> 0.35 makes the debug info a lot better fwiw
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<oprypin> jhass: im running master but don't forget that this is Windows
<oprypin> the story about debug info there is completely separate
alexherbo2 has quit [Ping timeout: 256 seconds]
<jhass> mmh
<jhass> you would expect LLVM to abstract it at least somewhat
<oprypin> latest fun one: `gawk -i inplace '{ gsub(".not_nil!", ".not_nil!(" NR ")"); print }' src/compiler/**/*.cr`
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
<oprypin> ok cool that just made it crash somehow
<oprypin> ok finally did it
<oprypin> but it worked!
<FromGitter> <Blacksmoke16> prob could make the default `line = __LINE__`?
<FromGitter> <Blacksmoke16> not stupid if it works P
<oprypin> didn't work on Windows
<FromGitter> <Blacksmoke16> ah, welp
DTZUZU has quit [Quit: WeeChat 2.8]