Today I Learned

Don't eclose markdown content into <p> tag

If you are using for example Gatsby like I do, don't enlose html from markdown into <p> tag. The content of <p> will be missing in some cases. Anyway<p> should not include any block elements such as <p>.

Instead of:

<p className="article-post" dangerouslySetInnerHTML={{ __html: html }} />

use:

<div className="article-post" dangerouslySetInnerHTML={{ __html: html }} />

How to rotate screen in QT5 QML?

QML Code:

import QtWebEngine 1.5
import QtQuick 2.10
import QtQuick.Layouts 1.3

Item {
  rotation: 90

  StackLayout {
    width: parent.height
    height: parent.width
    x: (parent.width - parent.height) / 2
    y: -(parent.width - parent.height) / 2
    Widget {}
    Widget {}
  }
}

How to get state of any GenServer in Elixir?

To get state of any process in erlang/elixir use :sys.get_state/1

By name:

:sys.get_state(MyGenServer)

By pid:

:sys.get_state(pid)

How to make SSH service discoverable in Elixir using mDNS?

To make service discoverable we need following services registered:

[
  # create domain for an ip
  %Mdns.Server.Service{domain: "somedomain.local", data: :ip, ttl: 450, type: :a},

  # make service discoverable
  %Mdns.Server.Service{domain: "_services._dns-sd._udp.local",data: "_ssh._tcp.local",ttl: 4500, type: :ptr},

  # register ssh service
  %Mdns.Server.Service{domain: "_ssh._tcp.local",data: "SOME NAME._ssh._tcp.local",ttl: 4500, type: :ptr},

  # point service to our domain and port (22)
  %Mdns.Server.Service{domain: "SOME NAME._ssh._tcp.local",data: {0,0,22, 'somedomain.local'},ttl: 4500,type: :srv},

  # empty txt service (some tools expext that)
  %Mdns.Server.Service{domain: "SOME NAME._ssh._tcp.local",data: [],ttl: 4500,type: :txt})
] |> Enum.each(&Mdns.Server.add_service/1)

Free PubSub in Elixir Phoenix Application

If you need a pubsub, to connect LiveViews for example just use YourAppWeb.Endpoint.

YourAppWeb.Endpoint.subscribe("topic")
YourAppWeb.Endpoint.broadcast("topic", "event", %{data: "data"})
def handle_info(%{event: "event", topic: "topic", payload: payload}) do
  # Do whatever you want
end