Kernel's function with arity | BeautyKernel's alias |
---|---|
!=/2 | not_eq? |
*/2 | multiply |
++/2 | list_concat |
+/1 | plus |
+/2 | plus |
--/2 | list_remove |
-/1 | minus |
-/2 | minus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule StackImp do | |
def pop(list) do | |
# Возвращает кортеж с вынутым значением, и остатком списка. | |
# подходит в качестве ответа для генсервера | |
List.pop_at(list, 0) | |
end | |
def push(list, item) do | |
new_list = [item | list] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule StackGenserverTest do | |
use ExUnit.Case | |
test "pops first item" do | |
{:ok, pid} = StackGenserver.start_link([1, 2, 3]) | |
assert 1 == StackGenserver.pop(pid) | |
end | |
test "pops empty list" do | |
{:ok, pid} = StackGenserver.start_link([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule StackGenserver do | |
use GenServer | |
# Client | |
def start_link(default) when is_list(default) do | |
GenServer.start_link(__MODULE__, default) | |
end | |
def push(pid, item) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Foo do | |
def bar do | |
Application.get_env(:foo, :bar) | |
end | |
end | |
Application.put_env(:foo, :bar, 3) | |
Foo.bar() # => 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Dynamic do | |
@methods ~w(method1 method2 method3)a | |
@methods | |
|> Enum.each( fn method -> | |
method_name = "prefix_#{method}" | |
def unquote(:"#{method_name}")(argument1, argument2) do | |
{unquote(method), argument1, argument2} | |
end | |
end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For MacOS and "Postgres" App Users | |
# where var-10 is version of postgreSQL | |
cd /Users/$USER/Library/Application\ Support/Postgres/var-10/ | |
rm postmaster.pid | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
..... | |
config :logger, :console, | |
level: :debug, | |
format: {LoggerFormatter, :format_log}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.eachSlice = function(size=1) { | |
return Array(Math.ceil(this.length / size)) | |
.fill() | |
.map(( _, idx) => { | |
return this.slice(idx * size, (1 + idx) * size) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Making btree_gin index and using it in search | |
*/ | |
CREATE EXTENSION btree_gin; | |
create index ix_table_1 on table_1 USING GIN (to_tsvector('simple', coalesce(table_1.seach_field.value::text, '')), table_1.id) | |
select * from table_1 | |
where to_tsvector('simple', coalesce(table_1.seach_field.value::text, '')) @@ to_tsquery( 'example:*' ); | |
-- index used |