Skip to content

Instantly share code, notes, and snippets.

View dch's full-sized avatar
🛋️

Dave Cottlehuber dch

🛋️
View GitHub Profile
@dch
dch / gist:1473866
Created December 13, 2011 21:01 — forked from kevsmith/gist:1473809
deadcode detecting escript
#!/usr/bin/env escript
%% -*- erlang -*-
%% Find unused exports in a given module
%% Example: deadcode mod_foo deps/foo/ebin deps/bar/ebin
%% Assumes this script is in a file named deadcode
main([Module0|Dirs]) ->
Module = list_to_atom(Module0),
{ok, _Pid} = xref:start(foo),
@dch
dch / couch-node.ini
Created December 29, 2011 17:17 — forked from davisp/couch-node.ini
Configuring CouchDB (trunk) to have a node.js handler.
; Just drop this in /etc/couchdb/local.d/ and then
; start CouchDB normally.
; Here couch_node can be anything as long as it's uniq.
[os_daemons]
couch_node = /Users/davisp/tmp/couch-node.js
@dch
dch / rr_db.erl
Created January 10, 2012 15:07 — forked from evanmiller/rr_db.erl
code from @evanmiller for couchdb with chicago boss (Chicagosaurus Rex)
-module(rr_db, [Server, PhotoRoot]).
-define(MIME_TYPE, "application/json").
-compile(export_all).
init() ->
inets:start(),
inets:start(httpc, [{profile, database}]).
reset() ->
@dch
dch / discussion.md
Created January 16, 2012 00:11 — forked from jhs/discussion.md
Log the conflict winner comparison

Conflict winners are chosen dynamically, every time a request for the document arrives. The revision tree is sort of like a git repository: most updates are based on a parent update. In general, you have a tree of changes, but usually it works out to a linear linked list.

Anyway, the winner is the version with the longest revision history. (That is arbitrary but deterministic, so two couches with the same revision trees will pick the same winner.)

couch_doc:to_doc_info_path does the main job: converting the revision tree into an array of paths from root to leaf. It returns this array sorted, with the longest path first. The diff here will print a log message every time the comparison function is called by lists:sort().

The execution path basically goes:

  1. couch_http_db:db_doc_req()
  2. couch_db:open_doc()
@dch
dch / gist:1685527
Created January 26, 2012 22:30 — forked from fdmanana/gist:1199903
Erlang OTP R14B, Mac OS X Lion 64bits and XCode 4.1

Issue

On Mac OS X Lion (64bits at least), we get random "Bus error 10" (or "Segmentation fault: 11") crashes if init:restart/0 is called and the crypto application is loaded. Why? XCode 4.1 ships an OpenSSL version that deprecates many functions used by OTP's crypto NIF (lib/crypto/c_src/crypto.c).

Example:

$ erl
@dch
dch / couchdb.rb
Created March 18, 2012 22:29
Improved Homebrew recipe for couchdb.rb getting ready for 1.2.0
require 'formula'
class Couchdb < Formula
homepage "http://couchdb.apache.org/"
url 'http://www.apache.org/dyn/closer.cgi?path=couchdb/1.1.1/apache-couchdb-1.1.1.tar.gz'
md5 'cd126219b9cb69a4c521abd6960807a6'
devel do
url 'http://git-wip-us.apache.org/repos/asf/couchdb.git', :using => :git, :tag => '1.2.x'
version '1.2.x'
@dch
dch / couchdb-1.2.0.diff
Created March 21, 2012 13:56
NB the recipes below are now in homebrew apart from OpenSSL 1.0.1 and modified Erlang
diff --git i/Library/Formula/couchdb.rb w/Library/Formula/couchdb.rb
index 3352b28..7c1203d 100644
--- i/Library/Formula/couchdb.rb
+++ w/Library/Formula/couchdb.rb
@@ -1,9 +1,14 @@
require 'formula'
class Couchdb < Formula
- url 'http://www.apache.org/dyn/closer.cgi?path=couchdb/1.1.1/apache-couchdb-1.1.1.tar.gz'
homepage "http://couchdb.apache.org/"
@dch
dch / hack.sh
Created March 22, 2012 10:30 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@dch
dch / by_month.js
Created March 25, 2012 09:17
couchdb map/reduce to compute browserling and testling usage data by month
{
map : function (doc) {
if (doc.type === 'usage' && doc.service && doc.time) {
var d = new Date(doc.time);
var y = d.getFullYear();
var m = d.getMonth() + 1;
var stamp = y + '/' + m;
var rec = {
stamp : stamp,
@dch
dch / erlbork.erl
Created March 27, 2012 20:00
test erlang's NIF call of md5_init to openssl
-module(erlbork).
-export([start/0]).
%% run using
%% erl -run erlbork
%% with or without +K true +A4
%% code from @davisp with thanks
start() ->
spawn(fun() -> restarts() end),
loop().