Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:05
    yxhuvud synchronize #11754
  • 11:58
    yxhuvud opened #11754
  • Jan 18 22:28
    straight-shoota closed #11751
  • Jan 18 17:33
    straight-shoota milestoned #11751
  • Jan 18 16:48
    Blacksmoke16 labeled #11753
  • Jan 18 16:42
    yxhuvud labeled #11753
  • Jan 18 16:42
    yxhuvud opened #11753
  • Jan 18 13:52
    straight-shoota synchronize #11751
  • Jan 18 13:34
    HertzDevil opened #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 12:54
    straight-shoota synchronize #11751
  • Jan 18 12:48
    straight-shoota labeled #11751
  • Jan 18 12:48
    straight-shoota opened #11751
  • Jan 18 12:45
    straight-shoota synchronize #11716
  • Jan 18 10:38
    straight-shoota milestoned #11742
  • Jan 18 01:09
    straight-shoota closed #11747
  • Jan 18 01:09
    straight-shoota closed #11745
  • Jan 17 19:16
    straight-shoota synchronize #11716
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
Ali Naqvi
@naqvis

pp "\u{ff}\u{fe}".chars # => ['ÿ', 'þ']

this is correct representation

From IRC (bridge bot)
@FromIRC
<postmodern> bytes shows extra unicode stuff in there [195, 191, 195, 190]
George Dietrich
@Blacksmoke16
are they multibyte chars?
From IRC (bridge bot)
@FromIRC
<postmodern> they shouldn't be, but i guess they are being interpreted as such
Ali Naqvi
@naqvis
since String is UTF-8 but you are dealing with UTF-16
so you should be invoking "\u{ff}\u{fe}".to_utf16 to get the correct byte representation
From IRC (bridge bot)
@FromIRC
<postmodern> crystal's utf8-by-default Strings are making it hard for me to define a String of garbage ASCII data
Ali Naqvi
@naqvis
for encoding other than UTF-8 you should be using stream instead of String
From IRC (bridge bot)
@FromIRC
<postmodern> ah ha, thanks