Skip to content

Instantly share code, notes, and snippets.

View jaydoane's full-sized avatar

Jay Doane jaydoane

  • IBM - Cloud Data Services
View GitHub Profile
@jaydoane
jaydoane / couchdb2.2_on_centos7.sh
Created October 4, 2018 18:35 — forked from nickva/couchdb2.2_on_centos7.sh
CouchDB 2.2 setup CentOS 7
# Verify
$ gpg --verify apache-couchdb-*.tar.gz.asc
$ sha256sum --check apache-couchdb-*.tar.gz.sha256
$ sha512sum --check apache-couchdb-*.tar.gz.sha512
# Set max files limits
$ sudo emacs /etc/security/limits.conf
(add)
retry_until(fn ->
Couch.get("/#{db_name}/_design/foo/_view/baz").body["total_rows"]
end, equals 2)
def retry_until(generate, condition, sleep \\ 100, timeout \\ 5000) do
retry_until(generate, condition, now(), sleep, timeout)
end
defp retry_until(generate, condition, start, sleep, timeout) do
if (now() > start + timeout) do
@jaydoane
jaydoane / req.erl
Last active October 27, 2017 23:21
Make parallel requests to a URL for some duration, and print out request rate and number of errors encountered
-module(req).
-export([
req_for/2,
parallel_req_for/3]).
-include_lib("ibrowse/include/ibrowse.hrl").
epoch_sec() ->
{MegaSec, Sec, MicroSec} = os:timestamp(),
@jaydoane
jaydoane / index.html
Last active May 20, 2017 23:02
Cloudant IAM Authorization Golden Path Sequence Diagram
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js"></script>
</head>
<body>
<div id="diagram"></div>
@jaydoane
jaydoane / gist:debe132470f04820810a2a67189c4729
Created September 22, 2016 17:52
failing active task isolation tests for Cloudant Local
________________________ TestActiveTasks.test_indexer_isolation ________________________
suites/api/test_active_tasks.py:171: in test_indexer_isolation
self._env['TESTY_DB_USER2_PASS']))
suites/api/test_active_tasks.py:266: in create_indexer_job
assert_that(response.status_code, is_(helpers.accepted()))
E AssertionError:
E Expected: one of (<200>, <201>, <202>, <{'result': 'created'}>)
E but: was <403>
______________________ TestActiveTasks.test_replication_isolation ______________________
suites/api/test_active_tasks.py:152: in test_replication_isolation
@jaydoane
jaydoane / discussion.md
Created June 29, 2016 06:13 — forked from jadeallenx/discussion.md
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.

@jaydoane
jaydoane / netcopy.erl
Last active June 8, 2016 23:58
Demonstrate behavioral differences between gen_tcp:shutdown/2 and ssl:shutdown/2
-module(netcopy).
-export([listen/4, sendfile/5]).
-export([generate_cert/0, generate_cert/2, test/1]).
-define(BASE_TCP_OPTS, [
binary, {reuseaddr, true}, {active, false}, {exit_on_close, false}]).
-define(DEFAULT_RECBUF_SIZE, 16*1024*1024).
-define(DEFAULT_FILE_READ_BUF_SIZE, 16*1024*1024).
@jaydoane
jaydoane / gist:e68d12f577267a6a3bc55de7e22d25b0
Created June 7, 2016 20:16
compaction daemon test errors
module 'couchdb_compaction_daemon_tests'
Compaction daemon tests
couchdb_compaction_daemon_tests:65: should_compact_by_default_rule...*failed*
in function couchdb_compaction_daemon_tests:wait_compaction_started/1 (test/couchdb_compaction_daemon_tests.erl, line 216)
in call from couchdb_compaction_daemon_tests:'-should_compact_by_default_rule/1-fun-7-'/1 (test/couchdb_compaction_daemon_tests.erl, line 78)
**error:{assertion_failed,[{module,couchdb_compaction_daemon_tests},
{line,218},
{reason,"Compaction starting timeout"}]}
output:<<"">>
-module(tcp_server).
-behaviour(gen_server).
%% API
-export([start_link/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
Use a ramdisk on OS X to speed up local dev cluster
Download ramdisk.sh:
https://gist.github.com/nickva/74f12b6163e578c3afb0649370f59dc5
$ chmod a+x ./ramdisk.sh
$ ./ramdisk.sh create 4000 # create a 4GB disk mounted to /Volumes/ramdisk
Create ramdisk...