Skip to content

Instantly share code, notes, and snippets.

View zhongwencool's full-sized avatar
🌊

zhongwencool zhongwencool

🌊
  • China Guǎng Zhōu
  • 12:50 (UTC +08:00)
View GitHub Profile
Difference Maxwell Tesla
Adapter support send_file send_stream send_multipart httpc ibrowse adapter don't support send file stream multipart
Method build get/* and get!/* only build get/*
Middleware be able to check argument and set default options in compile time don't support check argument in compile time
Connection store req_headers, req_body, resp_body, resp_headers replaces env’s headers and body by response, lead to lose req_headers and req_body context

PS: About Dynamic API clients.

Maxwell: only manipulating connection details by the Maxwell.Conn help functions.

iex(1)> GitHubClient.user_repos(“zhongwencool”)
[%{“statuses_url” => “https://api.github.com/repos/zhongwencool/maxwell/statuses/{sha}"…}…].
defmodule GitHubClient do
#generate get/1, get!/1 function
use Maxwell.Builder, ~w(get)a
middleware Maxwell.Middleware.BaseUrl, "https://api.github.com"
middleware Maxwell.Middleware.Opts, [connect_timeout: 3000]
middleware Maxwell.Middleware.Json
adapter Maxwell.Adapter.Hackney # default adapter is Maxwell.Adapter.Ibrowse
# response = '*************************'
response = Maxwell.Conn.new("http://httpbin.org/drip")
|> Maxwell.Conn.put_query_string(%{numbytes: 25, duration: 1, delay: 1, code: 200})
|> Maxwell.get!
|> Maxwell.Conn.get_resp_body
-module(gen_server_call_timeout).
%% API
-behaviour(gen_server).
%% API
-export([start/0]).
-export([run/2]).
-export([multi_run/0]).
-export([i/0]).
-module(mnesia_transform_benchmark).
%% API
-export([start/0]).
-export([benchmark/0]).
%%HOW TO TEST TRANSFORM
%%
%% 1. Compile
%% erlc mnesia_transform_benchmark.erl
%%
@zhongwencool
zhongwencool / mnesia_read_test.erl
Created October 13, 2016 08:33
[test] mnesia find object without transaction.
-module(mnesia_read_test).
-include_lib("stdlib/include/ms_transform.hrl").
-include_lib("stdlib/include/qlc.hrl").
%% API
-compile(export_all).
-record(person, {name, sex, age, height}).
-define(PERSON, person).
@zhongwencool
zhongwencool / zoo.app
Last active September 11, 2016 10:39
supervisor child_spec shutdown mechanism doesn't work when child process crash itself.
{application,zoo,
[{description,"Warm and lovely zoo"},
{vsn,"0.1.0"},
{registered,[]},
{mod,{zoo_app,[]}},
{applications,[kernel,stdlib, sasl]},
{env,[]},
{modules,[zoo_app,zoo_keeper,zoo_sup]}]}.
@zhongwencool
zhongwencool / test.erl
Last active July 25, 2016 20:40
Find top n items in a unordered list
-module(test).
-compile(export_all).
%% API
run_all_sorted_sublist(List, Num) ->
lists:sublist(lists:sort(
fun({_,A,_},{_,B,_}) -> A > B end,
List), Num).
run_gb_trees(List, Num) ->
@zhongwencool
zhongwencool / httpoison_request_response_example.ex
Last active January 27, 2021 16:02
maxwell vs httpoison vs httppotion examples
defmodule Httpoison.GitHub do
use HTTPoison.Base
def process_url(url) do
"https://api.github.com" <> url
end
def process_request_headers(headers) do
Dict.put headers, :"User-Agent", "github-httpoison"
end