Skip to content

Instantly share code, notes, and snippets.

View ninehills's full-sized avatar

Tao Yang ninehills

View GitHub Profile
@ninehills
ninehills / urandom-reads.py
Created August 11, 2021 10:44 — forked from drsnyder/urandom-reads.py
Demonstrate the contention on /dev/urandom with N threads.
# Create a user land file for testing.
# dd if=/dev/urandom of=/tmp/urandom bs=1M count=10
#
# urandom-reads.py infile threads
# Examples:
# time python2.6 urandom-reads.py /tmp/urandom
# time python2.6 urandom-reads.py /dev/urandom
#
# R to generate a plot of the read time distribution at each level of concurrency
# rdt = read.csv("output.csv", header=F)
@ninehills
ninehills / README.md
Last active December 25, 2020 04:49
使用百度云CFC提供百度云BOS的文件查看服务

使用百度云CFC提供百度云BOS的文件查看服务

用途:BOS需要一个简单的文件查看页面,用于查看和下载

操作步骤

在百度云CFC函数计算中创建新的“空白函数”,运行时选择“Python 3.6“,超时时间选择 30s。 触发器选择“HTTP触发器”,URL路径为/{path+},HTTP方法为GET,不开启验证

创建完成后,将bos_fileserver.py的代码贴入代码框,调整其中的

@ninehills
ninehills / benchmarks.ipynb
Created September 19, 2016 07:28 — forked from dongweiming/benchmarks.ipynb
benchmarks.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter
from pprint import pformat
def pprint_color(obj):
print highlight(pformat(obj), PythonLexer(), Terminal256Formatter())
@ninehills
ninehills / bing-wallpaper.sh
Created May 25, 2015 09:06
Auto download bing wallpapers.
#!/usr/bin/env bash
PICTURE_DIR="$HOME/Pictures/bing-wallpapers/"
mkdir -p $PICTURE_DIR
BING_URL="http://global.bing.com/?FORM=HPCNEN&setmkt=en-us&setlang=en-us#"
urls=( $(curl -s $BING_URL | \
grep -Eo "url:'.*?'" | \
sed -e "s/url:'\([^']*\)'.*/http:\/\/bing.com\1/" | \
- 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()