Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
main() {
TITLE="$(eclipseWindowTitle)"
if [[ -z "$TITLE" ]]; then
error "no title"
exit 1; # no title
fi
WORKSPACE="$(echo "$TITLE" | awk -F ' - ' '{print $(NF)}')"
@muhqu
muhqu / 00_readme.md
Last active August 29, 2015 14:16
CouchDB Replication Conflict Management

I had a misconception about couchdb's conflict management. I was under the impression that couchdb handles document deletes in the same way as document updates. In fact a delete creates just another revison that marks the document as deleted, also known as the tombstone revision.

When a document gets modified after replication, on both databases (source and target), and the document gets replicated again from source to target, it will be in conflict state. This is also true for a document that has been updated on the target and deleted from source. The document's tombstone revision gets replicated, but as couchdb's way of resolving conflicts is to 'delete' the unwanted revision, the just replicated tombstone revison is implicitly considered as the unwanted (or loosing) revision in this conflict. So the conflict is implicitly resolved by picking the revision that has not been deleted. The document in the target db doesn't show any _conflicts field but it shows the replicated tombstone rev in the `_

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "",
"Parameters" : {
"InstanceType" : {
"Description" : "",
"Type" : "String",
"Default" : "t2.micro",
@muhqu
muhqu / maskenvs
Created April 9, 2015 20:52
Mask ENV Vars
#!/bin/bash
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Mathias Leppich <mleppich@muhqu.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# creating 2 documents and deleting one of them
$ curl -X PUT 'http://127.0.0.1:5984/crap/thing-A' -d '{}'
{"ok":true,"id":"thing-A","rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl -X PUT 'http://127.0.0.1:5984/crap/thing-B' -d '{}'
{"ok":true,"id":"thing-B","rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl -X DELETE 'http://127.0.0.1:5984/crap/thing-B?rev=1-967a00dff5e02add41819138abb3284d'
{"ok":true,"id":"thing-B","rev":"2-eec205a9d413992850a6e32678485900"}
# checking for existence
$ curl -X GET 'http://127.0.0.1:5984/crap/thing-A'
{ topic: function () {
fs.stat('~/FILE', this.callback);
},
'after a successful `fs.stat`': {
topic: function (stat) {
fs.open('~/FILE', "r", stat.mode, this.callback);
},
'after a successful `fs.open`': {
topic: function (fd, stat) {
fs.read(fd, stat.size, 0, "utf8", this.callback);
#!/bin/bash
tee -a ~/couchjs-view.in \
| /usr/local/couchdb/bin/couchjs \
/usr/local/couchdb/share/couchdb/server/main.js \
| tee -a ~/couchjs-view.out
<?php
// WTF!
file_get_contents("http://127.0.0.1:31337/v1/posts/adjacent/65f1685dd814524417705a9bcd03e9e7?limit=5", false,
stream_context_create(array('http'=>array(
'method' => "GET",
'header' => array("Host: api.domain.com"),
'timeout' => 2,
))));
function postElem(post) {
var itemEl = $('<div class="item"><div class="image"><a><span class="img"><img></span></a><span class="txt"/></div></div>');
itemEl.attr('id', 'post-'+post.id);
itemEl.find('.image a').attr('href',S3_URL+"/"+post.id+"-m800le.jpg");
itemEl.find('.image img').attr('src',S3_URL+"/"+post.id+"-75se.jpg");
itemEl.find('.image .txt').text(post.caption || '');
return itemEl;
}