Skip to content

Instantly share code, notes, and snippets.

View ninehills's full-sized avatar

Tao Yang ninehills

View GitHub Profile
- What do Etcd, Consul, and Zookeeper do?
- Service Registration:
- Host, port number, and sometimes authentication credentials, protocols, versions
numbers, and/or environment details.
- Service Discovery:
- Ability for client application to query the central registry to learn of service location.
- Consistent and durable general-purpose K/V store across distributed system.
- Some solutions support this better than others.
- Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
- Centralized locking can be based on this K/V store.
#!/usr/bin/env python
# a simple multi-threaded TCP Black Hole server
import sys
from socket import *
import threading
import thread
import time
def handler(clientsock,addr):
try:
@ninehills
ninehills / .vimrc
Created October 9, 2014 02:00
Simple vimrc
set nocompatible
syntax enable
set encoding=utf-8
set showcmd " display incomplete commands
filetype plugin indent on " load file type plugins + indentation
"" Whitespace
set nowrap " don't wrap lines
set tabstop=4 shiftwidth=4 " a tab is 4 spaces
set expandtab " use spaces, not tabs
@ninehills
ninehills / tcpinfo.py
Last active August 29, 2015 14:06 — forked from maliubiao/tcpinfo.py
import os
import struct
import socket
state_table = (
"EMPTY SLOT",
"ESTABLISHED",
"SENT",
"RECV",
"WAIT1",
@ninehills
ninehills / logstack.py
Last active August 29, 2015 13:57
Log Python Call Stack
import inspect
import logging
import re
# from https://github.com/baniuyao/Python-CLog/blob/master/CLog.py
class LogRecordWithStack(logging.LogRecord):
def __init__(self, *args, **kargs):
super(LogRecordWithStack, self).__init__(*args, **kargs)
self.chain = self.get_meta_data()
@ninehills
ninehills / b64.py
Created March 19, 2014 13:52
64进制
# http://snipperize.todayclose.com/snippet/py/64-%E5%92%8C-10%E8%BF%9B%E5%88%B6--93237/
def encode_b64(n):
table = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'
result = []
temp = n
if 0 == temp:
¦ result.append('0')
else:
@ninehills
ninehills / fibonacci.go
Last active December 30, 2015 02:29
fibonacci 闭包 by go
package main
import "fmt"
// fibonacci 函数会返回一个返回 int 的函数。
func fibonacci() func() int {
sum1 := -1
sum2 := 1
return func() int {
sum := sum1 + sum2
@ninehills
ninehills / useradd.sh
Last active December 23, 2015 08:08
from doorgod dump local user
set -eu
getent passwd | grep "^${1}:" | head -1 >> /etc/passwd
cp -r /etc/skel /home/$1
chown -R $1 /home/$1
usermod -d /home/$1 $1
@ninehills
ninehills / fake_smtp.py
Created September 15, 2013 12:06
A fake smtp server, use system sendmail to send the mail. (need Python > 2.4)
#!/usr/bin/env python
"""A fake smtp server, use system sendmail to send the mail. (need Python > 2.4)"""
import smtpd
import asyncore
from subprocess import Popen, PIPE
class FakeSMTPServer(smtpd.SMTPServer):
"""A Fake smtp server"""