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
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>
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
<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> 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> 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>
<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
<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: 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