Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 04:54
    aarongodin synchronize #11765
  • 04:52
    aarongodin synchronize #11765
  • 04:42
    aarongodin synchronize #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:20
    FnControlOption synchronize #11476
  • Jan 24 18:06
    aarongodin opened #11765
  • Jan 24 17:42
    straight-shoota synchronize #11563
  • Jan 24 17:39
    FnControlOption synchronize #11476
  • Jan 24 17:05
    asterite closed #11756
  • Jan 24 14:30
    straight-shoota synchronize #11563
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 16:04
    HertzDevil opened #11764
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil opened #11763
  • Jan 23 15:20
    HertzDevil labeled #11761
  • Jan 23 15:10
    HertzDevil labeled #11762
  • Jan 23 15:10
    HertzDevil labeled #11762
From IRC (bridge bot)
@FromIRC
<kevinsjoberg> Oh, I'm dumb. Never mind, haha.
<kevinsjoberg> This works, https://play.crystal-lang.org/#/r/bh8o. I realized self is something else entirely when calling it outside the MyShard namespace.
Lewis E. Bogan
@lebogan

More with the raspberry pi compiling. So I'm clear: I need the current crystal version to compile the current crystal? I user the Portalier 0.33.0 and it compiled 0.33.0 but not 0.36.1. I got an error

In src/number.cr:147:67

 147 | def step(*, to limit = nil, by step, exclusive : Bool = false, &) : Nil
                                                                       ^
Error: duplicated argument name: 
make: *** [Makefile:122: .build/crystal] Error 1

The same happened when trying to compile 1.0.0.
Thanks

George Dietrich
@Blacksmoke16
You'd need to use 0.36.0 to complile 0.36.1 most likely
I.e. the one right before the one you want
Lewis E. Bogan
@lebogan
Yea, kinda thought so. Still trying to get 1.0.0 to compile for teaching purposes.
Jonathan Silverman
@mixflame
I got my websocket patch almost ready
I need to get around this IO::Error
Unhandled exception in spawn: Error writing to socket: Broken pipe (IO::Error)
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/evented.cr:82:13 in 'unbuffered_write'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/buffered.cr:217:5 in 'flush'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:106:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:103:3 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:90:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket.cr:78:5 in 'send'
  from lib/amber/src/amber/websockets/channel.cr:80:34 in 'rebroadcast!'
  from src/channels/text_channel.cr:18:5 in 'handle_message'
  from lib/amber/src/amber/websockets/channel.cr:49:9 in 'on_message'
  from lib/amber/src/amber/websockets/channel.cr:88:13 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'dispatch_received_message'
  from lib/redis/src/redis/strategy/subscription_loop.cr:34:17 in 'enter_message_reception_loop'
  from lib/redis/src/redis/strategy/subscription_loop.cr:19:7 in 'command'
  from lib/redis/src/redis.cr:311:7 in 'command'
  from lib/redis/src/redis/command_execution/value_oriented.cr:81:9 in 'void_command'
  from lib/redis/src/redis/commands.cr:1675:7 in 'subscribe'
  from lib/redis/src/redis/commands.cr:1665:7 in 'subscribe'
  from lib/amber/src/amber/websockets/adapters/redis.cr:24:11 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'run'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/fiber.cr:92:34 in '->'
  from ???
module Amber::WebSockets::Adapters
  # Allows websocket connections through redis pub/sub.
  class RedisAdapter
    @subscriber : Redis
    @publisher : Redis
    @listener : Hash(String,Proc(String, JSON::Any, Nil)) = Hash(String, Proc(String, JSON::Any, Nil)).new
    @subscribed : Bool = false

    def self.instance
      @@instance ||= new
    end

    # Establish subscribe and publish connections to Redis
    def initialize
      @subscriber = Redis.new(url: Amber.settings.redis_url)
      @publisher = Redis.new(url: Amber.settings.redis_url)

      if !@subscribed == true
        spawn do
          Fiber.yield
          puts "subscribing to #{CHANNEL_TOPIC_PATHS}"

          @subscribed = true
          @subscriber.subscribe(CHANNEL_TOPIC_PATHS) do |on|
            on.message do |_, m|
              msg = JSON.parse(m)
              sender_id = msg["sender"].as_s
              message = msg["msg"]
              topic = message["topic"].to_s.split(":").first
              @listener[topic].call(sender_id, message)
            end
            on.subscribe do |_, _|
              puts "subscribed to #{CHANNEL_TOPIC_PATHS}"
            end
            spawn do
              Fiber.yield
              to_subscribe = SUBSCRIBE_CHANNEL.receive
              @subscriber.subscribe(to_subscribe)
            end
          end
        end
      end
    end

    # Publish the *message* to the redis publisher with topic *topic_path*
    def publish(topic_path, client_socket, message)
      @publisher.publish(topic_path, {sender: client_socket.id, msg: message}.to_json)
    end

    # Register listener with topic path after one-time subscribe on initialization
    # So that it will be called when Redis pushes data to the subscription channel
    def on_message(topic_path, listener)
      @listener[topic_path] = listener
      SUBSCRIBE_CHANNEL.send(topic_path)
    end
  end
end
what am i doing that breaks thepipe?
Unhandled exception in spawn: Error writing to socket: Broken pipe (IO::Error)
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/evented.cr:82:13 in 'unbuffered_write'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/io/buffered.cr:217:5 in 'flush'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:106:5 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:103:3 in 'send'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket/protocol.cr:257:5 in 'close'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/http/web_socket.cr:111:5 in 'close'
  from lib/amber/src/amber/websockets/client_socket.cr:111:9 in 'disconnect!'
  from lib/amber/src/amber/websockets/client_socket.cr:102:9 in 'beat'
  from lib/amber/src/amber/websockets/client_sockets.cr:17:13 in '->'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/primitives.cr:255:3 in 'run'
  from /home/jonathan/.asdf/installs/crystal/1.0.0/share/crystal/src/fiber.cr:92:34 in '->'
  from ???
Jonathan Silverman
@mixflame
nevermind i fixed it
hopefully someone merges my stuff soon, it works to give scalability in websocket apps on amber
From IRC (bridge bot)
@FromIRC
<delucks> hey folks! I'm trying to compile a Crystal "hello world" on a SPARCv9 machine running OpenBSD6.8 using LLVM 10. I've built a ll file of the code on a x86 machine running the latest release of the compiler, but when building it on the target machine using llc, I get a segfault running DAG Pattern Instruction Selection. LLVM claims to support this target triplet :⁠) Has anyone successfully compiled Crystal
<delucks> code on SPARCv9/SPARC64?
George Dietrich
@Blacksmoke16
never heard of it
i dont see it on there so would prob need a PR to support it
From IRC (bridge bot)
@FromIRC
<delucks> thanks Blacksmoke16. Do you have any suggestions for how to debug this llvm compilation failure and get more info about where in the crystal codebase needs to be modified?
George Dietrich
@Blacksmoke16
from my understanding since this is a totally new arch, you'd need something like crystal-lang/crystal#3491
however that PR is quite old so im not sure if the exact implementation is still relevant
crystal-lang/crystal#9360 is a more recent example, but it's based on x86_64 as well, so it didn't need to define an abi for that arch
George Dietrich
@Blacksmoke16
granted im no expert on this, just basing things off stuff i read in past PRs/issues but the majority of platform support would be defining the related libC bindings in https://github.com/crystal-lang/crystal/tree/master/src/lib_c, then an abi like the ones https://github.com/crystal-lang/crystal/tree/master/src/llvm/abi, then letting the compiler know about this new target, then any other platform specifics
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