Skip to content

Instantly share code, notes, and snippets.

View lpgauth's full-sized avatar
😄
busy building cool stuff

Louis-Philippe Gauthier lpgauth

😄
busy building cool stuff
View GitHub Profile
@lpgauth
lpgauth / gist:3781989
Created September 25, 2012 13:45
erlc +'{parse_transform, seqbind}' seqbind.erl
seqbind.erl:none: error in parse transform 'seqbind': {undef,
[{seqbind,parse_transform,
[[{attribute,1,file,{"seqbind.erl",1}},
{attribute,1,module,seqbind},
{attribute,2,export,
[{parse_transform,2}]},
{attribute,3,export,[{i,3}]},
{attribute,5,record,
{state,
[{record_field,7,
@lpgauth
lpgauth / gist:3789152
Created September 26, 2012 16:53
basic auth with Cowboy
-module(auth_handler).
-compile({parse_transform, seqbind}).
-export([init/3, handle/2, terminate/2]).
-define(USERNAME, <<"admin">>).
-define(PASSWORD, <<"password">>).
%% public
init(_Transport, Req, []) ->
@lpgauth
lpgauth / gist:4587359
Last active December 11, 2015 10:29
Fix cowboy max_keepalive
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index a0f571b..107582f 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -519,7 +519,8 @@ resume(State, Env, Tail, Module, Function, Args) ->
end.
-spec next_request(cowboy_req:req(), #state{}, any()) -> ok.
-next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout},
+next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout,
➜ fifo USE_GDB=true erl -pa ebin/
GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done
(gdb) run
@lpgauth
lpgauth / gist:5146038
Last active December 14, 2015 20:48
ErlyDTL template VS file:file_read/1 + binary:replace/4
-module(benchmark).
-define(DEFAULT_CONCURENCY, 1).
-define(DEFAULT_SEQUENTIAL, 10000).
-export([
main/0
]).
%% public
@lpgauth
lpgauth / gist:5416086
Created April 18, 2013 20:46
Cassandra CompositeType column encoding (Erlang)
encode_composite_column(Column) ->
encode_composite_column(binary:split(Column, <<":">>), []).
encode_composite_column([], Acc) ->
iolist_to_binary(Acc);
encode_composite_column([H | T], Acc) ->
Size = byte_size(H),
encode_composite_column(T, [Acc ++ [<<0, Size/integer, H/binary, 0>>]]).
lpgauth@h005 ~/benchmark_webservers $ ./benchmark.sh
Cowboy webserver:
Running 10s test @ http://localhost:8080/
8 threads and 20 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 714.01us 0.90ms 7.83ms 80.45%
Req/Sec 4.08k 0.90k 6.00k 56.80%
Latency Distribution
50% 50.00us
75% 1.49ms
-module(macro).
-export([test/0]).
-define(TEST(Value), case Value of true -> true; (X) -> X end).
test() ->
true = ?TEST(true),
<<"test">> = ?TEST(<<"test">>).
-module(record).
-export([test/0]).
-record(request, {
timestamp,
handler,
bid
}).
-record(bid, {
diff --git a/lib/ssh/src/ssh_transport.erl b/lib/ssh/src/ssh_transport.erl
index beaffdc..c2e3c3f 100644
--- a/lib/ssh/src/ssh_transport.erl
+++ b/lib/ssh/src/ssh_transport.erl
@@ -206,6 +206,7 @@ key_exchange_init_msg(Ssh0) ->
kex_init(#ssh{role = Role, opts = Opts, available_host_keys = HostKeyAlgs}) ->
Random = ssh_bits:random(16),
Compression = case proplists:get_value(compression, Opts, none) of
+ zlib_openssh -> ["zlib@openssh.com", "none"];
zlib -> ["zlib", "none"];