Skip to content

Instantly share code, notes, and snippets.

View binarytemple's full-sized avatar

Bryan Hunt binarytemple

  • The mountains of mourne
View GitHub Profile
@binarytemple
binarytemple / elixir.diagnostics.markdown
Last active June 23, 2025 18:22
Generate a list of all processes in the system which are neither linked nor monitored.

Inspired by Stuff Goes Bad - Erlang in Anger

Is the global process count indicative of a leak? If so, you may need to investigate unlinked processes, or peek inside supervisors’ children lists to see what may be weird-looking.

defmodule Diags do 

  @doc """

Using IEX.pry within a test-case

Overview

I wanted to examine the output from an EEx template, I didn't want to polute the application code, and I wanted to build up some assertions around the template. These things start simple and often get complicated really quickly, so I wanted to get a start made early.

I also wanted to verify early on that I would be able to debug test code.

Erlang/Elixir doesn't have the kind of IDE support that something like Java or Python would provide at this stage.

[1, 2, 3] |> Stream.take_while(fn(x) -> x < 3 end) |> Stream.map(fn(x) -> x * 2 end)
Enum.to_list([1, 2, 3] |> Stream.take_while(fn(x) -> x < 3 end) |> Stream.map(fn(x) -> x * 2 end))
@binarytemple
binarytemple / utility.md
Last active September 21, 2024 19:19
Erlang decompiler I found on the web, works for Elixir beam files too

DON'T BOTHER USING - BROKE CODE

%% Author: PCHAPIER
%% Created: 25 mai 2010
-module(utility).

%%
%% Include files
%%

Print all application properties for an Elixir application (run from within iex -S mix)

Enum.each(Application.loaded_applications, fn({x,_,_}) -> IO.puts "#{x} #{inspect Application.get_all_env(x)}" end)

Some trivial experiments I performed while exploring the integration of Riak and Elixir (thanks Drew Kerrigan)

Error seen while running with a single node.

iex(120)> Riak.find("user", "hero")
** (FunctionClauseError) no function clause matching in Riak.find/4
    (riak) lib/riak.ex:301: Riak.find(:error_no_members, :error_no_members, "user", "hero")
    (riak) lib/riak.ex:301: Riak.find/3
    (riak) lib/riak.ex:282: Riak.find/2
#!/bin/bash
SOURCE=/tmp/int.erl
COMPILED=/tmp/int.beam
test -e $SOURCE || curl https://raw.githubusercontent.com/josevalim/otp/c7e82c6b406b632a191c791a1bd2162bde08f692/lib/debugger/src/int.erl > $SOURCE
erlc -o ${COMPILED%int.beam} $SOURCE
chmod 444 $COMPILED
chgrp admin $COMPILED
@binarytemple
binarytemple / match on elixir structs.md
Created April 19, 2016 20:56
match on elixir structs
iex(149)> %Riak.Object{} = r 
%Riak.Object{bucket: "user", content_type: 'application/json',
 data: "han solo the second", key: "hero",
 metadata: {:dict, 3, 16, 16, 8, 80, 48,
  {[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []},
  {{[], [], [], [], [], [], [], [], [], [],
    [["content-type", 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47,
      106, 115, 111, 110],
     ["X-Riak-VTag", 52, 107, 107, 70, 111, 69, 106, 68, 118, 108, 52, 107, 68,
function dme() { (git)-[master]-
target=${1:?must provide target vm name}
eval $(docker-machine env $target)
}

Today I'm sharing some notes and experiments I've made while investigating the integration of Elixir and Docker. For added fun I'm going to be testing/developing on OSX using docker instances managed by docker-machine. As usual we will also have the wierd glitchy versions of standard tools distributed by OSX to deal with. Lets get started.

The openssl bundled with OSX ( OpenSSL 0.9.8zg 14 July 2015 ) was unable to successfully talk to the modern SSL shipped with docker machine. Not the first time I've bumped up against problems with the stock OSX openssl, but I'm guessing unless it's got an Apple log.. that's unlikely to change any time soon. I then switched to using an openssl distributed via homebrew ( OpenSSL 1.0.2g 1 Mar 2016 ) and it worked perfectly well.

/usr/local/Cellar/openssl/1.0.2g/bin/openssl s_client -prexit \
-connect 192.168.103.138:2376 \
-CAfile /Users/adminuser/.docker/machine/certs/cert.pem \
-key /Users/adminuser/.docker/machine/certs/key.pem \
-CAfile /Users/adminuser/.docke