Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:59
    asterite reopened #11756
  • 16:05
    straight-shoota edited #11760
  • 16:04
    straight-shoota edited #11760
  • 16:04
    straight-shoota labeled #11760
  • 16:04
    straight-shoota opened #11760
  • 16:04
    straight-shoota labeled #11760
  • 14:58
    straight-shoota closed #11548
  • 14:58
    straight-shoota closed #11663
  • 14:58
    straight-shoota closed #11713
  • 14:58
    straight-shoota closed #7472
  • 14:58
    straight-shoota edited #11713
  • 14:49
    straight-shoota labeled #11754
  • 14:49
    straight-shoota labeled #11754
  • 14:49
    straight-shoota labeled #11754
  • 12:30
    yxhuvud synchronize #11754
  • Jan 21 23:53
    asterite closed #11711
  • Jan 21 22:59
    straight-shoota closed #11579
  • Jan 21 22:58
    straight-shoota closed #11691
  • Jan 21 21:10
    lbguilherme closed #11666
  • Jan 21 18:20
    straight-shoota milestoned #11548
From IRC (bridge bot)
@FromIRC
<delucks> thanks, super helpful. is there a process for accepting new architectures like this, or would that be a discussion for a future PR?
George Dietrich
@Blacksmoke16
afaik the last one just made a PR
that would probably suffice
could prob reference the rust implementation of the abi as it also uses llvm
nanobowers
@nanobowers
Hello all, new to crystal and trying to migrate some ruby code to crystal in an attempt to learn it. I'm trying to port something that uses rspec yield matchers: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/yield-matchers
and cannot seem to find a feature in Crystal's Spec that has equivalent functionality. Did I miss something, or is there a shard that does this?
George Dietrich
@Blacksmoke16
whats the thing you're wanting to test?
id just test that versus worrying about how many times something yields or something
nanobowers
@nanobowers
Also, if anyone knows of a cheat-sheet (mapping) of ruby stdlib to crystal stdlib, that would be helpful. There are a lot of similarities, but also plenty of differences and a lot of hunting to find the nearly equivalent thing
Jonathan Silverman
@mixflame
whew ok
Amber patch is perfect, 2 tests, working, and confirmed you don't have to use the hack anymore.
nanobowers
@nanobowers
@Blacksmoke16 For this particular thing i could creat an array and successively yield to construct it, but for some streaming cases maybe that wont work... In this particular case, i picked up a utility written in ruby with rspec tests that i didnt write and have little familiarity with - I was hoping to spend more time in the code and just migrate the tests as closely as possible, but now i'll have a chance to explore both in more detail.
George Dietrich
@Blacksmoke16
can you share the code?
Jonathan Silverman
@mixflame


require "../../../spec_helper"

module Amber
  describe Amber::WebSockets::Adapters::RedisAdapter do

    describe "#initialize" do
      it "should subscribe to CHANNEL_TOPIC_PATHS" do


        _, client_socket = create_user_socket
        _, client_socket2 = create_user_socket

        Amber::Server.pubsub_adapter = Amber::WebSockets::Adapters::RedisAdapter

        channel = UserSocket.channels[0][:channel]
        channel2 = UserSocket.channels[1][:channel]

        channel.subscribe_to_channel(client_socket, "{}")
        channel.subscribe_to_channel(client_socket2, "{}")

        channel2.subscribe_to_channel(client_socket2, "{}")
        channel2.subscribe_to_channel(client_socket, "{}")

        # channel.test_field.last.should eq "handle joined #{client_socket.id}"
        Amber::WebSockets::CHANNEL_TOPIC_PATHS.should eq ["user_room", "secondary_room"]

        redis_adapter = Amber::WebSockets::Adapters::RedisAdapter.new

        sleep 5.seconds

        redis_adapter.subscribed.should eq true
      end
    end

    describe "#publish" do
      it "should publish the message to the channel" do
        _, client_socket = create_user_socket
        _, client_socket2 = create_user_socket

        Amber::Server.pubsub_adapter = Amber::WebSockets::Adapters::RedisAdapter

        channel = UserSocket.channels[0][:channel]
        channel2 = UserSocket.channels[1][:channel]

        channel.subscribe_to_channel(client_socket, "{}")
        channel.subscribe_to_channel(client_socket2, "{}")

        channel2.subscribe_to_channel(client_socket2, "{}")
        channel2.subscribe_to_channel(client_socket, "{}")

        # channel.test_field.last.should eq "handle joined #{client_socket.id}"
        Amber::WebSockets::CHANNEL_TOPIC_PATHS.should eq ["user_room", "secondary_room"]

        redis_adapter = Amber::WebSockets::Adapters::RedisAdapter.new

        sleep 3.seconds

        redis_adapter.subscribed.should eq true

        channel = UserSocket.channels[0][:channel]
        message = JSON.parse({"event" => "message", "topic" => "user_room:123", "subject" => "msg:new", "payload" => {"message" => "hey guys"}}.to_json)
        channel.on_message("123", message)
        channel.test_field.last.should eq "hey guys"
      end
    end


  end
end
George Dietrich
@Blacksmoke16
sorry that was @nanobowers
Jonathan Silverman
@mixflame
oh, my bad
:)
George Dietrich
@Blacksmoke16
can you not just do like
it "with one item" do
  layout.each_line do |a, b|
    a.should eq [1]
    b.should eq 1
  end
end
or something along those lines?
wayy more readable imo
Layout.new*
or whatever the type is
nanobowers
@nanobowers
Yeah, probably so... I've used rspec for some time and never seen even half of the stuff i've seen used in this code.
George Dietrich
@Blacksmoke16
Spec module is deff a lot more simplistic than rspec, IMO for the better most of the time
nanobowers
@nanobowers
Are 'named' globals available? Saw very little discussion in the documentation and the compiler complains when the long-name versions of builtin globals are used e.g. $0 vs $PROGRAM_NAME and $? vs $CHILD_STATUS
George Dietrich
@Blacksmoke16
crystal doesn't have global vars
at least that the user can define on their own. The only real global vars are defined via the compiler, which are like $~ and $1, $n representing regex matches
nanobowers
@nanobowers
Makes sense, will need to add that to my list of things to find the Ruby equivalent for - I think i've figured out $? equiv vias Process.run()
Thanks for all of the help/advice
YusufCakan
@YusufCakan
how to people normally debug the crystal compiler. Are there any instructions on how to do this.
Jonathan Silverman
@mixflame
confirmed amber redis websocket adapter patch is stable and works with multiple amber processes :D
+tests added+
From IRC (bridge bot)
@FromIRC
<postmodern> is there an Enumerable method that finds the last occurance based on a block?
<jhass[m]> mmh, I don't think so but could maybe concort something with with_index and max?
Quinton Miller
@HertzDevil
you cannot traverse backwards with an Enumerable, but there's rindex for Indexable
From IRC (bridge bot)
@FromIRC
<jhass[m]> has some yet unhandled edge cases around the only match being the first one or no match of course
Quinton Miller
@HertzDevil
From IRC (bridge bot)
@FromIRC
<jhass[m]> Indexable#rfind could use reverse_each and break I guess
From IRC (bridge bot)
@FromIRC
<postmodern> how do i specify a literal ASCII string? "\xff\xfe" is being interpreted as a unicode string with one character instead of two
Ali Naqvi
@naqvis
"\u{ff}\u{fe}" if two separate chars
From IRC (bridge bot)
@FromIRC
<postmodern> ah, weird syntax but that seems to work
<postmodern> ah but that defines a unicode string of four bytes. i need a two-byte string of 0xff and 0xfe
Ali Naqvi
@naqvis
"\xff\xfe" is actually two byte String
pp "\xff\xfe".to_slice # => Bytes[255, 254]
can you please describe, what are you getting? and what's your expected output?
From IRC (bridge bot)
@FromIRC
<postmodern> i think the problem is because my code is using String#chars which returns unicode characters
Ali Naqvi
@naqvis
but FF FE is a UTF16-LE BOM
From IRC (bridge bot)
@FromIRC
<postmodern> yeah, kind of wish Crystal had a way to forcibly defining an ASCII string, so you can contain non-UTF binary strings of random data that could be misinterpreted as UTF codepoints