From 93f1fd0b58ab0d356023537ecfa83554c9f92594 Mon Sep 17 00:00:00 2001 From: Nirvana Date: Sat, 23 Aug 2014 15:39:42 -0500 Subject: [PATCH] Updated readme, fixed numeric() and alpha() --- README.md | 43 +++++++++++++++++++++---------------------- lib/flaky.ex | 4 ++-- mix.exs | 6 +----- package.exs | 6 ++++++ 4 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 package.exs diff --git a/README.md b/README.md index c7b8cbb..31b1cdf 100644 --- a/README.md +++ b/README.md @@ -8,21 +8,12 @@ It is a re-implementation of boundary's flake designed to be more easily embedde Do note, however, that you should be running only one such service per machine. (or technically, per network port MAC address since the MAC address is part of the key) -``` -**Note:** This configuration presumes you have an ethernet device named 'en0' -you will want to update this in mix.exs with your correct ethernet device name. - -Feel free to add some config file parsing if you wish. Preferably in Elixir, maybe using exconfig? -I would be happy to recieve such a pull request! -``` -## Status - -Believed to be working correctly. Seems damn fast. -The original Flake is used in production and stable, but this re-implementation, while trying to follow their methods exactly may have errors. I would recommend testing this or at least reviewing the code before putting into production! - ## API - ``` + # generate(base) => returns a flake in the given base + Flaky.generate(16) => 1480497347FB8F6B1118F650000 + + # numeric() and alpha() are conveniences for base 10 and 62. Flaky.numeric => 25725046379886392965847027351552 Flaky.alpha => 8hcWWAPPrayb5DuwML ``` @@ -34,15 +25,23 @@ between 2 and 62. ## Example ``` -iex(3)> Flaky.test - Flake, base 10:25169134539683400779552431276032 - Flake, base 62:8VxXJXgBJFc4b9Ygd7 -Time to generate 100000 flakes: 1074 milliseconds. -:ok -iex(4)> :gen_server.call(:flaky, :generate) -"25169137199058260165889939996672" -iex(5)> :gen_server.call(:flaky, {:generate, 62}) -"8VxXXbGSmDATluESbg" +$ iex -S mix +Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] + +Interactive Elixir (0.15.1) - press Ctrl+C to exit (type h() ENTER for help) +iex(1)> Flaky.generate(5) +"424122044124414241030213141324120301211234042" +iex(2)> Flaky.generate(10) +"25988255635718314112604438855680" +iex(3)> Flaky.generate(16) +"1480495539AB8F6B1118F650000" +iex(4)> Flaky.generate(62) +"8n8q3r3d3LjEzMdEoa" +iex(5)> Flaky.alpha +"8n8q4QNhihaEXlIGSu" +iex(6)> Flaky.numeric +"25988256081889713023417363791872" +iex(7)> ``` ## Further Reading diff --git a/lib/flaky.ex b/lib/flaky.ex index 764bba6..98c18cc 100644 --- a/lib/flaky.ex +++ b/lib/flaky.ex @@ -9,11 +9,11 @@ defmodule Flaky do end def numeric do - :gen_server.call(:flaky, {:generate, 10}) + Flaky.Server.generate(10) end def alpha do - :gen_server.call(:flaky, {:generate, 62}) + Flaky.Server.generate(62) end end diff --git a/mix.exs b/mix.exs index abd3d06..6dd8e33 100644 --- a/mix.exs +++ b/mix.exs @@ -3,15 +3,11 @@ defmodule Flaky.Mixfile do def project do [ app: :flaky, - version: "0.0.4", + version: "0.0.5", elixir: "~> 0.15.0", deps: deps ] end - # Note: This configuration presumes you have an ethernet device named 'en0' - # you will want to update this with your correct ethernet device name. - # Feel free to add exconfig as a dependency and make this read the device from a config file. - # Configuration for the OTP application def application do [ diff --git a/package.exs b/package.exs new file mode 100644 index 0000000..9851fda --- /dev/null +++ b/package.exs @@ -0,0 +1,6 @@ +Expm.Package.new(name: "flaky", description: "A decentralized, k-ordered id generation service in Elixir / Erlang (based on Flake)", + version: "0.1", keywords: ["Elixir", "Flake", "key", "distributed", "library"], + homepage: "nirvana.io", + maintainers: [[name: "Nirvana Organization", + email: "hello@nirvana.io"]], + repositories: [[github: "nirvana/flaky"]])