用途:BOS需要一个简单的文件查看页面,用于查看和下载
在百度云CFC函数计算中创建新的“空白函数”,运行时选择“Python 3.6“,超时时间选择 30s。
触发器选择“HTTP触发器”,URL路径为/{path+},HTTP方法为GET,不开启验证
创建完成后,将bos_fileserver.py的代码贴入代码框,调整其中的
| # 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) |
| 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()) |
| #!/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: |
| 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 |
| import os | |
| import struct | |
| import socket | |
| state_table = ( | |
| "EMPTY SLOT", | |
| "ESTABLISHED", | |
| "SENT", | |
| "RECV", | |
| "WAIT1", |
| 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() |