Skip to content

Instantly share code, notes, and snippets.

@lepoetemaudit
lepoetemaudit / deepmerge.ex
Last active February 16, 2017 03:36
Deep (recursively) merge maps in elixir
defmodule DeepMerge do
defp _merge(key, v1, v2) when is_map(v1) do
Map.merge(v1, v2, &_merge/3)
end
defp _merge(key, v1, v2), do: v2
def merge(map1, map2) when is_map(map1) and is_map(map2) do
Map.merge map1, map2, &_merge/3
end
@dmshvetsov
dmshvetsov / seed.rb
Last active June 1, 2019 15:29
How to seed your database with JSON/YAML. Source http://snippets.aktagon.com
json = ActiveSupport::JSON.decode(File.read('db/seeds/countries.json'))
json.each do |a|
Country.create!(a['country'], without_protection: true)
end