Skip to content

Instantly share code, notes, and snippets.

@KlausTrainer
KlausTrainer / smerl.erl
Created January 8, 2014 15:09
Smerl: Simple Metaprogramming for Erlang
%% @author Yariv Sadan <yarivsblog@gmail.com> [http://yarivsblog.com]
%% @copyright Yariv Sadan 2006-2007
%%
%% @doc Smerl: Simple Metaprogramming for Erlang
%%
%% Smerl is an Erlang library
%% that simplifies the creation and manipulation of Erlang modules in
%% runtime.
%%
%% You don't need to know Smerl in order to use ErlyWeb; Smerl
ExitPolicy accept *:22 # SSH
ExitPolicy accept *:43 # WHOIS
ExitPolicy accept *:53 # DNS
ExitPolicy accept *:79-81 # finger, HTTP
ExitPolicy accept *:88 # kerberos
ExitPolicy accept *:110 # POP3
ExitPolicy accept *:143 # IMAP
ExitPolicy accept *:194 # IRC
ExitPolicy accept *:220 # IMAP3
ExitPolicy accept *:389 # LDAP
@KlausTrainer
KlausTrainer / tls-cipher-check.sh
Created March 30, 2013 21:15
Get a list of a server's supported SSL/TLS ciphers. http://ubuntuforums.org/showthread.php?t=1909914
#!/bin/bash
if ! [ $1 ];
then
echo syntax: $0 host [-v]
exit
fi
if [ "$2" == "-v" ];
then
@KlausTrainer
KlausTrainer / _etc_init_mysql.conf
Created February 8, 2012 09:11
MySQL in tmpfs
# MySQL Service
description "MySQL Server"
author "Mario Limonciello <superm1@ubuntu.com>"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@KlausTrainer
KlausTrainer / group.erl
Created July 9, 2011 22:12
A native list function for CouchDB that groups view results by its first key element.
fun(Head, {Req}) ->
Fun = fun({Row}, {PrevKey, RowCount}) ->
Key = case couch_util:get_value(<<"key">>, Row) of
K when is_list(K) -> hd(K);
K -> K
end,
Doc = couch_util:get_value(<<"value">>, Row),
DocJson = couch_util:to_binary(couch_util:json_encode(Doc)),
KeyJson = <<"{\"key\":\"",Key/binary,"\"">>,
#!/usr/bin/env ruby
require 'rubygems'
require 'rest_client'
require 'json'
require 'cgi'
def bye
abort("Usage: #{$0} [log_file(s)] [couch_db_url]\nExample: #{$0} log/* http://admin:secret@127.0.0.1:5984/db")
@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
@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 / 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 / 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