-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_bins.exs
executable file
·90 lines (77 loc) · 2.81 KB
/
create_bins.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
defmodule TestStruct do
defstruct [:a, b: 1234]
end
defmodule TermGenerator do
@base_path "bins"
def generate() do
save(2, "small_int")
save(-2, "small_negative_int")
save(1234578, "int")
save(-1234578, "negative_int")
save(nil, "nil")
save(false, "false")
save(true, "true")
save([], "empty_list")
save("just some text", "small_string")
save(<<143, 45, 211, 57, 243, 220, 73, 235, 239, 201, 232, 189, 101>>, "non_utf8_string")
save(<<1,2,3,4>>, "binary")
save(<<95, 23::5>>, "bitbinary")
# save_large_string("large_string")
save(12.515, "float")
save(:oddţ, "odd_atom")
save(TermGenerator, "module_name")
save(%TestStruct{}, "struct")
save([1,2,3,4], "number_list")
save([1, "some", 2, "text"], "mixed_list")
save([1, 6 | 2], "improper_list")
save(%{just: "some key", other: "value"}, "atom_map")
save(%{
"float" => 3.14,
["list as a key"] => ["another", %{test: false}],
1 => "one",
:tuple => {1, :more},
"large" => 123456789123456789,
"nested" => %{ "ok" => [] }
}, "map")
save([just: "some key", other: "value", just: 1234], "keyword")
save({"test", "testing"}, "tuple")
save(123456789123456789123456789, "small_big_int")
save(Exp.exp(999,999), "large_big_int")
save({:row_data, "kkk", List.to_tuple(Enum.to_list(1..400)), 10}, "large_tuple")
# save(&testing/2, "function")
# save(self(), "pid")
# path = System.find_executable("echo")
# port = Port.open({:spawn_executable, path}, [:binary, args: ["hello world"]])
# save(port, "port")
# Port.close(port)
# save(make_ref(), "ref")
save_gzip(Enum.to_list(0..1000), "number_list_gzip")
end
def save(object, name) do
save_to_disk(object, "#{@base_path}/#{name}.bin")
end
def save_to_disk(object, path) do
File.write!(path, :erlang.term_to_binary(object))
end
def save_gzip(object, name) do
save_to_disk_gzip(object, "#{@base_path}/#{name}.bin")
end
def save_to_disk_gzip(object, path) do
File.write!(path, :erlang.term_to_binary(object, compressed: 6) |> IO.inspect)
end
def save_large_string(path) do
# generate some text
large_text = """
"""
save(large_text, path)
end
# defp testing(_, _), do: nil
end
defmodule Exp do
def exp(x,y) when is_integer(x) and is_integer(y) and y >= 0 do
exp_int(x,y)
end
defp exp_int(_,0), do: 1
defp exp_int(x,y), do: Enum.reduce(1..y, 1, fn _,acc -> x * acc end)
end
TermGenerator.generate()