Skip to content

Instantly share code, notes, and snippets.

rd(tst,{name,desc}). 
application:stop(mnesia). 
mnesia:create_schema([node()]). 
application:start(mnesia). 
mnesia:create_table(tsts,
 [{record_name, tst},
 {attributes, record_info(fields, tst)},
 {disc_copies, [node()]},
 {type, set}]).
#!/bin/bash
export TKN=$(curl -X POST 'http://localhost:8080/auth/realms/master/protocol/openid-connect/token' \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin" \
-d 'password=admin' \
-d 'grant_type=password' \
-d 'client_id=admin-cli' | jq -r '.access_token')
curl -X GET 'http://localhost:8080/auth/admin/realms' \
@koolquark
koolquark / postgresql.md
Last active November 21, 2018 19:10
Postgresql Create Database and User
CREATE DATABASE hello_dev;
CREATE USER devel WITH ENCRYPTED PASSWORD 'devel';
GRANT ALL PRIVILEGES ON DATABASE hello_dev TO devel;
ALTER USER devel CREATEDB;
# Also pg_hba.conf 
local all devel md5


@koolquark
koolquark / mongodb_erlang_skip_batch_size.txt
Created December 2, 2018 10:05
mongodb erlang skip and batchsize
2> application:ensure_all_started(mongodb).
{ok,[bson,poolboy,pbkdf2,mongodb]}
3>
3> Database = <<"test">>.
<<"test">>
4> {ok, Connection} = mc_worker_api:connect ([{database, Database},{w_mode, safe}]).
{ok,<0.181.0>}
5>
5> % Drop all the docs
5> Collection = <<"test">>.
@koolquark
koolquark / map_match.ex
Created June 21, 2019 11:06
Elixir - Map matching at function head
defmodule MapTest do
def hmap(%{ :a => "a"} = changeset) do
IO.inspect changeset
end
end
MapTest.hmap(%{ :a => "a", :b => "B" }) # matches
MapTest.hmap(%{ :a => "A", :b => "B" }) # clause error
@koolquark
koolquark / stack_trace.ex
Created June 21, 2019 15:42
Get Current Stack Trace in Elixir
Process.info(self(), :current_stacktrace)
@koolquark
koolquark / match_params.ex
Created June 21, 2019 15:51
Matching two parameter values at function head
defmodule FnEx do
def m( %{ :a => a } , a ) do
IO.puts "Hello"
end
end
@koolquark
koolquark / try_catch_throw.ex
Created June 21, 2019 16:04
Elixir - try catch throw example
defmodule Excep do
def ex() do
try do
throw("a")
catch
c ->
IO.inspect c # "a"
end
end
@koolquark
koolquark / anon_call.ex
Last active June 21, 2019 16:25
Elixir - Calling anonymous function at definition itself
(fn true -> IO.puts("yes its true") end).(true)
# Example
"hello" |> ( fn msg -> IO.puts(msg) end ).()
@koolquark
koolquark / if_compact.ex
Created June 21, 2019 16:27
Elixir - One-liner if
if v, do: "v", else: "no_v"