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
iex(64)> msg=%{"hello" => "there"}                                                                       
%{"hello" => "there"}
iex(65)> Enum.reduce( Map.to_list(msg) , "",  fn ({x,y},acc) -> x <> " " <>  y <> acc end ) 
"hello there"

add = fn x -> case x do {x,y,f} -> f.(x,y) {x,y} -> x + y _ -> raise("bad match") end end

@binarytemple
binarytemple / elixir anonymous function - wrapping case statement - arguments as single tuple.markdown
Last active April 2, 2016 08:38
elixir anonymous function - wrapping case statement - arguments as single tuple
iex(9)> 
add = fn x ->
case x do
{x,y,f} -> f.(x,y)
{x,y} -> x + y 
_ -> raise("bad match")
end
end
@binarytemple
binarytemple / install-ansible-master-using-pip.sh
Created March 18, 2016 11:14
install ansible master using pip
pip install -U git+https://github.com/ansible/ansible.git@devel#egg=ansible
@binarytemple
binarytemple / gist:5872bce8ee242bcaf5ad
Last active March 9, 2016 21:23
sending messages to logstash from docker

https://docs.docker.com/engine/admin/logging/overview/

docker run --log-driver=gelf --log-opt gelf-address=udp://logstash:12201 --log-opt tag="docker" packetops/hello-world 

docker run --log-driver=syslog --log-opt syslog-address=udp://logstash:10514 packetops/hello-world

docker volume ls

docker volume create --name mysql-data 
mysql-data

Create a file inside a volume, the container is terminated. The container is restarted, and the file is still there

Tutorial

Some helpful automation commands to determine machine state

Discovering the current environment

docker-machine env default 

Ensuring that the instance is stopped

@binarytemple
binarytemple / docker_machine.ex
Last active February 23, 2016 17:34
[elixir] extracting env information from docker-machine via command execution/parsing
```
defmodule DockerMachine do
def get_env() do
case System.cmd("docker-machine", ["env","local"]) do
{output,0} -> {
:success, output |>
String.split("\n") |>
Enum.filter(fn x -> x =~ "export DOCKER" end) |>
Enum.map( fn l ->
String.replace(l, ~r/export (.*)/,"\\1") |>
@binarytemple
binarytemple / elixir-notes---setting-the-environment.markdown
Created February 17, 2016 23:27
elixir notes - setting the environment

Q: dumb question - mix start console with test environment - trying to get HTTPoison examples working in the console but exjsx is marked as a :test only dependency.

Obviously I can edit the file, but I’d like to know how to control this with CLI flags or whatever.

A: MIX_ENV=test iex -S mix

@binarytemple
binarytemple / gist:c35098b95deaddd11fe9
Created February 11, 2016 12:03
quick and dirty network rx_bytes sanity check
cat ~/bin/rx_bytes_60_seconds
function rx_bytes() { ifconfig eth0 | sed -ne '/RX bytes/{s_RX bytes:\([0-9]*\).*_\1_;s_ __g;p}'; }
start=$(rx_bytes)
sleep 60
end=$(rx_bytes)
echo "60 second count - rx_bytes = $(( end - start ))"