Skip to content

Instantly share code, notes, and snippets.

View muhqu's full-sized avatar

Mathias Leppich muhqu

View GitHub Profile
@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 `_

#!/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 / README.md
Created November 3, 2014 08:11
Node.js HTTP Server that writes incoming requests as JSON stream to STDOUT

Usage

$ PORT=1234 http2json &
[1] 52577
$ curl -X GET :1234/HelloWorld
{"Time":1414602104,"Method":"GET","URL":"/HelloWorld","Body":null}
ok
$ curl -X PUT :1234/Foo -d Bar
{"Time":1414602240,"Method":"PUT","URL":"/Foo","Body":"Bar"}
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template",
"Parameters" : {
"InstanceType" : {
"Description" : "WebServer EC2 instance type",
"Type" : "String",
"Default" : "m1.small",
@muhqu
muhqu / private.xml
Created September 24, 2014 08:02
Karabiner private.xml for Logitech Devices
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>LOGITECH</vendorname>
<vendorid>0x046d</vendorid>
</devicevendordef>
<item>
<name>For Logitech Devices</name>
<item>
<name>Flip Scroll Wheel Vertical for Logitech Devices</name>
@muhqu
muhqu / demo.md
Created June 18, 2014 09:46
How to quick'n'dirty parse yml comments as descriptions

Input (sample.en.yml)

---
sample:
  plural-key:
    # This is a sample pluralisation key.
    zero: "There are no monkeys"
    one: "There is one monkey"
 two: "There are two monkeys"
#!/bin/bash
#
# The MIT License (MIT)
#
# Copyright (c) 2014 Mathias Leppich <[email protected]>
#
# 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
@muhqu
muhqu / tda-stale-ami-snapshots.sh
Created May 20, 2014 09:03
ShellScript to output EBS Snapshots that are no longer referenced by AMIs
#!/bin/bash
aws ec2 describe-snapshots --owner-ids $AWS_ACCOUNT_ID > snapshots.json
aws ec2 describe-images --owners $AWS_ACCOUNT_ID > images.json
cat snapshots.json \
| jq '.Snapshots[] | select(.Description//""|startswith("Created by CreateImage"))' \
> snapshot-to-ami.json
cat images.json \
#!/bin/bash
EIP="$1" # "50.16.123.123"
ASG="$2" # "www"
if [ -z "$EIP" ] || [ -z "$ASG" ]; then
echo "Usage: $(basename $0) EIP ASG"
echo "Example: $(basename $0) 50.16.123.123 www"
exit 1;
fi