Skip to content

Instantly share code, notes, and snippets.

@macintux
macintux / baderlang.md
Created May 27, 2014 15:41
Erlang style gotchas

Name your parameters

Erlang atoms are awesome. Use them.

Counter-example:

    Existing = get_bucket_type(BucketType, undefined, false),

What do undefined and false mean on the other end? Who knows?

@macintux
macintux / replace_list_item.erl
Created February 20, 2015 15:31
Handy function for replacing an element in a list
%% Replace the item at `Index' in `List' with `Element'.
%% Zero-based indexing. Deal with it.
-spec replace_list_element(non_neg_integer(), term(), list()).
replace_list_element(Index, Element, List) ->
{Prefix, Suffix} = lists:split(Index, List),
Prefix ++ [Element] ++ tl(Suffix).
@macintux
macintux / errors.erl
Created August 4, 2015 13:02
cuttlefish/lager errors
=ERROR REPORT==== 4-Aug-2015::09:01:01 ===
** gen_event handler lager_stderr_backend crashed.
** Was installed in lager_event
** Last event was: {log,{lager_msg,[],
[{application,cuttlefish},
{module,cuttlefish_conf},
{function,generate_element},
{line,122},
{pid,"<0.719.0>"},
{node,nonode@nohost}],
@macintux
macintux / rpncalc.erl
Created October 20, 2012 20:46
Seeking help with Dialyzer
%%% @author John Daily <jd@epep.us>
%%% @copyright (C) 2012, John Daily
%%% @doc
%%% Assignment from programmingpraxis.com
%%%
%%% @reference See <a href="http://programmingpraxis.com/2009/02/19/rpn-calculator/">RPN Calculator</a>.
%%% @end
-module(rpncalc).
-export([rpn/0]).
@macintux
macintux / chaseurls.erl
Created November 28, 2012 03:19
Generate list of HTTP redirects
%%% @author John Daily <jd@epep.us>
%%% @copyright (C) 2012, John Daily
%%% @doc
%%% The httpc module in inets does not appear to offer any way to
%%% determine the "real" URL if it follows a series of redirects
%%% during its request. This code addresses that gap.
%%%
%%% The code does not interpret any HTML-based redirect, such as a
%%% meta refresh.
@macintux
macintux / beam_decompile.erl
Created November 20, 2015 15:36 — forked from andelf/beam_decompile.erl
Erlang BEAM file decompile to .erl file
#!/usr/bin/env escript
% -*- mode: erlang -*-
main([BeamFile]) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(BeamFile,[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
Riak's MapReduce functionality cannot survive a node failure. If a vnode involved with a query fails while actively processing the request, the entire query will have to be re-run. The failed query should be automatically terminated, but you'll have to re-run the query yourself.
If you create queries using Riak Pipe (the technology layer beneath MapReduce), it is possible to create queries that can survive a vnode failure, but that is not a trivial exercise.
Regarding the empty result set you're seeing: one possibility is that a vnode has failed recently and has come back online without data. MapReduce will not currently trigger a read repair, but that problem should be resolved with the forthcoming Riak 1.3 release.
@macintux
macintux / gist:4712014
Created February 5, 2013 03:50
Does this mean that this is not actually valid UTF-8 data?
124> <<T7/utf8, Excess/binary>> = hd(Blob).
<<77,195,131,194,188,110,99,104,101,110>>
125> Excess.
<<195,131,194,188,110,99,104,101,110>>
126> T7.
77
@macintux
macintux / gist:5418295
Last active December 16, 2015 10:09
Draft of a blog post (or possibly a series of posts) diving into the meat of several key Riak configuration parameters. Internal links do not work, but I haven't worried about that since I'm not sure how closely GFM maps to Basho's blogging platform.