Skip to content

Instantly share code, notes, and snippets.

JSON 递归处理

数据

json = """
[
  {
    "k1": "v1",
    "k2": {
@xhh
xhh / AddPostgresTriggerAndFunctionForAllTables.exs
Created July 8, 2021 09:32 — forked from carterbryden/AddPostgresTriggerAndFunctionForAllTables.exs
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;
@xhh
xhh / main.exs
Created April 14, 2022 15:05
groups maps by common keys
list = [
%{id: 1, k: "k1", name: "name a", text: "text a"},
%{id: 1, k: "k1", name: "name b", other: "other b"},
%{id: 1, k: "k2", name: "name k2", other: "other k2"}
]
keys = [:id, :k]
list
|> Enum.group_by(&Map.take(&1, keys))
@xhh
xhh / wx.ex
Created June 8, 2022 14:09 — forked from dominicletz/wx.ex
wx.ex
defmodule Wx do
@vsn "0.0.2"
@author "Onorio Catenacci"
@author "Dominic Letz"
@last_revision_date "22 May 2019"
@moduledoc """
Elixir version of the constants found in the wx.hrl file
"""
import Bitwise
require Record
@xhh
xhh / exwx.exs
Last active June 21, 2022 09:59 — forked from rlipscombe/exwx.exs
Using wxWidgets from Elixir
#!/usr/bin/env elixir
defmodule Canvas do
@behaviour :wx_object
@title "Canvas Example"
@size {600, 600}
def start_link() do
:wx_object.start_link(__MODULE__, [], [])