Skip to content

Instantly share code, notes, and snippets.

View jmerriweather's full-sized avatar

Jonathan Merriweather jmerriweather

View GitHub Profile

/etc/network/interfaces:

auto eth0
iface eth0 inet dhcp
    wpa-driver wired
    wpa-conf /etc/wpa_supplicant.conf

/etc/wpa_supplicant.conf:

defmodule Foo do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
# Define workers and child supervisors to be supervised
children = [
running db nodes = ['n2@127.0.0.1','n1@127.0.0.1']
stopped db nodes = []
master node tables = []
remote = []
ram_copies = []
disc_copies = ['Elixir.Database','Elixir.Database.Message',
'Elixir.Database.User',schema]
disc_only_copies = []
[{'n1@127.0.0.1',disc_copies},{'n2@127.0.0.1',disc_copies}] = [schema,
'Elixir.Database',
nodes = [node | Node.list]
[:"n1@127.0.0.1", :"n2@127.0.0.1"]
iex(n1@127.0.0.1)6> Database.create!(disk: nodes)
:ok
# this will wait for all nodes to complete
iex(n1@127.0.0.1)7> :ok = Database.wait(15000)
:ok
iex(n1@127.0.0.1)6> Amnesia.start
:ok
~
iex(n2@127.0.0.1)3> Amnesia.start
:ok
iex(n1@127.0.0.1)4> nodes = [node | Node.list]
[:"n1@127.0.0.1", :"n2@127.0.0.1"]
iex(n1@127.0.0.1)5> Amnesia.Schema.create(nodes)
:ok
iex(n1@127.0.0.1)2> Amnesia.stop
:stopped
~
iex(n2@127.0.0.1)2> Amnesia.stop
:stopped
diff --git a/mix.exs b/mix.exs
index 683ee39..ffe337d 100644
--- a/mix.exs
+++ b/mix.exs
@@ -33,6 +33,7 @@ defmodule BlogpostAmnesia.Mixfile do
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
- {:cowboy, "~> 1.0"}]
+ {:cowboy, "~> 1.0"},
# needed to get defdatabase and other macros
use Amnesia
# defines a database called Database, it's basically a defmodule with
# some additional magic
defdatabase Database do
# this is just a forward declaration of the table, otherwise you'd have
# to fully scope User.read in Message functions
deftable User
iex(n1@127.0.0.1)1> Node.list
[:"n2@127.0.0.1"]
~
iex(n2@127.0.0.1)1> Node.list
[:"n1@127.0.0.1"]