Current section

Files

Jump to
ielixir resources boyle example.ipynb
Raw

resources/boyle example.ipynb

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Boyle usage\n",
"\n",
"## Creating new environment and sample usage"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{:ok, [\"my_new_env\", \"new_env\"]}"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.list()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"All dependencies are up to date\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[33mwarning: \u001b[0mfound quoted keyword \"coveralls\" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes\n",
" mix.exs:22\n",
"\n",
"\u001b[33mwarning: \u001b[0mredefining module IElixir.Mixfile (current version defined in memory)\n",
" mix.exs:1\n",
"\n"
]
},
{
"data": {
"text/plain": [
"{:ok, [\"my_new_env\", \"new_env\"]}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.mk(\"my_new_env\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"All dependencies are up to date\n"
]
},
{
"data": {
"text/plain": [
":ok"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.activate(\"my_new_env\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Resolving Hex dependencies...\n",
"Dependency resolution completed:\n",
"Unchanged:\n",
"\u001b[32m decimal 1.8.0\u001b[0m\n",
"\u001b[32m number 0.5.7\u001b[0m\n",
"All dependencies are up to date\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[33mwarning: \u001b[0mfound quoted keyword \"coveralls\" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes\n",
" mix.exs:22\n",
"\n",
"\u001b[33mwarning: \u001b[0mredefining module IElixir.Mixfile (current version defined in memory)\n",
" mix.exs:1\n",
"\n",
"\u001b[33mwarning: \u001b[0mredefining module Decimal.Mixfile (current version defined in memory)\n",
" /c/Users/piotr/workspace/IElixir/envs/my_new_env/deps/decimal/mix.exs:1\n",
"\n"
]
},
{
"data": {
"text/plain": [
":ok"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.install({:number, \"~> 0.5.7\"})"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{:ok, [\"my_new_env\", \"new_env\"]}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.list()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"my_new_env\""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.active_env_name()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Number library usage"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[33mwarning: \u001b[0mpassing float to Decimal.new/1 is deprecated as floats have inherent inaccuracy. Use Decimal.from_float/1 instead\n",
" (decimal) lib/decimal.ex:1181: Decimal.new/1\n",
" lib/number/currency.ex:110: Number.Currency.get_format/2\n",
" lib/number/currency.ex:101: Number.Currency.number_to_currency/2\n",
" (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6\n",
" (elixir) src/elixir.erl:258: :elixir.eval_forms/4\n",
"\n"
]
},
{
"data": {
"text/plain": [
"\"$2,034.46\""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Number.Currency.number_to_currency(2034.46)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"+1 (111) 222-3333\""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Number.Phone.number_to_phone(1112223333, area_code: true, country_code: 1)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"100%\""
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Number.Percentage.number_to_percentage(100, precision: 0)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"1.23 Thousand\""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Number.Human.number_to_human(1234)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"12,345,678.00\""
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Number.Delimit.number_to_delimited(12345678)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deactivating virtual environment"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
":ok"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.deactivate()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"nil"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.active_env_name()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"ename": "UndefinedFunctionError",
"evalue": "1",
"output_type": "error",
"traceback": [
"** %UndefinedFunctionError{arity: 1, exports: nil, function: :number_to_currency, module: Number.Currency, reason: nil}"
]
}
],
"source": [
"# Number library won't work if you deactivate the environment\n",
"Number.Currency.number_to_currency(2034.46)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Resolving Hex dependencies...\n",
"Dependency resolution completed:\n",
"Unchanged:\n",
"\u001b[32m decimal 1.5.0\u001b[0m\n",
"\u001b[32m number 0.5.7\u001b[0m\n",
"All dependencies up to date\n"
]
},
{
"data": {
"text/plain": [
":ok"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.activate(\"my_new_env\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"$2,034.46\""
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# and if you activate it will work again\n",
"Number.Currency.number_to_currency(2034.46)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{%{decimal: {:hex, :decimal, \"1.5.0\", \"b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68\", [:mix], [], \"hexpm\"}, number: {:hex, :number, \"0.5.7\", \"da1ee0434f3c7b84360d33b335d0ee2f86f247f45fbe2e7636e6f55680b464dd\", [:mix], [{:decimal, \"~> 1.2\", [hex: :decimal, repo: \"hexpm\", optional: false]}], \"hexpm\"}}, []}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.freeze()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{:ok, [\"my_new_env\"]}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.list()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{:ok, []}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Boyle.rm(\"my_new_env\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Elixir",
"language": "Elixir",
"name": "ielixir"
},
"language_info": {
"codemirror_mode": "elixir",
"file_extension": "ex",
"mimetype": "text/x-elixir",
"name": "elixir",
"nbconvert_exporter": "",
"pygments_lexer": "elixir",
"version": "1.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}