Skip to content

Instantly share code, notes, and snippets.

@KlausTrainer
KlausTrainer / check-password.c
Created November 5, 2014 11:38
Checking System Account Passwords on GNU/Linux
#include <stdlib.h>
#include <string.h>
#include <crypt.h>
#include <shadow.h>
int check_password(const char *plain_password, const char *crypt_password)
{
return strcmp(crypt(plain_password, crypt_password), crypt_password) == 0;
@KlausTrainer
KlausTrainer / batter-status-watcher.sh
Last active August 29, 2015 14:10
Monitors the remaining battery capacity on a GNU/Linux system, and sends a desktop notification if the remaining capacity falls below a certain threshold.
#!/bin/sh
# Monitors the remaining battery capacity on a GNU/Linux system, and
# sends a desktop notification if the remaining capacity falls below a
# certain threshold.
WARNING_THRESHOLD=7 # percent
ICON="/usr/share/icons/gnome/scalable/status/battery-low-symbolic.svg"
@KlausTrainer
KlausTrainer / comment.vim
Created November 21, 2014 17:58
functions to comment/uncomment lines
" File: Comment.vim
"
" Purpose: functions to comment/uncomment lines
"
" Author: Ralf Arens <ralf.arens@gmx.de>
"
" Last Modified: 2001-06-06 22:20:23 CEST
" All functions support comment styles, these are:
diff --git a/couchjs/c_src/SConscript b/couchjs/c_src/SConscript
index 757e028..0693f60 100644
--- a/couchjs/c_src/SConscript
+++ b/couchjs/c_src/SConscript
@@ -17,7 +17,10 @@ def require_lib(name):
print 'Could not find required library', name
Exit(1)
-env = Environment(CCFLAGS='-g -O2 -DXP_UNIX')
+env = Environment(CCFLAGS='-g -O2 -DXP_UNIX',
diff --git a/test/couch_doc_json_tests.erl b/test/couch_doc_json_tests.erl
index 56587cd..037886f 100644
--- a/test/couch_doc_json_tests.erl
+++ b/test/couch_doc_json_tests.erl
@@ -17,9 +17,10 @@
json_doc_test_() ->
+ TestCtx = test_util:start_couch(),
{
@KlausTrainer
KlausTrainer / BigCouch_read_request_handling.md
Created September 7, 2010 20:30
Handling Read Requests in BigCouch

Handling Read Requests in BigCouch

  • R=1, D=1, S=1: V

  • R=2, D=1, S=1:

    • V
    • 503 Service Unavailable
  • R=2, D=1, S=2:

@KlausTrainer
KlausTrainer / Consistency_in_BigCouch.md
Created September 30, 2010 20:58
Consistency in BigCouch

Consistency in BigCouch

In a BigCouch cluster, there are N replicas, who can either be in the state alive or dead. The case of all replicas being alive is defined as the absence of network partitions, i.e., no message is lost. Network partitions are modeled as total failure of one or more replica. For instance, take a set of network partitions P. For each network partition Pi, all replicas that are located in a different network partition than Pi, are defined as dead.

When there's a read or write request, the request first hits one of the replicas, which is referred to as the leader. The leader starts a voting round, i.e., it forwards the request to all replicas. When the leader receives a response from a replica, it's said that the replica has voted. A response may either contain a document version, or some error code indicating e.g. that the document was not found, or the revision number of a newly created document version.

If at least

@KlausTrainer
KlausTrainer / couchapp-autopush.sh
Created October 23, 2010 12:31
couchapp-autopush
#! /bin/sh -e
inotifywait -m -r --exclude "\.swp$" -e modify . | xargs -n 1 -I {} echo "couchapp push" | bash
@KlausTrainer
KlausTrainer / delete_documents_from_view_result.rb
Created December 27, 2010 19:11
Delete all documents whose id appears in a given view result.
#!/usr/bin/env ruby
require 'rubygems'
require 'rest_client'
require 'json'
require 'cgi'
def bye
abort("Usage: #{$0} [view_url]\nExample: #{$0} http://admin:secret@127.0.0.1:5984/db/_design/ddoc/_view/recent-posts")
@KlausTrainer
KlausTrainer / recover_git_commits.sh
Created March 22, 2011 11:50
recover lost git commits
for i in `git fsck --full | grep "dangling commit" | head | grep -o -E "[0-9a-f]+$"`; do git show $i | vim -; done