Skip to content

Instantly share code, notes, and snippets.

View UA3MQJ's full-sized avatar

Alex UA3MQJ

  • Secta
  • Russia, Rubinsk
View GitHub Profile
‽Erlang/OTP 19 [erts-8.3] [64-bit] [smp:8:8] [async-threads:10]
Interactive Elixir (1.4.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c("tst_gen.ex")
[TstGen]
iex(2)>
nil
iex(3)> {:ok, pid} = TstGen.start_link
{:ok, #PID<0.88.0>}
iex(4)>
iex(4)>
18:04:13.683 [error] GenServer #PID<0.355.0> terminating
** (stop) %DBConnection.ConnectionError{message: "tcp async recv: closed"}
Last message: {:tcp_closed, #Port<0.6368>}
State: %Postgrex.Notifications{listener_channels: %{"event" => %{#Reference<0.2125033689.3245080577.170420> => #PID<0.354.0>}}, listeners: %{#Reference<0.2125033689.3245080577.170420> => {"event", #PID<0.354.0>}}, parameters: nil, protocol: %Postgrex.Protocol{buffer: :active_once, connection_id: 30, connection_key: -507502396, null: nil, parameters: #Reference<0.2125033689.3245080577.170419>, peer: {{127, 0, 0, 1}, 5432}, postgres: :idle, queries: nil, sock: {:gen_tcp, #Port<0.6368>}, timeout: 15000, transactions: :naive, types: nil}}
18:04:13.683 [error] GenServer #PID<0.758.0> terminating
** (stop) %DBConnection.ConnectionError{message: "tcp recv: closed"}
Last message: nil
State: [types: Postgrex.DefaultTypes, database: "postgres", username: "postgres", password: "password", hostname: "127.0.0.1", port: 5432]
@UA3MQJ
UA3MQJ / Joken.md
Last active May 16, 2021 21:54
Elixir Joken JWT Examples v1.x

https://github.com/bryanjos/joken - A JSON Web Token (JWT) Library

1. Закодировать JWT - подпись секретным текстовым ключем "my_secret_key"

  token = %{user_id: 123}
  |> Joken.token()
  |> Joken.with_signer(Joken.hs256("my_secret_key"))
  |> Joken.sign()
  |> Joken.get_compact()
Сделал модуль
defmodule Tm do
def test(x) do
x + 1
end
end
запуск ноды iex --sname ui
второй ноды на том же хосте iex --sname ui2
@UA3MQJ
UA3MQJ / test.ex
Last active September 25, 2022 19:56
Elixir compare COND/CASE/IF
$ cat test.ex
defmodule Test do
def test_case(foo) do
case foo do
:bar -> true
:buz -> false
end
end
def test_cond(foo) do
@UA3MQJ
UA3MQJ / read_write_fifo_erlang.md
Created November 28, 2018 20:17 — forked from jaredmorrow/read_write_fifo_erlang.md
Reading and Writing to Fifo (named pipes) in Erlang

Erlang and Named Pipes

The intention of this post is to provide a solution (with examples) to a somewhat uncommon issue in Erlang. I hate searching for answers to the same problems over and over, and I had a hard time finding answers to this particular problem, so I wrote it all down once I figured it out. If one day you decide to read and write data through fifo's (named pipes) and then decide you want to read or write the other end of the pipe from Erlang, this post is for you.

The Problem

I wanted to read and write to a fifo from a C/C++ app and have an Erlang app communicate over the other end of that fifo. Put simply, Erlang doesn't really support what I was trying to do. You cannot just file:open/2 a fifo, or any special device for that matter, in Erlang and expect it to work. This is documented in Erlang's FAQ.

The Solution! ... ???

@UA3MQJ
UA3MQJ / Mnesia Links
Last active December 20, 2018 20:38
@UA3MQJ
UA3MQJ / Benum.ex
Created February 13, 2019 10:02 — forked from brweber2/Benum.ex
Elixir Enumerable for binaries....
defmodule Benum do
defimpl Enumerable, for: BitString do
def count(collection) when is_binary(collection) do
{:ok, Enum.reduce(collection, 0, fn v, acc -> acc + 1 end)}
end
def count(collection) do
{:error, __MODULE__}
end
def member?(collection, value) when is_binary(collection) do
{:ok, Enum.any?(collection, fn v -> value == v end)}
@UA3MQJ
UA3MQJ / gist:2c23c30b1044cf08aec19f48ae3e9b95
Created March 3, 2022 13:29
Команды для скачивания плейлистов видео с канала FPGA-SYSTEMS
mkdir 'Осваиваем Zynq'
cd 'Осваиваем Zynq'
youtube-dl -f best -ciw -o "%(title)s.%(ext)s" -i PLWMg96mLREOekNVh8-3U5JZv2NTCLMbP5
cd ..
mkdir 'Boards review'
cd 'Boards review'
youtube-dl -f best -ciw -o "%(title)s.%(ext)s" -i PLWMg96mLREOcCO5xT3gnr111e-6gKAc-E
cd ..