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 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 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 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 Stack 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 StackImpTest do | |
use ExUnit.Case | |
test "pops first item" do | |
assert {1, [2, 3]} = StackImp.pop([1,2,3]) | |
end | |
test "pops empty list" do | |
assert {nil, []} = StackImp.pop([]) | |
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
{"lastUpload":"2019-04-01T10:01:42.760Z","extensionVersion":"v3.2.7"} |
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
21:49:09 ➜ ~ echo 'Hello world' | |
Hello world |
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
user = User.first | |
require 'Benchmark' | |
Benchmark.bm do |x| | |
x.report { 1000.times do UserSerializer.serialize(user) end} | |
x.report { 1000.times do FJUserSerializer.new(user).serializable_hash 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
;WITH hours as ( | |
SELECT 0 hour_id, '00:00 - 01:00' hour_literal UNION | |
SELECT 1 hour_id, '01:00 - 02:00' hour_literal UNION | |
SELECT 2 hour_id, '02:00 - 03:00' hour_literal UNION | |
SELECT 3 hour_id, '03:00 - 04:00' hour_literal UNION | |
SELECT 4 hour_id, '04:00 - 05:00' hour_literal UNION | |
SELECT 5 hour_id, '05:00 - 06:00' hour_literal UNION | |
SELECT 6 hour_id, '06:00 - 07:00' hour_literal UNION | |
SELECT 7 hour_id, '07:00 - 08:00' hour_literal UNION | |
SELECT 8 hour_id, '08:00 - 09:00' hour_literal UNION |