RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
qard has joined #crystal-lang
qard has quit [Client Quit]
thews_ has quit [Excess Flood]
thews has joined #crystal-lang
thews has joined #crystal-lang
thews has quit [Changing host]
sz0 has quit [Quit: Connection closed for inactivity]
<hightower3> Hey I have hash = Hash.new("") and it tells me can't infer the type parameter K for the generic class Hash(K, V). Please provide it explicitly
<FromGitter> <bew> what is the type of the Hash?
<hightower3> String => String
<FromGitter> <aisrael> `Hash(String, String).new(“”)`?
<hightower3> Oh great, thanks
faustinoaq has quit [Ping timeout: 256 seconds]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<hightower3> Is there a way to quickly remove a type? Like, I have a Hash of String => A | Couple | Types, and I want to call hash.to_json but it doesn't allow me due to one of types not being serializable
<hightower3> But I am sure that type is not present in hash when I call .to_json
<FromGitter> <aisrael> `.as(Hash(String, A | Type))`?
<hightower3> Tried, got "Can't cast"
<FromGitter> <aisrael> Hehehe… hang on let me fire up the terminal
<hightower3> Let me double check I didn't miss anything
<FromGitter> <bew> no way I think, you'll need to create a new hash without this type
<FromGitter> <aisrael> Ouch
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <aisrael> Yeah so the easiest way I could think of was e.g. `hh = Hash.zip(h.keys, h.values.map(&.as(A | Type)))`
<hightower3> Worked like a charm thanks bew, aisreal
<hightower3> What I did is I collected all types (except the one non-serializable) into alias MyType = list
<hightower3> Then I declared hash as {} of String => MyType | NonSerializableType
<hightower3> and later before .to_json, I just did .as( MyType)
<FromGitter> <sclee15> Hello i am looking Crystal as a backend language. How really is it? I would like to know your experience.
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
DTZUZU has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
DTZUZU has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
codenoid has joined #crystal-lang
<codenoid> hi
<codenoid> i have NamedTuple with : @color : NamedTuple(h: String, b: String, g: String, w: String, f: String, e: String, bb: String, u: String)
<codenoid> how i can make it simple ?
<FromGitter> <bew> use a struct ?
<codenoid> 1 string definition for all key
<codenoid> how ? '-'
<FromGitter> <bew> using a struct, you'll be able to access it more easily (no `@color[:h]` but `@color.h`), and it'll be the same memory and performance wise
<codenoid> struct -> def
<codenoid> right
<FromGitter> <bew> you can use the macro `record` to generate the struct with its getters & initialize
moei has quit [Quit: Leaving...]
andrewzah has joined #crystal-lang
duane has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
andrewzah has quit [Quit: ""]
andrewzah has joined #crystal-lang
<FromGitter> <aisrael> @sclee15 We’ve started moving away from Ruby (+Sinatra) to Crystal (+Kemal). Admittedly, we don’t have large amounts of traffic so we wouldn’t feel any performance gains at this point
<FromGitter> <aisrael> What prompted the move, really, was two things. 1) Need type safety/checking, preferably at compile time, and, 2) Wanted smaller, leaner, Docker containers.
<codenoid> hi, i got `no argument named 'level'`, from src/logger.cr:22, but there is `property level : Severity`
<codenoid> `@logger = Logger.new(STDOUT, level: Logger::WARN)`
<codenoid> i'll remove level
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 248 seconds]
<codenoid> hi, i want request a built-in function in File, something like `File.folder_list("/var/some/parent/folder/")`, and it will return list of folder as array
alex`` has joined #crystal-lang
<FromGitter> <bew> checkout Dir
<codenoid> ok, wait
<codenoid> yeah
<codenoid> each_entry
<codenoid> `Dir.entries("/parent/folder/")`
Liothen has quit [Ping timeout: 268 seconds]
<codenoid> i'll make PR for that
<FromGitter> <bew> for what?
<codenoid> about `dir_etries` (return dir only), and `file_entries`, wdyt ?
<FromGitter> <bew> no need, and won't be accepted i think
<codenoid> ok then
<FromGitter> <bew> maybe `Dir.each_dir` & `Dir.each_file` though
<FromGitter> <bew> but you should open an issue first, before opening a PR
Liothen has joined #crystal-lang
Liothen has joined #crystal-lang
<FromGitter> <bew> see if this is something we want in the stdlib
<codenoid> yeah, (y)
<FromGitter> <aisrael> Why does it have to be in stdlib? I mean, you *can* just open `Dir` and add it there in your `core_ext` right?
watzon has quit [Ping timeout: 276 seconds]
watzon has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
wojnar has quit [Remote host closed the connection]
codenoid has quit [Quit: i sleep in my keyboard]
<watzon> I feel like the `key` option of `JSON.mapping` is kind of unintuitive
<watzon> Sorry, the `root` option
<watzon> I'm trying to create a mapping for https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show without having to create a separate `Relationships` class that only has one key
<watzon> I was thinking that I could set `root` to `relationship`, but that doesn't actually work
* watzon sent a long message: watzon_2018-03-01_06:47:40.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/jqZVGYNdnZksGdsoXCGMCAKz>
<FromGitter> <aisrael> I think `root:` does work, but maybe you can’t share the same `root:` for two different mapping entries?
<FromGitter> <watzon> That's the problem. It doesn't work in the way I thought and the way it does work seems kind of pointless.
<FromGitter> <aisrael> What I’ve done before (somewhat similar) was `MyClass.from_json(resp.body, “root”)`
<FromGitter> <watzon> Right, that's basically what the `root` option does under the hood iirc
<FromGitter> <aisrael> So you want `root:` to work for more than one mapping entry, in other words?
<FromGitter> <watzon> Basically. I feel like the ideal implementation would allow you to map a field to a value anywhere in the json object. Maybe a separate `path` option would be good for that?
<FromGitter> <watzon> You could say `target: { type: TargetUser, path: "relationship.target" }`
<FromGitter> <watzon> Or just modify the current `key` behaviour. Idk.
<FromGitter> <aisrael> Am such a white belt in Crystal macros-fu that I wouldn’t know what’s possible (or not), much less what makes sense or not :)
<FromGitter> <watzon> I feel like it could be possible, but maybe insanely difficult
<FromGitter> <watzon> It's basically the same idea as x-path in XML
<FromGitter> <watzon> But obviously implementation wise it's quite different
<FromGitter> <aisrael> So, `JsonPath`? :)
<FromGitter> <watzon> Haha there we go
<FromGitter> <watzon> I'm all for tackling it though. I've already learned a lot about macros through experimentation. Like with this https://github.com/watzon/tweeter/blob/master/src/tweeter/base.cr
<FromGitter> <aisrael> Yeah so just quickly glancing through `JSON.mapping` source and it uses a `JSON::PullParser` which tells me paths or shared roots might be quite difficult, or, inefficient (you might have to remem stuff
<FromGitter> <watzon> True. Do you know of a parsing approach that might work better?
<FromGitter> <aisrael> Well, in your specific case, I might define a `RelationShip` class with mapping `target: TargetUser`, `source: SourceUser` and then just `RelationShip.from_json(resp.body, “relationship”)`
<FromGitter> <aisrael> In the general case, I might consider writing a `json_path.cr` shard :D
<FromGitter> <watzon> Right. I'm considering just writing a new JSON parser as an exercise.
<FromGitter> <aisrael> If I wasn’t juggling too many things myself, I’d offer to help :)
<FromGitter> <watzon> Man I already have 4 crystal projects in the works lol. I really shouldn't add another one.
<FromGitter> <aisrael> lol
<FromGitter> <watzon> I'm writing a Docker API wrapper, Twitter API wrapper, Telegram Bot, and I just finished with a OAuth header lib
<FromGitter> <watzon> I just want to prevent this ridiculousness ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a97a845e4d1c63604aa5d5d]
<FromGitter> <watzon> I'm also trying to figure out a way to prevent this https://github.com/watzon/tweeter/blob/master/spec/tweeter/user_spec.cr#L41
<FromGitter> <watzon> It would be really nice if I could make my initializer accept a named tuple and convert that into the proper class. But it's insanely difficult to do.
jokke has quit [Ping timeout: 276 seconds]
rohitpaulk has joined #crystal-lang
jokke has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <sclee15> @aisrael Thanks
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
moei has joined #crystal-lang
<FromGitter> <CImrie> Hey! I'm new to Crystal but trying to build a web app that depends on Firebase Auth. Unfortunately they are using RSA for their JWT and it can't be changed. ⏎ I've spent the last couple of evenings trying to understand and bind RSA parts of OpenSSL but end up stumped with C memory issues etc (I've honestly never touched C before). ⏎ ⏎ Anyone know of good resources for understanding the openssl library?
<FromGitter> ... Their docs appear to 'name' the parameters but don't really go into any detail on how to use the library. ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5a97c5b1e4ff28713ade6237]
<FromGitter> <watzon> I actually needed RSA bindings as well, but I'm not familiar enough with the OpenSSL library. If you can figure it out make sure to open a PR though. It would be nice to get it merged in.
<FromGitter> <CImrie> I'll do my best lol! ⏎ I think I need to read up more on the C type system so that I know how to translate everything properly. I was getting stuff to compile but it would immediately crash due to invalid memory access.
<FromGitter> <CImrie> I think my next step will be to look at how Go/Ruby etc have done it and try to map that as closely as possible
<FromGitter> <mamantoha> @watzon https://github.com/sferik/twitter-crystal
<FromGitter> <watzon> Holy crap, how did I not know about that? I've been basing my shard off of the twitter gem
<FromGitter> <aisrael> I can’t believe no one’s done OpenSSL bindings for Crystal ye
<FromGitter> <watzon> @mamantoha looks like my implementation is closer to the original Ruby gem so far though
<RX14> @aisrael there's some shitty ones in the stdlib
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
maattdd_ has joined #crystal-lang
<crystal-gh> [crystal] j8r opened pull request #5760: Add Hash#last_key and Hash#last_value (master...last_key_value_hash) https://git.io/vAMRD
rohitpaulk has joined #crystal-lang
Papierkorb has joined #crystal-lang
Papierkorb has left #crystal-lang ["Konversation terminated!"]
flaviodesousa has joined #crystal-lang
duane has joined #crystal-lang
bonemind has joined #crystal-lang
codenoid has joined #crystal-lang
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<travis-ci> crystal-lang/crystal#4cf8a7c (ci/nightly - Update paths from distribution-scripts): The build was broken. https://travis-ci.org/crystal-lang/crystal/builds/347797493
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <Sija> could any1 confirm that using `crystal: nightly` in `.travis.yml` works?
<FromGitter> <Sija> there’s a mention of it in Travis CI docs (https://docs.travis-ci.com/user/languages/crystal/#Configuration-options)
<travis-ci> crystal-lang/crystal#4cf8a7c (ci/nightly - Update paths from distribution-scripts): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/347797493
<FromGitter> <Sija> it doesn’t
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
bonemind has quit [Quit: WeeChat 2.0.1]
codenoid_ has joined #crystal-lang
codenoid has quit [Ping timeout: 256 seconds]
maattdd_ has quit [Ping timeout: 252 seconds]
maattdd_ has joined #crystal-lang
<codenoid_> hmm, @crystallang twitter account is so quiet
<codenoid_> @CrystalLanguage
maattdd_ has quit [Ping timeout: 256 seconds]
sz0 has joined #crystal-lang
codenoid_ has quit [Ping timeout: 256 seconds]
codenoid has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<hightower2> Hey how can I get this working: https://play.crystal-lang.org/#/r/3nt2
<hightower2> (Apart from hash[:field] = hash[:field].as(Int32) + 1)
codenoid has quit [Quit: i sleep in my keyboard]
<jsn-> hightower2, why a hash, why not an object?
<hightower2> porting some code over and trying to do it with minimal changes.. but yeah, I'll need to convert
<FromGitter> <bew> You shouldn't try to have minimal changes, or it will become bad Crystal code (most of the time). You can keep the API or part of it the same, but your implementation can be different!
<FromGitter> <jwaldrip> Can someone from manas DM me.
<FromGitter> <jwaldrip> I have some questions related to contracting work, and im too lazy to email :-)
<FromGitter> <Sija> is there a built-in way to call a `Proc` defined with less arguments than given?
rohitpaulk has joined #crystal-lang
<hightower2> Is bountysource the only/best way to fund Crystal's development?
<hightower2> What do I use instead of Process.waitpid?
<FromGitter> <bew> Why not use it?
<FromGitter> <bew> @Sija what do you mean? Do you have an example?
<hightower2> bew: it isn't available, only Process.wait is
<FromGitter> <Sija> @bew in the example I’d like `foo` to receive first 2 arguments
<FromGitter> <bew> Huh no, why would you want that?
<FromGitter> <bew> @hightower right, why do you need that? Are you monitoring external process you didn't created?
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter> <Sija> @bew to skip needless arguments in cases like this: https://github.com/Sija/retriable.cr/blob/master/spec/retriable_spec.cr#L393
<hightower2> bew: well, yes in a way. I did create those processes, but they run standalone then, so I need waitpid on them
<hightower2> (i.e. what I mean to say is that probably whether I started them or not makes no difference)
<hightower2> (unless I'm missing part of the picture :)
illy_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
faustinoaq has joined #crystal-lang
faustinoaq has quit [Ping timeout: 240 seconds]
alex`` has quit [Ping timeout: 276 seconds]
<FromGitter> <bew> hightower, if you started it you should have a Process object representing the new process, on which you could call `the_process.wait`
<FromGitter> <bew> @Sija if I und3rstand correctly you want to write less things, and don't have to repeat the whole proc signature right?
<FromGitter> <bew> If you you can have the proc's type in an alias or something, and create a proc with the non-literal constructor I think
<FromGitter> <bew> Checkout the second code block in the description of Proc: https://crystal-lang.org/api/0.24.1/Proc.html
<FromGitter> <bew> `Proc(Int32, String).new { |x| x.to_s }` and you could have an alias for `Proc(Int32, String)`
<hightower2> bew: nice one, thanks
faustinoaq has joined #crystal-lang
duane has quit [Ping timeout: 256 seconds]