Skip to content

Instantly share code, notes, and snippets.

View dch's full-sized avatar
🛋️

Dave Cottlehuber dch

🛋️
View GitHub Profile
@dch
dch / USAGE.md
Created April 18, 2011 23:05 — forked from agaoglu/USAGE.md

CRUD requires jquery.deepjson.js to work so it should be included

<script type="text/javascript" src="js/jquery.deepjson.js"></script>

Then you can assign whatever's in crud.json to a variable or you can put crud.json into your evently directory and let couchapp push it to your application.

Simplest way to use it is

@dch
dch / compact_data.erl
Created June 24, 2011 01:57
useful examples using hovercraft
-module(compact_data).
-author('[email protected]').
-export([test_id_btree/1, test_db/4, test_view/1, test_view/4]).
-include("couch_db.hrl").
-define(ADMIN_USER_CTX, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
test_id_btree(N) ->
@dch
dch / couchdb-ec2-install.sh
Created November 30, 2011 12:30 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@dch
dch / gist:1411446
Created November 30, 2011 22:33 — forked from taxilian/gist:1095427
Building libcurl and openssl on windows statically

Building static libcurl and openssl on Windows

These instructions were tested on Windows 7 Professional w/ Visual Studio 2010

Building openssl

  1. Download the latest openssl from the website; at the time of this writing, it is 1.0.0d
  2. Extract it to your drive; I put it in c:\code\openssl-1.0.0d
  3. install ActiveState perl unless you already have a non-cygwin perl installed on windows
@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 / 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
#