Skip to content

Instantly share code, notes, and snippets.

Avatar

Tao Yang ninehills

View GitHub Profile
@ninehills
ninehills / urandom-reads.py
Created Aug 11, 2021 — forked from drsnyder/urandom-reads.py
Demonstrate the contention on /dev/urandom with N threads.
View urandom-reads.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)
@ninehills
ninehills / README.md
Last active Dec 25, 2020
使用百度云CFC提供百度云BOS的文件查看服务
View README.md

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

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

操作步骤

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

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

View benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View pprint_color.py
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
Auto download bing wallpapers.
View bing-wallpaper.sh
#!/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/" | \
View gist:f2388ade8c6ca27c3880
- 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.
View blackhole.py
#!/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:
View .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
View tcpinfo.py
import os
import struct
import socket
state_table = (
"EMPTY SLOT",
"ESTABLISHED",
"SENT",
"RECV",
"WAIT1",
@ninehills
ninehills / logstack.py
Last active Aug 29, 2015
Log Python Call Stack
View logstack.py
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()