Skip to content

Instantly share code, notes, and snippets.

@macintux
macintux / 21st century pledge of allegiance
Created July 4, 2013 14:53
The 4th of July seemed like a good opportunity to update the pledge.
I pledge subservience
To the government
Of the United States of America
And to the police state to which we kneel
One Nation under surveillance
unconstitutional
with paranoia and insecurity for all
@macintux
macintux / gist:6034995
Created July 19, 2013 03:50
Script to split large Riak cluster info outputs
#!/usr/bin/perl -w
use strict;
use warnings;
## Running this script:
## 1 Set $datadir to whatever folder you'd like to store the new files
## 2 Run this script with your cluster info file as input
## $ ./split.pl < cluster-info.out
##
@macintux
macintux / split-info
Last active December 19, 2015 23:29
For use with large cluster-info files generated via riak-admin. Will split them into more manageable file sizes.
#!/usr/bin/perl -w
use strict;
use warnings;
sub usage {
my ($errmsg) = @_;
my $msg = <<END;
Usage: split-info <info file> <output directory>
%%% @author John Daily
%%% @copyright (C) 2013, John Daily
%%% @doc
%%%
%%% @end
%%% Created : 3 Aug 2013 by John Daily
-module(etude51).
-compile(export_all).
@macintux
macintux / 2i.py
Created August 21, 2013 16:06
Perform secondary index (2i) searches on Twitter hashtags stored in Riak and count the matching tags.
#!/usr/local/bin/python
import riak
Riak = riak.RiakClient(pb_port=10017, protocol='pbc')
TweetsBucket = Riak.bucket('tweets')
results = TweetsBucket.get_index("hashtags_bin", "android",
"androie", return_terms=True)
@macintux
macintux / 2i-more.py
Created August 21, 2013 16:07
Perform secondary index (2i) searches on Twitter hashtags stored in Riak and count all hashtags in the matching tweets.
#!/usr/local/bin/python
import riak
Riak = riak.RiakClient(pb_port=10017, protocol='pbc')
TweetsBucket = Riak.bucket('tweets')
results = TweetsBucket.get_index("hashtags_bin", "android",
"androie", return_terms=False)
curl -XPOST http://localhost:8098/mapred
-H"Content-Type: application/json"
-d '{"inputs":"notifications","query":[{"map":{"language":"erlang","source":"fun(O,_,_) when element(1,O) == r_object -> S=byte_size(term_to_binary(riak_object:get_values(O))), if (S>1048576) -> {ok,C}=riak:local_client(),C:delete(riak_object:bucket(O),riak_object:key(O)),[riak_object:key(O)]; true -> [] end;(_,_,_) -> [] end."}}]}'
@macintux
macintux / example-erlang-types.md
Last active December 22, 2015 03:18
Erlang type examples, because I can never remember how they work and I utterly fail at reading docs

Doc: http://www.erlang.org/doc/reference_manual/typespec.html

-type square() :: tuple(pos_integer(), pos_integer()).
-type side() :: 'white'|'black'.
-type movefun() :: fun((square(), square(), side()) -> tuple(square(), list(square()))).
-type movedef() :: tuple(atom(), movefun()).

-record(move, { piece,
 start,
@macintux
macintux / wtf-erlang.md
Last active December 30, 2015 15:59
A rabbit hole of Erlang docs

I started working on some missing documentation in the Erlang stdlib, and found one particularly confusing rabbit hole.

gen_server.xml

In the documentation for gen_server, I found debug options for start_link which lacked type information:

    Dbg = trace | log | statistics | {logfile,FileName} | {install,{Func,FuncState}}</v>
        SOpts = [term()]

FileName isn't defined, Func and FuncState aren't defined, so I decided to dig into the source to document their types.