- plan for code that is easy to delete/replace rather than code that is easy to extend or reuse. As needs change, you're more likely to change the assumptions about what the system should do than in how many ways it should do it. If the code needs extending, it's then easy to replace it with a bit that's easy to extend
- planning for code that is easy to throw away is the best way I've found to properly bake in abstraction and isolation. The question is always "if I take this shit out or change its implementation entirely, do I need to replace anything else?". If the answer is "yes", then you may be leaking into other components. Fix it. turns out when you have that, it's also suddenly easier to reuse code.
- write a prototype of whatever significant task you have to do, and consider it a draft. Use it to figure out requirements or to make your first mistakes in. Throw it away. Try again. As I gain more experience I find my prototypes smaller and individually more solid, but anything where I lack experience t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16> hackney:get(<<"http://169.254.169.254/latest/meta-data/iam/security-credentials/">>, [], <<>>, [{connect_timeout,5000},{recv_timeout,5000}]). | |
{error,timeout} % <-- this is good | |
17> hackney:get(<<"http://169.254.169.254/latest/meta-data/iam/security-credentials/">>, [], <<>>, [{connect_timeout,5000},{recv_timeout,5000}]). | |
{error,closed} % <--- why is there no retry? | |
18> hackney:get(<<"http://169.254.169.254/latest/meta-data/iam/security-credentials/">>, [], <<>>, [{connect_timeout,5000},{recv_timeout,5000}]). | |
{error,closed} % <--- why is there no retry? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
meck:new(hackney, [passthrough]), | |
... | |
{ok, _, _, Ref1} = hackney:request("facebook.com"), hackney:body(Ref1), | |
{ok, _, _, Ref2} = hackney:request("google.com"), hackney:body(Ref2), | |
... | |
{_, Requests} = | |
lists:foldl(fun({_, {hackney, request, [Url|_]}, {ok, Status, Headers, Ref}}, {RMap, BMap}) -> | |
{RMap#{Ref=>Url}, BMap#{Url => {Status, Headers}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lowercase = package | |
UPPERCASE = source | |
A | |
/ \ | |
c B | |
==> A B c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dedup_test_mods(Mods) -> | |
extract_dedups([{expand_mod(atom_to_list(Mod)), Mod} || Mod <- Mods]). | |
expand_mod(ModStr) -> | |
case lists:suffix("_test", ModStr) of | |
true -> ModStr; | |
false -> ModStr ++ "_test" | |
end. | |
extract_dedups(Mods) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> [spawn(fun() -> io:format("~p~n", [random:uniform()]) end) || _ <- lists:seq(1,10)]. | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 | |
0.4435846174457203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(app_rest_handler). | |
%% general callbacks | |
-export([init/3, rest_init/2, rest_terminate/2, | |
service_available/2, allowed_methods/2, is_authorized/2, | |
forbidden/2, content_types_provided/2, content_types_accepted/2, | |
resource_exists/2]). | |
%% conditional/cache-related | |
-export([generate_etag/2, last_modified/2, expires/2]). | |
%% GET/HEAD callbacks | |
-export([to_json/2, to_html/2]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl | |
index 270946c..76a8f48 100644 | |
--- a/test/rebar_pkg_SUITE.erl | |
+++ b/test/rebar_pkg_SUITE.erl | |
@@ -94,12 +94,9 @@ good_cached(Config) -> | |
Cache = ?config(cache_dir, Config), | |
CachedFile = filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>), | |
?assert(filelib:is_regular(CachedFile)), | |
- FInfo = file:read_file_info(CachedFile), | |
{ok, Content} = file:read_file(CachedFile), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mutt PGP config | |
set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f" | |
set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f" | |
set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f" | |
set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f" | |
set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f" | |
set pgp_encrypt_only_command="pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0x8680CF48 -- -r %r -- %f" ## REPLACE WITH YOUR OWN KEY THINGY | |
set pgp_encrypt_sign_command="pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0x8680CF48 -- -r %r -- %f" ## REPLACE WITH YOUR OWN KEY THINGY | |
set pgp_import_command="gpg --no-verbose --import -v %f" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(demo). | |
% ... | |
check(Board) -> | |
case winner(Board) of | |
{victory, Player} -> % Player wins; | |
undefined -> | |
case is_full(Board) of | |
true -> draw; |