Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 14:05
    straight-shoota assigned #12284
  • 12:54
    straight-shoota milestoned #13045
  • 12:54
    straight-shoota milestoned #13045
  • 12:02
    straight-shoota labeled #13045
  • 12:02
    straight-shoota labeled #13045
  • 12:02
    straight-shoota assigned #13045
  • 12:02
    straight-shoota opened #13045
  • 10:40
    straight-shoota closed #13040
  • 10:37
    straight-shoota milestoned #12963
  • 10:34
    straight-shoota milestoned #13034
  • 10:34
    straight-shoota milestoned #13034
  • 00:58
    HertzDevil synchronize #13034
  • 00:47
    HertzDevil synchronize #13034
  • Feb 02 22:23
    HertzDevil ready_for_review #13034
  • Feb 02 22:22
    straight-shoota closed #13039
  • Feb 02 22:21
    straight-shoota closed #13020
  • Feb 02 22:21
    straight-shoota closed #11646
  • Feb 02 22:21
    HertzDevil synchronize #13034
  • Feb 02 19:26
    straight-shoota labeled #13044
  • Feb 02 19:26
    straight-shoota labeled #13044
From IRC (bridge bot)
@FromIRC
<postmodern> what does Error: expected block type to be a function type, not (Proc(String) | Proc(String, String)) exactly mean? I am trying to & pass a literal ->(match) { ... } object to a method's &block
<postmodern> oh wait, do i have to define override methods for each type of &block ?
<postmodern> hmm compiler gets confused by block argument arity if i do that
George Dietrich
@Blacksmoke16
can you make a playground link?
From IRC (bridge bot)
@FromIRC
<postmodern> will have to reduce my code down to a minimal example
Ali Naqvi
@naqvis
postmodern: you can’t type restrict block param with Proc union. You will have to define overload method
From IRC (bridge bot)
@FromIRC
<postmodern> @naqvis, i tried defining overrides, but then the compiler complained about block arity (giving 1, expected 0). do you have any advice for that?
Ali Naqvi
@naqvis
type restrict block param
def test(&block : Proc1)
def test(&block : Proc2)
block without type restriction is treated as arity 0
From IRC (bridge bot)
@FromIRC
<postmodern> i have things like (String -> String) for Proc1 and (-> String) for Proc2. Not sure if that's the proper syntax?
George Dietrich
@Blacksmoke16
the first yields and returns a string, the second doesnt yield anything but returns a string
From IRC (bridge bot)
@FromIRC
<postmodern> i should write up that self-contained example for carcin
Ali Naqvi
@naqvis
Mateusz Wieloch
@mateuszwieloch
Hey I'm trying to build a terminal UI that will have ability to choose between multiple options with arrow keys (something like in the image below). I'd appreciate advice where to start - what Crystal library provides needed functionality, whether to go low level like NCurses bindings or is there something providing it out of the box?
image.png
Ali Naqvi
@naqvis
Mateusz Wieloch
@mateuszwieloch
🙏🏻Thank you! Looks like it has what I need or at least what I can use as a starting point
Ali Naqvi
@naqvis
:thumbsup:
Ali Naqvi
@naqvis
Published wasmer-crystal WebAssembly runtime for Crystal
Vladislav Zarakovsky
@vlazar
:heart: Wow, that's so cool! So I can use any Rust libs compiled to WASM from Crystal now?
Ali Naqvi
@naqvis
thanks and yeah
:pray:
Vladislav Zarakovsky
@vlazar
A complete and mature WebAssembly runtime
Is "mature" part there about it being tested in prod?
Ali Naqvi
@naqvis
that applies to wasmer
Vladislav Zarakovsky
@vlazar
gotcha, thank you!
Ali Naqvi
@naqvis
:pray:
ddd
@Dan-Do
A silly question as I don't know wasm. Does it mean that we can run Crystal code in browser?
Ali Naqvi
@naqvis
no, you can't compile crystal code to wasm. But via this shard now you can run other wasm modules from Crystal
this shard embeds wasm runtime inside crystal
ddd
@Dan-Do
:thumbsup:
Vladislav Zarakovsky
@vlazar
which means if you miss something in Crystal shards you can check https://crates.io/categories/wasm or anything else that works when compiled to WASM
ddd
@Dan-Do
That's really valuable for the community :heart:
From IRC (bridge bot)
@FromIRC
<SamantazFox> Hmm, I have a weird bug. I'm investigation atm, but the general idea is that because of the decompression issues in HTTP::Client from stdlib
<SamantazFox> I did implement a decompression routine (iv-org/invidious#2623), but it raises the following exception "HTTP::Client::Response#body_io cannot be nil (NilAssertionError)" in some edge cases.
<SamantazFox> I've deployed that fix for a few days now, on bare metal Debian, without a problem. But we keep getting issue reports about it.
<SamantazFox> So I'm trying to figure out if the problem is due to docker, or some specific container.
ddd
@Dan-Do
Regarding the body_io, sometimes the client cannot parse the response. I have a monkey patch like this
class HTTP::Client::Response
  def self.from_io?(io, ignore_body = false, decompress = true, &block)
    line = io.gets(4096, chomp: true)
    return yield nil unless line

    pieces = line.split(3)
    if pieces.size < 2
      # return yield new status_code: 200, body_io: ChunkedContent.new(io)
      pieces = "HTTP/1.1 200 OK".split(3)
    end

    http_version = pieces[0]
    raise "Unsupported HTTP version: #{http_version}" unless HTTP::SUPPORTED_VERSIONS.includes?(http_version)
    status_code = pieces[1].to_i?
    unless status_code && 100 <= status_code < 1000
      raise "Invalid HTTP status code: #{pieces[1]}"
    end

    status = HTTP::Status.new(status_code)
    status_message = pieces[2]? ? pieces[2].chomp : ""
    body_type = HTTP::BodyType::OnDemand
    body_type = HTTP::BodyType::Mandatory if mandatory_body?(status)
    body_type = HTTP::BodyType::Prohibited if ignore_body
    HTTP.parse_headers_and_body(io, body_type: body_type, decompress: decompress) do |headers, body|
      return yield new status, nil, headers, status_message, http_version, body
    end
    nil
  end
end
The patch is
    if pieces.size < 2
      # return yield new status_code: 200, body_io: ChunkedContent.new(io)
      pieces = "HTTP/1.1 200 OK".split(3)
    end
(un)comment the line that works your you
From IRC (bridge bot)
@FromIRC
<SamantazFox> haaaaaaa flails
<SamantazFox> thanks!
<SamantazFox> whyyyy
<SamantazFox> why is the body_io niled?
<yxhuvud> Why does it matter to you?
From IRC (bridge bot)
@FromIRC
<SamantazFox> yxhuvud: because of a bug in the stdlib, a response's body is not always decompressed, and rather than checking if it was properly done, I've made a patch in my code to send the Content-Encoding header, which disables auto decompression, and do that by myself.