Skip to content

Instantly share code, notes, and snippets.

View angrycub's full-sized avatar

Charlie Voiselle angrycub

View GitHub Profile
@angrycub
angrycub / force_remove_s3_bucket.erl
Last active October 17, 2017 10:22
Snippet to forcibly remove a CS Bucket from a Riak CS User
Force_remove_s3_bucket = fun(UserID, Bucket) ->
Update_user_buckets = fun(User, Bucket) ->
Buckets = User#rcs_user_v2.buckets,
%% At this point any siblings from the read of the
%% user record have been resolved so the user bucket
%% list should have 0 or 1 buckets that share a name
%% with `Bucket'.
case [B || B <- Buckets, B#moss_bucket_v1.name =:= Bucket#moss_bucket_v1.name] of
[] ->
{ok, User#rcs_user_v2{buckets=[Bucket | Buckets]}};
@angrycub
angrycub / Garbage.erl
Last active October 17, 2017 10:22
Helper Shell Funs for Riak CS Cleanup
%% Shell functions that can be run in `riak-cs attach`
%% Peek({S3Bucket, Key}) will fetch an object and display the sibling count and
%% the number of manifests in the object.
Peek = fun({Bucket, Key}) ->
io:format("Peeking at ~p/~p.~n", [Bucket, Key]),
{ok, RcPid} = riak_cs_riak_client:checkout(),
ManifestBucket = riak_cs_utils:to_bucket_name(objects, Bucket),
ok = riak_cs_riak_client:set_bucket_name(RcPid, Bucket),
@angrycub
angrycub / preflist.erl
Created June 18, 2015 00:27
Get a Preflist for a bucket key
Preflist = fun(Bucket,Key) ->
BKey = {Bucket,Key},
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
DocIdx = riak_core_util:chash_key(BKey),
BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
[NValue] = [Y || {X1, Y} <- BucketProps, n_val == X1],
UpNodes = riak_core_node_watcher:nodes(riak_kv),
Preflist2 = riak_core_apl:get_apl_ann(DocIdx, NValue, Ring, UpNodes),
[IndexNode || {IndexNode, _Type} <- Preflist2]
end.
@angrycub
angrycub / listcask.erl
Last active August 29, 2015 14:22
ListCask redux
%% These are shell functions that can be used to output a keylist from a bitcask file in terms of Riak {Bucket,Key} tuples
%% They should be run from `riak attach`. Paste in the contents and run ListAll("filename.txt"). Profit.
ListCask = fun(Vnode,OutFile) ->
Bk_to_tuple =
fun(<<1:7, HasType:1, Sz:16/integer,
TypeOrBucket:Sz/bytes, Rest/binary>>) ->
case HasType of
0 ->
%% no type, first field is bucket
{TypeOrBucket, Rest};
@angrycub
angrycub / MonitoringRiak.md
Last active October 17, 2017 10:22
Additional Information about Monitoring Riak

Additional Information about Monitoring Riak

Riak is a complex system that includes many moving parts to monitor, such as the health of the hardware, the well-being of the software, and the responsiveness of the network. This document will discuss metrics, thresholds, and values that indicate when your monitoring system should be sending alarms.

System metrics to monitor

@angrycub
angrycub / lager_sensitive_formatter.erl
Created March 25, 2015 20:00
Modifying lager_default_formatter to make a filtering formatter
%% Copyright (c) 2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
@angrycub
angrycub / advanced.config
Created March 25, 2015 17:50
Advanced config to add a redacted_console.log (Paths are from a devrel)
[
{lager,
[
{error_logger_hwm,100},
{error_logger_redirect,true},
{crash_log_date,"$D0"},
{crash_log_size,10485760},
{crash_log_msg_size,65536},
{handlers,
[
@angrycub
angrycub / GetInfoByModule.erl
Last active September 21, 2024 19:19
Get Info and Status by Module
GetInfoAndStatusByModule = fun (Module) ->
IsProcessInModule = fun (Module, ProcessInfo) ->
case proc_lib:translate_initial_call(ProcessInfo) of
{ICMod, _ICFun, _ICArity} when Module =:= ICMod -> true;
_ -> false
end
end,
ProcessTable = erlang:processes(),
CurriedPredicate = fun (P) -> IsProcessInModule(Module, P) end,
Pids = lists:filter(CurriedPredicate, ProcessTable),
@angrycub
angrycub / configuration.md
Created January 2, 2015 17:05
Configuring PostFix on OSX 10.10

##Configure Postfix for Gmail SMTP## ###Edit file /etc/postfix/main.cf###

sudo vim /etc/postfix/main.cf

and add in the following to the bottom of the file:

relayhost = [smtp.gmail.com]:587
@angrycub
angrycub / QueryingRiakSearch2.0.md
Last active September 21, 2024 19:19
Querying Riak Search 2.0