Skip to content

Instantly share code, notes, and snippets.

View UA3MQJ's full-sized avatar

Alex UA3MQJ

  • Secta
  • Russia, Rubinsk
View GitHub Profile
@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! ... ???

@sofakingworld
sofakingworld / config.exs
Last active February 14, 2018 09:17
Форматирование логов
.....
config :logger, :console,
level: :debug,
format: {LoggerFormatter, :format_log},
@brweber2
brweber2 / Benum.ex
Last active April 4, 2022 03:38
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)}
@0xYUANTI
0xYUANTI / bench.erl
Created February 16, 2011 12:41
disk_log vs file
-module(bench).
-compile(export_all).
%% Luke Gorrie's favourite profiling macro.
-define(TIME(Tag, Expr),
(fun() ->
%% NOTE: timer:tc/4 does an annoying 'catch' so we
%% need to wrap the result in 'ok' to be able to
%% detect an unhandled exception.
{__TIME, __RESULT} =