<FromGitter>
<girng> now i have to leave in 30 minutes :( maybe i'll brainstorm ideas while at work, then, when i get home, implement them in code. so i don't waste time at home thinking about ideas. i can think of ideas anywhere!
<FromGitter>
<tenebrousedge> Definitely. I just read a book on cancer where it seemed like every breakthrough was the product of someone thinking on their way to work. Other people have their world-changing insights in the shower
<FromGitter>
<tenebrousedge> Archimedes did something similar
<FromGitter>
<Blacksmoke16> makes sense considering those times where there is nothing else to do but think :p
<FromGitter>
<Blacksmoke16> since the actual action of driving or taking a shower takes trivial amounts of brain function
<FromGitter>
<Blacksmoke16> helps pass the time
<FromGitter>
<girng> @tenebrousedge funny you mentioned that. i've actually thought of some game-dev related ideas in the shower or doing the dishes at home. and implemented them in crystal the next day
<FromGitter>
<girng> just out of nowhere too, very weird
<FromGitter>
<girng> the ideas would randomly pop up in my head
<FromGitter>
<girng> light bulb moment
<FromGitter>
<Daniel-Worrall> Is there a way I can coerce the arrays in this hash? https://carc.in/#/r/7039
<FromGitter>
<girng> @Blacksmoke16 true
<FromGitter>
<Daniel-Worrall> The hash is gonna have a lot of values so it'll be silly to have to _u64 every int
<FromGitter>
<Blacksmoke16> add `_u64` to end of the number
<FromGitter>
<Daniel-Worrall> After *every* number though...
<FromGitter>
<Blacksmoke16> are you manually typeing in the numbers or?
<FromGitter>
<Daniel-Worrall> atm, yes
<FromGitter>
<Blacksmoke16> `[123].map(&.to_u64)`
<FromGitter>
<Daniel-Worrall> that's still a lot
<FromGitter>
<Blacksmoke16> well what are you expecting? you're giving it an Int32 but wanting it to be typed to UInt64
<FromGitter>
<Blacksmoke16> you'll have to do something
<FromGitter>
<Daniel-Worrall> I'll just _u64 it all
<FromGitter>
<Blacksmoke16> π
<FromGitter>
<girng> π
<FromGitter>
<tenebrousedge> what they said
<FromGitter>
<Blacksmoke16> other option is like `UInt64.new(123)`
<FromGitter>
<Daniel-Worrall> It's the fact they're in arrays
<FromGitter>
<Blacksmoke16> in that case it prob gets autocated
<FromGitter>
<girng> blacksmoke always in here helping others. it's really amazing
<FromGitter>
<Blacksmoke16> but im thinking it cant auto cast it when its in an array since it would be of a diff type
<FromGitter>
<Daniel-Worrall> I think Crystal could handle this case, but it doesn't atm
<FromGitter>
<Blacksmoke16> actually hmm
<FromGitter>
<asterite> of UInt64 after the array literal
<FromGitter>
<Blacksmoke16> lol my bad
<FromGitter>
<Blacksmoke16> you can just do that ^
<FromGitter>
<Blacksmoke16> just about to say that ;P
<FromGitter>
<Blacksmoke16> `[123] of UInt64`
<FromGitter>
<Blacksmoke16> if you dont tell it the array is of type Array(Int32) which isnt valid based on your type restriction of Array(UInt64) but that tells it the array it should treat values in it as UInt64
<FromGitter>
<Daniel-Worrall> yeah, but that's a lot of code for each line of the hash
<FromGitter>
<Daniel-Worrall> I was hoping to handle it outside the contents
<FromGitter>
<Blacksmoke16> are you pushing the values into it? or creating it with them already in there?
<FromGitter>
<Daniel-Worrall> creating
<FromGitter>
<Daniel-Worrall> I guess I could iterate and push them on a different hash
<FromGitter>
<Blacksmoke16> sec
<FromGitter>
<Daniel-Worrall> but I've changed them all now, it's fine
<FromGitter>
<Blacksmoke16> fair enough
<FromGitter>
<watzon> Where is the documentation on how `with self yield` works?
<FromGitter>
<watzon> @vladfaust it was you that suggested that rather than writing another API wrapper I write something that simplifies writing API wrappers right?
laaron has quit [Remote host closed the connection]
<FromGitter>
<watzon> Or something along those lines
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
beepdog has quit [Remote host closed the connection]
olbat[m] has quit [Read error: Connection reset by peer]
DTZUZU2 has quit [Ping timeout: 250 seconds]
olbat[m] has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZU2 has joined #crystal-lang
<FromGitter>
<vladfaust> Yes, it was my suggestion
<FromGitter>
<alex-lairan> @bew thanks for the review !
ShalokShalom has joined #crystal-lang
<FromGitter>
<watzon> @vladfaust I'm working on something π
<FromGitter>
<vladfaust> Thatβs awesome. I could help on the arch. Invite me or publish the scratch as-is
<FromGitter>
<watzon> @vladfaust https://github.com/watzon/wapi that's what I have right now. Still working on the architecture. I'm trying to do Documentation Driven Development, so I'm writing docs first for most things and then writing the code to match.
<FromGitter>
<watzon> I'm basing the idea on the ApiStruct rubygem somewhat
<FromGitter>
<watzon> It's not possible to pass something by reference in Crystal is it? Just realized that it doesn't seem to be supported lol.
<FromGitter>
<alex-lairan> @watzon classes are passed by reference, struct by copy
<FromGitter>
<watzon> What I'm wondering is: what would be the best syntax for a `before_hook` which runs before a HTTP request and might modify the verb, uri, or options (in this case Halite::Options`. It would be nice if they didn't have to return anything from the hook and they could just modify the variables directly like you could do if you were passing by reference in a language like C++ or Rust.
<FromGitter>
<girng> Hello all!
<FromGitter>
<girng> How is everyone doing
<FromGitter>
<vladfaust> The project 1) needs an example of somewhat implemented wrapper, e.g. GitHub 2) must allow to use multiple API wrappers in a single app β β I don't get that assertion thing. β β Also you should not rely neither on Ruby implementation not on NodeJS examples. Crystal has its own philosophy and code practice. I don't understand why are you reinventing the wheel with custom logger
<FromGitter>
<vladfaust> And stick to Crystal primitives. Default logger, for example
<FromGitter>
<vladfaust> I want to choose which logging to use. Maybe I want Onyx logger, or Blacksmoke's
<FromGitter>
<watzon> True
<FromGitter>
<vladfaust> I also encourage you to use default HTTP client, i.e. have minimum deps
<FromGitter>
<vladfaust> I'll skip invitation for now, because you already have the code published
<FromGitter>
<watzon> Gotcha. I'll take all of that into consideration :)
<FromGitter>
<vladfaust> Good. And the last for now -- always stick to certain version constraints in `shards.yml`. I see some `master` thing there
<FromGitter>
<alex-lairan> > I like having my own logger haha. Gives me more flexibility. β β No, DI will give you this flexibility. β β Re-create it will lead to less flexibility, and maintenance :) [https://gitter.im/crystal-lang/crystal?at=5cee41957c1dab468c663648]
ShalokShalom has quit [Remote host closed the connection]
<FromGitter>
<drum445> How can I convert a hash of (String, JSON::Any) into the actual data types please?
<FromGitter>
<Blacksmoke16> @alex its an IO so you can do like `file.puts` or whatever
<FromGitter>
<Blacksmoke16> or you can also use the block form like https://crystal-lang.org/api/0.28.0/File.html#tempfile%28suffix%3AString%3F%3Dnil%2C%2A%2Cdir%3AString%3DDir.tempdir%2Cencoding%3Dnil%2Cinvalid%3Dnil%2C%26block%29-class-method
<FromGitter>
<Blacksmoke16> @drum445 good luck
<FromGitter>
<Blacksmoke16> can you not use the `JSON::Serializable` stuff instead?
return0e has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter>
<Blacksmoke16> @watzon uh oh, is my logger going to get some competition? :P
rohitpaulk has joined #crystal-lang
return0e has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 258 seconds]
rohitpaulk has joined #crystal-lang
DTZUZU has joined #crystal-lang
<FromGitter>
<pynixwang> how to convert a JSON::Any to data type?
<FromGitter>
<pynixwang> can't cast JSON::Any to Int64
<FromGitter>
<Blacksmoke16> should be what you want
<FromGitter>
<pynixwang> oh.
<FromGitter>
<pynixwang> i get error
<FromGitter>
<pynixwang> not deserialzie
<FromGitter>
<Blacksmoke16> hm?
<FromGitter>
<cserb> @Blacksmoke16 I totally forgot about `to_s(16)`. Thanks!
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<asterite> @Blacksmoke16 I'm not sure what was agreed in https://github.com/crystal-lang/crystal/pull/6989 and I won't have time to do anything related to Crystal for about two weeks, so...
<FromGitter>
<Blacksmoke16> id rename it to something more clear, like `ResponseError` or something
<FromGitter>
<girng> yah
<FromGitter>
<girng> @pynixwang if you still getting issues just do `JSON.parse(jsonstring)` it makes your life easier with complex json data, but i mean if you already know the data beforehand, stick to what blacksmoke has given u
<FromGitter>
<r00ster91> oh I need to write down all the arguments and the types again
<z64>
if you want a slightly more concise way with some tradeoffs, you can use `record A, .. { include JSON::Serializable }` https://carc.in/#/r/7092
<FromGitter>
<Blacksmoke16> records ftw
<FromGitter>
<r00ster91> hmm the `def initialize` thing doesn't work, I'm still getting a (given 2, expected 1) error. I think the macro is overwriting the `def initialize`
<FromGitter>
<r00ster91> aah I misread `PrivateChannel` as `PartialChannel` the whole time. that was the problem
<FromGitter>
<Blacksmoke16> :P that would do it
<FromGitter>
<girng> hi rooster
andrzejku has quit [Remote host closed the connection]
<FromGitter>
<r00ster91> hi
DTZUZU has quit [Ping timeout: 245 seconds]
DTZUZU has joined #crystal-lang
teardown has quit [Read error: Connection reset by peer]
teardown has joined #crystal-lang
sz0 has joined #crystal-lang
wymillerlinux has quit [Read error: Connection reset by peer]
alex`` has quit [Ping timeout: 250 seconds]
alex`` has joined #crystal-lang
<FromGitter>
<watzon> What's the best DI pattern for Crystal? I'm sure @Blacksmoke16 will have something to say on that topic.
wymillerlinux has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> https://carc.in/#/r/709o Is this a good way of caching a string that might be empty? (not nil) from an API
<FromGitter>
<drosehn> It's fine, afaik. Not sure why you'd capture it in method `foo` instead of in `initialize`. Mainly it seems odd to me that a method to return the value of `@foo` would ever modify the value as kept inside the object.
<FromGitter>
<Daniel-Worrall> so it can lazily fetch it from an API
<FromGitter>
<drosehn> If it were me, I might have the `foo` method *return* "foo" to the caller, but I wouldn't have it modify the value of `@foo`. Just my opinion.
<FromGitter>
<Daniel-Worrall> It's going to be a class built from JSON where a rare case makes the string empty and so if it is empty, you need to fetch it from a different API call, but I want to do it lazily instead of on creation
<FromGitter>
<drosehn> In any case, `foo.empty?` seems fine. Sometimes I'd do `foo.size == 0`, although I can't say that would be better.
<FromGitter>
<Daniel-Worrall> Normally I would just use getter
<FromGitter>
<drosehn> yeah, but the standard getter wouldn't work for this case. If you have a lot of values like this one, you could probably write a crystal macro to do most the work for you, and then use `alt_getter` instead of the standard `getter`.