Skip to content

Instantly share code, notes, and snippets.

View binarytemple's full-sized avatar

Bryan Hunt binarytemple

  • The mountains of mourne
View GitHub Profile

Riak local client

Riak local client is what you want to read from or write to Riak while running riak attach, and Erlang MapReduce job, or a post_commit hook.

Examples of using Riak local client

11: {ok,Client} = riak:local_client()

-> {ok,{riak_client,['[email protected]',undefined]}}

Riak tricks

Bitcask, fill the key storage memory up by continously storing lots of objects with big keys and small data.

while true ; 
    do echo run ; 
 curl -XPUT -H "Content-Type: application/text" -d 'foo' "http://127.0.0.1:8098/riak/default/test$(date +"%s")${RANDOM}${RANDOM}$(seq 1 2200 | tr -d '\n') " ;
[~%]brew install scala
==> Downloading http://www.scala-lang.org/files/archive/scala-2.11.1.tgz
######################################################################## 100.0%
==> Downloading https://raw.githubusercontent.com/scala/scala-dist/27bc0c25145a83691e3678c7dda602e765e13413/completion.d/2.9.1/scala
######################################################################## 100.0%
==> Caveats
To use with IntelliJ, set the Scala home to:
  /usr/local/opt/scala/idea

Bash completion has been installed to:

import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.
From 005be2e442074ea529ae0a188399eda553cb8783 Mon Sep 17 00:00:00 2001
From: evan <[email protected]>
Date: Tue, 18 Jun 2013 17:52:54 -0400
Subject: [PATCH] backport sfwi to R15B01
---
erts/emulator/beam/erl_init.c | 16 +++++++
erts/emulator/beam/erl_process.c | 89 ++++++++++++++++++++++++++++++++++++--
erts/emulator/beam/erl_process.h | 9 ++++
erts/etc/common/erlexec.c | 1 +

Curl siblings creation and listing example

curl -X PUT -H "Content-Type: application/json" -d '{"props":{"allow_mult":true}}' http://127.0.0.1:8098/buckets/sibling/props
curl -d 'test1' -H "Content-Type:text/plain" http://127.0.0.1:8098/buckets/sibling/keys/test1
curl -d 'test2' -H "Content-Type:text/plain" http://127.0.0.1:8098/buckets/sibling/keys/test1
curl -d 'test3' -H "Content-Type: text/plain" http://127.0.0.1:8098/buckets/sibling/keys/test1
curl -v http://127.0.0.1:8098/buckets/sibling/keys/test1 |  awk '/Siblings/{next}{print $0}' | while read i; do curl -v "http://127.0.0.1:8098/buckets/sibling/keys/test1?vtag=$i";echo; done | less
@binarytemple
binarytemple / ee.markdown
Last active August 29, 2015 14:03
ssh provisioning
./list_all_instances.py | cut -d, -f 6 | sed 1d |\
while read i; do ssh -n -i /Users/bryanhunt/Downloads/ee_training_day_1.pem "ubuntu@${i}" \
"sudo apt-get install nginx; sudo sed -i '/root[ ]*\//{/#/!{s_.*_root /var/cache/munin/www/;_}}' /etc/nginx/sites-available/default; sudo service nginx restart"; done
END=$(date --date="10 minutes" +"%s"); while [ $(date +"%s") -lt $END ]; do sleep 1; curl -d 'test2' -H "Content-Type: text/plain" http://127.0.0.1:8098/buckets/foo/keys/test$(date +"%s" ) ; done
%% Old version. Boo!!
tenant_id(TokenItems) ->
{struct, AccessItems} = proplists:get_value(<<"access">>, TokenItems, []),
{struct, UserItems} = proplists:get_value(<<"user">>, AccessItems, []),
case proplists:get_value(<<"tenantId">>, UserItems) of
undefined ->
failed;
TenantId ->
{ok, TenantId}
end.
-module(bitcask_merge).
-export([merge_dirs/0]).
bitcask_data_dir() ->
bitcask_data_dir(application:get_env(riak_kv, multi_backend),
application:get_env(bitcask, data_root)).
bitcask_data_dir(undefined, undefined) ->
undefined;
#!/usr/bin/env escript
%% -*- coding: utf-8 -*-
%%! -pa /usr/lib64/riak-cs/lib/riakc-1.3.1.1/ebin /usr/lib64/riak-cs/lib/riak_pb-1.3.0/ebin /usr/lib64/riak-cs/lib/protobuffs-0.8.0/ebin /usr/lib/riak-cs/lib/riakc-1.3.1.1/ebin /usr/lib/riak-cs/lib/riak_pb-1.3.0/ebin /usr/lib/riak-cs/lib/protobuffs-0.8.0/ebin /usr/lib/riak-cs/ebin
-include_lib("riak_cs/include/riak_cs.hrl").
-define(USERS_BUCKET, <<"moss.users">>).
-define(DEFAULT_RIAK_IP, "127.0.0.1").
-define(DEFAULT_RIAK_PORT, 8087).