ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.0 | Fund Crystal's development: https://crystal-lang.org/sponsors/ | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs/ | Gitter: https://gitter.im/crystal-lang/crystal
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 260 seconds]
DTZUZU_ is now known as DTZUZU
<FromGitter> <jwaldrip> Any good way to return an HTTP response from cache? Is it possible to io copy the response and store it as a string?
<FromGitter> <jwaldrip> Not seeing any shards out there for it
<FromGitter> <Blacksmoke16> whats the use case?
_ht has joined #crystal-lang
_whitelogger has joined #crystal-lang
_ht has quit [Quit: _ht]
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
postmodern has quit [Quit: Leaving]
alexherbo2 has joined #crystal-lang
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo28 is now known as alexherbo2
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <asterite> you can do respose to_io and then probably from_io
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
Human_G33k has quit [Ping timeout: 258 seconds]
HumanG33k has joined #crystal-lang
ua has quit [Ping timeout: 246 seconds]
ua has joined #crystal-lang
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 260 seconds]
<FromGitter> <j8r> `HTTP::Server::Response`?
<FromGitter> <j8r> I don't see any `to_io` or `from_io`
<FromGitter> <j8r> The framework can help, for example in Gripen the response is an object. Caching the response would be simply saving the object somewhere
DTZUZU has quit [Ping timeout: 258 seconds]
Stephie has left #crystal-lang ["Leaving"]
zorp has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#79f3022 (master - Fix Log.context.set docs for hash based data (#9470)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/697993540
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9470 ([ci skip] Fix Log.context.set docs for hash based data)
<FromGitter> <j8r> Why client response? I think he was talking about caching the server response?
<FromGitter> <Blacksmoke16> didnt specify, just said `HTTP response`
<FromGitter> <j8r> Maybe, then I don't see the point
<FromGitter> <jwaldrip> I was, my use case is that I want to cache the response and reserve from cache in memory, redis, etc.
<FromGitter> <Blacksmoke16> Wouldn't you be better off just storing the data then using etags
<FromGitter> <Blacksmoke16> To determine if you need to update it
DTZUZU has joined #crystal-lang
<FromGitter> <jwaldrip> I could, but I want caching to multiple clients
<FromGitter> <jwaldrip> the use case is for CrystalShards.org. The data changes every few hours at the very most, I just want to cache the pages so that I dont have to keep hitting the DB for information. I could do some view caching in the controllers, but as a first pass, I was just hoping to make a handler
<FromGitter> <Blacksmoke16> and in which case each page prob doesnt support the same caching mechanics so cant really use etags
<FromGitter> <jwaldrip> right
<FromGitter> <Blacksmoke16> so plan b, use the path as a key and the data is a value in redis with a ttl of an hour and call it a day?
<FromGitter> <jwaldrip> correct
<FromGitter> <Blacksmoke16> so whats the problem? that is totally doable
<FromGitter> <jwaldrip> But since the response is all an IO, I need to be able to rewind the response output... and then gets_to_end to store the data right?
<FromGitter> <jwaldrip> How can I just get a string oh whats been written to the response
<FromGitter> <jwaldrip> without the headers and other stuff
<FromGitter> <Blacksmoke16> we're talking about `HTTP::Server::Response` correct?
<FromGitter> <Blacksmoke16> like what you get back if i curl'd your site
<FromGitter> <jwaldrip> yes
<FromGitter> <jwaldrip> the server response
<FromGitter> <jwaldrip> This is what I have so far... but its grabbing the headers too
<FromGitter> <jwaldrip> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ee500efee693d6eb3c1528b]
<FromGitter> <Blacksmoke16> assuming you're streaming the response id imagine you would need to also stream the response to another IO to write to redis
<FromGitter> <Blacksmoke16> otherwise if you're just writing in one go, could just copy it
<FromGitter> <jwaldrip> can you IO copy the response
<FromGitter> <Blacksmoke16> maybe?
<FromGitter> <Blacksmoke16> or do something to wrap the actual response so that it can write the data to both things
<FromGitter> <Blacksmoke16> in conjunction with https://crystal-lang.org/api/master/HTTP/Server/Response.html#output=(output:IO)-instance-method
<FromGitter> <jwaldrip> Got it
<FromGitter> <jwaldrip> thank you
<FromGitter> <jwaldrip> Multiwriter was a good call
<FromGitter> <jwaldrip> Final:
<FromGitter> <jwaldrip> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ee50f0f29d8bc28f9f48198]
<FromGitter> <jwaldrip> Ill write a shard for it too
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <jwaldrip> I can simplify it too ;-)
<FromGitter> <Blacksmoke16> 🎉
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
<FromGitter> <mattrberry> Has there ever been talk about compiler warnings when creating a new instance variable outside of `initialize`? There have been a few times that I have misspelled an instance variable, which results in me creating a new instance variable rather than rebinding an existing one. For example, if I have the class ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I'd love it for crystal to warn me *at compile time*
<FromGitter> ... that I'm bringing a new instance variable into scope. It's all too often that the crystal vscode extension tab-completes a name in a way I didn't expect, and I end up in a situation like this [https://gitter.im/crystal-lang/crystal?at=5ee5415e7a7f8d2d63331cf9]
<FromGitter> <codenoid> hi folks, how you doing, hope everything getting better
<FromGitter> <Blacksmoke16> not that i know of, both have valid use caes
<FromGitter> <Blacksmoke16> might be a case for ameba, `unused instance variable` or something
<FromGitter> <mattrberry> Yeah, there's nothing inherently wrong with bringing a new instance variable into scope, but usually I'll still define all of my instance variables at the class level with their type, even if they're nilable
<FromGitter> <mattrberry> This would have saved me a decent chunk of time a number of times
<FromGitter> <Blacksmoke16> take an extra minute and read more carefully 😉
<FromGitter> <Blacksmoke16> or id imagine unit tests would catch most of the issues
rocx has quit [Quit: 👏 developers 👏 developers 👏 developers 👏 developers 👏 developers]
<FromGitter> <mattrberry> Unit tests would likely catch most of those, but most of my code is generated automatically atm, and I don't have unit tests for everything :/
<FromGitter> <Blacksmoke16> 😬 might not be a bad idea
<FromGitter> <mattrberry> Don't currently have the patience to write unit tests for all 512 gameboy opcodes + weird instruction behavior + obscure hardware behavior :p
<FromGitter> <Blacksmoke16> write the code that writes the tests ha
<FromGitter> <mattrberry> ez.
coderobe has quit [Ping timeout: 256 seconds]
Human_G33k has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.8]
HumanG33k has quit [Ping timeout: 256 seconds]
<FromGitter> <hanneskaeufler> Hey guys I'm lost right now trying to use the AST Visitor to visit all method definitions that have a return type of Nil. I can't figure out how to inspect the return type, and the compiler is giving me mixed signals. Code sample is here: https://play.crystal-lang.org/#/r/99gz
<FromGitter> <Blacksmoke16> I'm not sure that's exactly a public API
<FromGitter> <hanneskaeufler> Inspecting node.return_type.class says its a Crystal::Path, but using the `same?` method never returns true, and trying to access `.names` then says it's a `Crystal::Nop`, which I can't really follow ...
<FromGitter> <hanneskaeufler> > I'm not sure that's exactly a public API ⏎ ⏎ Probably not, but still I'd like to make sense of it :D
coderobe has joined #crystal-lang
<FromGitter> <Blacksmoke16> `Nop` means it doesnt have a return type restriction
<FromGitter> <hanneskaeufler> mhm, so `Nop` and `nil` (nil literal`) both mean the same in that context?
<FromGitter> <Blacksmoke16> no
<FromGitter> <hanneskaeufler> Or why is `return_type` defined as `AstNode?`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ee551dfa85de3039410bc04]
<FromGitter> <Blacksmoke16> first is `Nop`, 2nd is `Nil`, third is `Int32 | Nil`
<FromGitter> <Blacksmoke16> do remember you're not dealing with normal types here
<FromGitter> <Blacksmoke16> like that you use normally
<FromGitter> <hanneskaeufler> but first one returns `nil` as `return_type`, doesn't it?
<FromGitter> <Blacksmoke16> `Nil`
<FromGitter> <Blacksmoke16> we're looking at the type of the return value, not the actual value, although in this case, yes it'll be `nil` itself
<FromGitter> <Blacksmoke16> sec
<FromGitter> <hanneskaeufler> I think what is confusing is trying to print debug this
<FromGitter> <hanneskaeufler> yeah the type of return value is what interests me
<FromGitter> <hanneskaeufler> the `nop` method's return type isn't `Nop` for me though
<FromGitter> <Blacksmoke16> `Crystal::Nop`
<FromGitter> <Blacksmoke16> er maybe not
<FromGitter> <hanneskaeufler> ` pp! node.return_type.not_nil!` nil-exceptions for me :)
<FromGitter> <hanneskaeufler> play.crystal.lang times our for me right now when executing, would demonstrate on there otherwise^^
<FromGitter> <Blacksmoke16> is there an actual use case here? You could prob do something with macros maybe...
<FromGitter> <hanneskaeufler> ah well, my mutation test framework again ... https://github.com/hanneskaeufler/crytic. I want to write a mutation that simply drops method calls. In order to make sure that the mutated code type-checks, I only want to drop calls inside methods that don't return anything for now ...
<FromGitter> <hanneskaeufler> And to find all locations where I want to mutate, I visit the AST ...
<FromGitter> <Blacksmoke16> hm
<FromGitter> <hanneskaeufler> It seems like it should be possible but I can't figure out the condition for it :D
<FromGitter> <Blacksmoke16> im assuming you know its only going to be methods that have a restriction AND is `Nil`
<FromGitter> <hanneskaeufler> I figured, yes. Ideally I could get the type after the inference, but that's probably out of scope ...
<FromGitter> <hanneskaeufler> or not possible with the AST visitors
<FromGitter> <hanneskaeufler> ```code paste, see link``` ⏎ ⏎ Lol that compiles and passes my test, yay [https://gitter.im/crystal-lang/crystal?at=5ee556df5782a31278fa0ea5]
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <hanneskaeufler> But it needs *both* the cast as well as the case
<FromGitter> <hanneskaeufler> without the cast it say `names` is undefined on `Crystal::Nop`, which is weird
<FromGitter> <Blacksmoke16> makes sense, since its trying to make sure all children of `ASTNode` have the method you're calling
<FromGitter> <Blacksmoke16> which it doesnt
<FromGitter> <hanneskaeufler> mhm, why would it need to do that, we already know it's a `Path` when inside that branch?
<FromGitter> <Blacksmoke16> naw, you're casing on `node.return_type`
<FromGitter> <Blacksmoke16> there isnt a guarantee that that method would return the same type after the first call
<FromGitter> <Blacksmoke16> can do
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ee55813013105125a3322ad]
<FromGitter> <hanneskaeufler> https://crystal-lang.org/reference/syntax_and_semantics/case.html docs read to me as if that would be entirely identical
<FromGitter> <Blacksmoke16> but thats the same thing you did
<FromGitter> <Blacksmoke16> i first assigned the response of `node.return_type` to a local variable
<FromGitter> <hanneskaeufler> huh, you're right, the magic here is the assignment to a local variable
<FromGitter> <Blacksmoke16> that last section
<FromGitter> <hanneskaeufler> gotcha, kinda makes sense jupp
<FromGitter> <hanneskaeufler> thanks!
<FromGitter> <fenicks> Hi guys, ⏎ How can I encode this string as binary? `"\x66\x6f\x6f"`
<FromGitter> <Blacksmoke16> mm
<FromGitter> <Daniel-Worrall> #toslice ?
<FromGitter> <Blacksmoke16> that would give you the bytes
<FromGitter> <Daniel-Worrall> I misread
<FromGitter> <Blacksmoke16> `puts "foo".bytes.join " " { |b| b.to_s 2 }` kinda works
<FromGitter> <Daniel-Worrall> Yeah ^
<FromGitter> <Blacksmoke16> but i did notice it leaves off 0 bits
<FromGitter> <Daniel-Worrall> Probably also load
<FromGitter> <Blacksmoke16> i.e. would get 3 sets of 7 bits,
<FromGitter> <Daniel-Worrall> Lpad
<FromGitter> <Daniel-Worrall> Mobile autocorrect is kicking my ass today
<FromGitter> <Blacksmoke16> `puts "foo".bytes.join " " { |b| b.to_s(2).rjust(8, '0') }`
<FromGitter> <Blacksmoke16> something along those lines i guess
<FromGitter> <Blacksmoke16> @fenicks anything specific you're trying to do?
<FromGitter> <fenicks> @Blacksmoke16 yep I'm implementing test for Crystal RethinkDB driver and 1 of the tests need string to be encoded in binary to check the RethinkDB::binary call.
<FromGitter> <Blacksmoke16> 👍