Skip to content

Instantly share code, notes, and snippets.

View mreigen's full-sized avatar

Minh Reigen mreigen

  • Orange County / Los Angeles
View GitHub Profile
children_changes_params = [
%{"id" => 1, "age" => 30, "address" => "Los Angeles"},
%{"id" => 2, "age" => 28, "address" => "Manila"},
%{"id" => 3, "age" => 37, "address" => "Toulouse"}
]
multi =
Enum.reduce(children_changes_params, Ecto.Multi.new(), fn %{"id" => id} = child_params,
multi ->
with {:ok, child} <- Repo.find(Child, id) do
import Ecto.Query
...
defmacro store_items_not_exist(store_items_table_name, store_id, item_name) do
args = [
"NOT EXISTS (SELECT * FROM #{store_items_table_name} item WHERE item.store_id = ? AND item.name == ?)",
store_id,
item_name
]
import Ecto.Query
...
from(store in Store,
where: fragment("NOT EXISTS (SELECT * FROM APPLIANCES item WHERE item.store_id == ? AND item.name == 'VCR player')", store.id),
where: fragment("NOT EXISTS (SELECT * FROM GAME_CONSOLES item WHERE item.store_id == ? AND item.name == 'Sega Genesis console')", store.id),
where: fragment("NOT EXISTS (SELECT * FROM DELIVERY_TRUCKS truck WHERE truck.store_id == ?)", store.id)
)
import Ecto.Query
...
from(store in Store,
where: fragment("NOT EXISTS (SELECT * FROM APPLIANCES item WHERE item.store_id == ? AND item.name == 'VCR player')", store.id),
where: fragment("NOT EXISTS (SELECT * FROM GAME_CONSOLES item WHERE item.store_id == ? AND item.name == 'Sega Genesis console')", store.id)
)
def pp(what_to_print, debug_message \\ "") do
IO.puts("#{IO.ANSI.yellow()} START #{debug_message} ====================")
IO.puts(IO.ANSI.yellow() <> inspect(what_to_print, pretty: true, limit: :infinity))
IO.puts("#{IO.ANSI.yellow()} END #{debug_message} ====================\n\n")
what_to_print
end
describe "make COLD dishes when seasoning available" do
setup [:setup_cold_dish, :set_seasoning]
test "", context do
assert add_seasoning
end
end
describe "make COLD dishes when extra protein available" do
setup [:setup_cold_dish, :set_protein]
test "", context do
describe "make COLD dishes from left over when seasoning available" do
setup [:setup_cold_dish, :set_seasoning]
test "", context do
assert add_seasoning
end
end
describe "make COLD dishes from left over" do
setup [:setup_cold_dish]
test "", context do
...
end
end
defp setup_cold_dish(%{size: size}) do
end
defp setup_cold_dishes(context) do
temp = 35
size = if context.size, do: size, else: :small
dish = set_temperature(temp)
|> set_size(size)
|> set_time_in_fridge(:15_hours)
|> build_dish
%{temp: temp, size: size, cold_dish: dish}
end