Skip to content

Instantly share code, notes, and snippets.

%%% @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.

@macintux
macintux / joinpdfs.md
Created December 24, 2013 22:57
Consolidating PDFs from the command line in MacOS X

Assuming you've created a text file named "ordered" with the PDFs in the sequence you'd like to create:

$ cp /System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py /usr/local/bin/join-pdfs

$ perl -e '$first = <STDIN>; chomp $first; while(<STDIN>) { $index++; $intmdt = "foo$index.pdf"; chomp; system("join-pdfs -o $intmdt $first $_"); $first = $intmdt; }' < ordered

Now you'll have a host of foo.pdf files; the last one is the one you want to rename to something useful, then rm foo*.pdf.